def parse_piece_list(cls, white, black): board = Board() board.clear() for peice in white.split(" "): p = Piece.from_symbol(peice[0]) board.set_piece_at( square(ord(peice[1]) - ord('a'), int(peice[2]) - 1), p) for peice in black.lower().split(" "): p = Piece.from_symbol(peice[0]) board.set_piece_at( square(ord(peice[1]) - ord('a'), int(peice[2]) - 1), p) return board
def command(depth: int, board: chess.Board, msg: str): """ Accept UCI commands and respond. The board state is also updated. """ if msg == "quit": sys.exit() if msg == "uci": print("id name Andoma") # Andrew/Roma -> And/oma print("id author Andrew Healey & Roma Parramore") print("uciok") return if msg == "isready": print("readyok") return if msg == "ucinewgame": return if "position startpos moves" in msg: moves = msg.split(" ")[3:] board.clear() board.set_fen(chess.STARTING_FEN) for move in moves: board.push(chess.Move.from_uci(move)) return if "position fen" in msg: fen = " ".join(msg.split(" ")[2:]) board.set_fen(fen) return if msg[0:2] == "go": _move = next_move(depth, board) print(f"bestmove {_move}") return
def command(depth: int, board: chess.Board, msg: str): ''' Accept UCI commands and respond. The board state is also updated. ''' if msg == 'quit': sys.exit() if msg == 'uci': print("id name Andoma") # Andrew/Roma -> And/oma print("id author Andrew Healey & Roma Parramore") print("uciok") return if msg == 'isready': print('readyok') return if msg == 'ucinewgame': return if 'position startpos moves' in msg: moves = msg.split(' ')[3:] board.clear() board.set_fen(chess.STARTING_FEN) for move in moves: board.push(chess.Move.from_uci(move)) return if 'position fen' in msg: fen = ' '.join(msg.split(' ')[2:]) board.set_fen(fen) return if msg[0:2] == 'go': _move = next_move(depth, board) print(f'bestmove {_move}') return
def parse_uci(board: chess.Board, msg: str): #uci if msg == "quit": os._exit(0) if msg == "uci": print("id name DrawFish") print("id author Gymhgy & Stockfish authors") print("uciok") return if msg == "ucinewgame": return if msg == "isready": print("readyok") return if "position startpos moves" in msg: moves = msg.split(" ")[3:] board.clear() board.set_fen(chess.STARTING_FEN) for move in moves: board.push_uci(move) return if "position fen" in msg: fen = " ".join(msg.split(" ")[2:]) board.set_fen(fen) return if msg == "d": render(board) if msg == "play": side = chess.WHITE if input("w/b: ") == "w" else chess.BLACK if side == chess.WHITE: render(board) board.push(get_move(board)) while not board.is_game_over(): board.push(choose_move(board)) render(board) board.push(get_move(board)) print(board.result()) if msg[0:2] == "go": tl_str = "wtime" if board.turn == chess.WHITE else "btime" inc_str = "winc" if board.turn == chess.WHITE else "binc" split = msg.split() time_left = None increment = None if tl_str in split: try: time_left = int(split[split.index(tl_str) + 1]) except IndexError: time_left = None if inc_str in split: try: increment = int(split[split.index(inc_str) + 1]) except IndexError: increment = None move = choose_move(board, time_left, increment) print("bestmove %s" % move.uci())
def command(msg: str, board: chess.Board, defaultDepth: int, maxDepth: int): """ Accept UCI commands and respond. The board state is also updated. """ if msg == "quit": log("\n[KAISSA64] Session was ended...") return if msg == "uci": print("id name Kaissa64") print("id author Serge Gotsuliak") print("uciok") return if msg == "isready": print("readyok") return if msg == "ucinewgame": # TODO ... return # TODO Use chess.parse_uci() if "position startpos moves" in msg: moves = msg.split(" ")[3:] board.clear() board.set_fen(chess.STARTING_FEN) for move in moves: #log(f"... board.push {move}") board.push(chess.Move.from_uci(move)) return # Game started and we play whites if msg == "position startpos": log(f"... clear board") board.clear() board.set_fen(chess.STARTING_FEN) return if "position fen" in msg: fen = " ".join(msg.split(" ")[2:]) board.set_fen(fen) # TODO Duplcation with [go] part log(f"... searching with depth {defaultDepth}/{maxDepth}") #score, move = search(board, board.turn, depth, returnMove = True) #move, score, count = search(board, board.turn, defaultDepth, -10000, 10000) move, score, count = search(board, board.turn, defaultDepth, maxDepth) log(f"... push move {move} => {score}") board.push(move) log(f"<<< bestmove {move}") print(f"bestmove {move}") return if msg[0:2] == "go": log(f"... searching with depth {defaultDepth}/{maxDepth}") #score, move = search(board, board.turn, depth, returnMove = True) move, score, count = search(board, board.turn, defaultDepth, maxDepth) log(f"... push move {move} => {score}") board.push(move) log(f"<<< bestmove {move}") print(f"bestmove {move}") return