Esempio n. 1
0
def PlayerVsPlayer(startState = None):
	chess = Chess()
	chess.print_board()
	
	#Allows play from a specific state
	if (startState != None):
		chess.input_state()
		chess.print_board()
	
	#Play Chess!
	while(True):
		move = input('Input move: ')
		move = chess.convert_move(move)
		game = chess.move(move)
		
		if (game == None
			print(print_move)
			chess.print_board()
			return(chess)
		elif (game == False):
			continue
		else:
			chess.print_board()	
	return(chess)
	
def main():
	PlayerVsPlayer()	
main()
Esempio n. 2
0
def PlayerVsAI(startState, robot=False):	
	chess = Chess()
	
	#Open Serial Port
	if (robot == True):
		port = open_port()
	
	while(True):
		player = input("Input Human Player's Color ('white' or 'black'): ")
	
		if (player == 'white'):	
			computer = 'black'
			break
		elif (player == 'black'): 
			computer = 'white'
			break
		else:
			print("Error incorrect color/n")
			print();

	#Send player color information to Arduino when it is ready to recieve
	if (robot == True):
		ready = ''
		while(ready != 'R'):
			ready = arduino_ready(port)
		send_input(port, player)
	
	#Allows play from a specific state
	if (startState != None):
		chess.input_state()
	chess.print_board()
		
	#Max Recommended Difficulty: 5 layers. Averages around 15 seconds per move.
	layers = 5
	algorithm = Algorithm(chess, computer, layers)
	
	#Play Chess!
	while(True):
		if (chess.state.turn == player):
			
			if (robot == True):
				serial_input = None
				move = recieve_input(port)
				move = chess.coordinate_to_notation(move)
				move = chess.convert_move(move)
			else:
				move = input('Input move: ')
				move = chess.convert_move(move)
			
		else:
			#Comments for move timing
			#start_time = time.time()		
			move = algorithm.best_move()			
			#end_time = time.time()		
			#print("Move time: {}".format(end_time - start_time))
		
			#If ChessBot is connected, send move via serial port
			if (robot == True):
				serial_input = chess.convert_serial_move(move)
		
		print_move = chess.convert_move(move)
		game = chess.move(move)
		
		if (robot == True and serial_input != None):
			send_input(port, serial_input)		
		
		#Ensure game has not ended before
		if (game == None):
			print(print_move)
			chess.print_board()
			return(chess)
		elif (game == False):
			continue
		else:
			print(print_move)
			chess.print_board()
			
	return(chess)