-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcarcassonne_test.py
60 lines (50 loc) · 2.96 KB
/
carcassonne_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import random
from typing import Optional
from carcassonne.carcassonne_game import CarcassonneGame
from carcassonne.carcassonne_game_state import CarcassonneGameState
from carcassonne.objects.actions.action import Action
from carcassonne.objects.meeple_type import MeepleType
from carcassonne.tile_sets.supplementary_rules import SupplementaryRule
from carcassonne.tile_sets.tile_sets import TileSet
from utils.utils import DebugMultiTimer, DebugTimer
def print_state(carcassonne_game_state: CarcassonneGameState):
print_object = {
"scores": {
"player 1": carcassonne_game_state.scores[0],
"player 2": carcassonne_game_state.scores[1]
},
"meeples": {
"player 1": {
"normal": str(carcassonne_game_state.meeples[0]) + " / " + str(carcassonne_game_state.meeples[0] + len(list(filter(lambda x: x.meeple_type == MeepleType.NORMAL or x.meeple_type == MeepleType.FARMER, game.state.placed_meeples[0])))),
"abbots": str(carcassonne_game_state.abbots[0]) + " / " + str(carcassonne_game_state.abbots[0] + len(list(filter(lambda x: x.meeple_type == MeepleType.ABBOT, game.state.placed_meeples[0])))),
"big": str(carcassonne_game_state.big_meeples[0]) + " / " + str(carcassonne_game_state.big_meeples[0] + len(list(filter(lambda x: x.meeple_type == MeepleType.BIG or x.meeple_type == MeepleType.BIG_FARMER, game.state.placed_meeples[0]))))
},
"player 2": {
"normal": str(carcassonne_game_state.meeples[1]) + " / " + str(carcassonne_game_state.meeples[1] + len(list(filter(lambda x: x.meeple_type == MeepleType.NORMAL or x.meeple_type == MeepleType.FARMER, game.state.placed_meeples[1])))),
"abbots": str(carcassonne_game_state.abbots[1]) + " / " + str(carcassonne_game_state.abbots[1] + len(list(filter(lambda x: x.meeple_type == MeepleType.ABBOT, game.state.placed_meeples[1])))),
"big": str(carcassonne_game_state.big_meeples[1]) + " / " + str(carcassonne_game_state.big_meeples[1] + len(list(filter(lambda x: x.meeple_type == MeepleType.BIG or x.meeple_type == MeepleType.BIG_FARMER, game.state.placed_meeples[1]))))
}
}
}
print(print_object)
game = CarcassonneGame(
players=2,
tile_sets=[TileSet.BASE, TileSet.INNS_AND_CATHEDRALS],
supplementary_rules=[SupplementaryRule.ABBOTS, SupplementaryRule.FARMERS]
)
step_timer = DebugMultiTimer("Step")
render_timer = DebugMultiTimer("Render")
with DebugTimer("Game"):
while not game.is_finished():
with step_timer:
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)
with render_timer:
game.render()
step_timer.print()
render_timer.print()
print_state(carcassonne_game_state=game.state)
input("Press Enter to continue...")