This project contains a simple Java console application that simulates a pencil-taking game. The game is played with an arbitrary number of pencils, and players take turns taking 1, 2, or 3 pencils until no pencils are left. The player who takes the last pencil loses the game. The bot (Jack) is programmed to follow a winning strategy whenever possible.
- The game starts with a number of pencils determined by the user.
- Two players take turns; each player can take 1, 2, or 3 pencils on their turn.
- The player forced to take the last pencil loses the game.
- If the bot starts in a winning position, it will always win by following a specific strategy.
The bot's strategy is to always leave a multiple of 4 pencils to the opponent. If the bot finds itself in a position where the number of pencils is already a multiple of 4, it will take 1 pencil in the hope that the opponent makes a mistake.
To run this game, you will need a Java Runtime Environment (JRE) installed on your machine.
- Clone this repository to your local machine.
- Navigate to the directory containing the project files.
- Compile the Java code using
javac Main.java
. - Run the compiled code with
java Main
.
When you run the program, it will prompt you for the initial number of pencils and who will take the first turn. Input the number of pencils and the chosen player's name when prompted.
Contributions to this project are welcome. To contribute:
- Fork the repository.
- Create a new branch for your feature (
git checkout -b feature/fooBar
). - Commit your changes (
git commit -am 'Add some fooBar'
). - Push to the branch (
git push origin feature/fooBar
). - Create a new Pull Request.
This project is licensed under the MIT License - see the LICENSE.md file for details.
- This project is created for educational purposes as part of a computer science study program.
- Special thanks to the Technical University of Vienna for the inspiration.