haive.games.monopoly.utils¶

Monopoly game utilities and board logic.

This module provides utility functions for the monopoly game, including:
  • Board setup and property definitions

  • Game logic calculations

  • Card definitions and handling

  • Rent calculations

Functions¶

calculate_rent(property, state[, dice_roll])

Calculate rent for a property.

can_trade_properties(prop1, prop2, state)

Check if two properties can be traded.

check_game_end(state)

Check if the game should end.

create_board()

Create the initial board with all properties.

create_players(player_names)

Create initial players.

get_building_cost(property, buildings[, is_hotel])

Calculate cost to build houses or hotel.

get_properties_by_color(color)

Get all property names for a color group.

get_property_at_position(position)

Get property information at a board position.

handle_special_position(position, player, state)

Handle special board positions like GO, Jail, etc.

move_player(player, dice_roll)

Move a player based on dice roll.

roll_dice()

Roll two dice.

shuffle_cards()

Shuffle and return chance and community chest cards.

Module Contents¶

haive.games.monopoly.utils.calculate_rent(property, state, dice_roll=None)[source]¶

Calculate rent for a property.

Parameters:
  • property (haive.games.monopoly.models.Property)

  • state (haive.games.monopoly.state.MonopolyState)

  • dice_roll (int | None)

Return type:

int

haive.games.monopoly.utils.can_trade_properties(prop1, prop2, state)[source]¶

Check if two properties can be traded.

Parameters:
  • prop1 (haive.games.monopoly.models.Property)

  • prop2 (haive.games.monopoly.models.Property)

  • state (haive.games.monopoly.state.MonopolyState)

Return type:

bool

haive.games.monopoly.utils.check_game_end(state)[source]¶

Check if the game should end.

Parameters:

state (haive.games.monopoly.state.MonopolyState)

Return type:

tuple[bool, str | None]

haive.games.monopoly.utils.create_board()[source]¶

Create the initial board with all properties.

Return type:

dict[str, haive.games.monopoly.models.Property]

haive.games.monopoly.utils.create_players(player_names)[source]¶

Create initial players.

Parameters:

player_names (list[str])

Return type:

list[haive.games.monopoly.models.Player]

haive.games.monopoly.utils.get_building_cost(property, buildings, is_hotel=False)[source]¶

Calculate cost to build houses or hotel.

Parameters:
  • property (haive.games.monopoly.models.Property)

  • buildings (int)

  • is_hotel (bool)

Return type:

int

haive.games.monopoly.utils.get_properties_by_color(color)[source]¶

Get all property names for a color group.

Parameters:

color (haive.games.monopoly.models.PropertyColor)

Return type:

list[str]

haive.games.monopoly.utils.get_property_at_position(position)[source]¶

Get property information at a board position.

Parameters:

position (int)

Return type:

dict[str, Any] | None

haive.games.monopoly.utils.handle_special_position(position, player, state)[source]¶

Handle special board positions like GO, Jail, etc.

Parameters:
  • position (int)

  • player (haive.games.monopoly.models.Player)

  • state (haive.games.monopoly.state.MonopolyState)

Return type:

str

haive.games.monopoly.utils.move_player(player, dice_roll)[source]¶

Move a player based on dice roll.

Parameters:
  • player (haive.games.monopoly.models.Player)

  • dice_roll (haive.games.monopoly.models.DiceRoll)

Return type:

tuple[int, bool]

haive.games.monopoly.utils.roll_dice()[source]¶

Roll two dice.

Return type:

haive.games.monopoly.models.DiceRoll

haive.games.monopoly.utils.shuffle_cards()[source]¶

Shuffle and return chance and community chest cards.

Return type:

tuple[list[str], list[str]]