Skip to content

This project uses the form of a tic-tac-toe to practice, learn and optimize.

Notifications You must be signed in to change notification settings

javierparty/Tiny-Tic-tac-toe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 

Repository files navigation

A tiny Tic-tac-toe written in a few python lines.

ttt

The game has five stages and the bot calculates his move according to the stage of the game. The human player always begins.

1️⃣ First stage

The bot presents the clean board.

2️⃣ Second Stage

The bot calculates his first move using two criteria: a) If the player starts on the center (B2), the bot choose a corner randomly. b) If the player starts anywhere else, the bot chooses the center (B2).

3️⃣ Third stage

The bot checks if the player has played two times in the same row|column|diagonal (RCD). If this is the case, it checks if the third space in that RCD is empty. If it is, it plays on the empty space of that RCD, blocking the strategy of the player. If it is not empty and all the moves are on a diagonal, it chooses one of the two remaining corners randomly. If the player has not played two times in the same RCD, the bot looks for the next RCD that contains its first move and two empty spaces, and plays in one of these two spaces randomly.

4️⃣ Fourth stage

First, the bot checks if the player has three in a RCD, and therefore has won. If yes, the game is over. If not, it checks if it has two in a RCD. If this is the case, it plays the third spaces in that RCD and wins. If nobody has won, it repeats the procedure of the third stage.

5️⃣ Fifth stage

The same procedure of the fourth stage but if no body has won, it is a tie and the game is over.

About

This project uses the form of a tic-tac-toe to practice, learn and optimize.

Topics

Resources

Stars

Watchers

Forks

Languages