Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -880,259 +880,8 @@ def play_page():
|
|
| 880 |
st.session_state['last_score'] = score
|
| 881 |
st.session_state['last_game'] = gid
|
| 882 |
st.session_state['current_index'] = 0
|
| 883 |
-
def home_pe():
|
| 884 |
-
st.header("Home")
|
| 885 |
-
st.write("Create games, join games, and view leaderboard.")
|
| 886 |
-
|
| 887 |
-
# Dummy username for demonstration
|
| 888 |
-
if "username" not in st.session_state:
|
| 889 |
-
st.session_state["username"] = st.text_input("Enter your name", value="Guest")
|
| 890 |
-
|
| 891 |
-
username = st.session_state.get("username")
|
| 892 |
-
|
| 893 |
-
# --- Games ---
|
| 894 |
-
games = unified_get("games") or {}
|
| 895 |
-
players_map = unified_get("players") or {}
|
| 896 |
-
|
| 897 |
-
st.subheader("Recent Games")
|
| 898 |
-
for g in sorted(games.values(), key=lambda x: x.get("created_at", ""), reverse=True)[:10]:
|
| 899 |
-
gid = g.get("game_id")
|
| 900 |
-
st.markdown(f"### ๐ฎ Game: **{gid}** {'(Closed)' if g.get('closed') else ''}")
|
| 901 |
-
st.write(f"Host: {g.get('host')} โ Topics: {', '.join(g.get('topics', []))}")
|
| 902 |
-
st.write(f"Created: {g.get('created_at')}")
|
| 903 |
-
|
| 904 |
-
# Players in this game
|
| 905 |
-
players_here = players_map.get(gid, {}) or {}
|
| 906 |
-
st.write(f"Players joined: **{len(players_here)}**")
|
| 907 |
-
submitted_count = sum(1 for p in players_here.values() if p.get("submitted"))
|
| 908 |
-
st.write(f"Submitted: **{submitted_count} / {len(players_here)}**")
|
| 909 |
-
|
| 910 |
-
# Final scores
|
| 911 |
-
if players_here:
|
| 912 |
-
st.markdown("**๐ Final Scores**")
|
| 913 |
-
for uname_p, info in players_here.items():
|
| 914 |
-
if info.get("submitted"):
|
| 915 |
-
st.write(f"{info.get('avatar','๐ฎ')} **{uname_p}** โ "
|
| 916 |
-
f"Score: **{info.get('score',0)}**, "
|
| 917 |
-
f"Percentage: **{info.get('percentage',0)}%**")
|
| 918 |
-
|
| 919 |
-
# Player status
|
| 920 |
-
if players_here:
|
| 921 |
-
st.markdown("**๐ฅ Player Status**")
|
| 922 |
-
for uname_p, info in players_here.items():
|
| 923 |
-
status = "โ
Submitted" if info.get('submitted') else "โณ Playing"
|
| 924 |
-
st.write(f"{info.get('avatar','๐ฎ')} **{uname_p}** โ {status}")
|
| 925 |
-
|
| 926 |
-
# Buttons to join or challenge
|
| 927 |
-
if st.button(f"Join Game {gid}", key=f"join_{gid}"):
|
| 928 |
-
st.session_state["current_game_id"] = gid
|
| 929 |
-
st.session_state["username"] = username
|
| 930 |
-
st.success(f"You joined Game {gid}")
|
| 931 |
-
st.experimental_rerun() # redirect to play_page automatically
|
| 932 |
-
|
| 933 |
-
if st.button(f"Challenge friends with new game like {gid}", key=f"challenge_{gid}"):
|
| 934 |
-
new_id = f"{gid}_new" # Dummy new game id
|
| 935 |
-
# Add game to unified storage
|
| 936 |
-
games[new_id] = {
|
| 937 |
-
"game_id": new_id,
|
| 938 |
-
"host": username,
|
| 939 |
-
"topics": g.get("topics", []),
|
| 940 |
-
"created_at": now_iso(),
|
| 941 |
-
"closed": False
|
| 942 |
-
}
|
| 943 |
-
unified_set("games", games)
|
| 944 |
-
st.success(f"Challenge created: {new_id}")
|
| 945 |
-
st.session_state["current_game_id"] = new_id
|
| 946 |
-
st.experimental_rerun()
|
| 947 |
-
|
| 948 |
-
st.markdown("---")
|
| 949 |
-
|
| 950 |
-
# Weekly leaderboard
|
| 951 |
-
st.subheader("๐ Weekly Leaderboard (Top 10)")
|
| 952 |
-
weekly = get_weekly_leaderboard()
|
| 953 |
-
if not weekly:
|
| 954 |
-
st.info("No scores yet this week.")
|
| 955 |
-
else:
|
| 956 |
-
for i, r in enumerate(weekly, 1):
|
| 957 |
-
st.write(f"{i}. {r.get('avatar','๐ฎ')} **{r['name']}** "
|
| 958 |
-
f"(Game {r['game_id']}) โ {r['score']} pts")
|
| 959 |
-
|
| 960 |
# ---------- PLAY PAGE ----------
|
| 961 |
-
def y_page():
|
| 962 |
-
gid = st.session_state.get("current_game_id")
|
| 963 |
-
uname = st.session_state.get("username")
|
| 964 |
-
|
| 965 |
-
if not gid or not uname:
|
| 966 |
-
st.error("No active game or username found. Please join or create a game first.")
|
| 967 |
-
return
|
| 968 |
-
|
| 969 |
-
games = unified_get("games") or {}
|
| 970 |
-
players_map = unified_get("players") or {}
|
| 971 |
-
|
| 972 |
-
game = games.get(gid)
|
| 973 |
-
if not game:
|
| 974 |
-
st.error("Game not found.")
|
| 975 |
-
return
|
| 976 |
-
|
| 977 |
-
questions = game.get("questions", [{"question":"Sample Q1","options":["A","B","C","D"],"answer":"A"}])
|
| 978 |
-
if 'question_started_at' not in st.session_state or st.session_state['question_started_at'] is None:
|
| 979 |
-
st.session_state['question_started_at'] = time.time()
|
| 980 |
-
idx = st.session_state.get('current_index', 0)
|
| 981 |
-
if idx >= len(questions):
|
| 982 |
-
st.success("All done โ submit!")
|
| 983 |
-
return
|
| 984 |
|
| 985 |
-
q = questions[idx]
|
| 986 |
-
st.subheader(f"Question {idx+1}/{len(questions)}")
|
| 987 |
-
st.write(q["question"])
|
| 988 |
-
choice = st.radio("Choose an answer:", q["options"], key=f"choice_{idx}")
|
| 989 |
-
|
| 990 |
-
col1, col2 = st.columns(2)
|
| 991 |
-
|
| 992 |
-
with col1:
|
| 993 |
-
if st.button("Next", key=f"next_{idx}"):
|
| 994 |
-
answers = st.session_state.get('answers', [""]*len(questions))
|
| 995 |
-
answers[idx] = choice
|
| 996 |
-
st.session_state['answers'] = answers
|
| 997 |
-
st.session_state['current_index'] = idx+1
|
| 998 |
-
st.session_state['question_started_at'] = time.time()
|
| 999 |
-
st.experimental_rerun()
|
| 1000 |
-
|
| 1001 |
-
with col2:
|
| 1002 |
-
if st.button("Submit All", key=f"submit_{idx}"):
|
| 1003 |
-
answers = st.session_state.get('answers', [""]*len(questions))
|
| 1004 |
-
answers[idx] = choice
|
| 1005 |
-
# Update player score in players_map
|
| 1006 |
-
players_here = players_map.get(gid, {}) or {}
|
| 1007 |
-
players_here[uname] = {
|
| 1008 |
-
"submitted": True,
|
| 1009 |
-
"score": sum([10 for a in answers]), # dummy scoring
|
| 1010 |
-
"percentage": int(sum([10 for a in answers])/len(questions)),
|
| 1011 |
-
"avatar": "๐ฎ",
|
| 1012 |
-
"correct_flags": ["โ
"]*len(answers)
|
| 1013 |
-
}
|
| 1014 |
-
players_map[gid] = players_here
|
| 1015 |
-
unified_set("players", players_map)
|
| 1016 |
-
st.success(f"Submitted! Score: {players_here[uname]['score']}")
|
| 1017 |
-
st.session_state['current_index'] = 0
|
| 1018 |
-
st.experimental_rerun()
|
| 1019 |
-
|
| 1020 |
-
def home():
|
| 1021 |
-
st.header("Home")
|
| 1022 |
-
st.write("Create games, invite friends, play and climb the leaderboard.")
|
| 1023 |
-
|
| 1024 |
-
# Show last score if available
|
| 1025 |
-
if st.session_state.get('last_score') is not None:
|
| 1026 |
-
st.success(f"Your last score: {st.session_state.get('last_score')} (Game {st.session_state.get('last_game')})")
|
| 1027 |
-
|
| 1028 |
-
# Active players
|
| 1029 |
-
sessions = unified_get("sessions") or {}
|
| 1030 |
-
active_list = []
|
| 1031 |
-
threshold = timedelta(seconds=HEARTBEAT_THRESHOLD_SECONDS)
|
| 1032 |
-
for gid, users in sessions.items():
|
| 1033 |
-
for uname, rec in (users or {}).items():
|
| 1034 |
-
last = rec.get('last_heartbeat')
|
| 1035 |
-
if last:
|
| 1036 |
-
last_dt = datetime.fromisoformat(last)
|
| 1037 |
-
if datetime.utcnow() - last_dt < threshold:
|
| 1038 |
-
active_list.append((gid, uname, last))
|
| 1039 |
-
|
| 1040 |
-
st.subheader("Active players (recent)")
|
| 1041 |
-
st.markdown(f"**{len(active_list)} players active now**")
|
| 1042 |
-
for gid, uname, ts in active_list[:50]:
|
| 1043 |
-
st.write(f"โข **{uname}** (Game: {gid}) โ last {ts}")
|
| 1044 |
-
|
| 1045 |
-
st.markdown("---")
|
| 1046 |
-
|
| 1047 |
-
# Recent games
|
| 1048 |
-
games = unified_get("games") or {}
|
| 1049 |
-
players_map = unified_get("players") or {}
|
| 1050 |
-
|
| 1051 |
-
st.subheader("Recent games")
|
| 1052 |
-
for g in sorted(games.values(), key=lambda x: x.get("created_at", ""), reverse=True)[:10]:
|
| 1053 |
-
gid = g.get("game_id")
|
| 1054 |
-
|
| 1055 |
-
st.markdown(f"### ๐ฎ Game: **{gid}** {'(Closed)' if g.get('closed') else ''}")
|
| 1056 |
-
st.write(f"Host: {g.get('host')} โ Topics: {', '.join(g.get('topics', []))}")
|
| 1057 |
-
st.write(f"Created: {g.get('created_at')}")
|
| 1058 |
-
|
| 1059 |
-
# Players for this game
|
| 1060 |
-
players_here = players_map.get(gid, {}) or {}
|
| 1061 |
-
st.write(f"Players joined: **{len(players_here)}**")
|
| 1062 |
-
|
| 1063 |
-
# Submitted count
|
| 1064 |
-
submitted_count = sum(1 for p in players_here.values() if p.get("submitted"))
|
| 1065 |
-
st.write(f"Submitted: **{submitted_count} / {len(players_here)}**")
|
| 1066 |
-
|
| 1067 |
-
# Final scores
|
| 1068 |
-
if players_here:
|
| 1069 |
-
st.markdown("**๐ Final Scores**")
|
| 1070 |
-
for uname_p, info in players_here.items():
|
| 1071 |
-
if info.get("submitted"):
|
| 1072 |
-
st.write(
|
| 1073 |
-
f"{info.get('avatar','๐ฎ')} **{uname_p}** โ "
|
| 1074 |
-
f"Score: **{info.get('score', 0)}**, "
|
| 1075 |
-
f"Percentage: **{info.get('percentage', 0)}%**"
|
| 1076 |
-
)
|
| 1077 |
-
|
| 1078 |
-
# Player status
|
| 1079 |
-
if players_here:
|
| 1080 |
-
st.markdown("**๐ฅ Player Status**")
|
| 1081 |
-
for uname_p, info in players_here.items():
|
| 1082 |
-
status = "โ
Submitted" if info.get('submitted') else "โณ Playing"
|
| 1083 |
-
st.write(f"{info.get('avatar','๐ฎ')} **{uname_p}** โ {status}")
|
| 1084 |
-
|
| 1085 |
-
# Submitted players table
|
| 1086 |
-
submitted_players = {u:i for u,i in players_here.items() if i.get('submitted')}
|
| 1087 |
-
if submitted_players:
|
| 1088 |
-
st.markdown("**๐ฏ Submitted Players Results:**")
|
| 1089 |
-
df = pd.DataFrame([
|
| 1090 |
-
{
|
| 1091 |
-
"Avatar": info.get('avatar','๐ฎ'),
|
| 1092 |
-
"Player": uname,
|
| 1093 |
-
"Score": info.get('score',0),
|
| 1094 |
-
"Correct Answers": info.get('correct_flags',0)
|
| 1095 |
-
}
|
| 1096 |
-
for uname, info in submitted_players.items()
|
| 1097 |
-
])
|
| 1098 |
-
st.dataframe(df)
|
| 1099 |
-
|
| 1100 |
-
# Invite / Challenge if game is open
|
| 1101 |
-
if not g.get('closed'):
|
| 1102 |
-
st.info(f"Share this Game ID: {gid}")
|
| 1103 |
-
render_copy_button(gid, gid)
|
| 1104 |
-
|
| 1105 |
-
if st.session_state.get('username'):
|
| 1106 |
-
if st.button(f"Invite your friends to {gid}", key=f"invite_{gid}"):
|
| 1107 |
-
friends = get_friends_map().get(st.session_state['username'], [])
|
| 1108 |
-
if not friends:
|
| 1109 |
-
st.warning("No friends to invite.")
|
| 1110 |
-
else:
|
| 1111 |
-
for f in friends:
|
| 1112 |
-
send_game_invite(st.session_state['username'], f, gid)
|
| 1113 |
-
st.success("Invites sent to friends.")
|
| 1114 |
-
|
| 1115 |
-
if st.button(f"Challenge friends with a new game like {gid}", key=f"challenge_{gid}"):
|
| 1116 |
-
new_id = create_game(
|
| 1117 |
-
st.session_state.get('username','Host'),
|
| 1118 |
-
g.get('topics',[]),
|
| 1119 |
-
num_questions=len(g.get('questions',[]))
|
| 1120 |
-
)
|
| 1121 |
-
st.success(f"Challenge created: {new_id}")
|
| 1122 |
-
|
| 1123 |
-
st.markdown("---")
|
| 1124 |
-
|
| 1125 |
-
# Weekly Leaderboard
|
| 1126 |
-
st.subheader("๐ Weekly Leaderboard (Top 10)")
|
| 1127 |
-
weekly = get_weekly_leaderboard()
|
| 1128 |
-
if not weekly:
|
| 1129 |
-
st.info("No scores yet this week.")
|
| 1130 |
-
else:
|
| 1131 |
-
for i, r in enumerate(weekly, 1):
|
| 1132 |
-
st.write(
|
| 1133 |
-
f"{i}. {r.get('avatar','๐ฎ')} **{r['name']}** "
|
| 1134 |
-
f"(Game {r['game_id']}) โ {r['score']} pts"
|
| 1135 |
-
)
|
| 1136 |
# Create game
|
| 1137 |
def create_game(topics=None, num_questions=5, auto_close=True, ai_topic=None):
|
| 1138 |
topics = topics or []
|
|
@@ -1210,132 +959,6 @@ def join_game_page():
|
|
| 1210 |
# Play page
|
| 1211 |
# ----------------- Create Game -----------------
|
| 1212 |
|
| 1213 |
-
# ----------------- Play Page -----------------
|
| 1214 |
-
def playe():
|
| 1215 |
-
# Fetch game info
|
| 1216 |
-
gid = st.session_state.get('current_game_id')
|
| 1217 |
-
uname = st.session_state.get('username')
|
| 1218 |
-
avatar = st.session_state.get('avatar', '๐ฎ')
|
| 1219 |
-
|
| 1220 |
-
if not gid or not uname:
|
| 1221 |
-
st.error("No active game or username found.")
|
| 1222 |
-
return
|
| 1223 |
-
|
| 1224 |
-
games = unified_get("games") or {}
|
| 1225 |
-
game = games.get(gid)
|
| 1226 |
-
if not game:
|
| 1227 |
-
st.error("Game not found.")
|
| 1228 |
-
return
|
| 1229 |
-
|
| 1230 |
-
# Load questions
|
| 1231 |
-
questions = st.session_state.get('game_questions') or game.get('questions', [])
|
| 1232 |
-
if not questions:
|
| 1233 |
-
st.error("No questions loaded.")
|
| 1234 |
-
return
|
| 1235 |
-
|
| 1236 |
-
# Normalize questions to dict format
|
| 1237 |
-
for i, q in enumerate(questions):
|
| 1238 |
-
if isinstance(q, list) or isinstance(q, tuple):
|
| 1239 |
-
questions[i] = {
|
| 1240 |
-
"question": q[0],
|
| 1241 |
-
"options": q[1],
|
| 1242 |
-
"answer": q[2] if len(q) > 2 else ""
|
| 1243 |
-
}
|
| 1244 |
-
st.session_state['game_questions'] = questions
|
| 1245 |
-
|
| 1246 |
-
# Initialize timer
|
| 1247 |
-
if 'question_started_at' not in st.session_state or st.session_state['question_started_at'] is None:
|
| 1248 |
-
st.session_state['question_started_at'] = time.time()
|
| 1249 |
-
|
| 1250 |
-
# Current question index
|
| 1251 |
-
idx = st.session_state.get('current_index', 0)
|
| 1252 |
-
if idx >= len(questions):
|
| 1253 |
-
st.success("All done โ submit!")
|
| 1254 |
-
return
|
| 1255 |
-
|
| 1256 |
-
q = questions[idx]
|
| 1257 |
-
st.subheader(f"Question {idx+1}/{len(questions)}")
|
| 1258 |
-
st.write(q["question"])
|
| 1259 |
-
|
| 1260 |
-
elapsed = int(time.time() - st.session_state['question_started_at'])
|
| 1261 |
-
time_limit = 15
|
| 1262 |
-
st.markdown(f"**Time left:** {max(0, time_limit - elapsed)} seconds")
|
| 1263 |
-
|
| 1264 |
-
# Choice selection
|
| 1265 |
-
choice = st.radio("Choose an answer:", q["options"], key=f"choice_{idx}")
|
| 1266 |
-
|
| 1267 |
-
col1, col2 = st.columns(2)
|
| 1268 |
-
|
| 1269 |
-
# NEXT button
|
| 1270 |
-
with col1:
|
| 1271 |
-
if st.button("Next"):
|
| 1272 |
-
taken = time.time() - st.session_state['question_started_at']
|
| 1273 |
-
answers = st.session_state.get('answers', [""] * len(questions))
|
| 1274 |
-
times = st.session_state.get('answer_times', [None] * len(questions))
|
| 1275 |
-
answers[idx] = choice
|
| 1276 |
-
times[idx] = taken
|
| 1277 |
-
st.session_state['answers'] = answers
|
| 1278 |
-
st.session_state['answer_times'] = times
|
| 1279 |
-
st.session_state['current_index'] = idx + 1
|
| 1280 |
-
st.session_state['question_started_at'] = time.time() # reset timer
|
| 1281 |
-
|
| 1282 |
-
# Update heartbeat
|
| 1283 |
-
players = unified_get("players") or {}
|
| 1284 |
-
if players.get(gid, {}).get(uname):
|
| 1285 |
-
players[gid][uname]['last_heartbeat'] = now_iso()
|
| 1286 |
-
unified_set("players", players)
|
| 1287 |
-
heartbeat_unified(gid, uname)
|
| 1288 |
-
st.rerun()
|
| 1289 |
-
|
| 1290 |
-
# SUBMIT ALL button
|
| 1291 |
-
with col2:
|
| 1292 |
-
if idx == len(questions) - 1:
|
| 1293 |
-
if st.button("Submit All Answers"):
|
| 1294 |
-
taken = time.time() - st.session_state.get('question_started_at', time.time())
|
| 1295 |
-
answers = st.session_state.get('answers', [""] * len(questions))
|
| 1296 |
-
times = st.session_state.get('answer_times', [None] * len(questions))
|
| 1297 |
-
answers[idx] = choice
|
| 1298 |
-
times[idx] = taken
|
| 1299 |
-
st.session_state['answers'] = answers
|
| 1300 |
-
st.session_state['answer_times'] = times
|
| 1301 |
-
|
| 1302 |
-
# Compute score
|
| 1303 |
-
score, flags = compute_score(questions, answers, times)
|
| 1304 |
-
now = now_iso()
|
| 1305 |
-
row = {
|
| 1306 |
-
"name": uname,
|
| 1307 |
-
"score": score,
|
| 1308 |
-
"game_id": gid,
|
| 1309 |
-
"topics": ",".join(game.get('topics', [])),
|
| 1310 |
-
"timestamp": now,
|
| 1311 |
-
"avatar": avatar,
|
| 1312 |
-
"questions": " || ".join([q["question"] for q in questions]),
|
| 1313 |
-
"answers": " || ".join([str(a) for a in answers]),
|
| 1314 |
-
"correct_flags": " || ".join(flags),
|
| 1315 |
-
"percentage": round(score / len(questions) * 100, 2)
|
| 1316 |
-
}
|
| 1317 |
-
unified_push_leaderboard(row)
|
| 1318 |
-
|
| 1319 |
-
# Update player submission
|
| 1320 |
-
players = unified_get("players") or {}
|
| 1321 |
-
if players.get(gid) and players[gid].get(uname):
|
| 1322 |
-
players[gid][uname]['submitted'] = True
|
| 1323 |
-
players[gid][uname]['submitted_at'] = now
|
| 1324 |
-
players[gid][uname]['score'] = score
|
| 1325 |
-
players[gid][uname]['percentage'] = round(score / len(questions) * 100, 2)
|
| 1326 |
-
unified_set("players", players)
|
| 1327 |
-
|
| 1328 |
-
# Auto-close game if enabled
|
| 1329 |
-
if game.get('auto_close', True):
|
| 1330 |
-
games[gid]['closed'] = True
|
| 1331 |
-
games[gid]['closed_at'] = now
|
| 1332 |
-
unified_set("games", games)
|
| 1333 |
-
|
| 1334 |
-
st.success(f"Submitted! Score: {score}")
|
| 1335 |
-
st.balloons()
|
| 1336 |
-
st.session_state['last_score'] = score
|
| 1337 |
-
st.session_state['last_game'] = gid
|
| 1338 |
-
st.session_state['current_index'] = 0
|
| 1339 |
|
| 1340 |
|
| 1341 |
# Friends page
|
|
|
|
| 880 |
st.session_state['last_score'] = score
|
| 881 |
st.session_state['last_game'] = gid
|
| 882 |
st.session_state['current_index'] = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 883 |
# ---------- PLAY PAGE ----------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 884 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 885 |
# Create game
|
| 886 |
def create_game(topics=None, num_questions=5, auto_close=True, ai_topic=None):
|
| 887 |
topics = topics or []
|
|
|
|
| 959 |
# Play page
|
| 960 |
# ----------------- Create Game -----------------
|
| 961 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 962 |
|
| 963 |
|
| 964 |
# Friends page
|