game selection now has a nice table with players, access time etc. Users can now set an optional name for the game they create. This name gets displayed in game selection table.
This commit is contained in:
parent
e9d3a9aaaa
commit
2066a179cf
8 changed files with 167 additions and 155 deletions
121
default.css
121
default.css
|
@ -10,6 +10,20 @@ body {
|
|||
font-family: verdana, lucida, arial, helvetica, sans-serif;
|
||||
}
|
||||
|
||||
table {
|
||||
margin:auto;
|
||||
border-collapse:collapse;
|
||||
}
|
||||
tr{
|
||||
|
||||
}
|
||||
td {
|
||||
border: 1px solid #5e5e5e;
|
||||
padding: 5px;
|
||||
text-align: center;
|
||||
|
||||
}
|
||||
|
||||
#main {
|
||||
background: none;
|
||||
width: 600px;
|
||||
|
@ -30,10 +44,12 @@ body {
|
|||
|
||||
#main h1 {
|
||||
font-size: 2em;
|
||||
|
||||
}
|
||||
|
||||
#main h2 {
|
||||
font-size: 1.5em;
|
||||
margin-top:50px;
|
||||
}
|
||||
|
||||
#main h3 {
|
||||
|
@ -212,6 +228,12 @@ body {
|
|||
|
||||
/* ----------------------=-=-=- Forms -=-=-=--------------------- */
|
||||
/* pretty forms and buttons */
|
||||
input {
|
||||
/* top right bottom left */
|
||||
|
||||
border: 0px;
|
||||
}
|
||||
|
||||
input#text {
|
||||
border: 1px solid #333333;
|
||||
color: #333333;
|
||||
|
@ -247,11 +269,7 @@ input#submit:hover {
|
|||
}
|
||||
|
||||
|
||||
input {
|
||||
padding: 0px;
|
||||
border: 0px;
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
|
||||
/*input#goban:hover {
|
||||
padding: 0px;
|
||||
|
@ -268,96 +286,3 @@ input {
|
|||
#words form p {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* ------------=-=-=- language selection -=-=-=------------- */
|
||||
|
||||
#lang {
|
||||
position: fixed;
|
||||
float: right;
|
||||
right: 5px;
|
||||
top: 5px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
#lang a {
|
||||
color: #acacac;
|
||||
font-family: verdana, lucida, arial, helvetica, sans-serif;
|
||||
font-size: smaller;
|
||||
}
|
||||
|
||||
#lang a:hover {
|
||||
color: #707070;
|
||||
}
|
||||
|
||||
|
||||
/* ------------=-=-=- documentation -=-=-=------------- */
|
||||
|
||||
#doc ol,ul li {
|
||||
text-align: left;
|
||||
margin-left: 20px;
|
||||
}
|
||||
|
||||
#doc dl dt {
|
||||
text-align: left;
|
||||
margin-left: 20px;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
#doc h1 {
|
||||
padding-top: 25px;
|
||||
}
|
||||
|
||||
#doc h2 {
|
||||
padding-top: 20px;
|
||||
}
|
||||
|
||||
#doc h3 {
|
||||
padding-top: 10px;
|
||||
}
|
||||
|
||||
/* ------------=-=-=- special things -=-=-=------------- */
|
||||
|
||||
#partition_info p {
|
||||
margin-left: 10%;
|
||||
margin-right: 10%;
|
||||
font-family: monospace
|
||||
}
|
||||
|
||||
#words a.popup {
|
||||
line-height: inherit;
|
||||
color: inherit;
|
||||
text-decoration: inherit;
|
||||
font-weight: inherit;
|
||||
font-size: inherit;
|
||||
}
|
||||
|
||||
#words a.popup:hover {
|
||||
text-decoration: inherit;
|
||||
}
|
||||
|
||||
#words a.popup span {
|
||||
display: none;
|
||||
position: fixed;
|
||||
bottom: 10px;
|
||||
left: 9%;
|
||||
width: 80%;
|
||||
background: #f0f0f0;
|
||||
padding: 10px;
|
||||
border-color: #e0e0e0;
|
||||
border-width: 2px;
|
||||
border-style: solid;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#words a.popup:hover span {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
#words a.popup span p {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
#words a.popup span h3 {
|
||||
color: #909090;
|
||||
margin-top: 0px;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ def main(req,form):
|
|||
#free game slots of players
|
||||
for player in players:
|
||||
gameslot = get_game_slot_of_game(player,gamename)
|
||||
helper.debug(req,form,"delete: got %s as gameslot." % gameslot)
|
||||
if gameslot != "":
|
||||
psql.set_game_slot(player,gameslot,"")
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ def display_game_creation_form(req,sessionid,username):
|
|||
<p>Player One (Black): %s </p>
|
||||
<p>Player Two (White): %s </p>
|
||||
<p>Goban Size: %s fields </p>
|
||||
<p>Optional name for game: <input type="text" name="description" size="20" id="text"></p>
|
||||
<input type="hidden" name="sessionid" value="%s">
|
||||
<input type="hidden" name="username" value="%s">
|
||||
<input type="submit" id="submit" name="create" value="create game">
|
||||
|
@ -39,11 +40,16 @@ def process_creation_form(req,form):
|
|||
player1 = form["player1"]
|
||||
player2 = form["player2"]
|
||||
username = form["username"]
|
||||
try:
|
||||
description = form["description"]
|
||||
except:
|
||||
description = ""
|
||||
helper.debug(req,form,"game creation: will use '%s' as description." % description)
|
||||
|
||||
#check if at least one of the players is the current user
|
||||
if (player1 == username) or (player2 == username):
|
||||
#create game
|
||||
gamename = psql.create_goban_table(player1,player2,int(form["gobansize"]))
|
||||
gamename = psql.create_goban_table(player1,player2,int(form["gobansize"]),description)
|
||||
#update entries for player one and player two
|
||||
for player in [player1,player2]:
|
||||
gameslot = psql.get_free_game_slot(player)
|
||||
|
|
1
goban.py
1
goban.py
|
@ -135,6 +135,7 @@ def set_stone(gobandict, position,req,form):
|
|||
#write new sgf file into database
|
||||
psql.update_goban_table_field(name,"x1","sgf",new_sgf)
|
||||
psql.update_turn_number(name,turn+1)
|
||||
psql.set_time(name)
|
||||
return ""
|
||||
else: #move not ok
|
||||
return "This is not a legal move (says Gnugo)."
|
||||
|
|
31
helper.py
31
helper.py
|
@ -1,4 +1,4 @@
|
|||
import string,re
|
||||
import string,re,time
|
||||
|
||||
DEBUG = 1
|
||||
|
||||
|
@ -101,12 +101,39 @@ def dict_coords_to_gnugo_coords(coords,size):
|
|||
return letter+str(digit)
|
||||
|
||||
|
||||
def format_time(mytime):
|
||||
"""
|
||||
gets output of time.time()
|
||||
formats it nicely and returns as string.
|
||||
"""
|
||||
acttime = int(time.time())
|
||||
if mytime == None:
|
||||
retstring = ""
|
||||
elif acttime-mytime<86400: #given time is less than 24h ago
|
||||
tmp = acttime-mytime
|
||||
hour = int(tmp/3600)
|
||||
minute = int((tmp-hour*3600)/60)
|
||||
if hour == 0:
|
||||
retstring = "%dm ago" % (minute)
|
||||
else:
|
||||
retstring = "%dh %dm ago" % (hour,minute)
|
||||
else:
|
||||
mytime = int(mytime)
|
||||
retstring = time.strftime("%Y-%m-%d %H:%M",time.gmtime(mytime))
|
||||
return retstring
|
||||
|
||||
def clean_list(l):
|
||||
#removing None-entries
|
||||
clean = []
|
||||
for item in l:
|
||||
if (item != "None") and (item != None):
|
||||
clean.append(item)
|
||||
return clean
|
||||
|
||||
|
||||
def test():
|
||||
print dict_coords_to_gnugo_coords((6,5),7)
|
||||
|
||||
print format_time(time.time()-20000)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -9,8 +9,8 @@ def clear():
|
|||
def create():
|
||||
#psql.create_goban_table("gast","gast2",9)
|
||||
psql.create_user_table()
|
||||
psql.add_webgo_user("gast","gast")
|
||||
psql.add_webgo_user("gast2","gast2")
|
||||
#psql.add_webgo_user("gast","gast")
|
||||
#psql.add_webgo_user("gast2","gast2")
|
||||
|
||||
|
||||
def main():
|
||||
|
@ -18,4 +18,5 @@ def main():
|
|||
create()
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
41
login.py
41
login.py
|
@ -1,4 +1,5 @@
|
|||
import psql,init_webgo,helper,gamecreation
|
||||
from sets import Set as set
|
||||
from mod_python import *
|
||||
|
||||
def process_form(req,form):
|
||||
|
@ -42,29 +43,47 @@ def game_overview_form(req,form):
|
|||
username = form["username"]
|
||||
sessionid = form["sessionid"]
|
||||
|
||||
|
||||
data = helper.header()+ """
|
||||
<h2> Current Games: </h2>
|
||||
<form method="post">
|
||||
|
||||
"""
|
||||
gamelist = psql.get_user_game_list(username)
|
||||
#debug
|
||||
helper.debug(req,form,str(gamelist)+"<hr>\n")
|
||||
#display list of current games
|
||||
counter = 10
|
||||
counter = 10 - len(helper.clean_list(gamelist))
|
||||
tmp = ""
|
||||
for item in gamelist:
|
||||
if helper.clean_list(gamelist) != []:
|
||||
tmp += "<table><tr><td></td><td>Name of game</td><td>White</td>"
|
||||
tmp += "<td>Black</td><td>Time of Creation</td><td>Time of last move</td>"
|
||||
tmp += "<td></td></tr>"
|
||||
for item in set(helper.clean_list(gamelist)):
|
||||
if (item != None) and (item != "None"):
|
||||
tmp += '<input type="radio" name="game" value="%s"> %s<br>\n' % (item,item)
|
||||
#later write partners name and whether its our turn or not
|
||||
#data += "Your partner: %s."
|
||||
counter -= 1
|
||||
if tmp == "": #no current games
|
||||
tmp += '<tr><form method="post">\n'
|
||||
tmp += '<input type="hidden" name="sessionid" value="%s">\n' % sessionid
|
||||
tmp += '<input type="hidden" name="username" value="%s">\n' % username
|
||||
tmp += '<input type="hidden" name="game" value="%s">\n' % item
|
||||
tmp += '<td><input type=submit id="submit" name="play" value="Play"></td>\n'
|
||||
description = psql.get_description(item)
|
||||
if (description == None) or (description == "None") or (description == ""):
|
||||
description = item
|
||||
tmp += '<td>%s</td>\n' % description
|
||||
players = psql.get_players_for_game(item)
|
||||
tmp += '<td>%s</td>\n' % players[0]
|
||||
tmp += '<td>%s</td>\n' % players[1]
|
||||
tmp += '<td>%s</td>\n' % helper.format_time(psql.get_time(item,"created"))
|
||||
tmp += '<td>%s</td>\n' % helper.format_time(psql.get_time(item,"lastmove"))
|
||||
tmp += '<td><input type=submit id="submit" name="delete" value="Delete"></td>\n'
|
||||
tmp += '</tr></form>\n'
|
||||
if helper.clean_list(gamelist) != []:
|
||||
tmp += '</table>'
|
||||
|
||||
if gamelist == []: #no current games
|
||||
data += "You don't have any running games.\n"
|
||||
else:
|
||||
tmp += '<input type="hidden" name="sessionid" value="%s">\n' % sessionid
|
||||
tmp += '<input type="hidden" name="username" value="%s">\n' % username
|
||||
|
||||
data += tmp
|
||||
data += '<input type=submit id="submit" name="play" value="Play selected game">\n<input type=submit id="submit" name="delete" value="Delete selected game">\n</form>'
|
||||
#now comes the option for creating new games.
|
||||
data += "<h2>New Game:</h2>\n"
|
||||
if counter > 0:
|
||||
|
|
108
psql.py
108
psql.py
|
@ -1,5 +1,5 @@
|
|||
import helper,gnugo
|
||||
import pgdb,sys
|
||||
import pgdb,sys,time
|
||||
|
||||
DEBUG = 1
|
||||
|
||||
|
@ -32,7 +32,7 @@ def create_table(name,layout=""):
|
|||
executestring = "CREATE TABLE %s ( %s );" % (name,layout)
|
||||
sql_one_liner(executestring)
|
||||
|
||||
def create_goban_table(player1,player2,size):
|
||||
def create_goban_table(player1,player2,size,description=""):
|
||||
"""
|
||||
gets:player1, player2, size of goban.
|
||||
creates postgresql table containing goban data.
|
||||
|
@ -43,56 +43,59 @@ def create_goban_table(player1,player2,size):
|
|||
turn_number
|
||||
size
|
||||
name
|
||||
description
|
||||
player1
|
||||
player2
|
||||
sgf
|
||||
created
|
||||
lastmove
|
||||
|
||||
and the meaning of these fields:
|
||||
(turn_number,x1) is the current turn,
|
||||
(size,x1) is the length of a side of the goban,
|
||||
(name,x1) is the name of this goban.
|
||||
(description,x1) is the user-given name of this goban.
|
||||
(player1,x1) is the name of one player.
|
||||
(player2,x1) is the name of the other player.
|
||||
(sgf,x1) contains a sgf file with the current board.
|
||||
(created,x1) is the time of creation of the table
|
||||
(lastmove,x1) is the time of the last player move
|
||||
"""
|
||||
tablename = helper.generate_game_name()
|
||||
data="line text"
|
||||
data = "x1 text"
|
||||
data="line text, x1 text"
|
||||
create_table(tablename,data)
|
||||
#now insert additional variables
|
||||
tmplist=[]
|
||||
tmplist.append("turn_number")
|
||||
tmplist.append("1")
|
||||
insert_into_table(tablename,str(tuple(tmplist)))
|
||||
insert_into_table(tablename,strtuple("turn_number","1"))
|
||||
#size of goban
|
||||
tmplist=[]
|
||||
tmplist.append("size")
|
||||
tmplist.append(size)
|
||||
insert_into_table(tablename,str(tuple(tmplist)))
|
||||
insert_into_table(tablename,strtuple("size",size))
|
||||
#name of goban (=name of table in database)
|
||||
tmplist=[]
|
||||
tmplist.append("name")
|
||||
tmplist.append(tablename)
|
||||
insert_into_table(tablename,str(tuple(tmplist)))
|
||||
insert_into_table(tablename,strtuple("name",tablename))
|
||||
#description of goban (=user-given name)
|
||||
insert_into_table(tablename,strtuple("description",description))
|
||||
#name of player1
|
||||
tmplist=[]
|
||||
tmplist.append("player1")
|
||||
tmplist.append(player1)
|
||||
insert_into_table(tablename,str(tuple(tmplist)))
|
||||
insert_into_table(tablename,strtuple("player1",player1))
|
||||
#name of player2
|
||||
tmplist=[]
|
||||
tmplist.append("player2")
|
||||
tmplist.append(player2)
|
||||
insert_into_table(tablename,str(tuple(tmplist)))
|
||||
insert_into_table(tablename,strtuple("player2",player2))
|
||||
#empty sgf file as string
|
||||
tmplist=[]
|
||||
tmplist.append("sgf")
|
||||
sgf = gnugo.create_sgf_file(size)
|
||||
tmplist.append(sgf)
|
||||
insert_into_table(tablename,str(tuple(tmplist)))
|
||||
insert_into_table(tablename,strtuple("sgf",sgf))
|
||||
#time of creation
|
||||
insert_into_table(tablename,strtuple("created",str(int(time.time()))))
|
||||
#time of last move
|
||||
insert_into_table(tablename,strtuple("lastmove",str(int(time.time()))))
|
||||
|
||||
return tablename
|
||||
|
||||
|
||||
def strtuple(s1,s2):
|
||||
"""
|
||||
creating a string looking like a tuple.
|
||||
gets 2 strings.
|
||||
useful for inserting something into a table.
|
||||
"""
|
||||
tmplist = []
|
||||
tmplist.append(s1)
|
||||
tmplist.append(s2)
|
||||
return str(tuple(tmplist))
|
||||
|
||||
def create_user_table():
|
||||
"""
|
||||
|
@ -194,7 +197,6 @@ def get_user_game_list(name):
|
|||
ret.append(cursor.fetchone()[0]) #[0], because return is a list
|
||||
except:
|
||||
ret = "could not get info of all games -- table corrupt?"
|
||||
return ret
|
||||
cursor.close()
|
||||
return ret
|
||||
|
||||
|
@ -339,13 +341,6 @@ def update_goban_table_field(table,column,line,new_value):
|
|||
"""
|
||||
update_database_field(table,column,new_value,"line",line)
|
||||
|
||||
def update_goban_field(table,x,y,content):
|
||||
"""
|
||||
gets: goban dictionary, x,y coordinates, new content for field.
|
||||
modifies goban in database.
|
||||
"""
|
||||
update_goban_table_field(table,"x"+str(x),"y"+str(y),content)
|
||||
|
||||
def update_turn_number(table,new_number):
|
||||
"""
|
||||
gets: name of table,new turn number
|
||||
|
@ -367,6 +362,20 @@ def get_sgf(table):
|
|||
cursor.close()
|
||||
return sgf
|
||||
|
||||
def get_description(table):
|
||||
"""
|
||||
gets table name,
|
||||
returns content of "description" field.
|
||||
"""
|
||||
cursor=db.cursor()
|
||||
data="select x1 from %s where line='description';" % (table)
|
||||
cursor.execute(data)
|
||||
# Commit the changes
|
||||
db.commit()
|
||||
sgf = cursor.fetchone()[0]
|
||||
cursor.close()
|
||||
return sgf
|
||||
|
||||
|
||||
def fetchall_list_to_goban_dict(list):
|
||||
"""
|
||||
|
@ -393,8 +402,31 @@ def fetchall_list_to_goban_dict(list):
|
|||
return ret
|
||||
|
||||
|
||||
def get_time(table,whichtime):
|
||||
"""
|
||||
gets:
|
||||
- a table name,
|
||||
- a string equal "created" or "lastmove".
|
||||
returns either the time of creation or the time of the last player move for
|
||||
the table, depending of whichtime.
|
||||
"""
|
||||
cursor=db.cursor()
|
||||
data="select x1 from %s where line='%s';" % (table,whichtime)
|
||||
cursor.execute(data)
|
||||
# Commit the changes
|
||||
db.commit()
|
||||
try:
|
||||
time = int(cursor.fetchone()[0])
|
||||
except:
|
||||
time = None
|
||||
cursor.close()
|
||||
return time
|
||||
|
||||
|
||||
def set_time(tablename):
|
||||
"""
|
||||
gets name of goban table, sets lastmove to current time.
|
||||
"""
|
||||
update_goban_table_field(tablename,"x1","lastmove",int(time.time()))
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue