def simpleState(self): state = {} state['board'] = INITIAL state['who_moves'] = white() state['bad_move'] = False state['enpassant'] = (1, 2) return state
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 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()
def my_pieces(self): iswhite = self.who_moves == white() return self.white_pieces if iswhite else self.black_pieces
def is_black(self): return self.team != white()
def is_white(self): return self.team == white()