Spaces:
Sleeping
Sleeping
File size: 789 Bytes
a5f2e46 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | import chess
import random
class RandomBot:
def __init__(self):
pass
def predict(self, board: chess.Board) -> chess.Move:
legal_moves = list(board.legal_moves)
if not legal_moves:
raise ValueError("No legal moves available.")
# pick a random move
move = random.choice(legal_moves)
return move.uci(), None
if __name__ == "__main__":
bot = RandomBot()
board = chess.Board()
print("Initial board:")
print(board)
move = bot.predict(board)
print(f"RandomBot suggests move: {move}")
board.push(move)
print("Board after move:")
print(board)
move = bot.predict(board)
print(f"RandomBot suggests move: {move}")
board.push(move)
print("Board after move:")
print(board)
|