def new_piece(self, type_, pos): team = white() if type_.isupper() else black() cls = PIECES[type_.lower()] piece = cls(self, team, pos) self.cells[pos[0]][pos[1]] = piece if team == black(): self.black_pieces.append(piece) else: self.white_pieces.append(piece)
def heuristic(self): ac = 0 for piece in self.white_pieces: ac += piece.evaluations() for piece in self.black_pieces: ac -= piece.evaluations() if self.who_moves == black(): ac = -ac return ac
def testWhatAreMyPieces(self): b = self.board b.who_moves = white() self.assertIsNotNone(b.my_pieces(),\ "Should return my pieces aren't empty") self.assertItemsEqual(b.my_pieces(), b.white_pieces,\ "my pieces should be white pieces\ when who_moves is white" ) b.who_moves = black() self.assertIsNotNone(b.my_pieces(),\ "Should return my pieces when black aren't empty") self.assertItemsEqual(b.my_pieces(), b.black_pieces,\ "my pieces should be black pieces\ when who_moves is black" )
def testWhatAreMyPieces(self): b = self.board b.who_moves = white() self.assertIsNotNone(b.my_pieces(),\ "Should return my pieces aren't empty") self.assertItemsEqual(b.my_pieces(), b.white_pieces,\ "my pieces should be white pieces\ when who_moves is white") b.who_moves = black() self.assertIsNotNone(b.my_pieces(),\ "Should return my pieces when black aren't empty") self.assertItemsEqual(b.my_pieces(), b.black_pieces,\ "my pieces should be black pieces\ when who_moves is black")
depth = 3 def __init__(self, color, port): super(G10Bot, self).__init__() self.port = port self.color = color def select_move(self, board): move = nega_max_with_prune(board, self.depth, M_INF, P_INF) return move def on_move(self, state): board = Board(state) move = self.select_move(board) self.send_move(move[0], move[1]) print "Move (%s) -> (%s)" % (move[0], move[1]) def on_game_over(self, state): print 'Game Over' #====================================== if __name__ == '__main__': color = white() port = 50100 if len(sys.argv) > 1: if sys.argv[1] == 'black': color = black() port = 50200 bot = G10Bot(color, port) bot.port = port bot.start()
super(G10Bot, self).__init__() self.port = port self.color = color def select_move(self, board): move = nega_max_with_prune(board, self.depth, M_INF, P_INF) return move def on_move(self, state): board = Board(state) move = self.select_move(board) self.send_move(move[0], move[1]) print "Move (%s) -> (%s)" % (move[0], move[1]) def on_game_over(self, state): print 'Game Over' #====================================== if __name__ == '__main__': color = white() port = 50100 if len(sys.argv) > 1: if sys.argv[1] == 'black': color = black() port = 50200 bot = G10Bot(color, port) bot.port = port bot.start()
def kill_piece(self, piece): self.remove_piece(piece) if piece.team == black(): self.black_pieces.remove(piece) else: self.white_pieces.remove(piece)