Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrés Ambrois <andresambrois@gmail.com>2008-09-11 05:47:47 (GMT)
committer Andrés Ambrois <andresambrois@gmail.com>2008-09-11 05:47:47 (GMT)
commit629fe20da1281cd4fe82ca491ec96cf823b28db3 (patch)
tree69bbded896862f1c885ed9a18fad56ec844dffbb
parent945fc1978d1b4ac2fdf712bd6d37e539cb843bd1 (diff)
Mark territories at game end with pretty crosses. Update TODO
Modified patch by Nate Ridderman
-rw-r--r--TODO2
-rw-r--r--activity.py14
-rw-r--r--boardwidget.py35
-rw-r--r--gogame.py4
4 files changed, 44 insertions, 11 deletions
diff --git a/TODO b/TODO
index 97fe2ec..a8cd49c 100644
--- a/TODO
+++ b/TODO
@@ -1,8 +1,6 @@
TODO:
- Support spectators
- Add a pretty panel to display who's turn it is, and who is spectating
- - Stop the game after two passes, and detect a winner.
- Add Atari Go mode.
- Add a 'Help' button that will take you to the PlayGo wiki page.
- - Integrate with GnuGO
- Add different types of Ko and different rulesets.
diff --git a/activity.py b/activity.py
index b71adcd..ed30754 100644
--- a/activity.py
+++ b/activity.py
@@ -298,6 +298,7 @@ class PlayGo(Activity):
self.PlayerColor = 'B'
self.pass_count = 0
self.game.clear()
+ self.board.territories = None
self.board.status = self.game.status
self.board.do_expose_event()
self.show_score()
@@ -307,12 +308,14 @@ class PlayGo(Activity):
self.ai.clear()
def game_end(self):
- # TODO: Mark captured territories with pretty symbols
self.board.set_sensitive(False)
self.buttons_box.set_sensitive(False)
territories = self.game.get_territories()
- final_score = {'B':(len(territories['B']) - self.game.get_score()['W']),
+ self.board.territories = territories
+
+ final_score = {'B':(len(territories['B']) - self.game.get_score()['W']),
'W':(len(territories['W']) - self.game.get_score()['B'] + self.komi)}
+
if final_score['B'] > final_score['W']:
winner_string = _('Black wins!')
elif final_score['W'] > final_score['B']:
@@ -320,8 +323,7 @@ class PlayGo(Activity):
else:
winner_string = _('There was a tie!')
self.infopanel.show(_('Game ended! %s' % winner_string))
- self.infopanel.show_score(_('Final score: White %(W)d - Black %(B)d' % final_score))
-
+ self.infopanel.show_score(_('Final score: White %(W)d - Black %(B)d' % final_score))
def board_size_change(self, widget, size):
if size == self.size:
@@ -353,8 +355,8 @@ class PlayGo(Activity):
self._alert(_('AI'), _('PlayGo AI Deactivated'))
def notify_ai(self, x, y, color):
- logger.debug('Notifying AI of play by %s at %s x %s', color, x, y)
- self.ai.make_play(color, x, y)
+ logger.debug('Notifying AI of play by %s at %s x %s', color, x, y)
+ self.ai.make_play(color, x, y)
def play_ai(self):
if self.get_currentcolor() == self.get_playercolor():
diff --git a/boardwidget.py b/boardwidget.py
index 82cad61..9382092 100644
--- a/boardwidget.py
+++ b/boardwidget.py
@@ -31,14 +31,15 @@ class GoBoardWidget(gtk.Widget):
'insert-requested': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (gobject.TYPE_INT, gobject.TYPE_INT)),
}
+ #TODO: this should default to DEFAULT_SIZE, not 19, but this is defined in activity.py not here
def __init__(self, status, size=19):
gtk.Widget.__init__(self)
self.status = status
self.size = size
-
self.lastX = -1
self.lastY = -1
+ self.territories = None
def do_realize(self):
@@ -167,6 +168,10 @@ class GoBoardWidget(gtk.Widget):
self.draw_lines()
#Draw the stones
self.draw_stones(self.status)
+ #Draw scored terriotires if they exist (end of game)
+ if self.territories:
+ self.draw_scored_territories(self.territories)
+
def get_mouse_event_xy(self, event):
"""
@@ -224,7 +229,35 @@ class GoBoardWidget(gtk.Widget):
def draw_stones(self, status):
for x in status.keys():
self.draw_stone(x[0], x[1], status[x], self)
+
+ #TODO: right now the stone image is aliased to the background color, so this ends up looking a bit funky
+ #one fix would be to use non-aliased stone images, and let cairo alias them for us (can it?)
+ def draw_scored_territory(self, x, y, color, widget):
+ x = x + 1
+ y = y + 1
+ ctx = self.window.cairo_create()
+
+ if color == 'B':
+ ctx.set_source_rgba(0, 0, 0, 1)
+ else:
+ ctx.set_source_rgba(0xff, 0xff, 0xff, 1)
+ ctx.set_line_width(4)
+ # Horizontal mark
+ ctx.move_to(self.unit*x - self.unit/4, self.unit*y)
+ ctx.line_to(self.unit*x + self.unit/4, self.unit*y)
+
+ # Vertical mark
+ ctx.move_to(self.unit*x, self.unit*y - self.unit/4)
+ ctx.line_to(self.unit*x, self.unit*y + self.unit/4)
+
+ ctx.stroke()
+
+ def draw_scored_territories(self, territories):
+ for color in territories.keys():
+ for n in territories[color]:
+ self.draw_scored_territory(n[0], n[1], color, self)
+
def redraw_area(self, x, y):
x, y = self.get_pixel_from_coordinates(x, y)
self.window.invalidate_rect(gtk.gdk.Rectangle(int(x - self.unit/2), int(y - self.unit/2), int(self.unit), int(self.unit)), False)
diff --git a/gogame.py b/gogame.py
index fa8e705..894952f 100644
--- a/gogame.py
+++ b/gogame.py
@@ -191,10 +191,10 @@ class GoGame:
for current_element in current_group:
for x in self.neighbors(current_element):
if self.status.has_key(x):
- if self.status[x] != color:
+ if self.status[x] != color:
return None
elif not x in current_group:
- current_group.append(x)
+ current_group.append(x)
return set(current_group)
groups = {'B':set(), 'W':set()}