A Library for simulating a game of The Settlers of Catan
pip3 install pycatan
Run the bash file test.sh `.test.sh'
- Install virtualenv and virtualenvwrapper
- Create a new virtual environment (
mkvirtualenv test
) - Install pytest
- Run (from root directory)
python -m pytest tests
- Documentation
CatanGame
CatanBoard
CatanPlayer
- Etc
- Example game
- Something
Represents a game of Catan
board
- The
CatanBoard
in the game
- The
players
- An array of
CatanPlayer
s (representing the players)
- An array of
longest\_road\_owner
- The index of the player who has the longest road
Creates a new CatanGame
num_of_players
: The number of players playing the gameon_win
: Optional function to run when the game is wonstarting_board
: Whether or not to use the beginner's board
Builds a new settlement
player
: The index of the player who is building the settlementr
: The row at which to build the settlementi
: The index at which to build the settlementis_starting
: Whether or not the settlement is being build during the building phase, and thus should be build for free
Returns a CatanStatus
value.
Builds a new road
player
: The index of the player building the roadstart
: An array with the coordinate of one the the road's points (given[row, index]
)end
: An array with the coordinate of the road's other point (given[row, index]
)is_starting
: Whether or not the road is being built during the building phase and thus should be build for free
Returns a CatanStatus
value
Builds a city on top of a settlement
r
: The row at which to build the cityi
: The index at which to build the cityplayer
: The index of the player who is building the city
Returns a CatanStatus
value
Builds a new developement card
player
: The player who is building the developement card
Returns a CatanStatus
value
Uses a developement card
player
: The player who is using the cardcard
: TheCatanCard
value representing the type of cardargs
: Variable arguments in a dictionary depending on which type of developement card is playedCatanCards.DEV_ROAD
:args
contains'road_one'
and'road_two'
values, both of which are arrays of arrays coresponding to the point which the roads should be builtroad_one
: An array representing the first road in arrays representing points- Ex:
[[0, 0], [0, 1]]
would represent a road going from0, 0
to0, 1
- Ex:
road_two
: Same asroad_one
, but for the other road
CatanCards.DEV_KNIGHT
:args
contains'robber_pos'
and'victim'
values.robber_pos
: The position for the robber to be placed as an array, given as[row, index]
victim
: The index of the player to take the card from. Can beNone
if the player playing the knight card doesn't want to take a card from anybody.
CatanCards.DEV_MONOPOLY
:args
contains a'card_type'
value.card_type
: TheCatanCards
value representing the card the player wants to take
CatanCards.DEV_YOP
:args
contains'card_one'
and'card_two'
values.card_one
: TheCatanCards
value of the first card the player wants to takecard_two
: TheCatanCards
value of the second card
CatanCards.DEV_VP
: Do not callCatanGame.use_dev_card
onCatanCards.DEV_VP
, as players do not play VP cards, but keep them until the end of the game.
Distributes cards based on a dice roll
roll
: The dice roll
Returns nothing
Optional. Simulates 2 dice rolls added together.
Returns a number
Trades cards between players
player_one
: The first player in the tradeplayer_two
: The second player in the tradecards_one
: The cards the first player is givingcards_two
: The cards the second player is giving
Returns a CatanStatus
value
Trades 4 cards to the bank for 1 card. Also will trade only 2 cards if the player is connected to the right harbor
player
: The player who is trading the cardscards
: An array of numbers (CatanCard
values) to trade from the player to the bankrequest
: TheCatanCard
value the player will receive
Returns a CatanStatus
value
Represents a Catan game board.
CatanBoard.HEX_FOREST
- Represents a forest hex
CatanBoard.HEX_Hills
- Represents a hills hex
CatanBoard.HEX_MOUNTAINS
- Represents a mountains hex
CatanBoard.HEX_PASTURE
- Represents a pasture hex
CatanBoard.HEX_FIELDS
- Represents a fields hex
CatanBoard.HEX_DESERT
- Represents a desert hex
hexes
- An array representing the hexes on the board
hex_nums
- An array representing the number tokens on the board
points
- An array representing the intersections between hexes (where settlements are placed)
roads
- An array of
CatanBuildings
representing all the roads in the game
- An array of
harbors
- An array of
CatanHarbors
representing all the harbors on the board
- An array of
robber
- An array representing the robber's position (given as
[row, index]
)
- An array representing the robber's position (given as
Gets a CatanCards
value for a corresponding CatanBoard
Hex value
hex
: TheCatanBoard
hex value to get the card for
Ex: CatanBoard.get_card_from_hex(CatanBoard.HEX_HILLS)
would return CatanCards.CARD_BRICK
Returns a CatanCards
value
Represents a Catan Building
Represents a road
Represents a settlement
Represents a city
Contains values representing different resource and developement cards
Represents a wood resource card.
Represents a brick resource card.
Represents a sheep resource card.
Represents a ore resource card.
Represents a wheat resource card.
Represents a road building developement card.
Represents a victory point developement card.
Represents a monopoly developement card.
Represents a year of plenty developement card.
Represents a knight developement card.
Represents a harbor.
Represents a 2:1 Wood harbor
Represents a 2:1 Brick harbor
Represents a 2:1 Wheat harbor
Represents a 2:1 Ore harbor
Represents a 2:1 Sheep harbor
Returns a string representation of the harbor's type
Represents a player in the game.
Returns the number of victory points the player has.
include_dev
: Whether to include victory points from developement cards, which are only counted if the player wins and should be hidden otherwise.
Interger representation of different statuses returned by functions.
The function ran successfully
The player trying to perform an action lacks the necessary cards.
A building is blocking the action.
The point being used does not exist.
The player is trying to build a building which is not connected to any of their roads.
The player is trying to use a harbor which they are not connected to
The player is trying to use a building which does not exist
The player is trying to use a building which belongs to another player
The player is trying to build a city on an invalid location
There are not enough cards in the deck to perform this action
The input given is missing mandatory information
When running the test module, an error was encountered
We're going to make an example text-game of Catan using PyCatan
First, create a new file.
game.py
def main():
print("Playing Catan!")
if __name__ == "__main__":
main()
Now let's set up a new game of Catan
game.py
from PyCatan import CatanGame
def main():
num_of_players = int(input("How many players are playing? "))
game = CatanGame(num_of_players)