def encode(self, C): if 'debt' in self and len(self.debt): outs = tdict() for player, topay in self.debt.items(): outs[player] = GameActions('You are robbed, choose {} resources to discard.'.format(topay)) with outs[player]('robbed', desc='Choose resource to discard'): outs[player].add(tset(res for res, num in player.resources.items() if num > 0)) return outs out = GameActions() if 'loc' not in self: with out('loc', desc='Choose where to move the robber'): if 'knight' in self: out.add('cancel') options = tset(f for f in C.state.world.fields if 'robber' not in f) out.add(options) out.set_status('Choose where to move the robber.') else: with out('target', desc='Choose which player to steal from'): if 'knight' in self: out.add('cancel') out.add(self.steal_options) out.set_status('Choose what player to steal from.') return tdict({self.player: out})
def pick_target(self, C): out = GameActions() with out('target', desc='Choose which player to steal from'): if 'knight' in self: out.add('cancel') out.add(self.steal_options) out.set_status('Choose what player to steal from.') return tdict({self.player: out})
def encode_locs(self, C): out = GameActions() if 'knight' in self: with out('cancel', desc='Cancel playing knight'): out.add('cancel') with out('loc', desc='Choose where to move the robber'): options = tset(f for f in C.state.world.fields if 'robber' not in f) out.add(options) out.set_status('Choose where to move the robber.') return tdict({self.player: out})
def encode(self, C): out = GameActions() if self.settled is None: loc_name = 'settlement' with out('loc-settlement', 'Available Locations'): out.add(self.available) else: loc_name = 'road' with out('loc-road', 'Available Locations'): out.add( tset(e for e in self.settled.edges if e is not None and 'building' not in e), ) out.set_status('Choose a location to place a {}'.format(loc_name)) return tdict({self.player_order[-1]: out})
def encode(self, C): out = GameActions('You rolled: {}. Take your turn.'.format(self.roll)) if self.pre_check is not None: with out(name='pre'): if self.pre_check is not None: out.add(self.pre_check) self.pre_check = None out.set_status( 'Before rolling, you can play your knight or continue') else: # to avoid side info leak from lack of decision when having dev cards out.set_status('Confirm your turn beginning') out.add('continue') return tdict({self.player: out}) if self.devcard is not None: with out('cancel', desc='Undo playing dev card'): out.add('cancel') if self.devcard.name == 'Road Building': options = check_building_options(self.player, C.state.costs) with out('dev-road', C.state.msgs.build.road): out.add(options.road) elif self.devcard.name == 'Year of Plenty': with out('dev-res', desc='Select a second resource'): out.add(tset(self.player.resources.keys())) else: # end turn with out(name='pass', desc='End your turn'): out.add('pass') # building options = check_building_options(self.player, C.state.costs) for bldname, opts in options.items(): with out('build-{}'.format(bldname), C.state.msgs.build[bldname]): out.add(opts) # buy dev card if len(C.state.dev_deck) and can_buy(self.player, C.state.costs.devcard): with out('buy', desc='Buy a development card'): out.add(C.state.dev_deck) # trading with out('maritime-trade', desc='Maritime Trade (with the bank)'): options = bank_trade_options(self.player, C.state.bank_trading) if len(options): out.add('offer', tset((num, res) for res, num in options.items())) with out('domestic-trade', desc='Domestic Trade (with players)'): out.add('demand', tset(res for res in self.player.resources)) if self.player.num_res: out.add( 'offer', tset(res for res, num in self.player.resources.items() if num > 0)) # play dev card with out('play', desc='Play a development card'): if len(self.player.devcards): res = tset(self.player.resources.keys()) for card in self.player.devcards: if card in self.bought_devcards: pass elif card.name == 'Monopoly': out.add(card, res) elif card.name == 'Year of Plenty': out.add(card, res) elif card.name == 'Victory Point': pass else: out.add(card) return tdict({self.player: out})