def ai_move(): layout = request.args.get('layout') layout = json.loads(layout) board = Board(setup=layout) ai.move(board) layout = board.board() layout = json.dumps(layout) return layout
def move(board, col): my_bin = 0x0000000000000000 other_bin = 0x0000000000000000 for y in range(len(board)): for x in range(len(board[y])): if board[y][x] == col: my_bin |= 0x01 << x + y * 8 elif board[y][x] != " ": other_bin |= 0x01 << x + y * 8 #import cProfile #cProfile.runctx('move_y, move_x = alphabeta_move(my_bin, other_bin, 0, 4)', globals(), locals()) move_y, move_x = alphabeta_move(my_bin, other_bin, 0, 4) import ai #cProfile.runctx('print(move_y, move_x, "vs", ai.move(board, col))', globals(), locals()) print(move_y, move_x, "vs", ai.move(board, col)) if (board[move_y][move_x] != ' '): for y in range(8): for x in range(8): if board[y][x] == ' ': print("I LOST") return y, x return move_y, move_x
intro = False game_mode = mode game_board.reset() game_board.show() def draw_intro(): text = font.render("Select game mode", True, white) screen.blit(text, (.35 * game_w, .4 * game_h)) for button in buttons: button.draw(screen) pygame.display.flip() while not done: for e in pygame.event.get(): if e.type == QUIT: done = True elif e.type == MOUSEBUTTONUP and intro == False: if game_mode == MODE_VS or game_board.player == 'X': game_board.check() if game_mode != MODE_VS and game_board.player == '0': ai.move(game_board, game_mode) if intro: draw_intro() else: game_board.show() pygame.quit()
# Make an initial post to start the game new_game_command = { 'command': 'new game', 'apiKey': api_key, } # The server replies with the initial game state current_game_state = post_to_server(new_game_command) # The current game state tells you if you have any turns left while current_game_state['turns'] > 0: print('Remaining turns: %d' % current_game_state['turns']) # Use your AI to decide in which direction to move... next_move_direction = ai.move(current_game_state) # ...and send a new move command to the server next_move_command = { 'command': 'move', 'direction': next_move_direction, 'apiKey': api_key, } # After sending your next move, you'll get a new reply # and we start at the top of the loop again current_game_state = post_to_server(next_move_command) # If the game is over, our server will tell you how you did # Go to warmup.monkeymusicchallenge.com/team/<your-team-name> for more details print('\nGame over.\n')
"x": 0, "o": 0 }, { "x": 0, "o": 0 }, { "x": 0, "o": 0 }]] player = 1 useEnemyAIPrompt() else: quit() if (__name__ == "__main__"): useEnemyAIPrompt() print(f"{Fore.MAGENTA}Player 1: x\nPlayer 2: o\n") while True: renderBoard() restartOnFullCheck() print(f"{Fore.MAGENTA}Player {player}, where do you go? y x > ", end="") loc = input() if (loc == "exit"): quit() loc = list(loc.split(" ")) updateBoard(player, loc) restartOnFullCheck() if (useEnemyAI and player == 2): updateBoard(2, ai.move(board))
# Hopefully, our server will always be able to handle your requests # but you never know... if reply.status_code != requests.codes.ok: print(' The server replied with status code %d' % reply.status_code) try: print(' %s' % reply.json()['message']) except: pass sys.exit(1) # The server replies with the current state of the game current_game_state = reply.json() return current_game_state # Allright, time to get started! # Send a join game command and the server replies with the initial game state current_game_state = post_to_server({'command': 'join game'}) # The current game state tells you if you have any turns left while not current_game_state['isGameOver']: print('Remaining turns: %d' % current_game_state['remainingTurns']) # Use your AI to decide in which direction to move... next_command = ai.move(current_game_state) # After sending your next move, you'll get the new game state back current_game_state = post_to_server(next_command) print('\nGame over.\n')
def ai_move(self): button = ai.move(self.board, False, DIFFICULTY) logger.info(f"AI chose {button}") self.move(button)
[1, 1, 1, 1, -1, -1, 1, 1], [1, 1, 1, 1, 1, -1, 1, -1], [1, 1, 1, 1, 1, 1, 1, -1], [0, 1, 1, 1, 1, 1, 1, -1], [0, 1, 1, 1, 1, 1, 1, -1]], [[1, -1, -1, -1, 0, -1, 0, 1], [1, 1, -1, 1, 1, 1, 1, 1], [1, 1, 1, -1, 1, 1, 1, 1], [1, 1, 1, 1, -1, -1, 1, 1], [1, 1, 1, 1, 1, -1, 1, -1], [1, 1, 1, 1, 1, 1, 1, -1], [0, 1, 1, 1, 1, 1, 1, -1], [0, 1, 1, 1, 1, 1, 1, -1]], [[1, -1, -1, -1, 0, -1, 0, 1], [1, 1, -1, 1, 1, 1, 1, 1], [1, 1, 1, -1, 1, 1, 1, 1], [1, 1, 1, 1, -1, -1, 1, 1], [1, 1, 1, 1, 1, -1, 1, -1], [1, 1, 1, 1, 1, 1, 1, -1], [-1, -1, -1, -1, -1, -1, -1, -1], [0, 1, 1, 1, 1, 1, 1, -1]], [[1, -1, -1, -1, 0, -1, 0, 1], [1, 1, -1, 1, 1, 1, 1, 1], [1, 1, 1, -1, 1, 1, 1, 1], [1, 1, 1, 1, -1, -1, 1, 1], [1, 1, 1, 1, 1, -1, 1, -1], [1, 1, 1, 1, 1, 1, 1, -1], [1, 1, -1, -1, -1, -1, -1, -1], [1, 1, 1, 1, 1, 1, 1, -1]], [[1, -1, -1, -1, 0, -1, -1, 1], [1, 1, -1, 1, 1, 1, -1, 1], [1, 1, 1, -1, 1, 1, -1, 1], [1, 1, 1, 1, -1, -1, -1, 1], [1, 1, 1, 1, 1, -1, -1, -1], [1, 1, 1, 1, 1, 1, -1, -1], [1, 1, -1, -1, -1, -1, -1, -1], [1, 1, 1, 1, 1, 1, 1, -1]], [[1, 1, 1, 1, 1, 1, 1, 1], [1, 1, -1, 1, 1, 1, -1, 1], [1, 1, 1, -1, 1, 1, -1, 1], [1, 1, 1, 1, -1, -1, -1, 1], [1, 1, 1, 1, 1, -1, -1, -1], [1, 1, 1, 1, 1, 1, -1, -1], [1, 1, -1, -1, -1, -1, -1, -1], [1, 1, 1, 1, 1, 1, 1, -1]]]) ai = ai.AI(8, clr, 100) tar_board = chess_list[rnd] print(tar_board) x, y = 7, 2 tmp_board = ai.move(tar_board, clr, x, y) print(tmp_board) lst = ai.go(tar_board) # for i in lst: # print(i)
def ai_move(): """Method that moves the AI based on Minimax.""" print("\nAI moving...\n") ai.move(gb) gb.complete_turn()