❔ TicTacToe Minimax isnt working properly
Hello ive been trying to make a tictactoe game where the player plays against an AI that uses the minimax algorithm but the bot is making suboptimal moves and even after surfing the web i am confused as to why..
the methods i use to determine a move for the bot are
im attaching the whole code as a file
16 Replies
define "suboptimal moves"
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.the algorithm isnt taking the best moves in a given situation hence missing easy wins or losing when it could be easily avoided
in a given situationlike what?
in this example where the bot is X and its his and everything in white is already in the game he would play the red X therefore missing the easy win with the green one
excellent, let's run the algorithm for that state
this is our move logic, yeah?
what happens for a game state of
we get a maxEval of 3 with a move of y=1, x=1
going from this
to this
(dont mind the cyan square its the player's indicator)
why's that?
it ought to be a 4
er
rather
the optimal move is a 4
for y=2, x=0
is that one not returning a 4, or is the 4 not getting captured properly?
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.i think it returned a 3 for it too when debugging but since its the same it didnt overwrite it as a better eval
im not able to look into it today nor the first half of tomorrow but after that id be free if you're still eager to help resolve this issue
in the meantime you could of course look into it on yoyr own if you'd like
I have
if the evaluation for y=2,x=0 is returning 3, then that's your problem. It should be 4.