X-Git-Url: https://git.ucc.asn.au/?p=progcomp2013.git;a=blobdiff_plain;f=qchess%2Fsrc%2Fgame.py;h=de2439bf6732e739576929409744ea174b97dabc;hp=66b782fc31d2919ef3745e10b90137ec1c8f5531;hb=a238aa7acac990bae67644d1dc7f518ce3e2e8c6;hpb=09f14db7cb807613930260c6645b82eabd1e9517 diff --git a/qchess/src/game.py b/qchess/src/game.py index 66b782f..de2439b 100644 --- a/qchess/src/game.py +++ b/qchess/src/game.py @@ -176,6 +176,8 @@ class ReplayThread(GameThread): self.board.pieces = pieces self.board.king = king self.board.grid = grid + + # Update the player's boards def run(self): move_count = 0 @@ -207,33 +209,56 @@ class ReplayThread(GameThread): self.stop() break + log(move) + target = self.board.grid[x][y] + with self.lock: + if target.colour == "white": + self.state["turn"] = self.players[0] + else: + self.state["turn"] = self.players[1] move_piece = (tokens[2] == "->") - if move_piece: [x2,y2] = map(int, tokens[len(tokens)-2:]) - log(move) - self.board.update(move) + if isinstance(graphics, GraphicsThread): + with graphics.lock: + graphics.state["select"] = target + + if not move_piece: + self.board.update_select(x, y, int(tokens[2]), tokens[len(tokens)-1]) + if isinstance(graphics, GraphicsThread): + with graphics.lock: + graphics.state["moves"] = self.board.possible_moves(target) + time.sleep(turn_delay) + else: + self.board.update_move(x, y, x2, y2) + if isinstance(graphics, GraphicsThread): + with graphics.lock: + graphics.state["moves"] = [[x2,y2]] + time.sleep(turn_delay) + with graphics.lock: + graphics.state["select"] = None + graphics.state["moves"] = None + graphics.state["dest"] = None + + + + + for p in self.players: p.update(move) line = self.src.readline().strip(" \r\n") - if isinstance(graphics, GraphicsThread): - with self.lock: - if target.colour == "white": - self.state["turn"] = self.players[0] - else: - self.state["turn"] = self.players[1] + + + + + - with graphics.lock: - graphics.state["select"] = target - if move_piece: - graphics.state["moves"] = [[x2, y2]] - elif target.current_type != "unknown": - graphics.state["moves"] = self.board.possible_moves(target) +