From 09f14db7cb807613930260c6645b82eabd1e9517 Mon Sep 17 00:00:00 2001 From: Sam Moore Date: Wed, 30 Jan 2013 19:58:58 +0800 Subject: [PATCH] I think I just borked things... And then rewrote what I originally had anyway --- qchess/qchess.py | 28 +++++++++++++++++++++------- qchess/src/game.py | 26 ++++++++++++++++++++------ 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/qchess/qchess.py b/qchess/qchess.py index d2d0c23..5e3e5c5 100755 --- a/qchess/qchess.py +++ b/qchess/qchess.py @@ -1448,29 +1448,38 @@ class ReplayThread(GameThread): def reset_board(self, line): pieces = {"white" : [], "black" : []} king = {"white" : None, "black" : None} + grid = [[None] * w for _ in range(h)] for x in range(w): for y in range(h): self.board.grid[x][y] = None while line != "# Start game": + if line[0] == "#": + line = self.src.readline().strip(" \r\n") + continue + tokens = line.split(" ") [x, y] = map(int, tokens[len(tokens)-1].split(",")) current_type = tokens[1] - types = map(lambda e : e.strip("'[], "), tokens[2].split(",")) - - target = Piece(tokens[0], x, y, current_type) + types = map(lambda e : e.strip("'[], "), (tokens[2]+tokens[3]).split(",")) + + target = Piece(tokens[0], x, y, types) + target.current_type = current_type + try: target.choice = types.index(current_type) except: target.choice = -1 - pieces[token[0]].append(target) + pieces[tokens[0]].append(target) if target.current_type == "king": - king[token[0]] = target + king[tokens[0]] = target + grid[x][y] = target line = self.src.readline().strip(" \r\n") self.board.pieces = pieces self.board.king = king + self.board.grid = grid def run(self): move_count = 0 @@ -1491,8 +1500,11 @@ class ReplayThread(GameThread): line = self.src.readline().strip(" \r\n") continue - move = line.split(":")[1] + move = line.split(":") + move = move[len(move)-1].strip(" \r\n") tokens = move.split(" ") + + try: [x,y] = map(int, tokens[0:2]) except: @@ -1510,6 +1522,8 @@ class ReplayThread(GameThread): self.board.update(move) for p in self.players: p.update(move) + + line = self.src.readline().strip(" \r\n") if isinstance(graphics, GraphicsThread): with self.lock: @@ -2338,4 +2352,4 @@ if __name__ == "__main__": sys.exit(102) # --- main.py --- # -# EOF - created from make on Wed Jan 30 19:45:59 WST 2013 +# EOF - created from make on Wed Jan 30 19:58:45 WST 2013 diff --git a/qchess/src/game.py b/qchess/src/game.py index d91ea60..66b782f 100644 --- a/qchess/src/game.py +++ b/qchess/src/game.py @@ -144,29 +144,38 @@ class ReplayThread(GameThread): def reset_board(self, line): pieces = {"white" : [], "black" : []} king = {"white" : None, "black" : None} + grid = [[None] * w for _ in range(h)] for x in range(w): for y in range(h): self.board.grid[x][y] = None while line != "# Start game": + if line[0] == "#": + line = self.src.readline().strip(" \r\n") + continue + tokens = line.split(" ") [x, y] = map(int, tokens[len(tokens)-1].split(",")) current_type = tokens[1] - types = map(lambda e : e.strip("'[], "), tokens[2].split(",")) - - target = Piece(tokens[0], x, y, current_type) + types = map(lambda e : e.strip("'[], "), (tokens[2]+tokens[3]).split(",")) + + target = Piece(tokens[0], x, y, types) + target.current_type = current_type + try: target.choice = types.index(current_type) except: target.choice = -1 - pieces[token[0]].append(target) + pieces[tokens[0]].append(target) if target.current_type == "king": - king[token[0]] = target + king[tokens[0]] = target + grid[x][y] = target line = self.src.readline().strip(" \r\n") self.board.pieces = pieces self.board.king = king + self.board.grid = grid def run(self): move_count = 0 @@ -187,8 +196,11 @@ class ReplayThread(GameThread): line = self.src.readline().strip(" \r\n") continue - move = line.split(":")[1] + move = line.split(":") + move = move[len(move)-1].strip(" \r\n") tokens = move.split(" ") + + try: [x,y] = map(int, tokens[0:2]) except: @@ -206,6 +218,8 @@ class ReplayThread(GameThread): self.board.update(move) for p in self.players: p.update(move) + + line = self.src.readline().strip(" \r\n") if isinstance(graphics, GraphicsThread): with self.lock: -- 2.20.1