Nov 10, 2016

infinite loop - PROCJAM 2016 entry

7:24 PM Posted by Lucas Izumi , , , , No comments


Taken direclty from PROCJAM's page, "PROCJAM is a jam about making stuff that makes other stuff". I was always interested on procedural generation but never really tried doing anything. When I saw this jam was being hosted I thought "Why not?".

The Game
infinite loop is a puzzle game that uses the mechanics of a game I've previously released called "SHE". Solve puzzles, race against the clock and compete in online leaderboards!

You can download the game in the link below

Since I released "SHE" for A Game By Its Cover game jam I thought of making a system that creates puzzles automatically for it and I decided to try it during this jam. The idea was defining the rules that creates valid board states and using it to generate countless combinations. Each of these combinations is a puzzle for the player to solve.

To add a little more into it than just solving puzzles after puzzles without any other motivator, I added  the concept of level progression and online leaderboards. The game has a countdown timer which represents how much time the player will have to solve a puzzle. After solving a puzzle the player progresses a level and a bonus is added to the remaning time. The leaderboards (or highscores) are computed based on which level the player reached. For example, if a player solved 10 puzzles, he/she will be at level 10. Whoever solve the most puzzles (without quiting the game) will grab the top of the leaderboards.

Procedural Generation
In this section I'll explain my algorithm for procedural generation of puzzles in the game.
First of all, you'll need to understand how the mechanics work. The images below are screenshots taken from the "How to Play" section of the game (click on the image to zoom):
 

Given how green and red panels work, it is necessary to have at least 1 green panel in each column and 1 red panel in each row, otherwise it would be impossible to color some rows and columns with the given colors.
For example, once the board reaches the state in the image below, it is impossible to color any of the panels of the bottom row red.

If the player accidentally creates one of these states, he/she can reset the board and try again. The algorithm to create a board works similarly.

Player's Board Creation Algorithm
1) Each panel is assigned a random number. Based on this number the panel is colored red or green.


2) The algorithm starts checking all the rows and flagging them. If a row contains at least 1 red panel, the row is flagged as VALID.


3) When all the rows are checked, then it's time for the columns. The process is the same, but this time it checks whether there is at least 1 green panel in each column. If there is the column is flagged as VALID.


4) If, at any time, a row or column is flagged INVALID, the algorithm stops the checking process and start over (Go to step 1).

This process is repeated until all rows and columns are flagged as VALID, which means we have a board with a valid combination of panels.

Solution's Board Creation Algorithm
For the creation of solutions, the steps are much simpler. Since a solution can be a board with ANY combination of colors, we just need to use the previous algorithm's Step 1. Once the colors are sorted, that is already acceptable as a solution to the puzzle.

This game jam really helped me learn about new things and apply them directly into the game. Let me know what are your thoughts about the game, write a comment! :)

Until next time!