I guess this could be just a problem you introduced in this question. Near the end of your code there is an indentation issue: three statements need to be indented more to become part of the if is_win(board_list) block. So it is not picking up the winning move. The expected behavior is that bot player should choose 8 cell so it will be a win. While not winner and not is_board_full(board_list):īest_move = int(input("Enter your move (1-9): ")) - 1Ĭurrent_player = 2 if current_player = 1 else 1 Score = minimax(temp_list, depth + 1, True) Score = minimax(temp_list, depth + 1, False) def minimax(board_list, depth, maximizing): I have implemented the algorithm and it's working but it is not picking up the best move. But I want to improve the bot player to pick the best move using minimax algorithm. Bot player is assumed to be 1 which is "O" and human player is assumed to be 2 which is "X". And because tic-tac-toe has so few moves and possible outcomes, this algorithm can easily fit onto a microcontroller.I have build a small python tic tac toe game. By following the path that results in the highest (optimal) score, the player can maximize their chances of winning while minimizing their chances of losing. The algorithm is quite simple, as a tree of moves is generated for each possible turn down to a certain depth, and a score is assigned to each outcome for a given player- win, lose, or draw. The AI for his device isn't a neural network like most would assume, but rather a small implementation of the minimax algorithm. This fact about tic-tac-toe lets a program have the possibility to never lose, a goal that Michael Klements wanted to achieve with his DIY Tic-Tac-Toe Shield that features an AI opponent. The game is considered "solved", which means that two players who play perfectly result in a tied match. Tic-tac-toe is a classic game that involves placing X's and O's onto a 3x3 grid of squares and trying to get 3 of your shape in a row.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |