Hello there,
First and foremost, I want to express my gratitude for your engagement and participation in the discussions in Git Checkout. Your involvement is truly appreciated. In this edition of Git Checkout, I've discovered a repository that exemplifies a programming masterpiece, a puzzle that captivates the mind.
Last week, I was neck deep in a hackathon which focused on privacy and data security on digital platforms employing zero-knowledge proofs. In my quest for inspiration, I stumbled upon a fascinating repository that I'm eager to share with you. As usual, I will highlight some intriguing aspects of the repository and in the process you could learn some programming nuances. Additionally, I will suggest ways to contribute to the project, should you find interest, thereby providing avenues for you to initiate or enhance your journey in open-source contributions.
Without further delay, let's get started. Our agenda will include:
- The repository
- Contribution ideas
- A quote on Nonograms
Let's dive in;
The repository
Nonograms, also known as Griddlers or Picross, are brain-teasing logic puzzles. In these puzzles, you colour squares on a grid using numerical hints given for each row and column. These hints indicate the lengths of consecutive blocks of filled-in squares in that particular line. Successfully solving the puzzle uncovers a concealed image, blending the numerical challenge of Sudoku with the word clues of crosswords, and adding a unique visual element. For a clearer understanding, consider watching a YouTube tutorial that explains the rules and demonstrates how to solve these puzzles.
The Repo: nonogram
This repo is a treasure trove for programmers looking at developing logic games, the code is distributed across a few files of which we’d look at some of the interesting ones. From the foundational standpoint, ‘puzzle.js’, it sets up the game's structure. ‘solver.js’ is where puzzles meet their match against logic. ‘creator.js’ has the logic to generate new puzzles, ensuring there's always a challenge to be had.Â
src/puzzle.js : This file has the puzzle class which happens to be the heart of the Nonogram puzzle, managing the grid of cells, row/column hints, and overall puzzle state. Key functionalities include:
Initialising the puzzle with specified width and height.
Resetting the puzzle to a default state with empty cells and hints.
Checking the user's solution against the correct solution.
Retrieving cells by row, column, or index, facilitating interactions between the user interface and the puzzle logic.
src/solver.js : The solver class contains algorithms for solving the Nonogram puzzles using logical techniques similar to those a human might employ. It includes methods to:Â
Reset and initialise the solver state.
Apply a series of logical solving techniques, such as eliminating impossible fits, finding known positives and negatives, and more, to iteratively solve the puzzle.
Log solving progress and calculate the solving time, aiding in performance analysis and debugging.
src/creator.js : The Creator class is responsible for generating Nonogram puzzles. It offers methods to:Â
Create random puzzles with specified dimensions and optional density, ensuring puzzles are solvable.
Create puzzles from predefined grids or hint objects, allowing for custom puzzle creation.
Validate puzzle solvability using the Solver class to ensure generated puzzles can be solved.
These files together form a comprehensive system for creating, displaying, and solving Nonogram puzzles. The code provides a solid foundation for understanding key concepts in creating algorithms for problem solving.
I hope this gave you a quick peek into the development of the game.
Contribution Ideas
This is my favourite section, where I share insights that could pave your way into the world of open-source contributions. With that in mind, here are some accessible ideas that seem like easy opportunities to get started:
Puzzle Hints: This could be an interesting contribution that can help players. The purpose is to provide hints based on the current puzzle state, identifying the next solvable step without solving the entire puzzle. Below is a high level idea to implement it.
Modify the solver to include a method that can provide hints based on the current puzzle state, identify the next solvable step without solving the entire puzzle.
Add UI elements like a "Request Hint" button and components to display the hints, which may involve highlighting parts of the puzzle or showing textual advice.
Save and load puzzle: This feature allows users to save their current progress on a puzzle and later load it to continue solving from where they left off. Outlined below could be a way to implement this,
Update the backend to include a database capable of storing user-specific puzzle states.
Implement UI elements that allow users to save their current puzzle state at any moment, as well as options to load a saved state.Â
Implement serialisation logic to convert the current puzzle state into a storable format when saving, and deserialization logic to restore this state upon loading.
Hopefully this made sense and will get you closer to open source contributions.
A quote on nonogram / puzzle
"The beauty of a puzzle game lies in its simplicity. The rules are clear, but the path to the solution is clouded in mystery." - Will Wright
I instantly resonated with the emotion conveyed in the quote. The game's interface is simple and intuitive, with rules that are straightforward to understand. However, solving the puzzle is not as easy as it appears. It may require multiple attempts to succeed, or one might eventually decide to give up.
That's a wrap for today's issue. As always, I value your thoughts and ideas! Should you have a specific repository or topic in mind that you're eager to delve into, I'm here to listen!
I want to make this newsletter a shared adventure. Your suggestions are more than welcome and it might just be the focus of our next discussion.
If you like what you read, please do not hesitate to share the love.
Until next time,
Cheers,
– Krish