Finally, some mayonnaise.

Sunday Wombo Combo #2

Tina Ng
oneleif

--

Welcome to the second installment of Sunday Wombo Combo, a series of my development journey that is now statistically 76% chance more likely to continue, because I did not give up after the first post. This week brings you updates that are more about game development, because my game dev course instructor began knocking on my inbox for my assignment progress. Oops.

Before we get into the fun stuff, let’s check out this week’s kata highlight.

Supermarket Queue

Typical weekday after work

This kata made it to my highlight, because it presented a kind of problem that feels very easy to a human mind, but tricky to solve on a computer.

The kata basically asks you to give the time required for a set of check out counters to finish a fixed queue. These things naturally sprung to my mind when I consider a typical supermarket scenario:

  • Customers at the front of the queue would move to the first available counter.
  • Each and every customer in the queue would require different time to finish check out. Some might just want to buy a soda or a Mars bar. Some have four mouths to feed in the family, and got a month worth of taters to last the snow storm season.
  • That means the queue is more likely to flow after counters that are handling individual Mars bars and sodas.
  • Though of course, in this hypothetical scenario, the queue doesn’t change. No one is going to decide to drop out of the queue because they forgot bread, nor would a customer with a trolley full of apocalypse preparations let the Mars bar guy behind them to go first, out of politeness.

WARNING: I try not to spoil the actual solution in this article, but I might accidentally slip hints towards the correct answer. If you want to attempt this kata on your own first, stop right here and do that now!

I mentioned in my first Wombo Combo that I suck at maths. Therefore I approached this kata with the trail of thoughts I listed above. In my mind I would project a bird’s eye view of a supermarket checkout in my head, where customers of different purchases flow like water. I just need to get the time it would take this supermarket to finish that queue (assuming no one else is coming). All good.

The start of my code design went something akin to game development. I had an array of checkout counters, and an array of customers in queue. For each checkout counter that doesn’t have a customer attached, I pop the first customer off the queue array and add them to the first available counter. Each customer’s required time to complete check out is reduced by 1 on every loop as long as they are in the checkout array. Once that time hits 0, the checkout counter is ready to take a new customer, whose time will reduce on every loop by 1 again.

It was something like: for each checkout counter, if it doesn’t have a customer, or the checkout time is 0, pop the first one in. If it has a customer, reduce its checkout time by 1.

Sounds fine, right? Well when I hit the Run button, it passed the test where there’s no customer in queue. It passed the second test too with two customers.

Then I got a timeout error.

The for-loop took too long to process some tests that have long checkout time, or a lot of customers in the queue. I found out from this kata that Codewars has a maximum stall limit of 2 minutes. Considering the nature of katas, certainly no script is supposed to run for that long.

It was the only JavaScript kata that I could not complete so far and had to skip to the solutions. As most things go, the solution is stupidly simple. Everything that I’ve said above, are trails of how I have overcomplicated the problem.

If you have read this far and haven’t attempted the kata yet, I highly recommend giving it a go, or even just to look at the solution so you see what I mean.

Royal Game of Ur

I mentioned that my course instructor has been knocking on my inbox for my homework progress. In Unity I have been working on a digital replica of The Royal Game of Ur — an ancient board game which originated from Mesopotamia. This video from The British Museum, featuring Tom Scott, provided a fantastic introduction on how to play it.

(Sadly when I visited the museum in November 2019, the Mesopotamia area was under construction, so I couldn’t see the original board in person. Oh well.)

I have chosen this board game to be my course project because

  1. It has to be 2D, single-screen (no scrolling, camera stays in one place);
  2. This video was shown to me, right when I was struggling to decide what to make;
  3. It feels good to spread the word about this beautiful relic of the ancient days.

My final straw for making a replica of Royal Game of Ur was a piece of Mesopotamian history I stumbled into, but I struggle to find the source now. What I remembered was that one of the kings of Ur responded to a civilian revolt by diverting the city’s water source, intentionally causing drought to the residents. I took that piece of history and turned it into a motive to stop the king in my game — by challenging him to a Royal Game of Ur.

The game is made in Unity and, fortunately for me, there is already a Royal Game of Ur tutorial in Unity! I used this as my starting point just to get rid of the blank canvas, then began rolling my own implementation after a certain point of the creation process.

Yesterday I finished my version of the board game to its minimum playable state, complete with story dialogues and 5 levels. I just need to hand this in for a grade, but I will polish this for a public release on places like itch.io. For now, have a teaser from one of my development snapshot:

oneleif Highlight: The Quiet Game

I didn’t know what The Quiet Game was, nor who or what were Twenty One Pilots. Then Austin — a fellow member of oneleif — made an app to challenge us to be quiet. It is available on iOS and Android.

My throat gets sore very easily so it is a blessed task for me to stay quiet, but not for some (like Sabien).

Give The Quiet Game a try and see how long you can remain silent. Feel free to tweet your record time to oneleif. If you don’t feel like giving it a go, check out this negative review on the app:

And that’s a wrap for now! There are more things I wanted to share this week, such as new job, flat hunt, animation in Unity, but I will share some of these next week instead, particularly animation in Unity because this is a very new territory for me.

Thank you for reading this far. Stay tuned and take care till then.

Join oneleif Discord

--

--

Tina Ng
oneleif

Unity, Javascript, PC and 3DS gamer, storyteller, traveler.