Skip to main content

A Pythonic wargame engine for Guy Debord's Le Jeu de la Guerre

Project description

Pykrieg

A Pythonic wargame engine for Guy Debord's Le Jeu de la Guerre (A Game of War).

About

Pykrieg is a Python library that implements the complex rules of Guy Debord's strategic tabletop game, providing a clean, extensible API for developers to build custom interfaces, AI opponents, and analysis tools. The project is inspired by the successful python-chess library and follows similar design principles.

Planned Features

  • Complete Game Engine: Full implementation of Debord's strategic game rules
  • Clean API: Intuitive Pythonic interface modeled after python-chess
  • Extensible Design: Easy to create custom variants, unit types, and victory conditions
  • Format Support: Game record and position formats for saving/sharing games
  • Engine Protocol: UCI-like protocol for communication between engines and frontends
  • Well-Tested: Comprehensive test suite with 85%+ code coverage

Installation

pip install pykrieg

Quick Start

from pykrieg import Board, create_piece

# Create a board
board = Board()

# Add units using the factory function
board.create_and_place_unit(0, 0, 'INFANTRY', 'NORTH')
board.create_and_place_unit(5, 10, 'CAVALRY', 'NORTH')
board.create_and_place_unit(19, 24, 'INFANTRY', 'SOUTH')

# Or create units directly and place them
from pykrieg import Infantry, Cannon
unit = Cannon('NORTH')
board.place_unit(10, 10, unit)

# Query units on the board
print(board.count_units())  # Total number of units
print(board.count_units(unit_type='INFANTRY'))  # Count of infantry
print(board.get_units_by_owner('NORTH'))  # List of coordinates with North's units

# Serialize to FEN
from pykrieg import Fen
fen = Fen.board_to_fen(board)
print(fen)

# Deserialize from FEN
board2 = Fen.fen_to_board(fen)

# Check territory
print(board.get_territory(0, 0))  # 'NORTH'
print(board.get_territory(19, 24))  # 'SOUTH'

# Convert coordinates
print(Board.tuple_to_spreadsheet(0, 0))  # 'A1'
print(Board.spreadsheet_to_tuple('A1'))  # (0, 0)

# Movement
from pykrieg import generate_moves, is_valid_move, execute_move

# Get legal moves for a unit
moves = generate_moves(board, 5, 10)
print(f"Available moves: {moves}")  # List of (row, col) tuples

# Check if a move is valid
if is_valid_move(board, 5, 10, 7, 12):
    print("Move is valid!")

# Execute a move
moved_unit = execute_move(board, 5, 10, 7, 12)
print(f"Moved {moved_unit.unit_type} to (7, 12)")

# Or use Board convenience methods
moves = board.get_legal_moves(5, 10)  # Same as generate_moves()
is_valid = board.is_legal_move(5, 10, 7, 12)  # Same as is_valid_move()
unit = board.make_move(5, 10, 7, 12)  # Same as execute_move()

# Check unit movement properties
from pykrieg import get_movement_range, can_move
unit = board.get_unit(7, 12)
print(f"Movement range: {get_movement_range(unit)}")  # 0, 1, or 2
print(f"Can move: {can_move(unit)}")  # True or False

Documentation

Comprehensive documentation is available at docs/ covering:

  • Basic usage
  • API reference for Board, FEN, and utility functions
  • Coordinate system details
  • FEN format specification
  • Type definitions

Build documentation locally::

cd docs make html

Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

Donations

If you like the project and want to support future development, consider donating!

Donation Button

License

This project is licensed under the GNU General Public License v3.0 - see LICENSE for details.

The GPL v3 license ensures that:

  • The software remains free for all users
  • Derivative works must be shared under the same license (copyleft)
  • Commercial use is prohibited (requires separate commercial license)
  • Users have the freedom to study, modify, and distribute the software

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pykrieg-0.1.2.tar.gz (49.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pykrieg-0.1.2-py3-none-any.whl (26.9 kB view details)

Uploaded Python 3

File details

Details for the file pykrieg-0.1.2.tar.gz.

File metadata

  • Download URL: pykrieg-0.1.2.tar.gz
  • Upload date:
  • Size: 49.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for pykrieg-0.1.2.tar.gz
Algorithm Hash digest
SHA256 7ada4052e9c8b9052f58d0e523c4c8c7f5b72c3395b9bc278c4c7fa0503e2d12
MD5 5d0179e5a85f3b84aebd52ef5116001a
BLAKE2b-256 a8e893ffee893b7f3d3ec13c006629cacb65a23f234f0c008ab301abad9ea0bb

See more details on using hashes here.

File details

Details for the file pykrieg-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: pykrieg-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 26.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for pykrieg-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b83c2038ead9b7957986ffa9196b2395e28507812c3a1f334026207587f6ce05
MD5 ebcfec52860e79f6b3b74a7bad01de3f
BLAKE2b-256 54e22094076393d90c99c8da418796c2d0824f6a4ab3331f8be43c5a041a3d4b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page