A complete implementation of the Six Men's Morris (also known as Nine Men's Morris) game with both console and web interfaces.
- Console Interface: Full-featured command-line game with AI opponent
- Web Interface: Modern web UI with real-time game state
- AI Opponent: Intelligent computer player using minimax algorithm with alpha-beta pruning
- Game Rules: Complete implementation of Six Men's Morris rules including:
- Placement phase (first 12 pieces)
- Movement phase
- Mill formation and piece removal
- Flying rule (when only 3 pieces remain)
- Win conditions
Run the console version:
python main.pyGame Controls:
- 1: Take an action (place/move pieces)
- 2: Let computer play
- 3: Undo last move
- 4: Restart game
- 5: Quit
Start the web server:
python -m uvicorn app:app --reload --host 0.0.0.0 --port 8000Then open your browser to http://localhost:8000
Web Interface Features:
- Click on valid positions to place pieces during placement phase
- Click on your pieces then click destination during movement phase
- Use "Computer Move" button to let AI play
- Adjust AI depth for different difficulty levels
- Real-time game state updates
- Placement Phase: Players take turns placing their 6 pieces on valid board positions
- Movement Phase: Players move their pieces along the lines to adjacent positions
- Mills: Forming 3 pieces in a row allows you to remove an opponent's piece
- Flying: When you have only 3 pieces left, you can move to any position
- Winning: Reduce opponent to 2 pieces or block all their moves
- Backend: Python with FastAPI for web endpoints
- Frontend: HTML5, CSS3, JavaScript (ES6+)
- AI: Minimax algorithm with alpha-beta pruning
- Game Logic: Pure Python implementation
SixMensMorris/
├── main.py # Console game and core game logic
├── app.py # FastAPI web server
├── index.html # Web UI HTML
├── styles.css # Web UI styling
├── script.js # Web UI JavaScript
└── README.md # This file
The web interface communicates with the Python backend through these endpoints:
POST /start- Start a new gamePOST /place- Place a piecePOST /move- Move a piecePOST /remove_piece- Remove opponent's piecePOST /switch- Switch current playerPOST /undo- Undo last movePOST /computer_move- Make computer moveGET /get_board- Get current board stateGET /get_current_player- Get current playerGET /check_win- Check if game is wonGET /check_mill- Check if position forms a mill
The game logic is centralized in the Game class in main.py. Both the console and web interfaces use the same game logic, ensuring consistency across platforms.
To add new features:
- Implement the logic in the
Gameclass inmain.py - Add corresponding endpoints in
app.pyif needed for web interface - Update the web UI in
script.jsif needed
- Python 3.7+
- FastAPI
- Uvicorn (for web server)
Install dependencies:
pip install fastapi uvicornThis project is proprietary software. All rights reserved under copyright.