Codementor Events

Tic-Tac-Toe: The X-O Factor in Learning AI

Published Mar 10, 2025

A lot of people come to me and ask: What is a fun way to start coding AI?
My response is Tic-Tac-Toe.
It is the ultimate "X-cellent" way to learn AI — simple enough to avoid a brain-fry but tricky enough to keep you on your toes. Writing AI for it teaches fundamental concepts like Minimax, recursion, and game strategy, all without making you feel like you’re stuck in an infinite loop. Plus, it’s a great way to finally find an opponent who won’t "O-verreact" to losing 😉
Master Tic-Tac-Toe today, and who knows—maybe your AI will be the next grandmaster of the 3x3 grid!

See here for a sample code of classic tic-tac-toe code which I wrote https://github.com/nakulshah/ai/tree/main/tictactoe

Cheers,
SNS

Discover and read more posts from SNS
get started