Skip to content

About

A terminal-based Java game built as part of the Hyperskill Java Backend Developer track.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Last Pencil ✏️

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).

What I Learned

This project was a deep dive into core Java mechanics, specifically:

  • Scanner Buffer Management: Transitioned from nextInt() to nextLine() 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 a currentPlayer tracker to alternate turns cleanly.
  • Algorithmic Bot Logic: Built custom ArrayList sequences tracking intervals of 4 to dynamically calculate the bot's winning and losing positions.

How to Run

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.

About

A terminal-based Java game built as part of the Hyperskill Java Backend Developer track.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages