A terminal-based Java game built as part of the Hyperskill Java Backend Developer track. The game pits a human player against an automated bot in a classic game of Nim (taking turns removing 1-3 pencils until the last one is drawn).
This project was a deep dive into core Java mechanics, specifically:
- Scanner Buffer Management: Transitioned from
nextInt()tonextLine()combined with regex (\\d+) to prevent the program from crashing when a user inputs empty lines or text. - Game State Management: Consolidated duplicated player logic into a single
while(pencils > 0)loop using acurrentPlayertracker to alternate turns cleanly. - Algorithmic Bot Logic: Built custom
ArrayListsequences tracking intervals of 4 to dynamically calculate the bot's winning and losing positions.
Compile and run the Main.java file. Enter the initial number of pencils, choose who goes first (Human or Steve the Bot), and enter 1, 2, or 3 on your turn. The goal is to not to take the last pencil.