It is implementation of TicTacToe game with simple AI opponent. I followed instuctions from JetBrains Academy https://hyperskill.org/projects/48
You can build this app executable jar with gradle wrapper unix executable with this command. Make sure you have jdk 8 installed in your computer.
./gradlew jar
Or if you're on windows you can use this command, this will run the batch file
gradlew jar
You can find the executable jar file in build/libs/TicTacToe-1.0-SNAPSHOT.jar
After building the executable jar, you can run the jar with this command
java -jar build/libs/TicTacToe-1.0-SNAPSHOT.jar
First you need to enter 3 parameter to start the game,
start
to start the gameexit
to quit the gameYou can choose the player 1 or player 2 between these
user
for human playereasy
for easy difficulty botmedium
for medium difficulty bothard
for hard difficulty botSo, for example if you want to play against easy you can type these
Input command: start user easy
To make bot play first, you can type user as 3rd parameter, like this.
Input command: start medium user
You can also let bot play against each other, like this.
Input command: start hard hard
The rule is simple:
In this game, after you select user
(human player) to play the game, you can type in the coordinates to play the game. You'll be receiving this input command.
Enter the coordinates:
You need to type in the coordinate between for the X and Y position separated by space.
The X is the horizontal coordinate and the Y is the vertical coordinate.
The game board ideally look like this:
Y \ X | 1 | 2 | 3 |
---|---|---|---|
3 | X | ||
2 | |||
1 |
So if you want to put your piece at the top left of the board like this
| 1 | 2 | 3 |
---|---|---|---|
3 | X | ||
2 | |||
1 |
You'll need to type in.
Enter the coordinates: 1 3
The 2nd player can choose anything to block the 1st player. For example choosing the middle tile, you can type in.
Enter the coordinates: 2 2
| 1 | 2 | 3 |
---|---|---|---|
3 | X | ||
2 | O | ||
1 |
The game will continue and so on.
If the tile is already occupied, the game will tell you so.
Enter the coordinates: 1 3
This cell is occupied! Choose another one!
If you type in wrong coordinate, the game will also tell you.
Enter the coordinates: 33
You should two enter numbers with one space!
Enter the coordinates: 1 4
Coordinate should be from 1 to 3!
You'll continue until one of the players win like this.
---------
| X O X |
| O O O |
| X X |
---------
O_WINS
---------
| X O X |
| O X O |
| X |
---------
X_WINS
Or until board is full and no one win, it will be DRAW
---------
| X O X |
| O O X |
| X X O |
---------
DRAW