aboutsummaryrefslogtreecommitdiff
path: root/api/game/random.py
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-04-11 17:50:58 +0200
committerlonkaars <l.leblansch@gmail.com>2021-04-11 17:50:58 +0200
commit28f104de9ae9abe4b42abafbf3865ede5687996c (patch)
tree65e651f09d8fbf81380384692e45803cb4f9d61c /api/game/random.py
parent7b4859059b3bbabf4139ccdf3270a82c094f5d8e (diff)
dprint yapf python formatting
Diffstat (limited to 'api/game/random.py')
-rw-r--r--api/game/random.py36
1 files changed, 22 insertions, 14 deletions
diff --git a/api/game/random.py b/api/game/random.py
index 4d70b56..2dfbe0b 100644
--- a/api/game/random.py
+++ b/api/game/random.py
@@ -11,27 +11,35 @@ from socket_io import io
random_game = Blueprint('random', __name__)
+
@random_game.route('/random')
@auth_required("user")
def index(user_id):
- # get public_games (random opponent queue)
- public_games = cursor.execute("select game_id from games where private = FALSE and status = \"wait_for_opponent\"").fetchall()
+ # get public_games (random opponent queue)
+ public_games = cursor.execute(
+ "select game_id from games where private = FALSE and status = \"wait_for_opponent\""
+ ).fetchall()
+
+ game_started = False
- game_started = False
+ # create a new public game if the queue is empty
+ if len(public_games) == 0:
+ game_id = create_game(user_id)
+ player_1 = True
+ # otherwise join a random public game
+ else:
+ game_id = random.choice(public_games)[0]
- # create a new public game if the queue is empty
- if len(public_games) == 0:
- game_id = create_game(user_id)
- player_1 = True
- # otherwise join a random public game
- else:
- game_id = random.choice(public_games)[0]
+ start_game(game_id, user_id)
- start_game(game_id, user_id)
+ player_1 = False
+ game_started = True
- player_1 = False
- game_started = True
+ return {
+ "id": game_id,
+ "player_1": player_1,
+ "game_started": game_started
+ }, 200
- return { "id": game_id, "player_1": player_1, "game_started": game_started }, 200
dynamic_route = ["/game", random_game]