Astrodevil / Programming-Basics

This Repository Contains source codes of various programming languages. Please Contribute to make this Useful.
https://astrodevil.github.io/Programming-Basics/
MIT License
72 stars 121 forks source link

Create tic tac toe on minimax algo.cpp #286

Open Amulya77 opened 3 years ago

Amulya77 commented 3 years ago

tic tac toe game with computer using simple algo The classic Tic-Tac-Toe game (also called Noughts and Crosses) or Xs and Os is a paper-and-pencil game for two players, X and O, who take turns marking the spaces in a 3×3 grid. The player who succeeds in placing three of their marks in a horizontal, vertical, or diagonal row is the winner.

In this code, I've used minimax algorithm to help the computer where to go for the next move and win the puzzle.

Combinatorics : When considering only the state of the board, and after taking into account board symmetries (i.e. rotations and reflections), there are only 138 terminal board positions. A combinatorics study of the game shows that when "X" makes the first move every time, the game is won as follows :

91 distinct positions are won by (X) 44 distinct positions are won by (O) 3 distinct positions are drawn (often called a "cat's game") Pseudocode function minimax(node, depth, isMaximizingPlayer, alpha, beta): @Astrodevil

Astrodevil commented 3 years ago

Also add a readme with this file and put it inside folder, mention the details as you explained here about this game concept or setup