aboutsummaryrefslogtreecommitdiff
path: root/api/game/random.py
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-03-28 12:19:28 +0200
committerlonkaars <l.leblansch@gmail.com>2021-03-28 12:19:28 +0200
commit2f4536d6b08b69168ebf3e718cbd8e3002b9af5a (patch)
tree5307692fb341d7f924ee9b73f3751e7e56cfb192 /api/game/random.py
parent1f897d3f5ad11178cf4776ae4070c9d3e832f5f3 (diff)
added comments
Diffstat (limited to 'api/game/random.py')
-rw-r--r--api/game/random.py3
1 files changed, 3 insertions, 0 deletions
diff --git a/api/game/random.py b/api/game/random.py
index 7e4c512..4d70b56 100644
--- a/api/game/random.py
+++ b/api/game/random.py
@@ -14,13 +14,16 @@ 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()
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]