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.tar.gz (20.1 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-py3-none-any.whl (20.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hpyhex-0.2.0.tar.gz
  • Upload date:
  • Size: 20.1 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.tar.gz
Algorithm Hash digest
SHA256 e9a5367a96f4805f18feb38a74f8dc23cb4d7c7c2cf63654d43689b47aeb43b8
MD5 00a17001b833bf9a71eac9a18248a354
BLAKE2b-256 3ce58d2aa431bd3514010086f2c9e418e3a4827420e052787c674a89750bff7e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hpyhex-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 20.6 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-py3-none-any.whl
Algorithm Hash digest
SHA256 3b5d943407e794820385302922bc326c3a5ba82b30f5439cb2d4f257a0e3fd11
MD5 57b26bcfa65c7bddb9c2e70e3f70112a
BLAKE2b-256 2a02f7653d194c24ebec7a4c87a48ea8efc1c890f5bc21075ff6a189bb23fb33

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