# Random Chance and Deviations

Update to my last post. Sat down and played with the seed numbers for my random puzzle generator and got some interesting results. Now I have said many times that “numbers in a vacuum are meaningless” which I recently realized is just a rephrasing of “everything is relative” so I will give some base numbers for reference before anything else.

The target number of moves for these test puzzles is 8, this means (with 25 possible buttons to push) that the average chance for any given button to be pushed should be 32%. When I started my testing for smoothing out the average number of times any given button was pushed I made the default chance of a selection be around 5% and increment that by 10% each time a button was not selected (resetting each time one WAS selected). Since I was simulating the creation of 10,000 puzzles per cycle and averaging the results I was fairy certain that my results would be accurate.

As I said previously these numbers gave me results that clumped where the button presses would be with a large deviation from the desired 32% being around 10-15% above the target. As I raised and lowered the seed numbers the location and nature of the clump would shift but not completely disappear, for instance sometimes most of the buttons would have smoother deviation numbers but I would have two buttons with 15-20% lower chance to be selected. Then I tried a 12.5% default and incremental chance and got the best results yet (still not the desired results but better). On a lark I cut those numbers in half (around 6.5%) and got even better results. Surprised at first I started to see some logic to it and decided to go with an extreme case dropping both to 1% and then 0.1% I had found that the deviations had become negligible with a large deviation being around 1% and averaging closer to 0.3%. this meant that even if a clump existed it would be unnoticeable to an average player. Now my only concern is balancing the better deviation numbers with load times as the best solution requires more passes to create a puzzle.

# Math, Testing, More Math, and Getting Useful Data

So I had a bit of a brainstorm for how to make my randomized puzzles and decided to use a new method. But then I started to wonder how the distribution of moves on the play area would be. Would they clump in one spot? Would they clump according to some rule or at random? Or would I get a good spread? This is a bit of how I figured that out.

I have already been using the debug log for lots of data gathering but unfortunately with a sample size of 800-80,000 or more the Log system in Unity is simply not robust enough for my purposes (Turns out latter it could have been but I still prefer the way I ended up using). Namely I needed a better find function that could tell my: “how many toggles in this column/row” or “how many toggles for this specific button”. So I had the output placed in a txt file before copy pasting that into a Word file and putting the data in an Excel file for ease of viewing. After doing this once (for a sample size of 100 puzzle generations) I figured I could do more of the work in the programming. I then had a txt file with the toggles for the specific buttons. But I realized fairly quickly that this data, while helpful, was a bit hard to understand. So I made it instead output the average number of toggles per puzzle over the 10,000 simulated puzzles. And since this new method allowed me to control exactly the number of toggles per puzzle I could figure out the number of average button presses per button if it were an ideally even spread. This was better but still a bit hard to read. Then I finally figured out what I was looking for was who far off the ideal average the actual averages were. so once I started to also output the deviation I saw the pattern clearly. And yep, as I feared it was clumping in almost the exact place I thought it would. Time to tweak some more numbers and see if I can smooth it out.

# Random Number Programming and Magic the Gathering

I have been making progress on my Lights out game, coming up with new ideas, scaling back old ideas, putting some things to the side for latter, completely changing the user interface, and generally pulling my hair out at things that should “just work” seam to work on my machine and then just… don’t. So programming in a nutshell.

Now, what is that title about and how does it relate to my game?

Well for my game I have a section that generates random puzzles. As you can imagine this utilizes a random number generator, but it also uses a bunch of seed numbers (random between X and Y, target number, etc.) and I just recently realized a few mistakes I made when deciding these seed numbers. The most recent discovery was that for difficulty I was messing with entirely the wrong number and needed to change a different seed number to get the results I wanted, but more importantly I figured out that I was using the wrong scale of numbers. I had been using numbers in the 5-12 range and figured out I needed to use numbers in the 200-300 range. Why? Well lets get to one of the oldest design problems of Magic the Gathering to illustrate the problem.

In Magic both players start with 20 life, can generally generate one mana per turn of the game (dependent on deck and draw this can go way up or down but I digress), and start with 7 cards drawing one per turn by default. Those are the basic resources a player has to work with. In the first set of Magic they printed a card called Lightning Bolt, it cost one mana and dealt 3 damage to anything… and is widely considered one of the strongest direct damage cards in the game even 27 years latter with  about 4 sets per year. Latter they printed the card Shock, It was exactly like Lightning Bolt except it dealt 2 damage instead. Shock is considered a mediocre card, useful sometimes but your not excited to play with it. So why the giant disparity between reactions with the difference of 1 damage? Well the designers have said the ideal one mana direct damage spell would deal 2.5 damage, but they can only deal with whole numbers so it is either 2 damage or 3 damage. But imagine a world where all damage and life numbers were doubled. suddenly Lightning Bolt deals 6, Shock deals 4, and a new card could deal the new ideal of 5 damage. But because the resources they have to work with were set in stone 27 years ago they can’t actually tweak any of those numbers. Starting to see how this loops back?

By at first dealing with small numbers the number of changes I could make to the system was highly limited. But by dealing with giant numbers I can make much smaller changes for more precise control. Ironically Larger numbers allow for smaller changes.

This is a lesson I keep relearning, but as long as I don’t set things in stone and catch myself early enough I can afford to keep relearning it.

# What is different about my take on the game?

Lights Out is an old game with lots of versions available differentiated mostly by graphics, quality of life features, and how many levels the game has coded in.

My take on the game is slightly different.

In Lights Out the objective is to, you guessed it, turn off all the lights. I took a slightly different approach and made it like a more traditional puzzle. Instead of simply turning all the lights off the objective is to change a starting pattern to match an ending pattern. For instance turning an X on the grid in to a box around the edges (I don’t know if that example is even possible I simply use it as an easy to explain example). This can change the thinking on solving the puzzle quite a bit.

To that end I created another tool inside the game, a level editor. This editor allows the user to freely set up a start state before having them use the normal game rules to set up the end state. This ensures that any puzzle created by the editor is solvable. As for sharing these levels… I am currently working on that.

I also have a few ideas on creating procedurally generated levels using a similar method to the level editor.

# Why Lights Out?

Today I will talk about why I choose to take on making a lights out style game, and it starts (ironically) with an entirely different type of game. That game is 2048, or any or its derivative games (don’t remember what the first one was called). It was suggested to me to try and make a visually simple game that is easy to understand and can be ported to mobile. 2048 ticks all of these boxes. However I didn’t know how I would implement the mechanics of this game in my preferred engine: Unity. While thinking about Object interactions vs array driven interactions I remembered an old handheld game I used to play around with. That game was of course Lights Out. I realized it would be much simpler as it did not involve creating and destroying objects or much in the way of animation, while still being array driven and a bit object driven and giving me more experience that I might go back to 2084 with.

# Been a While… Here’s Whats Up

Been a while since I wrote one of these. I think I have established that I am terrible at the whole “Report on my week” style or the “Something interesting happened” style. This is because either I don’t think of the thing as interesting or just forget that I have something I could write about during the times I could write about it. So this time instead of just offloading everything in one post I am going to try and pace out my posts, plan ahead a bit and release them slowly over time. This should result in more frequent posts but much smaller posts. Lets see if it works in the coming weeks.

As for my current projects, I am working on putting together a “Lights Out” style game in Unity. Lights out is a game were a grid of 5X5 cubes are lit up in a pattern and you are trying to put out all the lights. However when you toggle one box all of its adjacent boxes also toggle, making for an interesting puzzle.

Look forward to future updates such as: why I choose this project, my take on some of the game play, and general development woes, oddities, and wtf moments.

I only just realized that I committed to updating this weekly just before I was going to have four weeks of shifted and changed schedules…. mart move.

This week I had to shift my schedule around a doctor’s appointment and so didn’t have my usual time to write this and am instead writing it now.

Next week my schedule is mostly normal but on Friday I am have something that will take up most of the middle of my day. No details yet but hopefully soon.

The week after that is a new set release at work and so all hands on deck for Friday and once again my schedule is shifted.

Then the week after THAT is World Con which I am both attending and helping with so expect some of these posts to be about that in the near future.

Long story short: these updates will be sporadic for the next few weeks and hopefully settle in to a Friday weekly schedule.

# The Grind Continues

I am never going to be able to post regularly am I? Hopefully with a few changes I might be able to manage it now. From now on I am going to try and post weekly either about something that happened that week in my life, a review of a game or movie, or just notes about Ideas I have had, about game ideas or anything else.

With that in mind I guess I should give a general status update today.

Still working at my warehouse job with a few prospects of different types of work there. Still improving my coding skills and getting back to an old project, fun side note is that I remember having a problem with the program last time I was working on it and when I went back to it I fixed the problem easily. Sometimes you just need time to back away from something. Helping out at Worldcon this year and might be on a panel (stay tuned for more info).

As the title says the daily grind continues.

# More work at work and beyond

Been a while since I posted here. Time to try and fix that again.

I have been working on a few programming jobs and continuing working at Channel Fireball. My programming work has mostly been contract work implementing smaller features for clients, mostly things that took a one or two hours (mostly looking up a new command or tweaking numbers). I have been working on a larger program called the anonomizer. It is similar to Neo Ipsum in that it inserts garbage text to see formatting styles, but instead of filling empty text boxes it replaces all existing text. It also forces you to save a new version of your project as a bit of idiot proofing. And while I don’t have much I can tell people yet I might be getting some more contract work that could turn in to something more.

At Channel Fireball things are also going well, progressing in my packaging training (almost to the point where I am trained to do everything in the packager role). But I also have an extra project that I am working on for the company: PROGRAMMING! Won’t go in to specifics but my bosses found out  I could program and said “here are some  things that need to be integrated/fixed in our current macros. Can you work on this.” So more paid programming work!