3 ms·
An advantage of coding interviews: some people just can't help themselves... To never lose at TicTacToe is not possible. If you're trying to never lose, you do
by tsegratis 6y ago
An advantage of coding interviews: some people just can't help themselves...
To never lose at TicTacToe is not possible. If you're trying to never lose, you don't want minimax, you want a brute force of the search space
Seems like space is 2^9, but actually a few if statements is enough. You said I must never lose?? Okay I take the center (corner has same outcome, but center simplifies)
You now have 2 choices: corner, or side. Internally I will rotate the board so your choice was square 0 or 1
012
3x5
678
If you chose square 1, I just need 2 if statements
play(0)
if(yourplay()!=8) return play(8)
play(3)
if(yourplay()!=5) return play(5)
return play(6)
If you chose square 0, ... it is left as an exercise for the examiner
- graton 6y agoTo never lose at TicTacToe is not possible Sorry I don't understand that. Normal playing at decent skill level is going to always lead to a draw, which is not losing. Am I missing something?
- tsegratis 6y agoI was counting failure to win as loss. Your take is correct and better My main other point :/ :) is a full -never-loosing- AI takes 6 if statements, and minimax is technically wrong for that goal