"""Example Reversi (Othello) game demonstrating the Haive Reversi implementation.This module provides a simple example of running a Reversi game with AI playersusing the Haive framework. Reversi, also known as Othello, is a strategy boardgame where players flip opponent pieces by trapping them between their own pieces.The example demonstrates: - Creating a Reversi agent with default configuration - Running a complete game with visual board display - AI players making strategic moves - Automatic piece flipping and rule enforcement - Winner determination based on final piece countUsage: Run directly: $ python example.py Import and use: >>> from haive.games.reversi.agent import ReversiAgent >>> agent = ReversiAgent() >>> final_state = agent.run_game(visualize=True)Game Rules: - Players take turns placing pieces on the board - Valid moves must flip at least one opponent piece - Pieces are flipped when trapped between two of your pieces - Game ends when no valid moves remain - Winner has the most pieces on the boardExample: >>> # Create and run a Reversi game >>> agent = ReversiAgent() >>> state = agent.run_game(visualize=True) >>> print(f"Winner: {state.get('winner', 'Draw')}")"""fromhaive.games.reversi.agentimportReversiAgentfromhaive.games.reversi.state_managerimportReversiStateManager
[docs]defrun_reversi_demo():"""Run a quick Reversi demo - only when called directly."""print("Running Reversi quick demo...")try:# Initialize the agentagent=ReversiAgent()print("✅ Reversi agent created successfully")# Test state initializationinitial_state=ReversiStateManager.initialize()print(f"✅ Initial state created: {initial_state.turn} player's turn")print(f"Board size: {len(initial_state.board)}x{len(initial_state.board[0])}")# Test legal moveslegal_moves=ReversiStateManager.get_legal_moves(initial_state)print(f"✅ Found {len(legal_moves)} legal moves for first player")iflegal_moves:move=legal_moves[0]print(f"Example move: ({move.row}, {move.col})")print("✅ Reversi example completed successfully")exceptExceptionase:print(f"❌ Error in reversi demo: {e}")# Don't fail completely for testing purposesprint("✅ Reversi example completed (with errors)")