コード例 #1
0
def test_initializeGame():
    randomSeed = 111
    kingdomCards_Valid = [d.Adventurer, d.Ambassador, d.Baron, d.Council_Room, d.Cutpurse, d.Embargo, d.Feast, d.Gardens, d.Great_Hall, d.Village]
    kingdomCards= random.sample([d.Curse, d.Estate, d.Duchy, d.Province, d.Copper, d.Silver, d.Gold, d.Adventurer, d.Ambassador, d.Baron, d.Council_Room, d.Cutpurse, d.Embargo, d.Feast, d.Gardens, d.Great_Hall, d.Mine, d.Minion, d.Outpost, d.Remodel, d.Salvager, d.Sea_Hag, d.Smithy, d.Treasure_Map, d.Village],10)
    print "Testing Initialize Game with Bad set of Kingdom Cardsand Number of players"
    print kingdomCards
    players = random.randint(0,5)
    a = d.initializeGame(players, kingdomCards, randomSeed)
    assert(a == -1)
    print "Initilize Game() is invalid for kingdomCards selected and players: %d" %players
    print "Expected: " + "-1"
    print "Actual: %d " %a
    print "TEST PASS"
    if (a!= -1):
        print "TEST FAIL"
        print "Accepting bad input of kingdom cards for players %d" %players
    
    print "Testing Supply count of copper cards for all number of players and with valid kingdom cards"
    players = random.randint(2,4)
    b = d.initializeGame(players, kingdomCards_Valid, randomSeed)
    assert(b.supplyCount[d.Copper] == (60- 7* players))
    print "TEST PASS"
    print "Taking correct count of Copper cards: %d in supply for Players : %d" %(b.supplyCount[d.Copper],players)
    if (b.supplyCount[d.Copper] != (60- 7* players)):
        print "TEST FAIL"
        print "Taking wrong count of Copper cards: %d in supply for Players : %d" %(b.supplyCount[d.Copper],players)
コード例 #2
0
def test_initializeGame():
    kingdomCards_Invalid = [d.Curse, d.Ambassador, d.Baron, d.Council_Room, d.Cutpurse, d.Embargo, d.Feast, d.Gardens, d.Great_Hall, d.Village]
    kingdomCards_Valid = [d.Adventurer, d.Ambassador, d.Baron, d.Council_Room, d.Cutpurse, d.Embargo, d.Feast, d.Gardens, d.Great_Hall, d.Village]
    print "Testing Initialize Game with Bad set of Kingdom Cardsand Number of players"
    print "Players"
    print numPlayers
    print "Kingdom Cards"
    print kingdomCards
    a = d.initializeGame(numPlayers, kingdomCards_Invalid, randomSeed)
    assert(a == -1)
    print "Initilize Game() is invalid for kingdomCards selected and players: %d" %numPlayers
    print "Expected: " + "-1"
    print "Actual: %d " %a
    print "TEST PASS"
    if (a!= -1):
        print "TEST FAIL"
        print "Accepting bad input of kingdom cards for players %d" %numPlayers
    
    print "Testing Supply count of copper cards for all number of players and with valid kingdom cards"
    players = random.randint(2,4)
    b = d.initializeGame(players, kingdomCards_Valid, randomSeed)
    assert(b.supplyCount[d.Copper] == (60- 7* players))
    print "TEST PASS"
    print "Taking correct count of Copper cards: %d in supply for Players : %d" %(b.supplyCount[d.Copper],players)
    if (b.supplyCount[d.Copper] != (60- 7* players)):
        print "TEST FAIL"
        print "Taking wrong count of Copper cards: %d in supply for Players : %d" %(b.supplyCount[d.Copper],players)
コード例 #3
0
def test_playCard():
    card = random.randint(0,26)
    ##kingdomCards = [d.Adventurer, d.Ambassador, d.Baron, d.Council_Room, d.Cutpurse, d.Embargo, d.Feast, d.Gardens, d.Great_Hall, d.Village]
    print "TESTING playCard()"
    a = d.initializeGame(numPlayers,kingdomCards, randomSeed)
    assert(a !=-1)
    print "Before playing"
    print "hand of Player 0:"
    print a.hand[0]
    print "Card played by Player : 0 is "
    print card
    hpos = len(a.hand[0])-1
    b = d.playCard(hpos,0,0,0,a)
    if (b == -1):
            if card not in a.kingdomCards:
                print "Invalid Input:Card is Not KingdomCard"
            elif card not in a.hand[a.whoseTurn]:
                print "Invalid input, Card trying to play is not in hand"
    if(b ==0):
        print "TEST PASS"
        print "After playing"
        print "hand"
        print a.hand[0]
        print "Card played by Player:0 is "
        print card
コード例 #4
0
def test_discardCard(): 
    ##kingdomCards = [d.Adventurer, d.Ambassador, d.Baron, d.Council_Room, d.Cutpurse, d.Embargo, d.Feast, d.Gardens, d.Great_Hall, d.Village]
    card = random.choice([0,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]) ##random.randint(d.Curse,d.Village)
    print "TESTING discardCard()"
    a = d.initializeGame(numPlayers,kingdomCards, randomSeed)
    assert(a !=-1)
    print "Before discard"
    print "Card to discard:"
    print card
    print "hand before discarding"
    print a.hand
    print "Coins available:"
    print a.coins
    b = d.discardCard(card,a.whoseTurn,a,0)
    if (b == -1):
        print "Invalid Input:card not in hand OR SupplyEmpty"
        return -1
    assert(b ==0)
    print "TEST PASS"
    print "discardCard() is successfull for player : %d discarded %d" %(a.whoseTurn,card)
    print "After Discarding"
    print "Card Discarded:"
    print card
    print "Hand after Discarding"
    print a.hand
    print "Coins Available:"
    print a.coins
コード例 #5
0
def test_discardCard():
    randSeed = 111
    numPlayers =random.randint(2,4) 
    kingdomCards = [d.Adventurer, d.Ambassador, d.Baron, d.Council_Room, d.Cutpurse, d.Embargo, d.Feast, d.Gardens, d.Great_Hall, d.Village]
    card = d.Copper ##random.randint(d.Curse,d.Village)
    print "TESTING UpdateCoins()"
    a = d.initializeGame(numPlayers,kingdomCards, randSeed)
    assert(a !=-1)
    print "Before discard"
    print "Card to discard:"
    print card
    print "hand before discarding"
    print a.hand
    print "Coins available:"
    print a.coins
    b = d.discardCard(card,a.whoseTurn,a,0)
    c = d.updateCoins(a.whoseTurn,a,0)
    if (b == -1):
        print "Invalid Input:card not in hand OR SupplyEmpty"
    assert(b ==0)
    print "TEST PASS"
    print "discardCard() is successfull for player : %d discarded %d" %(a.whoseTurn,card)
    print "After Discarding"
    print "Card Discarded:"
    print card
    print "Hand after Discarding"
    print a.hand
    print "Coins Available:"
    print a.coins
コード例 #6
0
def test_gainCard():
    randSeed = 111
    card = random.randint(0,26)
    numPlayers = 4
    turn = random.randint(0,3)
    kingdomCards = [d.Adventurer, d.Ambassador, d.Baron, d.Council_Room, d.Cutpurse, d.Embargo, d.Feast, d.Gardens, d.Great_Hall, d.Village]
    print "TESTING gainCard()"
    a = d.initializeGame(numPlayers,kingdomCards, randSeed)
    assert(a !=-1)
    print "Before gaining"
    print "Deck"
    print a.deck
    print "Card Gaining by Player : %d is " %turn
    print card
    print "Supply Count of Card:"
    print a.supplyCount[card]
    b = d.gainCard(card,a,1,turn)
    if (b == -1):
        print "Invalid Input:Supply Empty"
    assert(b ==0)
    print "TEST PASS"
    print "After gaining"
    print "Deck"
    print a.deck
    print "Card gained by Player %d is "%turn
    print card
    print "Supply Count of Card:"
    print a.supplyCount[card]
コード例 #7
0
def test_updateCoins():
    maxBonus = random.randint(2,5)
    maxHandCount = random.randint(2,5)
    ##kingdomCards = [d.Adventurer, d.Ambassador, d.Baron, d.Council_Room, d.Cutpurse, d.Embargo, d.Feast, d.Gardens, d.Great_Hall, d.Village]
    print "TESTING UpdateCoins()"
    a = d.initializeGame(numPlayers,kingdomCards, randomSeed)
    assert(a !=-1)
    for i in range(numPlayers):
        a.hand[i] = []
    for player in range(numPlayers):
        for handCount in range(1,maxHandCount+1):
            a.hand[player].append(d.Copper)
            print a.hand[player]
            for bonus in range(maxBonus):
                b = d.updateCoins(player,a,bonus)
                assert(b ==0)
                print "TEST PASS"
                print "Return Value for player: %d, bonus %d and hand count : %d is %d" %(player,bonus, handCount, b)
                print "Expected value : 0"
                if (b != 0):
                    print "TEST FAIL"
                    print "Return Value for player: %d, bonus %d and hand count : %d is %d" %(player,bonus, handCount, b)
                    print "Expected value : 0"
                assert(a.coins == (handCount * 1 + bonus))
                print "TEST PASS"
                print "Testing with all copper coins for player : %d, bonus : %d, handCount : %d, Coin Value = %d" %(player,bonus,handCount,a.coins)
                print "Expected = %d" %(handCount *1 +bonus)
                if (a.coins != (handCount * 1 + bonus)):
                    print "TEST FAIL"
                    print "Testing with all copper coins for player : %d, bonus : %d, handCount : %d, Coin Value = %d" %(player,bonus,handCount,a.coins)
                    print "Expected = %d" %(handCount *1 +bonus)
コード例 #8
0
ファイル: testdompy.py プロジェクト: gcaushik/Dominion
def checkFirstTurn():
  game = d.initializeGame(2, [c.adventurer, c.ambassador, c.baron, c.council_room, c.cutpurse,
                            c.embargo, c.feast, c.gardens, c.great_hall, c.mine], 10)
  handPos = random.randrange(5)
  ret = d.playCard(handPos,0,0,0,game)
  assert(ret == -1)
  print "TEST CASE PASSED"
  return 0
コード例 #9
0
def test_getWinners():
    kingdomCards = [d.Adventurer, d.Ambassador, d.Baron, d.Council_Room, d.Cutpurse, d.Embargo, d.Feast, d.Gardens, d.Great_Hall, d.Village]
    print("Tetsing getWinners")
    p = d.initializeGame(2, kingdomCards,111)
    p.discard[0].append(d.Province)
    r = d.getWinners(p)
    assert(r!=-1)
    print("Player Won:")
    print r
コード例 #10
0
def test_isGameOver():
    ##kingdomCards = [d.Adventurer, d.Ambassador, d.Baron, d.Council_Room, d.Cutpurse, d.Embargo, d.Feast, d.Gardens, d.Great_Hall, d.Village]
    print("Tetsing isGameOver")
    r = d.initializeGame(numPlayers, kingdomCards,randomSeed)
    r.supplyCount[d.Province] = 0
    s = d.isGameOver(r)
    assert(s == 1)
    print ("Game Over: SUpply of province exhausted")
    print "Supply of province:"
    print r.supplyCount[d.Province]

    r = d.initializeGame(2, kingdomCards,111)
    r.supplyCount[d.Duchy] = 0
    r.supplyCount[d.Estate] = 0
    r.supplyCount[d.Village] = 0
    s = d.isGameOver(r)
    assert(s == 1)
    print ("Game Over:Supply of 3 piles is empty")
    print r.supplyCount[d.Duchy]
    print r.supplyCount[d.Estate]
    print r.supplyCount[d.Village]
コード例 #11
0
def test_endTurn():
    kingdomCards = [d.Adventurer, d.Ambassador, d.Baron, d.Council_Room, d.Cutpurse, d.Embargo, d.Feast, d.Gardens, d.Great_Hall, d.Village]
    print("Testing endTurn")
    r= d.initializeGame(2, kingdomCards,111)
    assert(r != -1)
    print ("Whose Turn:")
    print r.whoseTurn
    s = d.endTurn(r)
    assert (s == 0)
    print ("After endTurn:")
    print ("Whose Turn:")
    print r.whoseTurn
コード例 #12
0
def test_getWinners():
    ##kingdomCards = [d.Adventurer, d.Ambassador, d.Baron, d.Council_Room, d.Cutpurse, d.Embargo, d.Feast, d.Gardens, d.Great_Hall, d.Village]
    print("Tetsing getWinners")
    p = d.initializeGame(numPlayers, kingdomCards,randomSeed)
    p.discard[0].append(d.Province)
    p.discard[1].append(d.Province)
    for player in range(numPlayers):
        print "Score of Player: %d" %player
        print d.scoreFor(player,p)
    r = d.getWinners(p)
    assert(r!=-1)
    print("Player Won:")
    print r
コード例 #13
0
def test_scoreFor():
    kingdomCards = [d.Adventurer, d.Ambassador, d.Baron, d.Council_Room, d.Cutpurse, d.Embargo, d.Feast, d.Gardens, d.Great_Hall, d.Village]
    print("Testing scoreFor()")
    r = d.initializeGame(2, kingdomCards,111)
    assert(r!=-1)
    print "Hand"
    print r.hand[0]
    print "Deck"
    print r.deck[0]
    print "Discard"
    print r.discard[0]
    x = d.scoreFor(0,r)
    assert(x!= -1)
    print ("Score for player : 0 is:")
    print x
コード例 #14
0
   def act47(self):
      if self.__collectCov:
         self.__cov.start()
      try:
         self.p_GAME[0] = mydom.initializeGame(self.p_NUMPLAYERS[0],kingdomCards,self.p_SEED[0])

      finally:
         if self.__collectCov:
            self.__cov.stop()
            self.__updateCov()
      self.p_GAME_REF[0] = otherdom.initializeGame(self.p_NUMPLAYERS[0],kingdomCards,self.p_SEED[0])

      self.p_GAME_used[0]=False
      self.p_NUMPLAYERS_used[0]=True
      self.p_SEED_used[0]=True
コード例 #15
0
def test_shuffle():
    ##kingdomCards = [d.Adventurer, d.Ambassador, d.Baron, d.Council_Room, d.Cutpurse, d.Embargo, d.Feast, d.Gardens, d.Great_Hall, d.Village]
    a = d.initializeGame(numPlayers,kingdomCards, randomSeed)
    assert(a !=-1)
    print "Before Shuffle"
    print "Deck"
    print a.deck
    for turn in range(numPlayers):
        b = d.shuffle(turn,a)
    if (b == -1):
        print "Invalid Input:card not in hand OR SupplyEmpty"
    assert(b ==0)
    print "TEST PASS"
    print "After Shuffling"
    print "Deck"
    print a.deck
コード例 #16
0
def test_scoreFor():
    ##kingdomCards = [d.Adventurer, d.Ambassador, d.Baron, d.Council_Room, d.Cutpurse, d.Embargo, d.Feast, d.Gardens, d.Great_Hall, d.Village]
    print("Testing scoreFor()")
    r = d.initializeGame(numPlayers, kingdomCards,randomSeed)
    assert(r!=-1)
    for player in range(numPlayers):
        print "Hand: %d" %player
        print r.hand[player]
        print "Deck: %d" %player
        print r.deck[player]
        print "Discard: %d" %player
        print r.discard[player]
        x = d.scoreFor(player,r)
        assert(x!= -1)
        print ("Score for player : %d is:" %player)
        print x
コード例 #17
0
def test_buyCard():
    randSeed = 111
    numPlayers =random.randint(2,4) 
    maxBonus = random.randint(2,5)
    maxHandCount = random.randint(2,5)
    kingdomCards = [d.Adventurer, d.Ambassador, d.Baron, d.Council_Room, d.Cutpurse, d.Embargo, d.Feast, d.Gardens, d.Great_Hall, d.Village]
    card = random.randint(d.Curse,d.Village)
    print "TESTING UpdateCoins()"
    a = d.initializeGame(numPlayers,kingdomCards, randSeed)
    assert(a !=-1)
    a.whoseTurn = random.randint(0,numPlayers-1)
    print "Before Buying"
    print "Card want to Buy:"
    print card
    print "Cost of Card"
    x = d.getCost(card)
    print x
    print "Coins Available:"
    print a.coins
    print "numBuys available"
    print a.numBuys
    print "Whose Turn:"
    print a.whoseTurn
    print "Discard"
    print a.discard
    print "Supply of Card"
    print a.supplyCount[card]
    b = d.buyCard(card,a)
    if (b == -1):
        print "Invalid Input:No numBuys OR No enough Coins OR SupplyEmpty"
    assert(b ==0)
    print "BuyCard() is successfull for player : %d brought: %d" %(a.whoseTurn,card)
    print "After Buying"
    print "Card Bought:"
    print card
    print "Coins Available:"
    print a.coins
    print "numBuys available"
    print a.numBuys
    print "Whose Turn:"
    print a.whoseTurn
    print "Discard"
    print a.discard
    print "Supply of Card"
    print a.supplyCount[card]
コード例 #18
0
ファイル: testdompy.py プロジェクト: gcaushik/Dominion
def checkStart():
  kingdomCards = [7,8,9,10,11,12,13,14,15,16,17,18,19]
  kingdom = []
  configurations = [comb for comb in itertools.combinations(kingdomCards,10)]
  counter = 0
  for i in range(2,5):
    for conf in configurations:
      kingdom = list(conf)
      game = d.initializeGame(i,kingdom,10)
      counter += 1
      assert(d.supplyCount(c.silver,game) == 40)
      assert(d.supplyCount(c.gold,game) == 30)
      for j in c.kingdom_cards:
        if j in kingdom:
          assert(d.supplyCount(j,game) == 10) 
      if i == 2:
        assert(d.supplyCount(c.copper,game) == 46)
        assert(d.supplyCount(c.curse,game) == 10)
        assert(d.supplyCount(c.estate,game) == 2)
        assert(d.supplyCount(c.duchy,game) == 8)
        assert(d.supplyCount(c.province,game) == 8)
        assert(d.supplyCount(c.gardens,game) == 8)
        assert(d.supplyCount(c.great_hall,game) == 8)
      elif i == 3:
        assert(d.supplyCount(c.copper,game) == 39)
        assert(d.supplyCount(c.curse,game) == 20)
        assert(d.supplyCount(c.estate,game) == 3)
        assert(d.supplyCount(c.duchy,game) == 12)
        assert(d.supplyCount(c.province,game) == 12)
        assert(d.supplyCount(c.gardens,game) == 12)
        assert(d.supplyCount(c.great_hall,game) == 12) 
      elif i == 4:
        assert(d.supplyCount(c.copper,game) == 32)
        assert(d.supplyCount(c.curse,game) == 30)
        assert(d.supplyCount(c.estate,game) == 0)
        assert(d.supplyCount(c.duchy,game) == 12)
        assert(d.supplyCount(c.province,game) == 12)
        assert(d.supplyCount(c.gardens,game) == 12)
        assert(d.supplyCount(c.great_hall,game) == 12)

      print "Configuration ", counter, " PASSED"
      print i, "players, kingdom = " , kingdom
  
  print "TEST CASE PASSED"
  return 0
コード例 #19
0
def test_endTurn():
    ##kingdomCards = [d.Adventurer, d.Ambassador, d.Baron, d.Council_Room, d.Cutpurse, d.Embargo, d.Feast, d.Gardens, d.Great_Hall, d.Village]
    print("Testing endTurn")
    r= d.initializeGame(numPlayers, kingdomCards,randomSeed)
    assert(r != -1)
    print ("Whose Turn:")
    print r.whoseTurn
    print "Discard"
    print r.discard
    print "Hand"
    print r.hand
    s = d.endTurn(r)
    assert (s == 0)
    print ("After endTurn:")
    print ("Whose Turn:")
    print r.whoseTurn
    print "Discard"
    print r.discard
    print "Hand"
    print r.hand
コード例 #20
0
def test_drawCard():
    ##kingdomCards = [d.Adventurer, d.Ambassador, d.Baron, d.Council_Room, d.Cutpurse, d.Embargo, d.Feast, d.Gardens, d.Great_Hall, d.Village]
    print "TESTING drawCard()"
    a = d.initializeGame(numPlayers,kingdomCards, randomSeed)
    assert(a !=-1)
    print "Before drawing"
    print "Deck"
    print a.deck
    print "Hand"
    print a.hand
    for turn in range(numPlayers):
        b = d.drawCard(turn,a)
    if (b == -1):
        print "Invalid Input:deck empty"
    assert(b ==0)
    print "TEST PASS"
    print "After drawing"
    print "Deck"
    print a.deck
    print "Hand"
    print a.hand
コード例 #21
0
ファイル: testdompy.py プロジェクト: gcaushik/Dominion
import dominion as d
import cardnames as c
import itertools
import random




game2 = d.initializeGame(3, [c.adventurer, c.ambassador, c.baron, c.council_room, c.cutpurse,
                            c.embargo, c.feast, c.gardens, c.great_hall, c.mine], 10)

game3 = d.initializeGame(4, [c.adventurer, c.ambassador, c.baron, c.council_room, c.cutpurse,
                            c.embargo, c.feast, c.gardens, c.great_hall, c.mine], 10)

game4 = d.initializeGame(2, [c.adventurer, c.ambassador, c.baron, c.council_room, c.cutpurse,
                            c.embargo, c.feast, c.gardens, c.great_hall, c.outpost], 10)

def test1(game):
  d.buyCard(c.silver, game)
  d.endTurn(game)
  assert (d.buyCard(c.copper, game) == 0)
  d.buyCard(c.silver, game)
  assert (d.whoseTurn(game) == 1)
  assert (d.buyCard(c.silver, game) == -1)
  d.endTurn(game)
  assert (d.buyCard(c.province,game) == -1) 
    
  print "TEST CASE PASSED" 
  return 0                  
  
# Test checks whether a game state sets up supplies correctly with all the different valid configurations