def test_cardsummary(self): # data setup self.set_up() card_summary = self.player.cardsummary() self.assertEqual(3, card_summary['VICTORY POINTS']) # add a card to the player stack and verify change in value # province has a victory point value of 6, total equal to 9 self.player.deck.append(Dominion.Province()) card_summary = self.player.cardsummary() self.assertEqual(9, card_summary['VICTORY POINTS'])
def test_use(self): player = Dominion.Player('Tony') self.assertEqual(10, len(player.stack())) trash = [] # makes sure player has no played cards and 5 cards in their hand self.assertEqual(5, len(player.hand)) self.assertEqual(0, len(player.played)) # adds woodcutter to hand player.hand += [Dominion.Woodcutter()] self.assertEqual(6, len(player.hand)) # asserts woodcutter is correct card and uses it self.assertEqual('Woodcutter', player.hand[5].name) player.hand[5].use(player, trash) # makes sure the player has the correct amount of cards played and cards in their hand self.assertEqual(1, len(player.played)) self.assertEqual(5, len(player.hand))
def test_basic_count(self): #print("totalbuypower test_basic_count...") #print(players[0].hand) bp1 = 0 for card in initial_hand: if card.name == "Copper": bp1 += 1 #print(bp1) bp2 = Dominion.totalbuypower(initial_hand) #print(bp2) self.assertEqual(bp1, bp2)
def test_cardsummary(self): self.player = Dominion.Player("Annie") # Clear the hand and deck completely self.player.hand = [] self.player.deck = [] # Deal with an empty summary summary = self.player.cardsummary() self.assertEqual(summary['VICTORY POINTS'], 0) card = Dominion.Woodcutter() self.player.hand.append(card) summary = self.player.cardsummary() # There's only one card inside the summary so far. self.assertEqual(len(summary), 2) self.assertIn(card.name, summary) self.player.hand.remove(card) summary = self.player.cardsummary() # Now the summary should only have the victory point entry again. self.assertNotIn(card.name, summary) newCard = Dominion.Cellar() self.player.hand.append(newCard) self.player.deck.append(card) summary = self.player.cardsummary() self.assertIn(card.name, summary) self.assertEqual(summary[card.name], 1) self.assertIn(newCard.name, summary) self.assertEqual(summary[newCard.name], 1) self.player.discard.append(card) summary = self.player.cardsummary() self.assertEqual(summary[card.name], 2)
def test_draw(self): player = Dominion.Player('Tony') self.assertEqual(10, len(player.stack())) # make sure player has 5 cards in hand and 5 cards in deck before drawing self.assertEqual(5, len(player.hand)) self.assertEqual(5, len(player.deck)) # draw and make sure player has 6 cards in hand and 4 in deck player.draw() self.assertEqual(6, len(player.hand)) self.assertEqual(4, len(player.deck))
def test_augment(self): player = Dominion.Player('Tony') self.assertEqual(10, len(player.stack())) trash = [] player.actions = 1 player.buys = 1 player.purse = 0 # adds market card and calls augment, reducing player actions by 1 after using it player.hand += [Dominion.Market()] self.assertEqual('Market', player.hand[5].name) player.hand[5].augment(player) player.hand[5].use(player, trash) player.actions -= 1 # makes sure actions, buys, and purse is accurate self.assertEqual(1, player.actions) self.assertEqual(2, player.buys) self.assertEqual(1, player.purse) self.assertEqual(6, len(player.hand))
def dataSetUp(self): # Data setup self.player_names = ["*Annie", "Ben", "*Carla"] self.nV = testUtility.GetNumVictory(self.player_names) self.nC = testUtility.GetNumCurses(self.player_names) self.box = testUtility.GetBoxes(self.nV) self.supply_order = testUtility.GetSupplyOrder() #Setup supply with 5 cards self.supply = testUtility.GetSupply(self.box, self.nV, self.nC, len(self.player_names), 5) self.trash = [] #set player self.player = Dominion.Player(self.player_names[1]) #Ben
def makeMegaCard(self): # for the sake of calculations mega card has a set value of 1 for all and name "mega Card" #make variables cost = 1 actions = 1 cards = 1 buys = 1 coins = 1 #call function actionCard = Dominion.Action_card("MegaCard", cost, actions, cards, buys, coins) return actionCard
def test_augment(self): #Think augment as the effect of each action card # when played it will alter the player's stats by the level of the card. # use it similarly as use. player = Dominion.Player("Duke") actionCard = Dominion.Action_card("MegaCard",1, 1, 1, 1, 1) player.actions = 0 player.buys = 0 player.purse = 0 assert player.actions == 0 assert player.buys == 0 assert player.purse == 0 assert len(player.hand) == 5 #call function actionCard.augment(player) #because the cards are all plus 1 assert player.actions == 1 assert player.buys == 1 assert player.purse == 1 assert len(player.hand) == 6
def addStandardCards(supply, numPlayers, nC, nV): supply["Copper"] = [Dominion.Copper()] * (60 - numPlayers * 7) supply["Silver"] = [Dominion.Silver()] * 40 supply["Gold"] = [Dominion.Gold()] * 30 supply["Estate"] = [Dominion.Estate()] * nV supply["Duchy"] = [Dominion.Duchy()] * nV supply["Province"] = [Dominion.Province()] * nV supply["Curse"] = [Dominion.Curse()] * nC return supply
def test_init(self): self.setUp() cost = 1 buypower = 5 card = Dominion.Coin_card(self.player.name, cost, buypower) self.assertEqual('Annie', card.name) self.assertEqual(buypower, card.buypower) self.assertEqual(cost, card.cost) self.assertEqual("coin", card.category) self.assertEqual(0, card.vpoints)
def setUp(self): # Instantiate player self.player = Dominion.Player('Annie') # Clear the player's balance and deck self.player.balance = 0 self.player.deck.clear() self.player.hand.clear() self.player.hold.clear() self.player.discard.clear() self.player.aside.clear() self.player.hold.clear()
def play_game(supply, supply_order, players): trash = [] #initialize the trash #Play the game turn = 0 while not Dominion.gameover(supply): turn += 1 print("\r") for value in supply_order: print (value) for stack in supply_order[value]: if stack in supply: print (stack, len(supply[stack])) print("\r") for player in players: print (player.name,player.calcpoints()) print ("\rStart of turn " + str(turn)) for player in players: if not Dominion.gameover(supply): print("\r") player.turn(players,supply,trash)
def setUp(self): self.player_name = testUtility.getPlayerNames() self.nC = testUtility.getNumberCurse(self.player_name) self.nV = testUtility.getNumberVictory(self.player_name) self.box = testUtility.getBoxes(self.nV) self.supply_order = testUtility.getSupplyOrder() # pick cards from box to be in supply self.supply = testUtility.getSupply(self.box, self.player_name, self.nV, self.nC) self.trash = [] self.player = Dominion.Player('Annie')
def GetStandardSupply(supply, player_names, nV, nC): #The supply always has these cards supply["Copper"] = [Dominion.Copper()] * (60 - len(player_names) * 7) supply["Silver"] = [Dominion.Silver()] * 40 supply["Gold"] = [Dominion.Gold()] * 30 supply["Estate"] = [Dominion.Estate()] * nV supply["Duchy"] = [Dominion.Duchy()] * nV supply["Province"] = [Dominion.Province()] * nV supply["Curse"] = [Dominion.Curse()] * nC return supply
def test_gameover(self): self.setUp() # Remove all provinces self.supply["Province"] = [] theGameIsOver = Dominion.gameover(self.supply) self.assertEqual(theGameIsOver, True) # Add the provinces back in. self.supply["Province"] = [Dominion.Province()] * 3 theGameIsOver = Dominion.gameover(self.supply) self.assertEqual(theGameIsOver, False) # Remove two other cards. Should not cause the game to be over. self.supply["Duchy"] = [] self.supply["Estate"] = [] theGameIsOver = Dominion.gameover(self.supply) self.assertEqual(theGameIsOver, False) # This is the third one to become empty, so it should end the game. self.supply["Gold"] = [] theGameIsOver = Dominion.gameover(self.supply) self.assertEqual(theGameIsOver, True) # Fourth one to be removed. Game should still end. self.supply["Silver"] = [] theGameIsOver = Dominion.gameover(self.supply) self.assertEqual(theGameIsOver, True)
def test_cardsummary(self): #This function will iterate and calculate cards in the deck. # it will filter out and register card names and count total number of cards #initate variables player = Dominion.Player("Duke") #set hand, and hand to 0 # reset discard to contain new Dominion cards player.hand = [] player.deck = [] assert len(player.stack()) == 0 # this way we can change and modify to show proper results player.deck = [Dominion.Province()] * 10 + [Dominion.Gold()] * 10 # call function testSummary = player.cardsummary() # assert assert testSummary['Gold'] == 10 assert testSummary['Province'] == 10 assert testSummary['VICTORY POINTS'] == 60
def test_draw(self): # draws a card from player deck. else if will use the discard pile, if still none nothing happens #initate variables player = Dominion.Player("Duke") #set hand, and hand to 0 # reset discard to contain new Dominion cards player.hand = [] player.deck = [] assert len(player.stack()) == 0 # add additional cards to change the expected points to be different # original from deck and stack == 3 player.discard = [Dominion.Province()] * 10 #call function player.draw() #assert # hand size should be 1 and deck should be at 9 assert len(player.hand) == 1 assert len(player.deck) == 9
def setUp(self): #Data Setup self.player_names = ["Annie","*Ben","*Carla"] self.players = testUtility.getPlayers(self.player_names) self.nV = testUtility.numVic(self.players) self.nC = testUtility.getCurses(self.players) self.box = testUtility.getBoxes(self.nV) self.supply_order = testUtility.getSupplyOrder() self.supply = testUtility.getSupply(self.box) testUtility.setSupply(self.supply, self.players, self.nV, self.nC) self.trash = [] self.player = Dominion.Player('Annie')
def GetSupply(player_names, supply, nV, nC): supply["Copper"]=[Dominion.Copper()]*(60-len(player_names)*7) supply["Silver"]=[Dominion.Silver()]*40 supply["Gold"]=[Dominion.Gold()]*30 supply["Estate"]=[Dominion.Estate()]*nV supply["Duchy"]=[Dominion.Duchy()]*nV supply["Province"]=[Dominion.Province()]*nV supply["Curse"]=[Dominion.Curse()]*nC return supply
def GetSupply(box, random10, player_names, nV, nC): supply = defaultdict(list, [(k, box[k]) for k in random10]) # The supply always has these cards supply["Copper"] = [Dominion.Copper()] * (60 - len(player_names) * 7) supply["Silver"] = [Dominion.Silver()] * 40 supply["Gold"] = [Dominion.Gold()] * 30 supply["Estate"] = [Dominion.Estate()] * nV supply["Duchy"] = [Dominion.Duchy()] * nV supply["Province"] = [Dominion.Province()] * nV supply["Curse"] = [Dominion.Curse()] * nC return supply
def test_initialization(self): for n in range(TestAction_card.NUM_TRIALS): cost, actions, cards, buys, coins = [ random.randint(1, 30) for i in range(5) ] card = Dominion.Action_card("name", cost, actions, cards, buys, coins) self.assertEqual(card.name, "name") self.assertEqual(card.category, "action") self.assertEqual(card.cost, cost) self.assertEqual(card.actions, actions) self.assertEqual(card.cards, cards) self.assertEqual(card.buys, buys) self.assertEqual(card.coins, coins)
def play(supply, supply_order, players, trash): # Play the game turn = 0 # Keep playing until someone wins while not Dominion.gameover(supply): turn += 1 print("\r") # Print the supply printSupply(supply_order, supply) # Print current scores for player in players: print(player.name, player.calcpoints()) print("\rStart of turn " + str(turn)) # Go through each player's turn for this round while no one wins for player in players: if not Dominion.gameover(supply): print("\r") player.turn(players, supply, trash)
def setUp(self): self.player_names = ["Annie", "*Becky", "*Carla"] self.supply_order = testUtility.supplyOrder #Pick 10 cards from box to be in the supply. self.supply = testUtility.buildSupply(self.player_names) #initialize the trash self.trash = [] #Costruct the Player objects self.players = testUtility.buildPlayers(self.player_names) self.player = Dominion.Player('Annie')
def test_calc_points(self): self.setUp() i = 0 for card in self.player.stack(): if card.vpoints == 0: self.player.hand.pop(i) i += 1 break i += 1 self.player.hand.insert(0, Dominion.Gardens()) #for card in self.player.stack(): # print(card.vpoints) testPoints = Dominion.Player.calcpoints(self.player) self.assertEqual(4, testPoints)
def playGame(supply, players): #get the supply order supply_order = _getSupplyOrder() #initialize the trash trash = [] #set the turn number turn = 0 while not Dominion.gameover(supply): turn += 1 print("\r") for value in supply_order: print(value) for stack in supply_order[value]: if stack in supply: print(stack, len(supply[stack])) print("\r") for player in players: print(player.name, player.calcpoints()) print("\rStart of turn " + str(turn)) for player in players: if not Dominion.gameover(supply): print("\r") player.turn(players, supply, trash)
def get_supply(box, player_names, nV, nC): boxlist = [k for k in box] random.shuffle(boxlist) random10 = boxlist[:10] supply = defaultdict(list, [(k, box[k]) for k in random10]) supply["Copper"] = [Dominion.Copper()] * (60 - len(player_names) * 7) supply["Silver"] = [Dominion.Silver()] * 40 supply["Gold"] = [Dominion.Gold()] * 30 supply["Estate"] = [Dominion.Estate()] * nV supply["Duchy"] = [Dominion.Duchy()] * nV supply["Province"] = [Dominion.Province()] * nV supply["Curse"] = [Dominion.Curse()] * nC return supply
def update_supply(supply, num_victory, num_curses, num_players): """ Sets the supply of some of the items Modifies the given supply dict Nothing returned """ supply["Copper"] = [Dominion.Copper()] * (60 - num_players * 7) supply["Silver"] = [Dominion.Silver()] * 40 supply["Gold"] = [Dominion.Gold()] * 30 supply["Estate"] = [Dominion.Estate()] * num_victory supply["Duchy"] = [Dominion.Duchy()] * num_victory supply["Province"] = [Dominion.Province()] * num_victory supply["Curse"] = [Dominion.Curse()] * num_curses
def test_calcPoints(self): # init data self.dataSetUp() # test before adding action cards self.assertEqual(3, self.player.calcpoints()) # should be 3 from 3 estates # add 2 provinces (6 points each) self.player.deck += [Dominion.Province()] * 2 # test calcPoints self.assertEqual(15, self.player.calcpoints()) # add 2 Duchies (3 points each) self.player.deck += [Dominion.Duchy()] * 2 # test calcPoints self.assertEqual(21, self.player.calcpoints()) # add 6 gardens (2 points each) self.player.deck += [Dominion.Gardens()] * 6 # test calcPoints self.assertEqual(33, self.player.calcpoints())
def print_final_score(players): dcs = Dominion.cardsummaries(players) vp = dcs.loc['VICTORY POINTS'] vpmax = vp.max() winners = [] for i in vp.index: if vp.loc[i] == vpmax: winners.append(i) if len(winners) > 1: winstring = ' and '.join(winners) + ' win!' else: winstring = ' '.join([winners[0], 'wins!']) print("\nGAME OVER!!!\n" + winstring + "\n") print(dcs)
def startGame(self): print("Starting Game...") chance = False if random.randint(0, 1) == 0: print("Playing with chance cards") chance = True self.game = Dominion.game( self.users.keys(), onlyWorking=self._args.workingCardsOnly, expansions=self._args.expansions, useChance=self._chanceCards, ) turn = self.game.next() players = self.game.getPlayers() stores = self.game.getStores() dStores = {} for store in stores: try: dStores[store.getName()] = (store.getCost(), len(store)) except OverflowError: dStores[store.getName()] = (store.getCost(), u"\u221E") stores = repr(dStores) currentPlayerName = turn.getPlayer().getName() print("starting player: " + currentPlayerName) for name, protocol in self.users.iteritems(): protocol.sendLine("starting") protocol.player = [p for p in players if p.getName() == name][0] protocol.updatePiles(["Hand"]) protocol.updateStash() protocol.sendLine("data: store: " + stores) if name == currentPlayerName: protocol.sendLine("your turn") protocol.phase = "Action" else: protocol.sendLine("turn: " + currentPlayerName) protocol.phase = "Wait"
window.addstr(0,0, "Add a card") for n, card in enumerate(cards): window.addstr(n+1, 0, "%i: %s" % ((n+1) % 10, card)) base = len(cards) window.addstr(base+2, 0, "W: Copper") window.addstr(base+3, 0, "E: Silver") window.addstr(base+4, 0, "R: Gold") window.addstr(base+6, 0, "S: Estate") window.addstr(base+7, 0, "D: Duchy") window.addstr(base+8, 0, "F: Province") window.addstr(base+10, 0, "C: Cancel") elif inputstate == 'remove': for n, card in enumerate(cards): window.addstr(n+1, 0, "%i: %s" % ((n+1) % 10, card)) base = len(cards) window.addstr(base+2, 0, "W: Copper") window.addstr(base+3, 0, "E: Silver") window.addstr(base+4, 0, "R: Gold") window.addstr(base+6, 0, "S: Estate") window.addstr(base+7, 0, "D: Duchy") window.addstr(base+8, 0, "F: Province") window.addstr(base+10, 0, "C: Cancel") window.refresh() modifs = Dominion.possibleModifs(resultbatch.base.purchaseSet, cardchoices.values()) except KeyboardInterrupt: pass finally: curses.endwin() stop_workers()
#initialize the trash trash = [] #Costruct the Player objects players = [] for name in player_names: if name[0]=="*": players.append(Dominion.ComputerPlayer(name[1:])) elif name[0]=="^": players.append(Dominion.TablePlayer(name[1:])) else: players.append(Dominion.Player(name)) #Play the game turn = 0 while not Dominion.gameover(supply): turn += 1 print("\r") for value in supply_order: print (value) for stack in supply_order[value]: if stack in supply: print (stack, len(supply[stack])) print("\r") for player in players: print (player.name,player.calcpoints()) print ("\rStart of turn " + str(turn)) for player in players: if not Dominion.gameover(supply): print("\r") player.turn(players,supply,trash)