Skip to content

emmaprice082/knightfall

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

53 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Knightfall - Python Frontend

Python frontend for Knightfall fog-of-war chess with Leo smart contract integration.

Knightfall Chess

๐ŸŽฎ Quick Start

Play Now (Local Mode)

cd /path/to/knightfall
python3 play_game.py

Commands:

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

Example Game

> 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
...

๐Ÿ“ File Structure

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

โœจ Features

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

๐Ÿ“š Documentation

๐Ÿ”ง Key Modules

game_state.py - Game State Manager

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 fog

Features:

  • Board representation (board1/board2 arrays)
  • Castling rights tracking
  • Move history recording
  • En passant support
  • Algebraic notation conversion

leo_interface_updated.py - Leo Integration

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

play_game.py - Interactive Game

Full-featured command-line interface:

python3 play_game.py

Features:

  • Move input with validation
  • Fog of war visualization
  • Move history
  • Castling rights display
  • Beautiful Unicode chess pieces

verify.py - Reference Implementation

Python reference implementation of chess logic (useful for testing and validation):

from verify import get_visible_squares, verify_move, create_masked_board

๐ŸŽฏ How It Works

User 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

๐Ÿ”„ Integration Status

โœ… 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

๐Ÿงช Testing

Test Game State

python3 game_state.py

Test Leo Interface

python3 leo_interface_updated.py

Play a Game

python3 play_game.py

๐Ÿ“Š Data Structures

Piece 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)

๐Ÿ› ๏ธ Development

Adding Features

  1. Update game_state.py if changing game state
  2. Update leo_interface_updated.py for Leo integration
  3. Update play_game.py for UI changes
  4. Update documentation
  5. Test thoroughly

Code Style

  • Follow PEP 8
  • Add docstrings to all functions
  • Type hints encouraged
  • Keep functions focused and small

๐Ÿค Contributing

  1. Fork the repository
  2. Create feature branch
  3. Make changes
  4. Add tests
  5. Update documentation
  6. Submit pull request

๐Ÿ“ License

MIT License - see LICENSE file for details

๐Ÿ”— Related Projects

๐Ÿ“ž Support

Issues?

  1. Check documentation files
  2. Review Python examples
  3. Test basic functionality
  4. Open GitHub issue

Questions?

  • See PYTHON_FRONTEND_README.md for API docs
  • See INTEGRATION_GUIDE.md for Leo integration
  • See ../knightfall-aleo/README.md for Leo docs

Happy Chess Playing! โ™Ÿ๏ธ

About

Fog of War Chess using Python (play via the terminal)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors