Sandwich matching

Super sandwich shuffle

Sandwich matching

In my recently developed game, Super sandwich shuffle, I had to think of a way to let the player select which sandwich they want to complete, and then match that sandwich ordersandwich to a part of the play field. I found out this sounds easier than it actually is. This is because the sandwiches are all different. In each sandwich the center one is always a piece of bread (because what is a sandwich without bread), this leaves the 8 other slots to be randomly filled with 6 ingredients, allowing this game to create up to 10,077,696 different sandwiches. Here is how I did it.

Generating sandwiches

correct and incorrect sandwich

incorrect and correct sandwich

Every sandwich starts out with a piece of bread in the middle, and then if the amount of ingredients is bigger than 4 it will also always add another piece of bread the sandwich. each


ingredients also has to be touching another ingredient, as shown in the image.

The pseudo code to generate a sandwich would be as follows:

Matching sandwiches

Now that a new sandwich order has been generated, we need to check the sandwich to a section of the field. In the game you just click on the sandwich order you want to complete and then click on the part in the field where you want it to match with, and in a fraction of a second the game checked the field to your selected sandwich order and the ingredients in the field have been replaced with new ones. Let’s have a look into what’s happening behind the scenes.

sandwich matchingAs soon as you click on the sandwich order, the sandwich will pop out and follow the player’s mouse around the field. centered on the center bread. then when the player clicks somewhere on the field the game will grab a 3 x 3 section of the field centered on the ingredients the played clicked on. As soon as the game knows both sections it needs to match, the sandwich order and the section of the play field, it will start comparing them.

It will start in the top left corner of the sandwich order, in the example you’ll see there is no ingredient. So instead of saying this would be a miss match it will just skip this one and continue with the next one, the top middle. If these match it will continue to the next ingredient, otherwise it will already know the sandwich order does not match the section of the field and stop checking. If the game manages to check all 9 slots where ingredients could be and it didn’t fail on any of them, it will remove the order and give you money depending on how fast you completed it. At the same time it will also remove the ingredients in the field and generate new ones.

Here is the piece of code that checks the 2 sections:



And there you go, a little insight on how super sandwich shuffle works. Hope you learned something from the things discussed here. Let me know what you think, and if you haven’t yet, please try out Super Sandwich Shuffle yourself!

Leave a Reply

Your email address will not be published. Required fields are marked *