I had once heard that Bill Gates’ first program was a TicTacToe game..
This was my 2nd C program project. I wanted to try to make this game by myself and I will say that it was tough.
I had learned to use ASCII art to make CLI to look attractive, so I used it as much as possible.
Each position on the grid is numbered, in order from 0.
Basic implementation was an multi dimentional array of the winning positions and check after every move.
This worked pretty well for Player Vs Player. But I wanted to try to make Player Vs Computer mode.
After alooot of research and understanding things I sat down to code and after considerable effort modified my whole program to accomodate that.
This was when the tough part came in, I had to make or find an algorithm and a system to predict the best way to figure out which moves had the highest rate of success, that is getting the board layout having atleast one match with the winnig positions.
Then I found that I needed to use the Minimax algorithm(A tree search algorithm) and set a score for every move and iterate through possibilities in terms of a tree.
Moving back a branch, the ones with the least future moves which leads to success will be chosen.
It was a huge deal for me back then and it took some time to get my head around the concept and then implement it.
This was the first time I used a recursion in my code…
The computer will keep on checking till the best postion is found and this function
think is called on every position move by player.
The best the player can do is draw against the computer.
The features can be summarised below:
The end product was pretty cool, I can challenge people to win against the computer, offering a reward.
No one did. Thats the gimmick. Computers are dumb, but boy, can they calculate quickly.