Skip to content

Drackorby/carcassonne

 
 

Repository files navigation

carcassonne

Carcassonne implementation in python

Example game

Features

  • Tilesets
    • Base game
    • The river
    • Inns and cathedrals
  • 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 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() 

RL setup

Make sure to have all packages from the requirements.txt installed in order to work with the stable baselines algorithm.

In order to be able to train with the self play setup you would need to create symlinks to the carcassone sjango server.

In carcassone_server/carcassone_server execute:

 ln -s ../../gym_data gym_data
 ln -s ../../wingedsheep wingedsheep

About

Carcassonne implementation in python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Jupyter Notebook 93.5%
  • Python 6.5%