##### Problem with a minimax algorith in Tic,Tac,Toe
 Problem with a minimax algorith in Tic,Tac,Toe Daniel_Gargallo Unladen Swallow Posts: 3 Threads: 1 Joined: Jan 2022 Reputation: Jan-23-2022, 12:55 PM Greetings to everyone, I am a student from Spain, so I am sorry if there's some words wrong. I am doing a project for school and now I have to do a bot who plays tic Tac toe. First, I programmed the game and after I watched a video to see how to do the bot ("https://www.youtube.com/watch?v=2Tr8LkyU78c"). Then I changed some parts of my code and some of the video code. Now, the bot "plays" but it shouldn't lose never and he does. The bot plays first. For example, in the sequence: (a1, b2, a2, a3, b1, c1) you can win. Another problem it is that at the beginning, it takes a lot of time to play the first move (more than expected), I don't have a lot of experience and I don¡t know why it happens. However, it's not a big problem, but, If you know why, I will also solve that problem. I will be grateful for any help. Daniel G ```possible_choices = ["a1", "a2","a3","b1", "b2","b3","c1","c2","c3"] init = {"a1" : 0, "a2" : 0, "a3":0, "b1": 0, "b2": 0, "b3":0, "c1" : 0, "c2": 0, "c3": 0} def jugadahumano(): jugada = str(input("inserte aqui su jugada del tipo : a1")) if (jugada in init.keys()) and (jugada in possible_choices): init[jugada]=1 possible_choices.remove(jugada) else: print("su jugada es incorrecta o bien ya hay una ficha sobre esa casilla") jugadahumano() def jugadarobi(): bestScore = -1000 bestMove = 0 for key in init.keys(): if (init[key]==0): init[key]=2 score = minimax(init,False) init[key]=0 if (score > bestScore): bestScore = score bestMove = key init[bestMove]= 2 def minimax(board, isMaximizing): if (whichmarkwon(2)): return 1 elif (whichmarkwon(1)): return -1 elif (checkDraw()): return 0 elif (isMaximizing==True): bestScore = -800 for key in init.keys(): if (init[key]== 0): board[key]=2 score = minimax(init,False) board[key]=0 if (score>bestScore): bestScore = score return bestScore elif (isMaximizing==False): bestScore = 800 for key in init.keys(): if (init[key]== 0): init[key]==1 score = minimax(init,True) init[key]==0 if(score

 Possibly Related Threads… Thread Author Replies Views Last Post tic tac toe python minimax alpha beta FSNWRMH 6 1,527 Dec-19-2023, 06:40 PM Last Post: deanhystad

Forum Jump:

### User Panel Messages

##### Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020