display of a board seems to work again.
This commit is contained in:
parent
f09a9e86e0
commit
6c3db3caf8
6 changed files with 119 additions and 100 deletions
|
@ -32,11 +32,9 @@ class CreateAccount:
|
||||||
<input name="password1" type="text" class="text" size="20"></p>
|
<input name="password1" type="text" class="text" size="20"></p>
|
||||||
<p>Please retype your Password:<br>
|
<p>Please retype your Password:<br>
|
||||||
<input name="password2" type="text" class="text" size="20"></p>
|
<input name="password2" type="text" class="text" size="20"></p>
|
||||||
<i nput type="hidden" name="sessionid" value="%s">
|
|
||||||
<i nput type="hidden" name="createaccount" value="process">
|
|
||||||
<p><input type="submit" class="submit" value="create account"></p>
|
<p><input type="submit" class="submit" value="create account"></p>
|
||||||
</form>
|
</form>
|
||||||
""" % helper.generate_session_id()
|
"""
|
||||||
data += helper.footer()
|
data += helper.footer()
|
||||||
return(data)
|
return(data)
|
||||||
|
|
||||||
|
|
12
default.css
12
default.css
|
@ -173,8 +173,6 @@ td {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------=-=-=- Forms -=-=-=--------------------- */
|
/* ----------------------=-=-=- Forms -=-=-=--------------------- */
|
||||||
/* pretty forms and buttons */
|
/* pretty forms and buttons */
|
||||||
input {
|
input {
|
||||||
|
@ -213,3 +211,13 @@ input.submit:hover {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* The Board--------------------------------------------------------------------------- --------------------------------- */
|
||||||
|
#board a, a:link, a:visited {
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#board img {
|
||||||
|
border:none;
|
||||||
|
}
|
91
goban.py
91
goban.py
|
@ -3,101 +3,14 @@
|
||||||
DEBUG = 1
|
DEBUG = 1
|
||||||
|
|
||||||
import sys,string
|
import sys,string
|
||||||
import cgi
|
|
||||||
import helper,gnugo,database
|
import helper,gnugo,database
|
||||||
|
from cherrypy import cpg
|
||||||
picklefile = "goban.pickledump"
|
from cherrypy.lib import httptools
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def display_goban(goban,req,form):
|
|
||||||
"""
|
|
||||||
gets: dictionary containing the layout of the used goban.
|
|
||||||
returns: string containing the HTML code for a clickable goban.
|
|
||||||
"""
|
|
||||||
data = ""
|
|
||||||
|
|
||||||
hoshis19x19 = [(4,4),(4,10),(4,16),(10,4),(10,10),(10,16),(16,4),(16,10),(16,16)]
|
|
||||||
hoshis13x13 = [(4,4),(4,10),(7,7),(10,4),(10,10)]
|
|
||||||
hoshis9x9 = [(3,3),(3,7),(5,5),(7,3),(7,7)]
|
|
||||||
|
|
||||||
|
|
||||||
data += '\n<p>\n<form method="post">\n'
|
|
||||||
data += """<input type="hidden" name="sessionid" value="%s">
|
|
||||||
<input type="hidden" name="username" value="%s">
|
|
||||||
<input type="hidden" name="game" value="%s">
|
|
||||||
""" % (form["sessionid"],form["username"],form["game"])
|
|
||||||
|
|
||||||
#TODO: check form[game] before the following asignment
|
|
||||||
mygame = database.GobanTable.byName(form["game"])
|
|
||||||
sgf = mygame.sgf
|
|
||||||
helper.debug(req,form,sgf)
|
|
||||||
gobandict = gnugo.parse_static_gnugo_sgf(sgf)
|
|
||||||
|
|
||||||
try:
|
|
||||||
size = goban["size"]
|
|
||||||
except:
|
|
||||||
#TODO: proper error management
|
|
||||||
raise "[EE] display_goban: got broken goban dictionary."
|
|
||||||
sys.exit(1)
|
|
||||||
for x in range(1,size+1):
|
|
||||||
for y in range(1,size+1):
|
|
||||||
# check for white or black stone
|
|
||||||
if gobandict[(x,y)] == 1:
|
|
||||||
stone = "_white"
|
|
||||||
elif gobandict[(x,y)] == 2:
|
|
||||||
stone = "_black"
|
|
||||||
else:
|
|
||||||
stone = ""
|
|
||||||
sx = str(x)
|
|
||||||
sy = str(y)
|
|
||||||
# check position:
|
|
||||||
if (x == 1) and (y == 1): # upper left
|
|
||||||
data += '<input type=image class="goban" src="img/topleftline'+stone+'.png" name="('+sx+','+sy+')"\n>'
|
|
||||||
elif (x == 1) and (y == size): # upper right
|
|
||||||
data += '<input type=image class="goban" src="img/toprightline'+stone+'.png" name="('+sx+','+sy+')"\n><br\n>'
|
|
||||||
elif (x == size) and (y == size): # lower right
|
|
||||||
data += '<input type=image class="goban" src="img/bottomrightline'+stone+'.png" name="('+sx+','+sy+')"\n><br>\n'
|
|
||||||
elif (x == size) and (y == 1): # lower left
|
|
||||||
data += '<input type=image class="goban" src="img/bottomleftline'+stone+'.png" name="('+sx+','+sy+')"\n>'
|
|
||||||
elif (y == 1): #left line
|
|
||||||
data += '<input type=image class="goban" src="img/leftline'+stone+'.png" name="('+sx+','+sy+')"\n>'
|
|
||||||
elif (x == 1): # top line
|
|
||||||
data += '<input type=image class="goban" src="img/topline'+stone+'.png" name="('+sx+','+sy+')"\n>'
|
|
||||||
elif (y == size): # right line
|
|
||||||
data += '<input type=image class="goban" src="img/rightline'+stone+'.png" name="('+sx+','+sy+')"\n><br\n>'
|
|
||||||
elif (x == size): #bottom line
|
|
||||||
data += '<input type=image class="goban" src="img/bottomline'+stone+'.png" name="('+sx+','+sy+')"\n>'
|
|
||||||
else: # hoshi or empty inner field
|
|
||||||
defaultfield = '<input type=image class="goban" src="img/centerline'+stone+'.png" name="('+sx+','+sy+')"\n>'
|
|
||||||
#too lazy to make special images for hoshi fields with stones:
|
|
||||||
if gobandict[(x,y)] == 1:
|
|
||||||
hoshifield = '<input type=image class="goban" src="img/centerline_white.png" name="('+sx+','+sy+')"\n>'
|
|
||||||
elif gobandict[(x,y)] == 2:
|
|
||||||
hoshifield = '<input type=image class="goban" src="img/centerline_black.png" name="('+sx+','+sy+')"\n>'
|
|
||||||
else: #empty hoshi
|
|
||||||
hoshifield = '<input type=image class="goban" src="img/hoshi.png" name="('+sx+','+sy+')"\n>'
|
|
||||||
if size == 19: # 9 hoshis
|
|
||||||
if (x,y) in hoshis19x19:
|
|
||||||
data += hoshifield
|
|
||||||
else:
|
|
||||||
data += defaultfield
|
|
||||||
elif size == 13:
|
|
||||||
if (x,y) in hoshis13x13:
|
|
||||||
data += hoshifield
|
|
||||||
else:
|
|
||||||
data += defaultfield
|
|
||||||
elif size == 9:
|
|
||||||
if (x,y) in hoshis9x9:
|
|
||||||
data += hoshifield
|
|
||||||
else:
|
|
||||||
data += defaultfield
|
|
||||||
data += '\n<input type="hidden" name="play" value="foo">'
|
|
||||||
data += '\n</form></p>'
|
|
||||||
return data
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
7
login.py
7
login.py
|
@ -148,12 +148,11 @@ class Overview:
|
||||||
tmp += "<table><tr><td></td><td>Name of game</td><td>White</td>"
|
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>Black</td><td>Time of Creation</td><td>Time of last move</td>"
|
||||||
tmp += "<td></td></tr>"
|
tmp += "<td></td></tr>"
|
||||||
for item in helper.clean_list(gamelist):
|
for item in gamelist:
|
||||||
if (item != None) and (item != "None"):
|
if (item != None) and (item != "None"):
|
||||||
tmp += '<tr><form method="post">\n'
|
tmp += '<tr>\n<form action="/playgame/" method="get">\n'
|
||||||
tmp += '<input type="hidden" name="username" value="%s">\n' % username
|
|
||||||
tmp += '<input type="hidden" name="game" value="%s">\n' % item
|
tmp += '<input type="hidden" name="game" value="%s">\n' % item
|
||||||
tmp += '<td><input type=submit class="submit" name="play" value="Play"></td>\n'
|
tmp += '<td><input type=submit class="submit" value="Play"></td>\n'
|
||||||
mygame = database.GobanTable.get(item)
|
mygame = database.GobanTable.get(item)
|
||||||
description = mygame.description
|
description = mygame.description
|
||||||
if (description == None) or (description == "None") or (description == ""):
|
if (description == None) or (description == "None") or (description == ""):
|
||||||
|
|
6
main.py
6
main.py
|
@ -1,5 +1,5 @@
|
||||||
import sys, traceback,string,time
|
import sys, traceback,string,time
|
||||||
import login,createaccount,helper,gamecreation
|
import login,createaccount,helper,gamecreation,playgame
|
||||||
from cherrypy import cpg
|
from cherrypy import cpg
|
||||||
|
|
||||||
class WebGoSite:
|
class WebGoSite:
|
||||||
|
@ -18,12 +18,14 @@ cpg.root.createaccount = createaccount.CreateAccount()
|
||||||
cpg.root.login = login.Login()
|
cpg.root.login = login.Login()
|
||||||
cpg.root.overview = login.Overview()
|
cpg.root.overview = login.Overview()
|
||||||
cpg.root.gamecreation = gamecreation.GameCreation()
|
cpg.root.gamecreation = gamecreation.GameCreation()
|
||||||
|
cpg.root.playgame = playgame.PlayGame()
|
||||||
|
|
||||||
cpg.server.start(configMap={'sessionStorageType' : 'ram',
|
cpg.server.start(configMap={'sessionStorageType' : 'ram',
|
||||||
'sessionCookieName' : 'WebGoSessionCookie',
|
'sessionCookieName' : 'WebGoSessionCookie',
|
||||||
'sessionTimeout' : 15, #Session expires in n minutes
|
'sessionTimeout' : 15, #Session expires in n minutes
|
||||||
|
|
||||||
'staticContentList':
|
'staticContentList':
|
||||||
[['default.css','default.css']]
|
[['default.css','default.css'],
|
||||||
|
['img','img']]
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
99
playgame.py
99
playgame.py
|
@ -1,5 +1,7 @@
|
||||||
import goban,helper,database,login,gnugo
|
import goban,helper,database,login,gnugo
|
||||||
import string
|
import string
|
||||||
|
from cherrypy import cpg
|
||||||
|
from cherrypy.lib import httptools
|
||||||
|
|
||||||
DEBUG = 1
|
DEBUG = 1
|
||||||
|
|
||||||
|
@ -87,3 +89,100 @@ def main(req,form):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
req.write('Error: You have to select a game to play it!')
|
req.write('Error: You have to select a game to play it!')
|
||||||
|
|
||||||
|
class PlayGame:
|
||||||
|
"""
|
||||||
|
displays a game and processes user input.
|
||||||
|
"""
|
||||||
|
def index(self,game,coord=None):
|
||||||
|
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
|
||||||
|
else:
|
||||||
|
return self.display_goban(game)
|
||||||
|
|
||||||
|
else:
|
||||||
|
httptools.redirect("/login")
|
||||||
|
|
||||||
|
def display_goban(self,gamename):
|
||||||
|
"""
|
||||||
|
gets: dictionary containing the layout of the used goban.
|
||||||
|
returns: string containing the HTML code for a clickable goban.
|
||||||
|
"""
|
||||||
|
data = helper.header()
|
||||||
|
data += '<div id="board">'
|
||||||
|
hoshis19x19 = [(4,4),(4,10),(4,16),(10,4),(10,10),(10,16),(16,4),(16,10),(16,16)]
|
||||||
|
hoshis13x13 = [(4,4),(4,10),(7,7),(10,4),(10,10)]
|
||||||
|
hoshis9x9 = [(3,3),(3,7),(5,5),(7,3),(7,7)]
|
||||||
|
|
||||||
|
|
||||||
|
#TODO: check form[game] before the following asignment
|
||||||
|
mygame = database.GobanTable.get(gamename)
|
||||||
|
sgf = mygame.sgf
|
||||||
|
gobandict = gnugo.parse_static_gnugo_sgf(sgf)
|
||||||
|
size = mygame.size
|
||||||
|
|
||||||
|
for x in range(1,size+1):
|
||||||
|
for y in range(1,size+1):
|
||||||
|
# check for white or black stone
|
||||||
|
if gobandict[(x,y)] == 1:
|
||||||
|
stone = "_white"
|
||||||
|
elif gobandict[(x,y)] == 2:
|
||||||
|
stone = "_black"
|
||||||
|
else:
|
||||||
|
stone = ""
|
||||||
|
sx = str(x)
|
||||||
|
sy = str(y)
|
||||||
|
# check position:
|
||||||
|
if (x == 1) and (y == 1): # upper left
|
||||||
|
#data += '<input type=image class="goban" src="/img/topleftline'+stone+'.png" name="coord" value="('+sx+','+sy+')"\n>'
|
||||||
|
data += '<a href="/playgame/?coord=%s,%s&game=%s"><img src="/img/topleftline%s.png"\n></a>' % (sx,sy,gamename,stone)
|
||||||
|
elif (x == 1) and (y == size): # upper right
|
||||||
|
data += '<a href="/playgame/?coord=%s,%s&game=%s"><img src="/img/toprightline%s.png"\n></a><br>' % (sx,sy,gamename,stone)
|
||||||
|
elif (x == size) and (y == size): # lower right
|
||||||
|
data += '<a href="/playgame/?coord=%s,%s&game=%s"><img src="/img/bottomrightline%s.png"\n></a><br>' % (sx,sy,gamename,stone)
|
||||||
|
elif (x == size) and (y == 1): # lower left
|
||||||
|
data += '<a href="/playgame/?coord=%s,%s&game=%s"><img src="/img/bottomleftline%s.png"\n></a>' % (sx,sy,gamename,stone)
|
||||||
|
elif (y == 1): #left line
|
||||||
|
data += '<a href="/playgame/?coord=%s,%s&game=%s"><img src="/img/leftline%s.png"\n></a>' % (sx,sy,gamename,stone)
|
||||||
|
elif (x == 1): # top line
|
||||||
|
data += '<a href="/playgame/?coord=%s,%s&game=%s"><img src="/img/topline%s.png"\n></a>' % (sx,sy,gamename,stone)
|
||||||
|
elif (y == size): # right line
|
||||||
|
data += '<a href="/playgame/?coord=%s,%s&game=%s"><img src="/img/rightline%s.png"\n></a><br>' % (sx,sy,gamename,stone)
|
||||||
|
elif (x == size): #bottom line
|
||||||
|
data += '<a href="/playgame/?coord=%s,%s&game=%s"><img src="/img/bottomline%s.png"\n></a>' % (sx,sy,gamename,stone)
|
||||||
|
else: # hoshi or empty inner field
|
||||||
|
defaultfield = '<a href="/playgame/?coord=%s,%s&game=%s"><img src="/img/centerline%s.png"\n></a>' % (sx,sy,gamename,stone)
|
||||||
|
#too lazy to make special images for hoshi fields with stones:
|
||||||
|
if gobandict[(x,y)] == 1:
|
||||||
|
hoshifield = '<a href="/playgame/?coord=%s,%s&game=%s"><img src="/img/centerline_white.png"\n></a>' % (sx,sy,gamename)
|
||||||
|
elif gobandict[(x,y)] == 2:
|
||||||
|
hoshifield = '<a href="/playgame/?coord=%s,%s&game=%s"><img src="/img/centerline_black.png"\n></a>' % (sx,sy,gamename)
|
||||||
|
else: #empty hoshi
|
||||||
|
hoshifield = '<a href="/playgame/?coord=%s,%s&game=%s"><img src="/img/hoshi.png"\n></a>' % (sx,sy,gamename)
|
||||||
|
if size == 19: # 9 hoshis
|
||||||
|
if (x,y) in hoshis19x19:
|
||||||
|
data += hoshifield
|
||||||
|
else:
|
||||||
|
data += defaultfield
|
||||||
|
elif size == 13:
|
||||||
|
if (x,y) in hoshis13x13:
|
||||||
|
data += hoshifield
|
||||||
|
else:
|
||||||
|
data += defaultfield
|
||||||
|
elif size == 9:
|
||||||
|
if (x,y) in hoshis9x9:
|
||||||
|
data += hoshifield
|
||||||
|
else:
|
||||||
|
data += defaultfield
|
||||||
|
data += '</div>'
|
||||||
|
data += helper.footer()
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
index.exposed = True
|
Loading…
Reference in a new issue