+ def run(self):
+ move_count = 0
+ last_line = ""
+ line = self.src.readline().strip(" \r\n")
+ while line != "# EOF":
+
+
+ if self.stopped():
+ break
+
+ if len(line) <= 0:
+ continue
+
+
+ if line[0] == '#':
+ last_line = line
+ line = self.src.readline().strip(" \r\n")
+ continue
+
+ tokens = line.split(" ")
+ if tokens[0] == "white" or tokens[0] == "black":
+ self.reset_board(line)
+ last_line = line
+ line = self.src.readline().strip(" \r\n")
+ continue
+
+ move = line.split(":")
+ move = move[len(move)-1].strip(" \r\n")
+ tokens = move.split(" ")
+
+
+ try:
+ [x,y] = map(int, tokens[0:2])
+ except:
+ last_line = line
+ 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:])
+
+ 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:
+ if target.current_type != "unknown":
+ graphics.state["moves"] = self.board.possible_moves(target)
+ else:
+ graphics.state["moves"] = None
+ 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)
+
+ last_line = line
+ line = self.src.readline().strip(" \r\n")
+
+
+ end = self.board.end_condition()
+ if end != None:
+ self.final_result = end
+ self.stop()
+ break
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ if self.end and isinstance(graphics, GraphicsThread):
+ #graphics.stop()
+ pass # Let the user stop the display
+ elif not self.end and self.board.end_condition() == None:
+ global game
+ # Work out the last move
+
+ t = last_line.split(" ")
+ if t[len(t)-2] == "black":
+ self.players.reverse()
+ elif t[len(t)-2] == "white":
+ pass
+ elif self.state["turn"] != None and self.state["turn"].colour == "white":
+ self.players.reverse()
+
+
+ game = GameThread(self.board, self.players)
+ game.run()
+ else:
+ pass