Skip to content

Undefeatable Tic-Tac-Toe Bot program In C language and its linking with python

License

Notifications You must be signed in to change notification settings

aadishgoel/Bot-Program-In-C

Repository files navigation

Undefeatable-Bot-Program-For-TIC-TAC-TOE-In-C

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:-

Input:

  • 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

Output:

These are Co-ordinates for the move

2 1

According to Matrix Co-ordinates:
00 01 02
10 11 12
20 21 22

Intial Status:

0 0 1
0 2 0
1 0 0

Move:

2 1

Final Status:

0 0 1
0 2 0
1 2 0

GUI-Display

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.

Upto Here it is in C

with the name of bot_tictactoe.c

File used on Hacker Earth

was with the name of bot_reversetictactoe.c
with a slight modification of taking transverse of input matrix

Now Python 3 in Action

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

And For Running by One Click CMD bash

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

Note:

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.

Try it and Enjoy :)

About

Undefeatable Tic-Tac-Toe Bot program In C language and its linking with python

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published