def main(): game = ttt.GameState.new_game() human_player = ttt.Player.x # bot_player = ttt.Player.o bot = minimax.MinimaxAgent() while not game.is_over(): print_board(game.board) if game.next_player == human_player: #Now take two inputs to move pawns from "from_point" to "to_point" human_from_move = input('--Enter piece to move: ') human_to_move = input('--Enter location to move to: ') from_point = point_from_coords(human_from_move.strip()) to_point = point_from_coords(human_to_move.strip()) move = ttt.Move(from_point, to_point) print("Moved piece from: ", from_point, " to: ", to_point) else: move = bot.select_move(game) print(move.from_point, move.to_point) #Check valid from/to movement game = game.apply_move(move) print_board(game.board) winner = game.winner() if winner is None: print("It's a draw.") else: print('Winner: ' + str(winner))
def main(): game = hexapawn.GameState.new_game() human_player = hexapawn.Player.x # bot_player = hexapawn.Player.o bot = minimax.MinimaxAgent() while not game.is_over(): print_board(game.board) if game.next_player == human_player: human_move = input('-- ') #get the starting position, the location of the piece the player selected to move start = hexapawn.Point(int(human_move[1]), COL_NAMES.index(human_move[0])+1) #get the end position, the location the player wants to move to. end = hexapawn.Point(int(human_move[3]), COL_NAMES.index(human_move[2])+1) move = hexapawn.Move(start, end) print() else: move = bot.select_move(game) #apply move only if the move is valid if(game.is_valid_move(move)): game = game.apply_move(move) print_board(game.board) winner = game.winner() if winner is None: print("It's a draw.") else: print('Winner: ' + str(winner))
def main(): game = hxp.GameState.new_game() human_player = hxp.Player.x # bot_player = hxp.Player.o bot = minimax.MinimaxAgent() while not game.is_over(): if game.next_player == human_player: print("===================") print_board(game.board) print("Human player's turn") print("===================") moves = game.legal_moves() print('\n'.join('{} {}'.format(idx, m) for idx, m in enumerate(moves))) human_select = int(input('-- ').strip()) move = moves[human_select] else: print("===================") print_board(game.board) print("AI player's turn") print("===================") move = bot.select_move(game) game = game.apply_move(move) print_board(game.board) winner = game.winner() if winner is None: print("It's a draw.") else: print('Winner: ' + str(winner))
def main(): game = hexapawn.GameState.new_game() human_player = hexapawn.Player.x bot = minimax.MinimaxAgent() print( "\n=====================================================================" ) print( "===========================HEXAPAWN==================================" ) print( "=====================================================================\n" ) print( textwrap.fill( 'HEXAPAWN IS PLAYED WITH CHESS PAWNS ON A 3 BY 3 BOARD. THE ' 'PAWNS ARE MOVED AS IN CHESS - ONE SPACE FORWARD TO AN EMPTY ' 'SPACE OR ONE SPACE FORWARD AND DIAGONALLY TO CAPTURE AN ' 'OPPOSING MAN. ON THE BOARD, YOUR PAWNS ARE \'X\', THE ' 'COMPUTER\'S PAWNS ARE \'0. TO ENTER A MOVE, TYPE THE LEGAL' ' MOVE FROM THE OPTIONS PROVIDED BELOW AS A HINT. GOOD LUCK!'), '\n') print( "=====================================================================\n" ) while not game.is_over(): try: if game.next_player == human_player: print_board(game.board) print("Your Turn - Agent") print("===================") moves = game.legal_moves() print('\n'.join('{} {}'.format(idx, m) for idx, m in enumerate(moves))) human_select = int(input('-- ').strip()) move = moves[human_select] else: print("===================") print_board(game.board) print("AI's turn") print("===================") move = bot.select_move(game) except: print('\n====================================') print('Invalid Selection.. Please try again') print('====================================\n') continue game = game.apply_move(move) print_board(game.board) winner = game.winner() if winner is None: print("It's a draw.") else: print('Winner: ' + str(winner))
def main(): board_size = 9 game = goboard.GameState.new_game(board_size) bots = { # gotypes.Player.black: agent.RandomBot(), # gotypes.Player.white: agent.RandomBot(), gotypes.Player.black: minimax.MinimaxAgent(), gotypes.Player.white: minimax.MinimaxAgent(), } count = 0 while not game.is_over(): count += 1 time.sleep(0.3) print(chr(27) + "[2J") print_board(game.board) # <1> bot_move = bots[game.next_player].select_move(game) # bot_move = bots[ game.next_player ].select_move( game ) print_move(game.next_player, bot_move) game = game.apply_move(bot_move)
def main(): game = goboard.GameState.new_game(BOARD_SIZE) bot = minimax.MinimaxAgent() while not game.is_over(): print_board(game.board) if game.next_player == gotypes.Player.black: human_move = input('-- ') point = point_from_coords(human_move.strip()) move = goboard.Move.play(point) else: move = bot.select_move(game) print_move(game.next_player, move) game = game.apply_move(move)
def main(): board_size = 9 game = goboard.GameState.new_game(board_size) # bot = agent.RandomBot() bot = minimax.MinimaxAgent() while not game.is_over(): print(chr(27) + "[2J") print_board(game.board) if game.next_player == gotypes.Player.black: human_move = input('-- ').upper() point = point_from_coords(human_move.strip()) move = goboard.Move.play(point) else: move = bot.select_move(game) if DEBUG_MODE: explain(move) print("move END --------------") print_move(game.next_player, move) game = game.apply_move(move)
def main(): game = ttt.GameState.new_game() human_player = ttt.Player.x bot = minimax.MinimaxAgent() while not game.is_over(): print_board(game.board) if game.next_player == human_player: human_move = input('-- ') point = point_from_coords(human_move.strip()) move = ttt.Move(point) else: move = bot.select_move(game) game = game.apply_move(move) print_board(game.board) winner = game.winner() if winner is None: print("It's a draw.") else: print('Winner: ', str(winner))