示例#1
0
def main(pigalgo, stonealgo, numStoneAgents, numPigAgents, maxDepth=None, quiet=False):

# calling the particular algorithms 
	if pigalgo == 'random':
		pigplayers =  [pigAgent.rrandomPigAgent(i) for i in range(numPigAgents)]
	elif pigalgo == 'simple':
		pigplayers =  [pigAgent.simplePigAgent(i) for i in range(numPigAgents)]
	elif pigalgo == 'complex':
		#there isnt really a pig complex agent so revert to simple
		pigplayers =  [pigAgent.simplePigAgent(i) for i in range(numPigAgents)]
	elif pigalgo == 'minimax':
		pigplayers =  [pigAgent.minimaxPigAgent(i) for i in range(numPigAgents)]
	elif pigalgo == 'alphabetaminimax':
		pigplayers =  [pigAgent.alphaBetaPigAgent(i) for i in range(numPigAgents)]
	else:
		raise Exception('Invalid algo name')


	if stonealgo == 'random':
		stoneplayers =  [stoneAgent.rrandomStoneAgent() for _ in range(numStoneAgents)]
	elif stonealgo == 'simple':
		stoneplayers =  [stoneAgent.simpleStoneAgent() for _ in range(numStoneAgents)]
	elif stonealgo == 'complex':
		stoneplayers =  [stoneAgent.complexStoneAgent() for _ in range(numStoneAgents)]
	elif stonealgo == 'minimax':
		stoneplayers =  [stoneAgent.minimaxStoneAgent() for _ in range(numStoneAgents)]
	elif stonealgo == 'alphabetaminimax':
		stoneplayers =  [stoneAgent.alphaBetaStoneAgent() for _ in range(numStoneAgents)]	
	else:
		raise Exception('Invalid algo name')

	players = pigplayers + stoneplayers
	
	GS = GameState(N_ROWS, N_COLS, players, numPigs=numPigAgents, quiet=quiet)
	
	# Tkinter window config
	if(not quiet):
		window = tk.Toplevel()
		window.title('Block The Pig')
		window.minsize(width=500, height=500)
		window.protocol('WM_DELETE_WINDOW', cleanUp)

	# Draw window
	if(not quiet):
		GS.draw(window)

	def update():
		if GS.allPigsEscaped() or GS.allPigsCaptured() or GS.allPigsEscapedOrCaptued():
			if(not quiet):
				cleanUp()
			
			score = GS.nPigsEscaped()
			print ('Game ended with:', score)
			return score

		GS.play() # where the magic happens
		if(not quiet):
			GS.draw(window)
			# Bug in line below
			root.after(TIME_DELAY, update)

		else:
			return(0 + update())

	if(not quiet):
		root.after(TIME_DELAY, update)
	else:
		return( 0 + update())

	#
	if(not quiet):
		root.mainloop()