def get_road(self, C): out = GameActions('Choose a location to place a 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), ) return tdict({self.active: out})
def decide_claim(self, C): out = GameActions( 'You have fulfilled the requirements to claim victory.') with out('end', 'End the game?'): out.add(tset(['yes', 'no'])) return tdict({p: out for p in self.candidates})
def collect(self, C): player = self.winners[len(self.picks)] out = GameActions('What card do you choose in the auction?') with out('pick', 'Claim card'): out.add(C.state.market.neutral) return tdict({player: out})
def decide_tax(self, C): outs = tdict() for p, num in self.taxable.items(): out = GameActions( 'You have too many cards, you must discard {} due to tax'. format(util.format_quantity('card', num))) with out('tax', 'Discard card'): out.add(p.hand) outs[p] = out return outs
def choose_bid(self, C): outs = tdict() for p in C.players: if p not in self.bids: out = GameActions( 'How much do you want to bid in the auction?') with out('bid', 'Your bid'): out.add(tset(range(p.money + 1))) outs[p] = out return outs
def encode(self, C): # complete trade if 'trade' in self: out = GameActions('Choose second card to exchange') with out('cancel', 'Cancel trade'): out.add('cancel') with out('trade', 'Second card to exchange'): cards = tset() if self.trade not in C.state.market: cards.update(C.state.market) for p in C.players: if self.trade not in p.market: cards.update(p.market) out.add(cards) else: out = GameActions('You have {} actions left'.format(self.num)) # trade # 1. can choose card from some other market # 2. can choose card from my own market # get cards from all markets except my own (self.player) with out('trade', 'Select card from other player markets'): for p, cards in self.market.items(): if p == self.player and 'trade' not in self: continue elif 'trade' in self and p != self.player: continue opts = cards if len(opts): out.add(opts) print('market phase out', out) # pickup # can pickup card from my own market # play royal # can play any royal from my hand # royal action # can take action of current royal, let's say king # exchange building # 1. can pick up one card from one of my buildings # 2. pick one card from my market OR my hand return tdict({self.player: out})
def encode(self, C): out = GameActions('Place a tick into one of free spots') free = C.state.board.get_free() if not len(free): C.state.winner = None raise GameOver with out('tic', desc='Available spots'): out.add(tset(free)) 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 decide_steal(self, C): 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
def get_offer(self, C): offer, demand = self.offer, self.demand out = GameActions('You are proposing a trade') with out('cancel', 'Cancel trade'): out.add('cancel') with out('submit', 'Submit trade'): out.add('submit') with out('trade', 'Change trade'): out.add('demand', tset(res for res in demand)) out.add( 'offer', tset(res for res, num in self.player.resources.items() if num - offer[res] > 0)) # TODO: add trade to info 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 get_counter(self, C): outs = tdict() for p, r in self.responses.items(): if r is None: offer, demand = self.offer, self.demand status = 'Respond to trade' if p in self.counter_offers: offer, demand = self.counter_offers[p] status = 'Respond to trade with your counter-trade' out = GameActions(status) with out('reject', 'Reject trade'): out.add('reject') with out( 'accept', 'Accept {}trade'.format( 'counter-' if p in self.counter_offers else '')): if trade_available(p, demand): out.add('accept') if 'allow_counter_trades' not in C.state or C.state.allow_counter_trades: # TODO: add this to config/settings with out('counter', 'Counter by amending the trade'): out.add('demand', tset(res for res in demand)) out.add( 'offer', tset(res for res, num in p.resources.items() if num - offer[res] > 0)) outs[p] = out # TODO: add trades to out.info for AIs return outs
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 get_maritime(self, C): out = GameActions('What resource would you like for {} {}'.format( *self.maritime_msg)) with out('cancel', desc='Cancel trade'): out.add('cancel') with out('maritime-trade', desc='Select the resource to receive'): out.add(tset(self.demand.keys())) return tdict({self.player: out})
def get_preroll(self, C, knight): out = GameActions('You can play your knight before rolling') with out('continue', 'Continue with your turn'): out.add('continue') with out('knight', 'Play your knight'): out.add( knight) # TODO: maybe allow user to pick which knight to use return tdict({self.player: out})
def get_year_of_plenty(self, C): out = GameActions( 'You activated Year of Plenty, choose a second resource to collect' ) with out('cancel', desc='Undo playing dev card'): out.add('cancel') with out('dev-res', desc='Select a second resource'): out.add(tset(self.player.resources.keys())) return tdict({self.player: out})
def get_road_building(self, C): out = GameActions( 'You activated Road Building, and can now build a second road') with out('cancel', desc='Undo playing dev card'): out.add('cancel') options = check_building_options(self.player, C.state.costs) with out('dev-road', C.state.msgs.build.road): out.add(options.road) return tdict({self.player: out})
def encode(self, C): out = GameActions('Place a tick into one of free spots') free = C.state.board.get_free() with out('actionType1', desc='First kind of action'): out.add(tset({'a', 'b', 'c'})) with out('actionType2', desc='Second kind of action'): out.add(tset({1, 2, 3})) return tdict({self.player: out})
def final_decision(self, C, accepts, counters): status = 'No one has accepted your trade' if len(accepts) or len(counters): status = 'Players have responded to your trade' out = GameActions(status) with out('cancel', 'Cancel trade'): out.add('cancel') with out('accept', 'Accept trade with:'): if len(accepts): out.add(accepts) with out('counter', 'Accept counter-trade from:'): if len(counters): out.add(counters) # TODO: add trades to out.info for AIs return tdict({self.player: out})
def encode(self, C): full = tdict() for player in self.active: out = GameActions('Select what cards to bring to the market') with out('select', 'Select card'): opts = player.hand - self.sel[player] if len(opts): out.add(opts) with out('unselect', 'Unselect card'): if len(self.sel[player]): out.add(self.sel[player]) with out('ready', 'Ready for the market'): out.add('ready') full[player] = out return full
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})
def encode(self, C): if self.maritime is not None: out = GameActions('What resource would you like for {} {}'.format(*self.maritime_msg)) with out('cancel', desc='Cancel trade'): out.add('cancel') with out('maritime-trade', desc='Select the resource to receive'): out.add(tset(self.demand.keys())) return tdict({self.player:out}) if self.partners is not None: out = GameActions('Some players accepted your offer') with out('cancel', desc='Cancel trade'): out.add('cancel') with out('domestic-confirm', desc='Select player to confirm trade'): out.add(self.partners) return tdict({self.player:out}) if self.responses is not None: outs = tdict() for p, resp in self.responses.items(): if resp is None: out = GameActions(writef('Do you accept the trade proposed by {}.', self.player)) out.info.offer = self.offer out.info.demand = self.demand with out('domestic-response', desc='Choose to accept or reject trade'): if trade_available(p, self.demand): out.add('accept') out.add('reject') outs[p] = out return outs out = GameActions('Choose what resources to trade') with out('cancel', desc='Cancel trade'): out.add('cancel') with out('send', desc='Send trade offer to opponents'): out.add('send') 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)) return tdict({self.player:out})
def get_main_turn(self, C): out = GameActions('You rolled: {}. Take your turn.'.format(self.roll)) with out('pass', 'End your turn'): out.add('pass') 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) 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) 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)) with out('play', desc='Play a development card'): if len(self.player.devcards) and self.devcard is None: 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})
def choose_actions(self, C): player = self.active out = GameActions('You have {} action{} remaining'.format( self.actions, 's' if self.actions > 1 else '')) with out('pass', 'Pass action'): out.add('pass') with out('trade', 'Trade in the market'): out.add(player.market) out.add(C.state.market.neutral) for p in C.players: if p != player and len(p.market): out.add(p.market) with out('hide', 'Hide a card from your stand'): out.add(player.market) with out('sell', 'Sell 2 of our cards for a coin'): if len(player.market) >= 2: out.add(player.market) with out('favor', 'Use a royal as a favor'): out.add(card for card in player.market if card.isroyal()) out.add(card for card in player.hand if card.isroyal()) with out('royal', 'Pay 1 coin to take the royal action'): if player.money > 0: out.add('royal') with out('store', 'Store a card in your building'): for name, buildings in player.buildings.items(): for bld in buildings: out.add(bld.storage) with out('downgrade', 'Pick up a card from one of your buildings'): for name, buildings in player.buildings.items(): if name != 'farm': for bld in buildings: out.add(bld.storage) return tdict({player: out})
def encode(self, C): out = GameActions('Place a tick into one of free spots') with out('tic', desc='Available spots'): out.add(tset(['a', 'b'])) return tdict({self.player: out})
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 get_settlement(self, C): out = GameActions('Choose a location to place a settlement') with out('loc-settlement', 'Available Locations'): out.add(self.available) return tdict({self.active: out})