basic gameplay works again. What does not yet work: Things like proper error management, display of current turn and player etc.
This commit is contained in:
parent
6c3db3caf8
commit
611d67ddaf
4 changed files with 35 additions and 47 deletions
35
playgame.py
35
playgame.py
|
@ -98,10 +98,11 @@ class PlayGame:
|
|||
username = cpg.request.sessionMap["username"]
|
||||
myuser = database.Users.byUsername(username)
|
||||
sessionid = cpg.request.sessionMap["_sessionId"]
|
||||
print game
|
||||
if myuser.sessionid == sessionid:
|
||||
if coord != None:
|
||||
return coord
|
||||
ret = self.process_form(game,coord)
|
||||
if ret == "":
|
||||
return self.display_goban(game)
|
||||
else:
|
||||
return self.display_goban(game)
|
||||
|
||||
|
@ -183,6 +184,32 @@ class PlayGame:
|
|||
data += helper.footer()
|
||||
return data
|
||||
|
||||
|
||||
|
||||
def process_form(self,gamename,coord):
|
||||
"""
|
||||
gets name of a go game, coordinates of user's move.
|
||||
processes move.
|
||||
"""
|
||||
x,y = string.split(coord,",")
|
||||
position = (int(x),int(y))
|
||||
mygame = database.GobanTable.get(gamename)
|
||||
size = mygame.size
|
||||
turn = mygame.turn_number
|
||||
sgf = mygame.sgf
|
||||
gobandict = gnugo.parse_static_gnugo_sgf(sgf)
|
||||
gobandict["name"] = gamename
|
||||
gobandict["turn_number"] = turn
|
||||
gobandict["sgf"] = sgf
|
||||
if (gobandict[position] == 0): #empty field
|
||||
if gnugo.is_legal(gobandict,position): #gnugo says the move is ok
|
||||
#let gnugo make the above move, let gnugo write move to file
|
||||
new_sgf = gnugo.make_move_in_sgf(gobandict,position)
|
||||
#write new sgf file into database
|
||||
mygame.sgf = new_sgf
|
||||
mygame.turn_number = turn + 1
|
||||
mygame.set_time()
|
||||
return ""
|
||||
else: #move not ok
|
||||
return "This is not a legal move (says Gnugo)."
|
||||
else: #position not empty
|
||||
return "Could not make move: Field not empty."
|
||||
index.exposed = True
|
Loading…
Add table
Add a link
Reference in a new issue