Example #1
0
def geniusGame():
	board = Board()
	while True:
		board.printBoard()
		if board.inEndState():
			print("        Game Over")
			with open('bestScores.txt','a') as f: f.write("10000: " + str(np.amax(board.board)) + "\n")
			return
		change = searchEM(board)
		if change != 0:
			board.addRandomTile()
Example #2
0
def newTurn(theBoard):
	
	#show board
	for y in range(4):
		print ("+-----+-----+-----+-----+\n|", end = "")
		for x in range(4):
			if theBoard[x,y] == 0:
				print ("     |", end = "")
			elif theBoard[x,y] < 10:
				print(" ", end = " ")
				print(theBoard[x,y], end = "  |")
			elif theBoard[x,y] < 100:
				print (" ", end = "")
				print(theBoard[x,y], end = "  |")
			elif theBoard[x,y] < 1000:
				print (" ", end = "")
				print(theBoard[x,y], end = " |")
			elif theBoard[x,y] < 10000:
				print (" ", end = "")
				print(theBoard[x,y], end = "|")
			elif theBoard[x,y] < 100000:
				print(theBoard[x,y], end = "|")
		print ("\n", end = "")
	print ("+-----+-----+-----+-----+")
		
	change = 0
	if inEndState(theBoard):
		print("        Game Over")
		return
	#userInput = raw_input('Pick a move (a, w, s, d, g for genius, q for quit): ')
	userInput = raw_input('Pick a move (a, w, s, d, q for quit): ')
	interpCmd = {'a': 'L', 'w': 'U', 'd':'R', 's': 'D'}
	if userInput == "g":
		change = searchEM(theBoard)
	elif userInput == "q":
		return
	else:
		change = moveDir(theBoard, interpCmd[userInput])
	if change != 0:
		addRandomTile(theBoard)
	newTurn(theBoard)
	return
Example #3
0
def heuristicTest(theBoard,count):
	#show board
	#"""
	for y in range(4):
		print ("+-----+-----+-----+-----+\n|", end = "")
		for x in range(4):
			if theBoard[x,y] == 0:
				print ("     |", end = "")
			elif theBoard[x,y] < 10:
				print(" ", end = " ")
				print(theBoard[x,y], end = "  |")
			elif theBoard[x,y] < 100:
				print (" ", end = "")
				print(theBoard[x,y], end = "  |")
			elif theBoard[x,y] < 1000:
				print (" ", end = "")
				print(theBoard[x,y], end = " |")
			elif theBoard[x,y] < 10000:
				print (" ", end = "")
				print(theBoard[x,y], end = "|")
			elif theBoard[x,y] < 100000:
				print(theBoard[x,y], end = "|")
		print ("\n", end = "")
	print ("+-----+-----+-----+-----+")
	#"""

	if inEndState(theBoard):
		#print("        Game Over")
		with open('bestScores.txt','a') as f: f.write(str(np.amax(theBoard)) + "\n")
		return
		
	change = searchEM(theBoard)
	#change = genius(theBoard)
	if change != 0:
		addRandomTile(theBoard)
	heuristicTest(theBoard,count+1)
	return