Skip to main content

Simplified implementations of the HappyHex game components and hexagonal system in Python.

Project description

hpyhex

Simplified implementations of the HappyHex game components and hexagonal system.

Installation

pip install hpyhex

Features

  • Hexagonal grid representation
  • Basic game mechanics for HappyHex
  • Utility functions for hexagonal calculations

Author

Developed by William Wu.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Usage

from hpyhex.hex import Hex, Piece, HexEngine
from hpyhex.game import Game, PieceFactory

# Create a hexagonal coordinate
coo = Hex(0, 1)

# Create a piece by name
piece = PieceFactory.get_piece("triangle_3_a")

# Create a game engine with radius 3
engine = HexEngine(radius=3)

# Add a piece to the engine
engine.add_piece(piece, coo)

# Eliminate lines and get score
score = len(engine.eliminate()) * 5

# Create a game with engine radius and queue size
game = Game(engine=3, queue=5)
print(game)

# Make a move using a custom algorithm
def simple_algorithm(engine, queue):
	# Always place the first piece at the center
	return 0, Hex(0, 0)
game.make_move(simple_algorithm)

Main Classes

  • Hex: Represents a hexagonal grid coordinate using a custom line-based system. Supports arithmetic, hashing, and tuple compatibility.
  • Piece: Represents a shape made of 7 blocks, optimized for memory and performance. Use PieceFactory to create pieces by name or byte value.
  • HexEngine: Manages the hexagonal grid, supports adding pieces, eliminating lines, and computing entropy.
  • PieceFactory: Utility for creating pieces by name, byte, or randomly. Provides access to all predefined pieces.
  • Game: Manages the game state, piece queue, score, and turn. Supports adding pieces and making moves with algorithms.

Quickstart

  1. Install the package:
    pip install hpyhex
    
  2. Import and use the main classes as shown above.
  3. Create custom algorithms to interact with the game environment.

Benchmarking Algorithms

The package includes benchmarking tools to evaluate and compare algorithms:

from hpyhex.benchmark import benchmark, compare

# Benchmark a single algorithm
avg_score, avg_turn = benchmark(simple_algorithm, engine_radius=3, queue_size=5, eval_times=10)

# Compare two algorithms
similarity = compare(alg1, alg2, engine_radius=3, queue_size=5, eval_times=100)

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

hpyhex-0.2.0.1.tar.gz (20.7 kB view details)

Uploaded Source

Built Distribution

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

hpyhex-0.2.0.1-py3-none-any.whl (21.2 kB view details)

Uploaded Python 3

File details

Details for the file hpyhex-0.2.0.1.tar.gz.

File metadata

  • Download URL: hpyhex-0.2.0.1.tar.gz
  • Upload date:
  • Size: 20.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for hpyhex-0.2.0.1.tar.gz
Algorithm Hash digest
SHA256 94b0946160f26af3d4cd2728747158d733693347d46e294c919e334ab33f0e44
MD5 d57ff19f945f862d9cc8e1c6894c3b56
BLAKE2b-256 e629a94086308decae0ccdf7977d1a18850ac8708f4302ce24fc36470d54e8d5

See more details on using hashes here.

File details

Details for the file hpyhex-0.2.0.1-py3-none-any.whl.

File metadata

  • Download URL: hpyhex-0.2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 21.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for hpyhex-0.2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a8e44e723ee99bf593f94cdee9c3cffacb32d55386149b1ef80f9bde44548784
MD5 c2f7b7ef89b4d358386e304807fd7c9d
BLAKE2b-256 9f33b726c6d9543e1d5f1acc0c641b6dfa9051e21a5a5977f68827fbaa6107ad

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