1- from dataclasses import fields , asdict , dataclass , field
1+ from dataclasses import fields , dataclass , field
22from itertools import combinations , starmap , product
33from typing import Self , Type
44
5- from dacite import from_dict
6-
7- from hashabledict import hashabledict
85from .StateExtractor import StateExtractor
6+ from .entities .AllResources import AllResources
97from .entities .BasicResources import BasicResources
108from .entities .Board import Board
119from .entities .Player import Player
10+ from .entities .Tier import Tier
11+ from .entities .extended_lists .Aristocrats import Aristocrats
12+ from .entities .extended_lists .PlayerAristocrats import PlayerAristocrats
13+ from .entities .extended_lists .PlayerCards import PlayerCards
14+ from .entities .extended_lists .PlayerReserve import PlayerReserve
1215from .moves import (
1316 Move ,
1417 GrabThreeResource ,
@@ -34,14 +37,15 @@ class Game:
3437 _state_extractor : Type [StateExtractor ] = StateExtractor
3538
3639 def __post_init__ (self ):
37- if not self .board or not self . players :
40+ if not self .players :
3841 self .players = tuple (Player () for _ in range (self .n_players ))
42+ if not self .board :
3943 self .board = Board (self .n_players )
44+ if not self ._performed_the_last_move :
4045 self ._performed_the_last_move = dict (
4146 (player , False ) for player in self .players
4247 )
4348 self .is_blocked = dict ((player , False ) for player in self .players )
44- self ._last_turn = False
4549 self .current_player = self .players [0 ]
4650
4751 def perform (self , action : Move ) -> Self :
@@ -60,7 +64,6 @@ def next_turn(self) -> None:
6064 self ._last_turn = True
6165 self ._performed_the_last_move [self .current_player ] = self ._last_turn
6266 self .current_player = self .players [0 ]
63- self ._turn_counter += 1
6467
6568 def is_terminal (self ) -> bool :
6669 return all (self ._performed_the_last_move .values ()) or (
@@ -85,8 +88,38 @@ def get_state(self) -> tuple:
8588 return self ._state_extractor .get_state (self )
8689
8790 def copy (self ) -> Self :
88- dict_repr = asdict (self , dict_factory = hashabledict )
89- game = from_dict (Game , dict_repr )
91+ game = Game (
92+ players = tuple (
93+ Player (
94+ resources = AllResources (
95+ (resources := player .resources ).red ,
96+ resources .green ,
97+ resources .blue ,
98+ resources .black ,
99+ resources .white ,
100+ resources .gold ,
101+ ),
102+ cards = PlayerCards (tuple (player .cards )),
103+ reserve = PlayerReserve (tuple (player .reserve )),
104+ aristocrats = PlayerAristocrats (tuple (player .aristocrats )),
105+ )
106+ for player in self .players
107+ ),
108+ board = Board (
109+ n_players = (board := self .board ).n_players ,
110+ tiers = list (Tier (tier .hidden , tier .visible ) for tier in board .tiers ),
111+ aristocrats = Aristocrats (board .aristocrats ),
112+ resources = AllResources (
113+ board .resources .red ,
114+ board .resources .green ,
115+ board .resources .blue ,
116+ board .resources .black ,
117+ board .resources .white ,
118+ board .resources .gold ,
119+ ),
120+ ),
121+ n_players = self .n_players ,
122+ )
90123 game .current_player = game .players [0 ]
91124 for player in game .players :
92125 game .is_blocked [player ] = next (
0 commit comments