$ python3 main.py
- Initialize Program.
- Ask for Player 1 and Player 2 identity and preffered Symbol to Player 1 either X or O.
- Print out 3 x 3 grid given values from available location
- ask player one for the location he want to mark, validate is location and update available_locations along with player's location array.
- check for win; break if win : continue if not
- increment move by 1, switch player and goto: 2
- check if total moves are 9 declare a tie.
- prompt a rematch -> reset scores and meta data.
- Player 1 is a decider for Player 2 mark as well, if he doesn't choose O Player 2 gets it and vice-versa. Player identity is mandatory as of now.
- valid input for players move is Number - that specify location of the grid, everything except it is not valid and error will be thrown.
Given a 3 x 3 grid with the pre-filled values from 1 to 9 marked left to right, here are the possible "win" cases:
[[1,2,3], [4,5,6], [7,8,9], # vertical lines
[1,4,7], [2,5,8], [3,6,9], # horizontal lines
[1,5,9], [3,5,7]] # diagonal lines
- If you've won the round, next round looser will have an advantage by making the first move.
- If it's a tie, alternative player will have advantage.
Machine mode works on two major priciples,
- Defend - Machine should defend any mark which allows opponent to win or to make any advancement towards wining
- Attack - make advancements towards winning.
which means after every step user takes it runs an analysis towards making it's next move by:
- getting the available slots (moves).
- compare machine and opponent's marked data against win scenarios to,
- rank each possible move with following levels:
- 0 - no affect on attack or defensiveness
- 1,2 - advancement towards making a win/defend
- 3 [Power Move] - win or stop opponent from winning
- once all moves are ranked; top rankers are picked up and randomly choosen.