Skip to main content

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

Reason this release was yanked:

Wrong content

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: hpyhex-0.1.0.tar.gz
  • Upload date:
  • Size: 2.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.1.0.tar.gz
Algorithm Hash digest
SHA256 ca9e3373a7edf2113d2d81eafdee90d7fc7010eb40ccc07f093ce03f8cb75a3c
MD5 73647ec5b3f989adf43fe6d05923e451
BLAKE2b-256 f480725b0dbd81b5335d3f5c0f89ddffe58c3604e624ba47f0fd24a2f3a516af

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hpyhex-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 2.9 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a1733d495b85c51cf4b72c0d0d0b163f001cdcf4572dc9483ef651048d2f8b85
MD5 50ca19d7349f1a4d61147b73e106f34b
BLAKE2b-256 303ec8ddfcb27a7c40ee42ad8099a0cc08652fc94358510101c042baea995c79

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