Explore Courses Blog Tutorials Interview Questions
0 votes
in AI and Deep Learning by (50.2k points)

I know this has been asked a lot and I've searched other code but most of what I've seen doesn't seem flawless (never loses) and simple, elegant and efficient. And I'm unable to decide which type of solution would fit that description.

The solutions I've seen are:

(1) Using minimax with alpha-beta pruning. This seems complicated to me and possibly unnecessary for such a simple game? Is it probably too complicated? If not, would I need to do a lot of hard coding or am I misunderstanding the algorithm?

(2) Write your code using the pseudocode strategy from Wikipedia... I'm not exactly sure how to implement this. For example, it just says "check for forks". Would most of these checks be done by having an array of winning lines and checking if they'd be filled in or something like that? If not, can someone give me hints on what data structures or any basic tips on how to implement the checks posed in the pseudocode here: I've also seen algorithms that give a numerical value to an 'X' square and an 'O' square and then use the sum to decide the winner but I don't see why this is particularly useful.

Any other reasonable solutions?

1 Answer

0 votes
by (108k points)

A simple tic tac toe game builds in vanilla javascript, along with some nice HTML & CSS. There are 2 implementations of this tic tac toe game one is the simple one in which both the user & the bot can win. The other is an implementation where the bot always wins or it ties. But never loses.

Things you can use for building this algorithm:

  • Minimax Algorithm For Smart AI

  • HTML, CSS, JS, Some Es6 Sugar

For better understanding refer the following link:

Browse Categories