3x3 Tic-Tac-Toe console game (human vs computer, turn by turn) written in Scala.
The human player may choose:
- his/her own mark (x or o)
- which player makes the first move (human or computer)
- the difficulty of the computer (easy or hard)
- to start a new game after a game has ended
The easy computer just randomly selects a free position on the board and thus is easy to beat (in most cases).
The hard computer is based on the NegaMax algorithm (which is a slight modification of the MiniMax algorithm) and thus is unbeatable. Here is a very illustrative explanation of the MiniMax algorithm by Patrick Winston.
The NegaMax variation is simply based on the idea that
max(a, b) = -min(-a, -b)
and thus there is no need to explicitly distinguish in which level the evaluation step of a move takes places. This is done by a value called level
which equals max=1
for the computer's turn or min=-1
for the player's turn.
-
Clone this repository to any destination path you want (for example '~/Downloads/tic-tac-toe').
-
Open terminal and navigate to this directory:
$ cd ~/Downloads/tic-tac-toe
-
Compile project:
$ sbt compile
-
Run tests:
$ sbt test
-
Run tic-tac-toe game:
$ sbt run
The computer🤖 makes a decision...
The computer🤖 chose the move row = 1, column = 3
x | x | o
-----------
| o |
-----------
| |
Have fun! :)