Python frontend for Knightfall fog-of-war chess with Leo smart contract integration.
cd /path/to/knightfall
python3 play_game.pyCommands:
move <from> <to> - Make a move (e.g., 'move e2 e4')
show - Show current board
fog - Show board with fog of war
history - Show move history
help - Show help
quit - Exit
> move e2 e4
โ
Move executed!
> move e7 e5
โ
Move executed!
> fog
=== Board with Fog of War ===
a b c d e f g h
โโโโโโโโโโโโโโโโโโโ
8โ โ โ โ โ โ โ โ โ โ8
7โ โ โ โ โ โ โ โ โ โ7 โ Fog hides enemy moves
...
knightfall/
โโโ game_state.py โ Game state manager (matches Leo)
โโโ leo_interface_updated.py โ Leo smart contract integration
โโโ play_game.py โ Interactive CLI game โญ
โโโ verify.py โ Python reference implementation
โโโ PYTHON_FRONTEND_README.md โ Complete Python API docs
โโโ INTEGRATION_GUIDE.md โ Leo โ Python integration guide
โโโ README.md โ This file
Implemented:
- โ All chess piece movements
- โ Check/checkmate detection
- โ Castling (full validation)
- โ En passant
- โ Move history tracking
- โ Fog of war visibility
- โ GameState matching Leo struct
- โ Leo integration framework
Coming Soon:
- โณ Leo CLI subprocess calls
- โณ On-chain move validation
- โณ Network multiplayer
- โณ Wager system
- โณ ELO ratings
- PYTHON_FRONTEND_README.md - Complete Python API documentation
- INTEGRATION_GUIDE.md - Leo integration guide with code examples
- LEO_ARCHITECTURE.md - Hybrid Leo/Python architecture decisions
- LEO_INTEGRATION_STATUS.md - ๐ Current Leo usage & future roadmap
- ../knightfall-aleo/README.md - Leo smart contracts documentation
- ../knightfall-aleo/DEPLOYMENT.md - Production deployment guide
Complete game state matching Leo's GameState struct:
from game_state import GameState
game = GameState()
# Access board
piece = game.get_piece(52) # e2 square
game.set_piece(52, 0) # Clear square
# Make moves
game.make_move(52, 36) # e2 to e4
# Display
game.print_board() # Full board
game.print_board(visibility_bitboard) # With fogFeatures:
- Board representation (board1/board2 arrays)
- Castling rights tracking
- Move history recording
- En passant support
- Algebraic notation conversion
Bridge between Python and Leo smart contracts:
from leo_interface_updated import GameManager
manager = GameManager()
manager.start_new_game()
# Make moves (validates with Leo)
manager.make_move_algebraic("e2", "e4")
manager.make_move_algebraic("e7", "e5")
# Show board with fog
manager.show_board(with_fog=True)
# Get history
history = manager.get_move_history()Features:
- Move validation (via Leo)
- En passant detection (via Leo)
- Visibility calculation (via Leo)
- Masked board generation
- Game coordination
Full-featured command-line interface:
python3 play_game.pyFeatures:
- Move input with validation
- Fog of war visualization
- Move history
- Castling rights display
- Beautiful Unicode chess pieces
Python reference implementation of chess logic (useful for testing and validation):
from verify import get_visible_squares, verify_move, create_masked_boardUser Input ("move e2 e4")
โ
play_game.py
โ
GameManager
โ
โโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโ
โ โ โ
GameState LeoInterface
(Python) (Bridge)
โ โ
โโโโโโโโโโโโโโโโโโโโ
โ
knightfall_logic.aleo (validation)
knightfall_game.aleo (visibility)
Current State:
- Python manages game state locally (fast, responsive)
- Leo integration ready (placeholders for subprocess calls)
- Framework complete for network deployment
โ Phase 1: Local Development (COMPLETE)
- Python game state manager
- Leo integration framework
- Interactive CLI game
- Complete documentation
โณ Phase 2: Leo CLI Integration (NEXT)
- Add transition wrappers to Leo programs
- Implement subprocess calls
- Parse Leo output
- See:
INTEGRATION_GUIDE.md
๐ Phase 3: Network Deployment (FUTURE)
- Deploy to testnet/mainnet
- Multiplayer matchmaking
- Wager system
- ELO ratings
- See:
../knightfall-aleo/DEPLOYMENT.md
python3 game_state.pypython3 leo_interface_updated.pypython3 play_game.pyPiece Encoding:
Empty: 0
Black: 1-6 (pawn=1, rook=2, knight=3, bishop=4, queen=5, king=6)
White: 11-16 (pawn=11, rook=12, knight=13, bishop=14, queen=15, king=16)
Square Indexing:
Square 0 = a8 (top-left)
Square 63 = h1 (bottom-right)
square = row * 8 + col (0-63)
Visibility Bitboard:
u64 bitboard: 64-bit integer
Bit i = 1 โ square i is visible
Bit i = 0 โ square i is hidden (fog)
- Update
game_state.pyif changing game state - Update
leo_interface_updated.pyfor Leo integration - Update
play_game.pyfor UI changes - Update documentation
- Test thoroughly
- Follow PEP 8
- Add docstrings to all functions
- Type hints encouraged
- Keep functions focused and small
- Fork the repository
- Create feature branch
- Make changes
- Add tests
- Update documentation
- Submit pull request
MIT License - see LICENSE file for details
- Leo Smart Contracts:
../knightfall-aleo/ - Aleo: https://aleo.org/
- Leo Language: https://leo-lang.org/
Issues?
- Check documentation files
- Review Python examples
- Test basic functionality
- Open GitHub issue
Questions?
- See
PYTHON_FRONTEND_README.mdfor API docs - See
INTEGRATION_GUIDE.mdfor Leo integration - See
../knightfall-aleo/README.mdfor Leo docs
Happy Chess Playing! โ๏ธ
