Welcome to the Last Pencil game! This is a simple text-based game where a player and a bot take turns removing pencils from a pile. The goal is to avoid being the one to take the last pencil.
- Run the
game.pyscript to start the game. - Enter the number of pencils you want to use for the game.
- Choose who goes first: the player or the bot.
- Take turns with the bot to remove 1 to 3 pencils from the pile.
- The one who takes the last pencil loses the game.
The bot has two strategies based on its position:
- In a losing position the bot either takes a random number of pencils or the last pencil.
- In a winning position (e.g., when there are 4, 8, 12... or 3, 7, 11... pencils left), the bot aims to force the opponent into a losing position.
- Clone this repository to your local machine.
- Ensure you have Python installed (the game was written in Python 3.11.4).
- Run the game by executing
python game.pyin your terminal or your IDE of choice.
How many pencils would you like to use:
0
The number of pencils should be positive.
How many pencils would you like to use:
five
The number of pencils should be an integer.
How many pencils would you like to use:
5
Who will be the first (John, Bender):
Mary
Choose between John and Bender.
Who will be the first (John, Bender):
john
|||||
John's turn:
6
Possible values: '1', '2' or '3'.
|||||
John's turn:
1
||||
Bender's turn:
3
|
John's turn:
0
Possible values: '1', '2' or '3'.
|
John's turn:
1
Bender won!