Here it is a c language code for Undefeatable Bot for Tic Tac Toe game. The bot can play game acting as first player or either as second player according to your choice. It plays One by One move according to the current situation on the board. Bot is Designed in a way to win every battle. Even if the opponent plays the most optimal move It will not let you lose. Bot was originally created for a bot contest.
Here is the link to that :-
https://www.hackerearth.com/practice/algorithms/string-algorithm/manachars-algorithm/practice-problems/multiplayer/tic-tac-toe/
Here is how to use the program:-
- The 3x3 board matrix representing the current situation
0 representing the empty place
1 representing the first player
2 representing the second player
- Player Id for Bot
Can be 1 or 2, representing the bot Id
0 0 1
0 2 0
1 0 0
2
These are Co-ordinates for the move
2 1
According to Matrix Co-ordinates:
00 01 02
10 11 12
20 21 22
0 0 1
0 2 0
1 0 0
2 1
0 0 1
0 2 0
1 2 0
You Can see a running visual display of this code here :-
https://www.hackerearth.com/practice/algorithms/string-algorithm/manachars-algorithm/practice-problems/multiplayer/tic-tac-toe/
If you Run this code run there it will use code as first player
But If you want to see its performance as second player
than use it against aadish goel(My bot)
I have uploaded the same code there with this name.
with the name of bot_tictactoe.c
was with the name of bot_reversetictactoe.c
with a slight modification of taking transverse of input matrix
In application.py
There is a interface in which You can play with that bot
It uses the program exe file i.e bot_tictactoe.exe
write this in notepad
echo off
color a
cls
python application.py
pause
and save as .bat file
for eg. tictacAPP.bat
So, next it will play just by a click
If your computer gives python is not recognized as an internal or external command
than put python in envirnoment variable of your computer
by going in properties of MyComputer.