Exemple #1
0
def random_GameState2(w,s):
	cardlist=[d.adventurer, d.ambassador, d.baron, d.council_room, d.cutpurse,
                            d.embargo, d.feast, d.smithy, d.village,d.sea_hag]
	g=d.initializeGame(w, cardlist, s)
	for i in xrange(10):
		if d.isGameOver(g):
			break
		d.buyCard(random.choice(cardlist),g)
		d.playCard(len(g.hand[g.whoseTurn])-1,random.randrange(0,len(g.hand[g.whoseTurn])-1),random.choice(cardlist),random.choice(cardlist),g)
		d.endTurn(g)
	return g
Exemple #2
0
def random_GameState(w,s):
	#x=random.randrange(2,5)
	g=d.initializeGame(w, [d.adventurer, d.ambassador, d.baron, d.council_room, d.cutpurse,
                            d.embargo, d.feast, d.gardens, d.great_hall,d.mine], s)
	for i in xrange(10):
		if d.isGameOver(g):
			break
		d.buyCard(random.randrange(7,17),g)
		d.playCard(len(g.hand[g.whoseTurn])-1,random.randrange(1,16),random.randrange(1,16),random.randrange(1,17),g)
		d.endTurn(g)
	return g
Exemple #3
0
def playCardTest():
	player=random.randrange(2,5)
	seed=random.randrange(3,11)

	game = d.initializeGame(player, [d.adventurer, d.ambassador, d.baron, d.council_room, d.cutpurse,
								d.embargo, d.feast, d.gardens, d.great_hall, d.mine], seed)
				
#for i in range(MAX_TEST):
	turn=random.randrange(0,player)
	game.whoseTurn=turn
	play=random.choice(game.kingdomCards)
	#play=d.baron
	if play==d.adventurer:
		deck=random.randrange(0,MAX_DECK)
		discard=random.randrange(0,MAX_DECK)
		hand=random.randrange(0,MAX_HAND-1)
		game.deck[turn]=[]
		game.discard[turn]=[]
		game.hand[turn]=[]
		for i in range(deck):
			game.deck[turn].append(random.randrange(d.curse,d.mine+1))
		for j in range(discard):
			game.discard[turn].append(random.randrange(d.curse,d.mine+1))
		for k in range(hand):
			game.hand[turn].append(random.randrange(d.curse,d.mine+1))
		pos=random.randrange(0,hand)
		game.hand[turn].insert(pos,d.adventurer) # insert the kingdom card to position
		choice1=-1 #adventurer does not need player any choise so set all -1 and bonus use default
		choice2=-1
		choice3=-1
		d.playCard(pos,choice1,choice2,choice3,game)
	elif play==d.ambassador:
		pass #still not clearn this card effect
	elif play==d.baron: #I think have some bug at the baron implementation
		hand=random.randrange(0,MAX_HAND-1)
		discard=random.randrange(0,MAX_DECK)
		game.hand[turn]=[]
		game.discard[turn]=[]
		for j in range(discard):
			game.discard[turn].append(random.randrange(d.curse,d.mine+1))
		for k in range(hand):
			game.hand[turn].append(random.randrange(d.curse,d.mine+1))
		pos=random.randrange(0,hand)
		game.hand[turn].insert(pos,d.baron)
		choice1=random.randrange(0,hand)
		choice2=random.randrange(0,2)
		choice3=-1 # don't need 3
		d.playCard(pos,choice1,choice2,choice3,game)
	elif play==d.council_room:
		hand1=[]
		deck1=[]
		for i in range(player):
			hand1.append(random.randrange(0,MAX_HAND-1))
		for j in range(player):
			deck1.append(random.randrange(0,MAX_DECK))
		game.hand[turn]=[]
		game.deck[turn]=[]
		for j in range(hand1[turn]):
			game.hand[turn].append(random.randrange(d.curse,d.mine+1))
		for k in range(deck1[turn]):
			game.deck[turn].append(random.randrange(d.curse,d.mine+1))
		pos=random.randrange(0,hand1[turn])
		game.hand[turn].insert(pos,d.council_room)
		
		for a in range(player):
			if a != turn:
				game.hand[a]=[]
				game.deck[a]=[]
				for b in range(hand1[a]):
					game.hand[a].append(random.randrange(d.curse,d.mine+1))
				for c in range(deck1[a]):
					game.deck[a].append(random.randrange(d.curse,d.mine+1))
		choice1=-1 #don't need choice so set all -1
		choice2=-1
		choice3=-1
		d.playCard(pos,choice1,choice2,choice3,game)
	elif play==d.cutpurse:
		hand1=[]
		deck1=[]
		for i in range(player):
			hand1.append(random.randrange(0,MAX_HAND-1))
		for j in range(player):
			deck1.append(random.randrange(0,MAX_DECK))
		game.hand[turn]=[]
		game.deck[turn]=[]
		for j in range(hand1[turn]): # current player
			game.hand[turn].append(random.randrange(d.curse,d.mine+1))
		for k in range(deck1[turn]):
			game.deck[turn].append(random.randrange(d.curse,d.mine+1))
		pos=random.randrange(0,hand1[turn])
		game.hand[turn].insert(pos,d.cutpurse)
		
		for a in range(player): #other player
			if a !=turn:
				game.hand[a]=[]
				game.deck[a]=[]
				for b in range(hand1[a]):
					game.hand[a].append(random.randrange(d.curse,d.mine+1))
				for c in range(deck1[a]):
					game.deck[a].append(random.randrange(d.curse,d.mine+1))
		
		choice1=-1
		choice2=-1
		choice3=-1
		d.playCard(pos,choice1,choice2,choice3,game)
		
	elif play==d.embargo:
		hand=random.randrange(0,MAX_HAND-1)
		game.hand[turn]=[]
		for i in range(hand):
			game.hand[turn].append(random.randrange(d.curse,d.mine+1))
		pos=random.randrange(0,hand)
		game.hand[turn].insert(pos,d.embargo)
		####random supplyCount
		for card in game.kingdomCards:
			game.supplyCount[card]=random.randrange(0,11)
		#####random embargo token
		for token in game.kingdomCards:
			game.embargoTokens[token]=random.randrange(0,99)
		choice1=random.randrange(d.adventurer,d.mine+1) #random pick one 
		choice2=-1
		choice3=-1
		d.playCard(pos,choice1,choice2,choice3,game)
	elif play==d.feast:
		hand=random.randrange(0,MAX_HAND-1)
		game.hand[turn]=[]
		for i in range(hand):
			game.hand[turn].append(random.randrange(d.curse,d.mine+1))
		pos=random.randrange(0,hand)
		game.hand[turn].insert(pos,d.feast)
		for card in game.kingdomCards:
			game.supplyCount[card]=random.randrange(0,11)
		choice1=random.choice(game.kingdomCards)
		choice2=-1
		choice3=-1
		d.playCard(pos,choice1,choice2,choice3,game)
	elif play==d.great_hall:
		deck=random.randrange(0,MAX_DECK)
		discard=random.randrange(0,MAX_DECK)
		hand=random.randrange(0,MAX_HAND-1)
		game.deck[turn]=[]
		game.discard[turn]=[]
		game.hand[turn]=[]
		for i in range(deck):
			game.deck[turn].append(random.randrange(d.curse,d.mine+1))
		for j in range(discard):
			game.discard[turn].append(random.randrange(d.curse,d.mine+1))
		for k in range(hand):
			game.hand[turn].append(random.randrange(d.curse,d.mine+1))
		pos=random.randrange(0,hand)
		
		game.hand[turn].insert(pos,d.great_hall)
		game.numActions=random.randrange(0,99)
		
		choice1=-1
		choice2=-1
		choice3=-1
		d.playCard(pos,choice1,choice2,choice3,game)
	elif play==d.mine:
		hand=random.randrange(0,MAX_HAND-1)
		game.hand[turn]=[]
		for k in range(hand):
			game.hand[turn].append(random.randrange(d.curse,d.mine+1))
		pos=random.randrange(0,hand)
		game.hand[turn].insert(pos,d.mine)
		for card in range(d.copper,d.gold+1): ##random moey
			game.supplyCount[card]=random.randrange(0,50)
		choice1=random.choice(game.hand[turn])
		choice2=random.randrange(d.copper,d.gold+1)
		choice3=-1
		d.playCard(pos,choice1,choice2,choice3,game)
	elif play==d.smithy:
		deck=random.randrange(0,MAX_DECK)
		discard=random.randrange(0,MAX_DECK)
		hand=random.randrange(0,MAX_HAND-1)
		game.deck[turn]=[]
		game.discard[turn]=[]
		game.hand[turn]=[]
		for i in range(deck):
			game.deck[turn].append(random.randrange(d.curse,d.mine+1))
		for j in range(discard):
			game.discard[turn].append(random.randrange(d.curse,d.mine+1))
		for k in range(hand):
			game.hand[turn].append(random.randrange(d.curse,d.mine+1))
		pos=random.randrange(0,hand)
		game.hand[turn].insert(pos,d.smithy)
		choice1=-1
		choice2=-1
		choice3=-1
		d.playCard(pos,choice1,choice2,choice3,game)
	elif play==d.village:
		deck=random.randrange(0,MAX_DECK)
		discard=random.randrange(0,MAX_DECK)
		hand=random.randrange(0,MAX_HAND-1)
		game.deck[turn]=[]
		game.discard[turn]=[]
		game.hand[turn]=[]
		for i in range(deck):
			game.deck[turn].append(random.randrange(d.curse,d.mine+1))
		for j in range(discard):
			game.discard[turn].append(random.randrange(d.curse,d.mine+1))
		for k in range(hand):
			game.hand[turn].append(random.randrange(d.curse,d.mine+1))
		pos=random.randrange(0,hand)
		game.hand[turn].insert(pos,d.village)
		game.numActions=random.randrange(0,99)
		choice1=-1
		choice2=-1
		choice3=-1
		
		d.playCard(pos,choice1,choice2,choice3,game)
	elif play==d.sea_hag:
		hand=random.randrange(0,MAX_HAND-1)
		game.hand[turn]=[]
		for k in range(hand):
			game.hand[turn].append(random.randrange(d.curse,d.mine+1))
		pos=random.randrange(0,hand)
		game.hand[turn].insert(pos,d.sea_hag)
		
		discard1=[]
		deck1=[]
		for i in range(player):
			discard1.append(random.randrange(0,MAX_HAND-1))
		for j in range(player):
			deck1.append(random.randrange(0,MAX_DECK))
		for a in range(player):
			if a!=turn:
				game.discard[a]=[]
				game.deck[a]=[]
				for b in range(discard1[a]):
					game.discard[a].append(random.randrange(d.curse,d.mine+1))
				for c in range(deck1[a]):
					game.deck[a].append(random.randrange(d.curse,d.mine+1))
		choice1=-1
		choice2=-1
		choice3=-1
		d.playCard(pos,choice1,choice2,choice3,game)
Exemple #4
0
def test_playCard(c,x,s):
	g=random_GameState(x,s)
	g2=random_GameState2(x,s)
	#c=d.mine
	if c==d.adventurer:
		g.hand[g.whoseTurn].insert(0,d.adventurer)
		r=d.playCard(0,-1,-1,-1,g)
		assert r==0
		assert g.hand[g.whoseTurn].pop() in (d.copper,d.silver,d.gold)
	elif c==d.ambassador:
		pass
	if c==d.baron:
		g.hand[g.whoseTurn].insert(0,d.baron)
		c1=random.randrange(1,len(g.hand[g.whoseTurn])-1)
		h1=g.hand[g.whoseTurn][c1]
		c2=random.randrange(-1,1)
		r=d.playCard(0,c1,c2,-1,g)
		if h1==d.estate and c2==0:
			assert r==0
		elif c2==-1:
			assert r==0
		else:
			assert r==-1
	elif c==d.council_room:
		h=len(g.hand[g.whoseTurn])
		g.hand[g.whoseTurn].insert(0,d.council_room)
		r=d.playCard(0,-1,-1,-1,g)
		assert r==0
		assert len(g.hand[g.whoseTurn])==h+4
	elif c==d.cutpurse:
		g.hand[g.whoseTurn].insert(0,d.cutpurse)
		r=d.playCard(0,-1,-1,-1,g)
		assert r==0
	elif c==d.embargo:
		g.hand[g.whoseTurn].insert(0,d.embargo)
		ct=random.randrange(7,17)
		nt=g.embargoTokens[ct]
		r=d.playCard(0,ct,-1,-1,g)
		assert r==0
		assert g.embargoTokens[ct]==nt+1
	elif c==d.feast:
		g.hand[g.whoseTurn].insert(0,d.feast)
		ch1=random.randrange(7,17)
		r=d.playCard(0,ch1,-1,-1,g)
		if d.getCost(ch1)<6:
			assert r==0
		else:
			assert r==-1
	elif c==d.great_hall:
		g.hand[g.whoseTurn].insert(0,d.great_hall)
		h=len(g.hand[g.whoseTurn])
		a=g.numActions
		r=d.playCard(0,-1,-1,-1,g)
		assert r==0
		assert len(g.hand[g.whoseTurn])==h
		assert g.numActions==a
	elif c==d.mine:
		g.hand[g.whoseTurn].insert(0,d.mine)
		ch1=random.randrange(1,len(g.hand[g.whoseTurn]))
		h1=g.hand[g.whoseTurn][ch1]
		ch2=random.randrange(4,7)
		r=d.playCard(0,ch1,ch2,-1,g)
		if h1==d.copper and ch2==d.silver:
			assert r==0
		elif (h1==d.silver or h1==d.gold) and ch2==d.gold:
			assert r==0
		else:
			assert r==-1
	elif c==d.smithy: #test for backup action cards, so use g2
		h=len(g2.hand[g2.whoseTurn])
		g2.hand[g2.whoseTurn].insert(0,d.smithy)
		r=d.playCard(0,-1,-1,-1,g2)
		assert r==0
		assert len(g2.hand[g2.whoseTurn])==h+3
	elif c==d.village:
		h=len(g2.hand[g2.whoseTurn])
		a=g2.numActions
		g2.hand[g2.whoseTurn].insert(0,d.village)
		r=d.playCard(0,-1,-1,-1,g2)
		assert r==0
		assert len(g2.hand[g2.whoseTurn])==h+1
		assert g2.numActions==a+2
	elif c==d.sea_hag:
		g2.hand[g2.whoseTurn].insert(0,d.sea_hag)
		r=d.playCard(0,-1,-1,-1)
		assert r==0
		for player in range(g2.players):
			if player != g2.whoseTurn:
				assert g2.deck[player].pop()==d.curse
	else:
		pass