webgo now utilizes gnugo to evaluate moves. The game is now playable (though I dont know what happens if someone wins/finishes a game :))
This commit is contained in:
parent
2630332479
commit
cc76ec975b
12 changed files with 504 additions and 83 deletions
42
playgame.py
42
playgame.py
|
@ -9,15 +9,13 @@ 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 turn_number modulo 2 == 0: are we player two?
|
||||
#if player 2 can play: are we player two?
|
||||
# yes:return True, else return False
|
||||
if turn_number % 2 == 0:
|
||||
if me == player2:
|
||||
|
@ -41,42 +39,46 @@ def main(req,form):
|
|||
"""
|
||||
display selected goban and manage user input.
|
||||
"""
|
||||
helper.debug(req,form,str(form.keys())+"<hr>")
|
||||
|
||||
|
||||
try:
|
||||
gamename = form["game"]
|
||||
except:
|
||||
gamename = ""
|
||||
if gamename != "":
|
||||
|
||||
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)
|
||||
#check if user has already clicked onto a field:
|
||||
foundx = False
|
||||
click_on_field = False
|
||||
for item in form.keys():
|
||||
if string.find(item,").x") > 0:
|
||||
foundx = True
|
||||
if foundx:
|
||||
click_on_field = True
|
||||
if click_on_field:
|
||||
#if yes: is this the user's turn? then process form.
|
||||
if is_my_turn(req,form,gobandict):
|
||||
(gobandict,retstring) = goban.process_form(req,form,gobandict)
|
||||
|
||||
#do stuff
|
||||
data = helper.header()
|
||||
|
||||
|
||||
data += "Turn number: "+str(gobandict["turn_number"])+". "
|
||||
helper.debug(req,form,"its my turn , i am going to process the form: --")
|
||||
retstring = goban.process_form(req,form,gobandict)
|
||||
if retstring != "":
|
||||
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))
|
||||
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)])
|
||||
|
||||
#check whether its our turn
|
||||
#if yes: print 'your move' and display goban and process move
|
||||
#if not: print '...s move' and display goban.
|
||||
if is_my_turn(req,form,gobandict):
|
||||
data += ("Its your turn.<br>")
|
||||
data += "<br>Its your turn.<br>\n"
|
||||
else:
|
||||
data+= ("This is not your turn. You have to wait for the move of the other player.<br>")
|
||||
|
||||
|
||||
data += "<br>This is not your turn. You have to wait for the move of the other player.<br>\n"
|
||||
#print goban
|
||||
data += goban.display_goban(gobandict,req,form)
|
||||
data += login.navigation_bar(req,form)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue