Shoe House Goblin Devlog #2

Shoe House Goblin Devlog #2 – The Fun Part

Alright I have completed the first task. And it was an easy one. If you have seen the outline of the game from previous post, you would recognize this one: Generating random labels for the shoe boxes.

For this task I needed two things:

  • Generate a number of random and unique labels that can contain numbers, letters or symbols
  • Easily tweak the complexity of labels. For example, I may want labels consisting of four letters only. Or I may want label with two letters, three numbers and one symbol.

Creating random numbers or strings is easy but product labels often have a specific pattern. For example they may start with a bunch of letters designating the brand and the country of manufacturer etc and then some numbers indicating product or batch numbers.

So my program will take a pattern string and generate random labels based on that. Then I run each generated label through a ‘longest common substring’ algorithm to determine uniqueness. I have made the uniqueness pretty strict. If the longest common substring’s length is more then one then that label is discarded and a new one is generated.

My pattern looks like this: *A8$
* designates a color value, A designates an alphabet, 8 is for numbers and $ is for symbols.

So I can provide to my program a pattern like “AAAA” and it’ll generate labels with four letters each. Essentially it just loops over the pattern string’s characters and picks a replacement for each based on what character it is. So for ‘A’ it’ll randomly pick from an array of alphabets.

Similarly the pattern “AA888$” will generate labels with two letters, three numbers and a symbol. The order of characters is important here which will be consistent among all generated labels.

As you can see I can make these patterns virtually as complex as I want, as a result increasing the difficulty of the game. I can also adjust how many unique labels I want generated. There are, however, cases where program will keep discarding labels because they are not unique enough and end up running an infinite loop. I have added a way to automatically kill the loop after a certain number of failed tries and warn me so I don’t mistakenly create some impossible configuration.

This is pretty much it. You may have noticed the title of this devlog. Yes this is the fun part for me. Creating simple little systems that may or may not end up in the final game 😀 The boring part comes at the end when I have to polish the game 🙁

There is nothing visual in the game yet so I’ll be working on that next and I’ll probably add some drag and drop interactions as well.