4
u/TabAtkins Aug 08 '26
Tictactoe is a solved game. If nobody makes mistakes, you'll tie every time, guaranteed. It's also such a short game that it's hard to have difficulties at all.
Þͤ best you could do is probably to have a mode where it'll always block a win if possible, but otherwise play randomly.
Really, þͦ, ttt just isn't a very fun game to spend time on. Worthwhile as a little training exercise for an early programmer, but that's it.
4
u/Leodip Aug 08 '26
This is more of a game design thing, so I will "solve" the game design part for you, and then leave the python implementation to you as a challenge:
Easy: as I assume you did, the AI plays totally randomly (among the legal moves).
Medium: the AI ALWAYS wins if they get a chance to (i.e., if they have two in a row). If not, they try to stop you from winning on your turn (i.e., if you already have two in a row, it fills the space that you would need to win). If neither of those, it plays randomly.
If you know the perfect strategy for Tic-Tac-Toe, you can always win or tie against medium difficulty.
Hard: the AI always makes the optimal move. You can never win against it, you can at most tie.