示例#1
0
文件: qcheck.py 项目: huangca/work
def test_buyCard(x,c):
	g=d.initializeGame(x, [d.adventurer, d.ambassador, d.baron, d.council_room, d.cutpurse,
                            d.embargo, d.feast, d.gardens, d.great_hall,d.mine], 2)
		
	if g.numBuys<1 or g.supplyCount[c]==0 or g.coins<d.getCost(c):
		assert d.buyCard(c, g)==-1
	else:
		assert d.buyCard(c, g)==0
示例#2
0
文件: qcheck.py 项目: huangca/work
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