Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentbons committed May 22, 2020
2 parents bca4d7d + 8cab4c7 commit 7923202
Showing 1 changed file with 32 additions and 19 deletions.
51 changes: 32 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# carcassonne
Carcassonne implementation in python

Expand All @@ -12,27 +13,39 @@ Carcassonne implementation in python
* Abbots
* Farmers

## Installation

* Clone the project
* Go to the project folder
* Run:

pip install .

You can now use the API in other projects.

## API

Code example for a game with two players

import random
from typing import Optional
from main.carcassonne_game import CarcassonneGame
from main.objects.actions.action import Action
from main.tile_sets.tile_sets import TileSet
game = CarcassonneGame(
players=2,
tile_sets=[TileSet.BASE, TileSet.THE_RIVER, TileSet.INNS_AND_CATHEDRALS],
supplementary_rules=[SupplementaryRule.ABBOTS, SupplementaryRule.FARMERS]
)
while not game.is_finished():
player: int = game.state.current_player
valid_actions: [Action] = game.get_possible_actions()
action: Optional[Action] = random.choice(valid_actions)
if action is not None:
game.step(player, action)
game.render()
from typing import Optional
from wingedsheep.carcassonne.carcassonne_game import CarcassonneGame
from wingedsheep.carcassonne.carcassonne_game_state import CarcassonneGameState
from wingedsheep.carcassonne.objects.actions.action import Action
from wingedsheep.carcassonne.tile_sets.supplementary_rules import SupplementaryRule
from wingedsheep.carcassonne.tile_sets.tile_sets import TileSet
game = CarcassonneGame(
players=2,
tile_sets=[TileSet.BASE, TileSet.THE_RIVER, TileSet.INNS_AND_CATHEDRALS],
supplementary_rules=[SupplementaryRule.ABBOTS, SupplementaryRule.FARMERS]
)
while not game.is_finished():
player: int = game.get_current_player()
valid_actions: [Action] = game.get_possible_actions()
action: Optional[Action] = random.choice(valid_actions)
if action is not None:
game.step(player, action)
game.render()

0 comments on commit 7923202

Please sign in to comment.