clearsilvered display of goban finished.
This commit is contained in:
parent
a000c9dd9a
commit
942aaa00f9
1 changed files with 27 additions and 57 deletions
72
playgame.py
72
playgame.py
|
@ -60,13 +60,11 @@ class PlayGame:
|
||||||
else:
|
else:
|
||||||
httptools.redirect("/login")
|
httptools.redirect("/login")
|
||||||
|
|
||||||
def display_goban(self,gamename):
|
def display_goban(self,gamename,settings={}):
|
||||||
"""
|
"""
|
||||||
gets: dictionary containing the layout of the used goban.
|
gets: dictionary containing the layout of the used goban.
|
||||||
returns: string containing the HTML code for a clickable 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)]
|
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)]
|
hoshis13x13 = [(4,4),(4,10),(7,7),(10,4),(10,10)]
|
||||||
hoshis9x9 = [(3,3),(3,7),(5,5),(7,3),(7,7)]
|
hoshis9x9 = [(3,3),(3,7),(5,5),(7,3),(7,7)]
|
||||||
|
@ -78,62 +76,31 @@ class PlayGame:
|
||||||
gobandict = gnugo.parse_static_gnugo_sgf(sgf)
|
gobandict = gnugo.parse_static_gnugo_sgf(sgf)
|
||||||
size = mygame.size
|
size = mygame.size
|
||||||
|
|
||||||
|
settings["Data.GobanSize"] = size
|
||||||
|
settings["Data.GameName"] = gamename
|
||||||
for x in range(1,size+1):
|
for x in range(1,size+1):
|
||||||
for y in range(1,size+1):
|
for y in range(1,size+1):
|
||||||
# check for white or black stone
|
settings["Data.Goban.%d.%d.x" % (x,y)] = x
|
||||||
|
settings["Data.Goban.%d.%d.y" % (x,y)] = y
|
||||||
if gobandict[(x,y)] == 1:
|
if gobandict[(x,y)] == 1:
|
||||||
stone = "_white"
|
settings["Data.Goban.%d.%d.color" % (x,y)] = "_white"
|
||||||
elif gobandict[(x,y)] == 2:
|
elif gobandict[(x,y)] == 2:
|
||||||
stone = "_black"
|
settings["Data.Goban.%d.%d.color" % (x,y)] = "_black"
|
||||||
else:
|
#now check wether or not this field is hoshi
|
||||||
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 size == 19: # 9 hoshis
|
||||||
if (x,y) in hoshis19x19:
|
if (x,y) in hoshis19x19:
|
||||||
data += hoshifield
|
settings["Data.Goban.%d.%d.hoshi" % (x,y)] = 1
|
||||||
else:
|
else: pass
|
||||||
data += defaultfield
|
|
||||||
elif size == 13:
|
elif size == 13:
|
||||||
if (x,y) in hoshis13x13:
|
if (x,y) in hoshis13x13:
|
||||||
data += hoshifield
|
settings["Data.Goban.%d.%d.hoshi" % (x,y)] = 1
|
||||||
else:
|
else: pass
|
||||||
data += defaultfield
|
|
||||||
elif size == 9:
|
elif size == 9:
|
||||||
if (x,y) in hoshis9x9:
|
if (x,y) in hoshis9x9:
|
||||||
data += hoshifield
|
settings["Data.Goban.%d.%d.hoshi" % (x,y)] = 1
|
||||||
else:
|
else: pass
|
||||||
data += defaultfield
|
|
||||||
data += '</div>'
|
return helper.cs_render("templates/playgame.cs",settings)
|
||||||
data += helper.footer()
|
|
||||||
return data
|
|
||||||
|
|
||||||
def process_form(self,gamename,coord):
|
def process_form(self,gamename,coord):
|
||||||
"""
|
"""
|
||||||
|
@ -150,6 +117,7 @@ class PlayGame:
|
||||||
gobandict["name"] = gamename
|
gobandict["name"] = gamename
|
||||||
gobandict["turn_number"] = turn
|
gobandict["turn_number"] = turn
|
||||||
gobandict["sgf"] = sgf
|
gobandict["sgf"] = sgf
|
||||||
|
settings = {}
|
||||||
if (gobandict[position] == 0): #empty field
|
if (gobandict[position] == 0): #empty field
|
||||||
if gnugo.is_legal(gobandict,position): #gnugo says the move is ok
|
if gnugo.is_legal(gobandict,position): #gnugo says the move is ok
|
||||||
#let gnugo make the above move, let gnugo write move to file
|
#let gnugo make the above move, let gnugo write move to file
|
||||||
|
@ -160,7 +128,9 @@ class PlayGame:
|
||||||
mygame.set_time()
|
mygame.set_time()
|
||||||
return ""
|
return ""
|
||||||
else: #move not ok
|
else: #move not ok
|
||||||
return "This is not a legal move (says Gnugo)."
|
settings["Data.Message"] = "This is not a legal move (says Gnugo)."
|
||||||
|
return self.display_goban(gamename,settings)
|
||||||
else: #position not empty
|
else: #position not empty
|
||||||
return "Could not make move: Field not empty."
|
settings["Data.Message"] = "Could not make move: Field not empty."
|
||||||
|
return self.display_goban(gamename,settings)
|
||||||
index.exposed = True
|
index.exposed = True
|
Loading…
Reference in a new issue