Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZach Stephens <zxs3926@rit.edu>2011-05-20 16:02:59 (GMT)
committer Zach Stephens <zxs3926@rit.edu>2011-05-20 16:02:59 (GMT)
commit76f1481b3b12c725a28eacc61d9ff35ac8f42c2d (patch)
treef2b82d81961de79173a0effab33674927acfc316
parent3bf559404826b29a76f4dfb87286a7e66b2b4a8f (diff)
Occupied pieces with editing marks have been added. Toolbar buttons changed to make the editor be more connected to the game than independent. Board widget modified to add the new pixel buffers, gogame modified to ignore editing pieces, and activity modified to make the basics of the editor work.HEADmaster
-rw-r--r--MANIFEST8
-rw-r--r--activity.py489
-rw-r--r--boardwidget.py36
-rw-r--r--edittoolbar.py63
-rw-r--r--gogame.py13
-rw-r--r--images/CircleBlackOccupied.gifbin0 -> 1551 bytes
-rw-r--r--images/CircleWhiteOccupied.gifbin0 -> 1465 bytes
-rw-r--r--images/SquareBlackOccupied.gifbin0 -> 1537 bytes
-rw-r--r--images/SquareWhiteOccupied.gifbin0 -> 1473 bytes
-rw-r--r--images/TriangleBlackOccupied.gifbin0 -> 1569 bytes
-rw-r--r--images/TriangleWhiteOccupied.gifbin0 -> 1469 bytes
-rw-r--r--images/XBlackOccupied.gifbin0 -> 1547 bytes
-rw-r--r--images/XWhiteOccupied.gifbin0 -> 1446 bytes
13 files changed, 319 insertions, 290 deletions
diff --git a/MANIFEST b/MANIFEST
index c6ad863..170a5cd 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -26,6 +26,14 @@ images/CircleBlack.gif
images/SquareBlack.gif
images/CircleWhite.gif
images/XBlack.gif
+images/XWhiteOccupied.gif
+images/TriangleBlackOccupied.gif
+images/SquareWhiteOccupied.gif
+images/TriangleWhiteOccupied.gif
+images/CircleBlackOccupied.gif
+images/SquareBlackOccupied.gif
+images/CircleWhiteOccupied.gif
+images/XBlackOccupied.gif
bin/gnugo
bin/README
bin/COPYING
diff --git a/activity.py b/activity.py
index 2868d62..7c283d5 100644
--- a/activity.py
+++ b/activity.py
@@ -56,6 +56,11 @@ class PlayGo(Activity):
self.script = ["", "This is the main board for a game of Go.", "There are three different board sizes to choose from; 9 x 9, 13 x 13, and 19 x 19.", "This game is played by placing stones down on the board.", "One person has black stones, and the other has white stones.", "To place a stone, move your mouse to the where you want to put the stone and click.", "Territories are created when you place stones of your color near other stones.", "If empty places on the board are surrounded by your pieces alone, then it counts as your territory.", "Scoring is based on a lot of different things.", "During the game, your score increases based on the amount of pieces you capture that are your opponents.", "When the game ends, territory is also added to these scores.", "A liberty is when there is a blank space next to one of your pieces.", "In this example, the black piece has four liberties.", "Those liberties are shown by the four squares around the piece.", "At one time, a piece can only have four liberties.", "To capture an opponents piece, it must have no more liberties.", "In this example, the black piece would be captured if white placed a piece where the triangle is.", "This would give white one point.", "Seki is a situation where both players share liberties.", "In this example, the black and white pieces share the two liberties that have circles in them.", "It is recommended for neither player to place pieces in those spots, because the other opponent could then capture the other player's pieces.", "Ko is a situation which prevents a game from going on forever.", "The example above shows a normal ko situation.", "If white were to place a piece where the X is, then it would capture the black piece.", "Black can't place a piece back in the same place though, since it would allow black and white capture the same pieces over and over.", "Superko is similar to ko, but on a larger scale.", "The superko rule states that the board can't be brought back to a previous position.", "This can happen when there is many ko's on the board, and players could keep capturing them forever.", "In the example above, there are two ko's that could be captured over and over, causing a superko.", "Life and death are important things to consider in Go.", "When some of your pieces become surrounded, then they are considered to be dead.", "This is because they could be captured at any time.", "It is important to know when a group of pieces are dead, since it will let you place pieces where they may be more useful.", "A ko fight is when two players challenge each other with their kos.", "When fighting, they will place pieces that will give them advantage as long as the opponent doesn't stop them.", "In this example, a white piece was taken where the circle was.", "During white's turn they then place the white piece with the x, which gives the black player a choice.", "They can either place a spot where the circle is, or stop the white player from having territory that won't be capturable.", "Semeai, or \"Capture Race\", is when there is a mutual capturing contest between the two players.", "These situations are usually won by whomever moves first in the race, since they tend to involve the same amount of moves on both sides.", "The current board is a common example of semeai.", "Sente and gote are terms for who has initiative at a current time.", "Sente means that you are making the first move, which the opponent may then have to respond to.", "Gote is the direct opposite, where you have to play a piece in respose to your opponent's move.", "In this example, black has played at x in sente.", "This places white in gote, where they must respond where the circle is or they will lose their pieces eventually.", "It's important to know when you have initiative in the game, since it will commonly exchange between the players.", "Maintaining sente and keeping out of gote will give you a higher chance of winning, since you will be able to make your opponent play where you want them to play.", "The game ends with both players have passed in the same turn.", "When that happens, each player's score is settled.", "First, the pieces that were captured by each player are counted.", "Then, the score of each player's territories are added to their scores.", "Finally, the komi (a point handicap given for playing second) is added to the white player.", "Whomever has the higher score after this is the winner!"]
self.next_script_frame = [0,1,3,6,8,11,15,18,21,25,29,33,38,41,48]
+
+ self.is_editing = 0
+ self.edit_type = 0
+ self.edit_status = { }
+
# Set the activity toolbox
toolbox = ActivityToolbox(self)
self.set_toolbox(toolbox)
@@ -80,8 +85,7 @@ class PlayGo(Activity):
# Set the editor toolbox
self.editToolbar = EditToolbar(self)
toolbox.add_toolbar(_('Editor'), self.editToolbar)
- self.editToolbar.connect('add-black', self.add_black_cb)
- self.editToolbar.connect('add-white', self.add_white_cb)
+ self.editToolbar.connect('edit', self.edit_cb)
self.editToolbar.connect('add-x', self.add_x_cb)
self.editToolbar.connect('add-circle', self.add_circle_cb)
self.editToolbar.connect('add-triangle', self.add_triangle_cb)
@@ -102,6 +106,10 @@ class PlayGo(Activity):
self.tutorialToolbar.grey_out_previous()
self.tutorialToolbar.grey_out_next()
self.tutorialToolbar.grey_out_category()
+ self.editToolbar.grey_out_add_x()
+ self.editToolbar.grey_out_add_triangle()
+ self.editToolbar.grey_out_add_circle()
+ self.editToolbar.grey_out_add_square()
if not handle.object_id:
self.infopanel.show(_('Welcome to PlayGo!'))
@@ -180,58 +188,191 @@ class PlayGo(Activity):
self.show_all()
def insert_cb(self, widget, x, y, announce=True, ai_play=False):
- ''' The insert function. It makes the play and manages turn changing
- stone drawing, etc.
+
+ if self.is_editing == 0:
+ ''' The insert function. It makes the play and manages turn changing
+ stone drawing, etc.
- Parameters x and y are the coordinates of the play ((0,0) is top left),
- widget points to the widget that emitted the signal connected to this
- function, announce is True when we need to announce this play to
- other people collaborating, and ai_play is True when this is called
- by the AI, so we know not to ask for an AI play again '''
-
- # Check if it's our turn only if it's a local play (announce is True)
- # Calls by other players will always be out of turn for us.
- if announce and self.get_currentcolor() != self.get_playercolor():
- logger.debug('Play at %s x %s was out-of-turn!', x, y)
- self.infopanel.show(_('It\'s not your turn!'))
- return False
- # Make the play only if it wasn't a pass move.
- if x != -1:
- self.pass_count = 0
- error = self.game.illegal(x, y, self.get_currentcolor())
- if error:
- self.infopanel.show(error)
+ Parameters x and y are the coordinates of the play ((0,0) is top left),
+ widget points to the widget that emitted the signal connected to this
+ function, announce is True when we need to announce this play to
+ other people collaborating, and ai_play is True when this is called
+ by the AI, so we know not to ask for an AI play again '''
+
+
+
+ # Check if it's our turn only if it's a local play (announce is True)
+ # Calls by other players will always be out of turn for us.
+ if announce and self.get_currentcolor() != self.get_playercolor():
+ logger.debug('Play at %s x %s was out-of-turn!', x, y)
+ self.infopanel.show(_('It\'s not your turn!'))
return False
- # Make the play
- captures = self.game.play((x, y), self.get_currentcolor())
- if self.ai_activated and not ai_play:
- self.notify_ai(x, y, self.get_currentcolor())
- self.gameToolbar.grey_out_size_change()
- if captures: self.redraw_captures(captures)
- self.show_score()
- self.board.draw_stone(x, y, self.get_currentcolor(), widget)
- # Player passed
+ # Make the play only if it wasn't a pass move.
+ if x != -1:
+ self.pass_count = 0
+ error = self.game.illegal(x, y, self.get_currentcolor())
+ if error:
+ self.infopanel.show(error)
+ return False
+ # Make the play
+ captures = self.game.play((x, y), self.get_currentcolor())
+ if self.ai_activated and not ai_play:
+ self.notify_ai(x, y, self.get_currentcolor())
+ self.gameToolbar.grey_out_size_change()
+ if captures: self.redraw_captures(captures)
+ self.show_score()
+ self.board.draw_stone(x, y, self.get_currentcolor(), widget)
+ # Player passed
+ else:
+ self.pass_count += 1
+ # Announce the local play
+ if self.get_shared() and announce:
+ self.collaboration.Play(x, y)
+ self.change_turn()
+ if x == -1:
+ self.infopanel.show(_('Opponent passed'))
+ # If this is the second consecutive pass, the game ends
+ if self.pass_count == 2:
+ self.game_end()
+ return
+ # If we are playing a local game with AI turned off, change the color
+ if not self.get_shared() and not self.ai_activated:
+ self.change_player_color()
+ # Else, if the AI is on, and this wasn't played by it, request a play by it.
+ elif self.ai_activated:
+ self.change_player_color()
+ if not ai_play:
+ self.play_ai()
+
+ self.edit_status = self.game.status
else:
- self.pass_count += 1
- # Announce the local play
- if self.get_shared() and announce:
- self.collaboration.Play(x, y)
- self.change_turn()
- if x == -1:
- self.infopanel.show(_('Opponent passed'))
- # If this is the second consecutive pass, the game ends
- if self.pass_count == 2:
- self.game_end()
- return
- # If we are playing a local game with AI turned off, change the color
- if not self.get_shared() and not self.ai_activated:
- self.change_player_color()
- # Else, if the AI is on, and this wasn't played by it, request a play by it.
- elif self.ai_activated:
- self.change_player_color()
- if not ai_play:
- self.play_ai()
+ if self.edit_type == 0:
+ if not self.board.status.has_key((x, y)):
+ self.board.status[(x,y)] = 'X'
+ elif self.board.status[(x,y)] == 'B':
+ self.board.status[(x,y)] = 'E'
+ elif self.board.status[(x,y)] == 'W':
+ self.board.status[(x,y)] = 'F'
+ elif self.board.status[(x,y)] == 'X':
+ del self.board.status[(x,y)]
+ elif self.board.status[(x,y)] == 'T':
+ self.board.status[(x,y)] = 'X'
+ elif self.board.status[(x,y)] == 'C':
+ self.board.status[(x,y)] = 'X'
+ elif self.board.status[(x,y)] == 'S':
+ self.board.status[(x,y)] = 'X'
+ elif self.board.status[(x,y)] == 'E':
+ self.board.status[(x,y)] = 'B'
+ elif self.board.status[(x,y)] == 'F':
+ self.board.status[(x,y)] = 'W'
+ elif self.board.status[(x,y)] == 'G':
+ self.board.status[(x,y)] = 'E'
+ elif self.board.status[(x,y)] == 'H':
+ self.board.status[(x,y)] = 'F'
+ elif self.board.status[(x,y)] == 'I':
+ self.board.status[(x,y)] = 'E'
+ elif self.board.status[(x,y)] == 'J':
+ self.board.status[(x,y)] = 'F'
+ elif self.board.status[(x,y)] == 'K':
+ self.board.status[(x,y)] = 'E'
+ else:
+ self.board.status[(x,y)] = 'F'
+ elif self.edit_type == 2:
+ if not self.board.status.has_key((x, y)):
+ self.board.status[(x,y)] = 'T'
+ elif self.board.status[(x,y)] == 'B':
+ self.board.status[(x,y)] = 'G'
+ elif self.board.status[(x,y)] == 'W':
+ self.board.status[(x,y)] = 'H'
+ elif self.board.status[(x,y)] == 'X':
+ self.board.status[(x,y)] = 'T'
+ elif self.board.status[(x,y)] == 'T':
+ del self.board.status[(x,y)]
+ elif self.board.status[(x,y)] == 'C':
+ self.board.status[(x,y)] = 'T'
+ elif self.board.status[(x,y)] == 'S':
+ self.board.status[(x,y)] = 'T'
+ elif self.board.status[(x,y)] == 'E':
+ self.board.status[(x,y)] = 'G'
+ elif self.board.status[(x,y)] == 'F':
+ self.board.status[(x,y)] = 'H'
+ elif self.board.status[(x,y)] == 'G':
+ self.board.status[(x,y)] = 'B'
+ elif self.board.status[(x,y)] == 'H':
+ self.board.status[(x,y)] = 'W'
+ elif self.board.status[(x,y)] == 'I':
+ self.board.status[(x,y)] = 'G'
+ elif self.board.status[(x,y)] == 'J':
+ self.board.status[(x,y)] = 'H'
+ elif self.board.status[(x,y)] == 'K':
+ self.board.status[(x,y)] = 'G'
+ else:
+ self.board.status[(x,y)] = 'H'
+ elif self.edit_type == 1:
+ if not self.board.status.has_key((x, y)):
+ self.board.status[(x,y)] = 'C'
+ elif self.board.status[(x,y)] == 'B':
+ self.board.status[(x,y)] = 'I'
+ elif self.board.status[(x,y)] == 'W':
+ self.board.status[(x,y)] = 'J'
+ elif self.board.status[(x,y)] == 'X':
+ self.board.status[(x,y)] = 'C'
+ elif self.board.status[(x,y)] == 'T':
+ self.board.status[(x,y)] = 'C'
+ elif self.board.status[(x,y)] == 'C':
+ del self.board.status[(x,y)]
+ elif self.board.status[(x,y)] == 'S':
+ self.board.status[(x,y)] = 'C'
+ elif self.board.status[(x,y)] == 'E':
+ self.board.status[(x,y)] = 'I'
+ elif self.board.status[(x,y)] == 'F':
+ self.board.status[(x,y)] = 'J'
+ elif self.board.status[(x,y)] == 'G':
+ self.board.status[(x,y)] = 'I'
+ elif self.board.status[(x,y)] == 'H':
+ self.board.status[(x,y)] = 'J'
+ elif self.board.status[(x,y)] == 'I':
+ self.board.status[(x,y)] = 'B'
+ elif self.board.status[(x,y)] == 'J':
+ self.board.status[(x,y)] = 'W'
+ elif self.board.status[(x,y)] == 'K':
+ self.board.status[(x,y)] = 'I'
+ else:
+ self.board.status[(x,y)] = 'J'
+ else:
+ if not self.board.status.has_key((x, y)):
+ self.board.status[(x,y)] = 'S'
+ elif self.board.status[(x,y)] == 'B':
+ self.board.status[(x,y)] = 'K'
+ elif self.board.status[(x,y)] == 'W':
+ self.board.status[(x,y)] = 'L'
+ elif self.board.status[(x,y)] == 'X':
+ self.board.status[(x,y)] = 'S'
+ elif self.board.status[(x,y)] == 'T':
+ self.board.status[(x,y)] = 'S'
+ elif self.board.status[(x,y)] == 'C':
+ self.board.status[(x,y)] = 'S'
+ elif self.board.status[(x,y)] == 'S':
+ del self.board.status[(x,y)]
+ elif self.board.status[(x,y)] == 'E':
+ self.board.status[(x,y)] = 'K'
+ elif self.board.status[(x,y)] == 'F':
+ self.board.status[(x,y)] = 'L'
+ elif self.board.status[(x,y)] == 'G':
+ self.board.status[(x,y)] = 'K'
+ elif self.board.status[(x,y)] == 'H':
+ self.board.status[(x,y)] = 'L'
+ elif self.board.status[(x,y)] == 'I':
+ self.board.status[(x,y)] = 'K'
+ elif self.board.status[(x,y)] == 'J':
+ self.board.status[(x,y)] = 'L'
+ elif self.board.status[(x,y)] == 'K':
+ self.board.status[(x,y)] = 'B'
+ else:
+ self.board.status[(x,y)] = 'W'
+ self.board.do_expose_event()
+
def undo_cb(self, widget=None, data=None):
if self.game.undo():
self.board.queue_draw()
@@ -354,6 +495,7 @@ class PlayGo(Activity):
self.CurrentColor = 'B'
self.PlayerColor = 'B'
self.pass_count = 0
+ self.edit_status = { }
self.game.clear()
self.board.territories = None
self.board.status = self.game.status
@@ -366,6 +508,13 @@ class PlayGo(Activity):
self.tutorialToolbar.grey_out_next()
self.tutorialToolbar.grey_out_category()
self.tutorialToolbar.activate_begin()
+ self.editToolbar.activate_edit()
+ self.editToolbar.grey_out_add_x()
+ self.editToolbar.grey_out_add_square()
+ self.editToolbar.grey_out_add_circle()
+ self.editToolbar.grey_out_add_triangle()
+ self.editToolbar.activate_save()
+ self.editToolbar.activate_load()
self.gameToolbar.activate_size_change()
self.gameToolbar.activate_ai()
self.current_tutorial = 0;
@@ -486,6 +635,13 @@ class PlayGo(Activity):
self.tutorialToolbar.activate_previous()
self.tutorialToolbar.activate_next()
self.tutorialToolbar.activate_category()
+ self.editToolbar.grey_out_edit()
+ self.editToolbar.grey_out_add_x()
+ self.editToolbar.grey_out_add_square()
+ self.editToolbar.grey_out_add_circle()
+ self.editToolbar.grey_out_add_triangle()
+ self.editToolbar.grey_out_save()
+ self.editToolbar.grey_out_load()
self.infopanel.show(self.script[0])
@@ -507,178 +663,6 @@ class PlayGo(Activity):
self.board.set_sensitive(False)
self.buttons_box.set_sensitive(False)
self.board.territories = None
- if self.current_tutorial == 1:
- self.game.clear()
- elif self.current_tutorial == 3:
- self.game.clear()
- elif self.current_tutorial == 6:
- self.game.clear()
- self.game.status[(7,0)] = 'B'
- self.game.status[(8,1)] = 'B'
- self.game.status[(9,1)] = 'B'
- self.game.status[(10,1)] = 'B'
- self.game.status[(11,1)] = 'B'
- self.game.status[(12,0)] = 'B'
- self.game.status[(0,7)] = 'B'
- self.game.status[(0,1)] = 'W'
- self.game.status[(1,2)] = 'W'
- self.game.status[(1,3)] = 'W'
- self.game.status[(1,4)] = 'W'
- self.game.status[(1,5)] = 'W'
- self.game.status[(1,6)] = 'W'
- elif self.current_tutorial == 8:
- self.game.status = self.game.status
- elif self.current_tutorial == 11:
- self.game.clear()
- self.game.status[(11,4)] = 'B'
- self.game.status[(10,4)] = 'S'
- self.game.status[(12,4)] = 'S'
- self.game.status[(11,3)] = 'S'
- self.game.status[(11,5)] = 'S'
- elif self.current_tutorial == 15:
- self.game.clear()
- self.game.status[(9,3)] = 'B'
- self.game.status[(8,4)] = 'B'
- self.game.status[(15,9)] = 'B'
- self.game.status[(15,10)] = 'B'
- self.game.status[(8,3)] = 'W'
- self.game.status[(8,5)] = 'W'
- self.game.status[(9,4)] = 'W'
- self.game.status[(7,4)] = 'T'
- elif self.current_tutorial == 18:
- self.game.clear()
- self.game.status[(8,2)] = 'B'
- self.game.status[(9,1)] = 'B'
- self.game.status[(9,0)] = 'B'
- self.game.status[(7,0)] = 'W'
- self.game.status[(7,1)] = 'W'
- self.game.status[(7,2)] = 'W'
- self.game.status[(8,0)] = 'C'
- self.game.status[(8,1)] = 'C'
- elif self.current_tutorial == 21:
- self.game.clear()
- self.game.status[(9,9)] = 'B'
- self.game.status[(10,8)] = 'B'
- self.game.status[(10,10)] = 'B'
- self.game.status[(11,9)] = 'B'
- self.game.status[(9,8)] = 'W'
- self.game.status[(9,10)] = 'W'
- self.game.status[(8,9)] = 'W'
- self.game.status[(10,9)] = 'X'
- elif self.current_tutorial == 25:
- self.game.clear()
- self.game.status[(9,9)] = 'B'
- self.game.status[(10,8)] = 'B'
- self.game.status[(10,10)] = 'B'
- self.game.status[(11,9)] = 'B'
- self.game.status[(9,12)] = 'B'
- self.game.status[(9,14)] = 'B'
- self.game.status[(8,13)] = 'B'
- self.game.status[(9,8)] = 'W'
- self.game.status[(9,10)] = 'W'
- self.game.status[(8,9)] = 'W'
- self.game.status[(9,13)] = 'W'
- self.game.status[(10,12)] = 'W'
- self.game.status[(10,14)] = 'W'
- self.game.status[(11,13)] = 'W'
- elif self.current_tutorial == 29:
- self.game.clear()
- self.game.status[(7,0)] = 'B'
- self.game.status[(8,0)] = 'B'
- self.game.status[(8,1)] = 'B'
- self.game.status[(9,0)] = 'B'
- self.game.status[(9,1)] = 'B'
- self.game.status[(9,2)] = 'B'
- self.game.status[(10,1)] = 'B'
- self.game.status[(10,2)] = 'B'
- self.game.status[(11,0)] = 'B'
- self.game.status[(11,1)] = 'B'
- self.game.status[(12,0)] = 'B'
- self.game.status[(6,0)] = 'W'
- self.game.status[(7,1)] = 'W'
- self.game.status[(7,2)] = 'W'
- self.game.status[(8,3)] = 'W'
- self.game.status[(9,3)] = 'W'
- self.game.status[(10,3)] = 'W'
- self.game.status[(11,2)] = 'W'
- self.game.status[(12,2)] = 'W'
- self.game.status[(12,1)] = 'W'
- self.game.status[(13,1)] = 'W'
- self.game.status[(13,0)] = 'W'
- elif self.current_tutorial == 33:
- self.game.clear()
- self.game.status[(10,16)] = 'B'
- self.game.status[(10,17)] = 'B'
- self.game.status[(11,15)] = 'B'
- self.game.status[(11,17)] = 'B'
- self.game.status[(11,18)] = 'B'
- self.game.status[(12,16)] = 'B'
- self.game.status[(12,17)] = 'B'
- self.game.status[(12,18)] = 'B'
- self.game.status[(13,16)] = 'B'
- self.game.status[(13,17)] = 'B'
- self.game.status[(14,18)] = 'B'
- self.game.status[(2,18)] = 'W'
- self.game.status[(3,18)] = 'W'
- self.game.status[(3,17)] = 'W'
- self.game.status[(4,16)] = 'W'
- self.game.status[(5,17)] = 'W'
- self.game.status[(6,17)] = 'W'
- self.game.status[(7,17)] = 'W'
- self.game.status[(7,18)] = 'W'
- self.game.status[(8,18)] = 'W'
- self.game.status[(4,18)] = 'T'
- self.game.status[(11,16)] = 'C'
- self.game.status[(5,18)] = 'S'
- elif self.current_tutorial == 38:
- self.game.clear()
- self.game.status[(7,0)] = 'B'
- self.game.status[(7,1)] = 'B'
- self.game.status[(7,2)] = 'B'
- self.game.status[(7,3)] = 'B'
- self.game.status[(7,4)] = 'B'
- self.game.status[(8,5)] = 'B'
- self.game.status[(9,5)] = 'B'
- self.game.status[(10,0)] = 'B'
- self.game.status[(10,1)] = 'B'
- self.game.status[(10,2)] = 'B'
- self.game.status[(10,3)] = 'B'
- self.game.status[(10,4)] = 'B'
- self.game.status[(9,0)] = 'W'
- self.game.status[(9,1)] = 'W'
- self.game.status[(9,2)] = 'W'
- self.game.status[(9,3)] = 'W'
- self.game.status[(9,4)] = 'W'
- self.game.status[(10,5)] = 'W'
- self.game.status[(11,5)] = 'W'
- self.game.status[(12,0)] = 'W'
- self.game.status[(12,1)] = 'W'
- self.game.status[(12,2)] = 'W'
- self.game.status[(12,3)] = 'W'
- self.game.status[(12,4)] = 'W'
- elif self.current_tutorial == 41:
- self.game.clear()
- self.game.status[(3,0)] = 'B'
- self.game.status[(3,1)] = 'B'
- self.game.status[(4,2)] = 'B'
- self.game.status[(5,2)] = 'B'
- self.game.status[(6,2)] = 'B'
- self.game.status[(7,2)] = 'B'
- self.game.status[(8,2)] = 'B'
- self.game.status[(9,1)] = 'B'
- self.game.status[(4,0)] = 'W'
- self.game.status[(4,1)] = 'W'
- self.game.status[(5,1)] = 'W'
- self.game.status[(6,0)] = 'W'
- self.game.status[(6,1)] = 'W'
- self.game.status[(7,1)] = 'W'
- self.game.status[(8,1)] = 'W'
- self.game.status[(8,0)] = 'C'
- self.game.status[(9,1)] = 'X'
- elif self.current_tutorial == 48:
- self.game.clear()
- else:
- self.game.status = self.game.status
self.board.status = self.game.status
self.board.do_expose_event()
@@ -862,7 +846,6 @@ class PlayGo(Activity):
self.game.status[(6,2)] = 'B'
self.game.status[(7,2)] = 'B'
self.game.status[(8,2)] = 'B'
- self.game.status[(9,1)] = 'B'
self.game.status[(4,0)] = 'W'
self.game.status[(4,1)] = 'W'
self.game.status[(5,1)] = 'W'
@@ -871,7 +854,7 @@ class PlayGo(Activity):
self.game.status[(7,1)] = 'W'
self.game.status[(8,1)] = 'W'
self.game.status[(8,0)] = 'C'
- self.game.status[(9,1)] = 'X'
+ self.game.status[(9,1)] = 'E'
elif self.current_tutorial == 48:
self.game.clear()
else:
@@ -885,53 +868,67 @@ class PlayGo(Activity):
# ----------- Editor Functions ------------------ #
- def add_black_cb(self, widget=None):
- self.editToolbar.grey_out_add_black()
- self.editToolbar.activate_add_white()
- self.editToolbar.activate_add_x()
- self.editToolbar.activate_add_circle()
- self.editToolbar.activate_add_triangle()
- self.editToolbar.activate_add_square()
- def add_white_cb(self, widget=None):
- self.editToolbar.grey_out_add_white()
- self.editToolbar.activate_add_black()
- self.editToolbar.activate_add_x()
- self.editToolbar.activate_add_circle()
- self.editToolbar.activate_add_triangle()
- self.editToolbar.activate_add_square()
+
+ def edit_cb(self, widget=None):
+ if self.is_editing == 0:
+ self.is_editing = 1
+ if self.edit_type == 0:
+ self.editToolbar.grey_out_add_x()
+ self.editToolbar.activate_add_circle()
+ self.editToolbar.activate_add_triangle()
+ self.editToolbar.activate_add_square()
+ elif self.edit_type == 1:
+ self.editToolbar.activate_add_x()
+ self.editToolbar.grey_out_add_circle()
+ self.editToolbar.activate_add_triangle()
+ self.editToolbar.activate_add_square()
+ elif self.edit_type == 2:
+ self.editToolbar.activate_add_x()
+ self.editToolbar.activate_add_circle()
+ self.editToolbar.grey_out_add_triangle()
+ self.editToolbar.activate_add_square()
+ else:
+ self.editToolbar.activate_add_x()
+ self.editToolbar.activate_add_circle()
+ self.editToolbar.activate_add_triangle()
+ self.editToolbar.grey_out_add_square()
+ else:
+ self.is_editing = 0
+ self.editToolbar.grey_out_add_x()
+ self.editToolbar.grey_out_add_circle()
+ self.editToolbar.grey_out_add_triangle()
+ self.editToolbar.grey_out_add_square()
+ self.board.status = self.edit_status
+ self.game.status = self.edit_status
def add_x_cb(self, widget=None):
self.editToolbar.grey_out_add_x()
- self.editToolbar.activate_add_white()
- self.editToolbar.activate_add_black()
+ self.edit_type = 0
self.editToolbar.activate_add_circle()
self.editToolbar.activate_add_triangle()
self.editToolbar.activate_add_square()
def add_circle_cb(self, widget=None):
self.editToolbar.grey_out_add_circle()
- self.editToolbar.activate_add_white()
+ self.edit_type = 1
self.editToolbar.activate_add_x()
- self.editToolbar.activate_add_black()
self.editToolbar.activate_add_triangle()
self.editToolbar.activate_add_square()
def add_triangle_cb(self, widget=None):
self.editToolbar.grey_out_add_triangle()
- self.editToolbar.activate_add_white()
+ self.edit_type = 2
self.editToolbar.activate_add_x()
self.editToolbar.activate_add_circle()
- self.editToolbar.activate_add_black()
self.editToolbar.activate_add_square()
def add_square_cb(self, widget=None):
self.editToolbar.grey_out_add_square()
- self.editToolbar.activate_add_white()
+ self.edit_type = 3
self.editToolbar.activate_add_x()
self.editToolbar.activate_add_circle()
self.editToolbar.activate_add_triangle()
- self.editToolbar.activate_add_black()
def save_cb(self, widget=None):
self.infopanel.show(_("To be implemented in the future!"))
diff --git a/boardwidget.py b/boardwidget.py
index 5c08532..7a1ba46 100644
--- a/boardwidget.py
+++ b/boardwidget.py
@@ -93,7 +93,14 @@ class GoBoardWidget(gtk.Widget):
self.TriangleWhitePixbuf = gtk.gdk.pixbuf_new_from_file("./images/TriangleWhite.gif")
self.SquareBlackPixbuf = gtk.gdk.pixbuf_new_from_file("./images/SquareBlack.gif")
self.SquareWhitePixbuf = gtk.gdk.pixbuf_new_from_file("./images/SquareWhite.gif")
-
+ self.XBlackOccupiedPixbuf = gtk.gdk.pixbuf_new_from_file("./images/XBlackOccupied.gif")
+ self.XWhiteOccupiedPixbuf = gtk.gdk.pixbuf_new_from_file("./images/XWhiteOccupied.gif")
+ self.CircleBlackOccupiedPixbuf = gtk.gdk.pixbuf_new_from_file("./images/CircleBlackOccupied.gif")
+ self.CircleWhiteOccupiedPixbuf = gtk.gdk.pixbuf_new_from_file("./images/CircleWhiteOccupied.gif")
+ self.TriangleBlackOccupiedPixbuf = gtk.gdk.pixbuf_new_from_file("./images/TriangleBlackOccupied.gif")
+ self.TriangleWhiteOccupiedPixbuf = gtk.gdk.pixbuf_new_from_file("./images/TriangleWhiteOccupied.gif")
+ self.SquareBlackOccupiedPixbuf = gtk.gdk.pixbuf_new_from_file("./images/SquareBlackOccupied.gif")
+ self.SquareWhiteOccupiedPixbuf = gtk.gdk.pixbuf_new_from_file("./images/SquareWhiteOccupied.gif")
self.gc = self.style.fg_gc[gtk.STATE_NORMAL]
@@ -183,7 +190,14 @@ class GoBoardWidget(gtk.Widget):
self.ScaledTriangleWhitePixbuf = self.TriangleWhitePixbuf.scale_simple( int(self.unit), int(self.unit), gtk.gdk.INTERP_BILINEAR )
self.ScaledSquareBlackPixbuf = self.SquareBlackPixbuf.scale_simple( int(self.unit), int(self.unit), gtk.gdk.INTERP_BILINEAR )
self.ScaledSquareWhitePixbuf = self.SquareWhitePixbuf.scale_simple( int(self.unit), int(self.unit), gtk.gdk.INTERP_BILINEAR )
-
+ self.ScaledXBlackOccupiedPixbuf = self.XBlackOccupiedPixbuf.scale_simple( int(self.unit), int(self.unit), gtk.gdk.INTERP_BILINEAR )
+ self.ScaledXWhiteOccupiedPixbuf = self.XWhiteOccupiedPixbuf.scale_simple( int(self.unit), int(self.unit), gtk.gdk.INTERP_BILINEAR )
+ self.ScaledCircleBlackOccupiedPixbuf = self.CircleBlackOccupiedPixbuf.scale_simple( int(self.unit), int(self.unit), gtk.gdk.INTERP_BILINEAR )
+ self.ScaledCircleWhiteOccupiedPixbuf = self.CircleWhiteOccupiedPixbuf.scale_simple( int(self.unit), int(self.unit), gtk.gdk.INTERP_BILINEAR )
+ self.ScaledTriangleBlackOccupiedPixbuf = self.TriangleBlackOccupiedPixbuf.scale_simple( int(self.unit), int(self.unit), gtk.gdk.INTERP_BILINEAR )
+ self.ScaledTriangleWhiteOccupiedPixbuf = self.TriangleWhiteOccupiedPixbuf.scale_simple( int(self.unit), int(self.unit), gtk.gdk.INTERP_BILINEAR )
+ self.ScaledSquareBlackOccupiedPixbuf = self.SquareBlackOccupiedPixbuf.scale_simple( int(self.unit), int(self.unit), gtk.gdk.INTERP_BILINEAR )
+ self.ScaledSquareWhiteOccupiedPixbuf = self.SquareWhiteOccupiedPixbuf.scale_simple( int(self.unit), int(self.unit), gtk.gdk.INTERP_BILINEAR )
#Draw the board
self.window.draw_drawable(self.gc, self.BoardPixmap, 0, 0, 0, 0, self.allocation.width, self.allocation.height)
@@ -264,8 +278,24 @@ class GoBoardWidget(gtk.Widget):
ct.set_source_pixbuf(self.ScaledCircleWhitePixbuf, self.unit*x - self.unit/2, self.unit*y - self.unit/2 )
elif color == 'S':
ct.set_source_pixbuf(self.ScaledSquareBlackPixbuf, self.unit*x - self.unit/2, self.unit*y - self.unit/2 )
- else:
+ elif color == 'R':
ct.set_source_pixbuf(self.ScaledSquareWhitePixbuf, self.unit*x - self.unit/2, self.unit*y - self.unit/2 )
+ elif color == 'E':
+ ct.set_source_pixbuf(self.ScaledXBlackOccupiedPixbuf, self.unit*x - self.unit/2, self.unit*y - self.unit/2 )
+ elif color == 'F':
+ ct.set_source_pixbuf(self.ScaledXWhiteOccupiedPixbuf, self.unit*x - self.unit/2, self.unit*y - self.unit/2 )
+ elif color == 'G':
+ ct.set_source_pixbuf(self.ScaledTriangleBlackOccupiedPixbuf, self.unit*x - self.unit/2, self.unit*y - self.unit/2 )
+ elif color == 'H':
+ ct.set_source_pixbuf(self.ScaledTriangleWhiteOccupiedPixbuf, self.unit*x - self.unit/2, self.unit*y - self.unit/2 )
+ elif color == 'I':
+ ct.set_source_pixbuf(self.ScaledCircleBlackOccupiedPixbuf, self.unit*x - self.unit/2, self.unit*y - self.unit/2 )
+ elif color == 'J':
+ ct.set_source_pixbuf(self.ScaledCircleWhiteOccupiedPixbuf, self.unit*x - self.unit/2, self.unit*y - self.unit/2 )
+ elif color == 'K':
+ ct.set_source_pixbuf(self.ScaledSquareBlackOccupiedPixbuf, self.unit*x - self.unit/2, self.unit*y - self.unit/2 )
+ else:
+ ct.set_source_pixbuf(self.ScaledSquareWhiteOccupiedPixbuf, self.unit*x - self.unit/2, self.unit*y - self.unit/2 )
ctx.paint()
diff --git a/edittoolbar.py b/edittoolbar.py
index 2c3a57d..ad356ef 100644
--- a/edittoolbar.py
+++ b/edittoolbar.py
@@ -30,8 +30,7 @@ class EditToolbar(gtk.Toolbar):
__gtype_name__ = 'EditToolbar'
__gsignals__ = {
- 'add-black': (SIGNAL_RUN_FIRST, TYPE_NONE, []),
- 'add-white': (SIGNAL_RUN_FIRST, TYPE_NONE, []),
+ 'edit': (SIGNAL_RUN_FIRST, TYPE_NONE, []),
'add-x': (SIGNAL_RUN_FIRST, TYPE_NONE, []),
'add-circle': (SIGNAL_RUN_FIRST, TYPE_NONE, []),
'add-triangle': (SIGNAL_RUN_FIRST, TYPE_NONE, []),
@@ -43,26 +42,14 @@ class EditToolbar(gtk.Toolbar):
def __init__(self, activity):
gtk.Toolbar.__init__(self)
self.activity = activity
-
- # Add Black Toggle Button
- add_black_icon = join(dirname(__file__), 'images', 'black.gif')
- add_black_image = gtk.Image()
- add_black_image.set_from_file(add_black_icon)
- self._add_black_button = ToolButton()
- self._add_black_button.set_icon_widget(add_black_image)
- self._add_black_button.connect('clicked', self._add_black_cb)
- self.insert(self._add_black_button, -1)
- self._add_black_button.show()
-
- # Add White Toggle Button
- add_white_icon = join(dirname(__file__), 'images', 'white.gif')
- add_white_image = gtk.Image()
- add_white_image.set_from_file(add_white_icon)
- self._add_white_button = ToolButton()
- self._add_white_button.set_icon_widget(add_white_image)
- self._add_white_button.connect('clicked', self._add_white_cb)
- self.insert(self._add_white_button, -1)
- self._add_white_button.show()
+ self._is_editing = 0
+
+ # Edit Button
+ self._edit_button = ToolButton()
+ self._edit_button.set_label(_('Edit'))
+ self._edit_button.connect('clicked', self._edit_cb)
+ self.insert(self._edit_button, -1)
+ self._edit_button.show()
# Separator
separator = gtk.SeparatorToolItem()
@@ -135,26 +122,22 @@ class EditToolbar(gtk.Toolbar):
widget.show()
self.insert(tool_item, -1)
tool_item.show()
-
- def _add_black_cb(self, widget):
- self._add_black_button.set_sensitive(False)
- self.emit('add-black')
-
- def activate_add_black(self):
- self._add_black_button.set_sensitive(True)
-
- def grey_out_add_black(self):
- self._add_black_button.set_sensitive(False)
-
- def _add_white_cb(self, widget):
- self._add_white_button.set_sensitive(False)
- self.emit('add-white')
- def activate_add_white(self):
- self._add_white_button.set_sensitive(True)
+ def _edit_cb(self, widget):
+ if self._is_editing == 0:
+ self._is_editing = 1
+ self._edit_button.set_label(_('Finished'))
+ else:
+ self._is_editing = 0
+ self._edit_button.set_label(_('Edit'))
+ self._edit_button.set_sensitive(True)
+ self.emit('edit')
+
+ def activate_edit(self):
+ self._edit_button.set_sensitive(True)
- def grey_out_add_white(self):
- self._add_white_button.set_sensitive(False)
+ def grey_out_edit(self):
+ self._edit_button.set_sensitive(False)
def _add_x_cb(self, widget):
self._add_x_button.set_sensitive(False)
diff --git a/gogame.py b/gogame.py
index ce674f2..acc1921 100644
--- a/gogame.py
+++ b/gogame.py
@@ -135,7 +135,16 @@ class GoGame:
def illegal(self, x, y, color):
""" Check if a play by color at pos would be an illigal move, and return pretty errors"""
if self.status.has_key((x, y)):
- return _('There already is a stone there!')
+ if self.status[(x,y)] == 'X':
+ del self.status[(x,y)]
+ elif self.status[(x,y)] == 'T':
+ del self.status[(x,y)]
+ elif self.status[(x,y)] == 'C':
+ del self.status[(x,y)]
+ elif self.status[(x,y)] == 'S':
+ del self.status[(x,y)]
+ else:
+ return _('There already is a stone there!')
if self.checkKo((x, y), color):
return _('Ko violation!')
@@ -175,6 +184,8 @@ class GoGame:
for y in self.neighbors(x):
if not self.status.has_key(y) and y != exc and y != pos: # found a liberty
return []
+ elif self.status.has_key(y) and (self.status[y] == 'X' or self.status[y] == 'C' or self.status[y] == 'T' or self.status[y] == 'S'):
+ return []
elif self.status.has_key(y) and self.status[y]==color \
and not y in newlyFound and not y in st: # found another stone of same color
n.append(y)
diff --git a/images/CircleBlackOccupied.gif b/images/CircleBlackOccupied.gif
new file mode 100644
index 0000000..d68ed94
--- /dev/null
+++ b/images/CircleBlackOccupied.gif
Binary files differ
diff --git a/images/CircleWhiteOccupied.gif b/images/CircleWhiteOccupied.gif
new file mode 100644
index 0000000..d9e2018
--- /dev/null
+++ b/images/CircleWhiteOccupied.gif
Binary files differ
diff --git a/images/SquareBlackOccupied.gif b/images/SquareBlackOccupied.gif
new file mode 100644
index 0000000..aee615d
--- /dev/null
+++ b/images/SquareBlackOccupied.gif
Binary files differ
diff --git a/images/SquareWhiteOccupied.gif b/images/SquareWhiteOccupied.gif
new file mode 100644
index 0000000..8ea55a3
--- /dev/null
+++ b/images/SquareWhiteOccupied.gif
Binary files differ
diff --git a/images/TriangleBlackOccupied.gif b/images/TriangleBlackOccupied.gif
new file mode 100644
index 0000000..b7410f7
--- /dev/null
+++ b/images/TriangleBlackOccupied.gif
Binary files differ
diff --git a/images/TriangleWhiteOccupied.gif b/images/TriangleWhiteOccupied.gif
new file mode 100644
index 0000000..55e5a69
--- /dev/null
+++ b/images/TriangleWhiteOccupied.gif
Binary files differ
diff --git a/images/XBlackOccupied.gif b/images/XBlackOccupied.gif
new file mode 100644
index 0000000..3560df7
--- /dev/null
+++ b/images/XBlackOccupied.gif
Binary files differ
diff --git a/images/XWhiteOccupied.gif b/images/XWhiteOccupied.gif
new file mode 100644
index 0000000..9419976
--- /dev/null
+++ b/images/XWhiteOccupied.gif
Binary files differ