127 lines
2.4 KiB
Python
Executable File
127 lines
2.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import random
|
|
|
|
from helpers import get_client_cert
|
|
from db import *
|
|
from urllib import parse
|
|
|
|
TLS_CLIENT_HASH = get_client_cert()
|
|
user_id = check_hash(TLS_CLIENT_HASH)
|
|
user_name = get_name(user_id) or "[Not Set]"
|
|
game_id = get_game_id(user_id) or "[Not Set]"
|
|
|
|
word=os.getenv("QUERY_STRING").upper()
|
|
|
|
print("# Gemini Boggle")
|
|
|
|
conn=create_connection()
|
|
with conn:
|
|
cur = conn.cursor()
|
|
cur.execute("SELECT board,words,graph FROM games WHERE id=?",(game_id,))
|
|
row = cur.fetchone()
|
|
if row:
|
|
board=row[0]
|
|
words=row[1]
|
|
graph=row[2]
|
|
|
|
a=board.split(',')
|
|
w=words.split(',')
|
|
g=graph.split(',')
|
|
|
|
b=[]
|
|
for j in range(4):
|
|
b.append([])
|
|
for i in range(4):
|
|
b[j].append(a[j*4+i])
|
|
|
|
print("```")
|
|
for j in range(4):
|
|
for i in range(4):
|
|
print(b[j][i],end=" ")
|
|
print()
|
|
print("```")
|
|
|
|
if word:
|
|
i=-1
|
|
for j in range(len(w)):
|
|
if w[j]==word:
|
|
i=j
|
|
break
|
|
if i!=-1:
|
|
if g[i]=='0':
|
|
g[i]='1'
|
|
|
|
set_game_graph(game_id,','.join(g))
|
|
|
|
pw=get_words(game_id,user_id)
|
|
if not pw:
|
|
pw=word
|
|
else:
|
|
pw=pw.split(',')
|
|
pw.append(word)
|
|
pw=','.join(pw)
|
|
|
|
add_plays(game_id,user_id,pw)
|
|
|
|
|
|
l=len(word)
|
|
if l==3 or l==4: p=1
|
|
elif l==5: p=2
|
|
elif l==6: p=3
|
|
elif l==7: p=5
|
|
elif l>=8: p=11
|
|
|
|
add_score(user_id,p)
|
|
score=get_score(user_id)
|
|
|
|
print("you guessed",word,"plus",p,"points")
|
|
|
|
s=1
|
|
for t in g:
|
|
if t=='0':
|
|
s=0
|
|
break
|
|
|
|
if s==1:
|
|
set_game_stats(game_id,"STOP")
|
|
print("game is finished")
|
|
|
|
else:
|
|
print(word,"is already guessed")
|
|
else:
|
|
print(word,"not found")
|
|
|
|
print()
|
|
|
|
print("game:",game_id)
|
|
print("username:",user_name)
|
|
|
|
score=get_score(user_id)
|
|
print("your score is",score)
|
|
|
|
g=get_game_graph(game_id).split(',')
|
|
lg=len(g)
|
|
c=0
|
|
for t in g:
|
|
if t=='1':
|
|
c+=1
|
|
|
|
|
|
print("words guessed",c,"left",lg-c,"total",lg)
|
|
|
|
|
|
print()
|
|
|
|
stats=get_game_stats(game_id)
|
|
if stats=='PLAY':
|
|
print("=> guess.cgi guess a word")
|
|
elif stats=='STOP':
|
|
print("game is finished")
|
|
|
|
print("=> list.cgi list")
|
|
print("=> rank.cgi ranking")
|
|
print("=> lobby.cgi lobby")
|
|
print("=> login.cgi login")
|
|
print("=> new_game.cgi new game")
|