before this change WebGo had 2 represenations of the goban simultaneously (one in sgf and the other as a table in the database). This was just too ugly, even for me. Now all relevant functions use the parser from the last commit.It seems to work ...

This commit is contained in:
phear 2005-10-09 17:27:17 +00:00
parent 5ab93abaf2
commit e9d3a9aaaa
5 changed files with 149 additions and 136 deletions

View file

@ -1,4 +1,4 @@
import goban,helper,psql,login
import goban,helper,psql,login,gnugo
import string
DEBUG = 1
@ -9,31 +9,32 @@ def is_my_turn(req,form,gobandict):
check wether or not the current this is the players turn.
return true or false.
"""
#INFO: player1 is black,player2 is white. black starts the game.
me = form["username"]
player1 = gobandict["player1"]
player2 = gobandict["player2"]
#get turn_number.
turn_number = gobandict["turn_number"]
#if player 2 can play: are we player two?
# yes:return True, else return False
if turn_number % 2 == 0:
if me == player2:
return True
else:
return False
#else:are we player1?
# yes:return True, else return False
else:
if me == player1:
return True
else:
return False
play = gobandict["play"]
if ((player1 == me) and (play == "white")) or ((player2 == me) and (play == "black")):
return True
else:
return false
def create_gobandict(req,form,gamename):
"""
gets a gamename
loads sgf, transforms it to dict, writes stuff like player names to dict
returns dict
"""
#read goban table from database
tmplist = psql.read_table(gamename)
#make a dictionary out of the list
tmpdict = psql.fetchall_list_to_goban_dict(tmplist)
sgf = psql.get_sgf(gamename)
gobandict = gnugo.parse_static_gnugo_sgf(sgf)
for key in ["player1","player2","turn_number","name","sgf"]:
gobandict[key] = tmpdict[key]
return gobandict
def main(req,form):
"""
@ -48,10 +49,7 @@ def main(req,form):
data = ""
req.write(helper.header())
#helper.debug(req,form,str(form.keys()))
#read goban table from database
tmplist = psql.read_table(gamename)
#make a dictionary out of the list
gobandict = psql.fetchall_list_to_goban_dict(tmplist)
gobandict = create_gobandict(req,form,gamename)
#check if user has already clicked onto a field:
click_on_field = False
for item in form.keys():
@ -66,11 +64,12 @@ def main(req,form):
helper.debug(req,form,"playgame.main says: "+str(retstring))
else:
#reload gobandict, it has been changed.
gobandict = psql.fetchall_list_to_goban_dict(psql.read_table(gamename))
gobandict = create_gobandict(req,form,gamename)
else:
helper.debug(req,form,"its not my turn.")
data += """<br>Turn number: %s. %s plays.\n
""" % (str(gobandict["turn_number"]), ["White","Black"][int(gobandict["turn_number"] % 2)])
""" % (str(gobandict["turn_number"]), (string.capitalize(gobandict["play"])))
#check whether its our turn
#if yes: print 'your move' and display goban and process move