Sokoban type game

Recently, I’ve been programming a specific variant of Sokoban. This version has boxes that can be multiple tiles large, the ability to push multiple boxes (recursively), spikes (which boxes can go over but the pusher can’t), and posts (which the pusher can go over but boxes can’t). I’ll call it ”Sokenban”.

Now the important difference between Sokenban and Sokoban is the multiple tile large boxes and the recursive pushing. Multiple tile large boxes means that each box is labeled with a letter, and all boxes with the same letter move together. This already complicates things. Every time the pusher pushes a box the game doesn’t just check if the location the box is moving to is empty and then move both the pusher and box one tile in that direction, the game actually has to check the location that every box of the letter is moving to, and if all those locations are floors, then move all the boxes of that letter to that location (and move the pusher aswell). To complicate things further, if any of those movements would result in a box on top of another box, this second box and all boxes with that letter will also have to move, and they might run into other boxes, who knows how big a stack of boxes the pusher might move in one turn.

And so in order to get this to work, I have to programme it in a specific way. See, with classic Sokoban it is easy to tell if a move (a single tile in one direction) is legal (that is it doesn’t result in two boxes on top of each other or a box on a wall tile) before even performing the move. The code only needs to update the box locations if it knows the move is legal ahead of time. And generally that is the clever way to do things, since it saves on how much data is changed. But if I were to try to implement that system in Sokenban, it would be much more difficult. In fact, as far as I can tell, it is nearly impossible to know ahead of time whether or not a move by the pusher would result in an illegal position before actually simulating that move. But if you simulate that move and it turns out to be illegal that’s a problem isn’t it? Not necessarily.

The way I’ve programmed Sokenban in the video game I’m making all requires one essential extra mechanic, undoing, because I already need to be keeping track of the previous positions of boxes and the pusher, so that if the player made a mistake that softlocked the puzzle, they could press the undo button and “rewind” their last move. In fact, the game already records the position of every box and pusher, after every move, such that the player can undo all the way up to the beginning of the puzzle if they wanted to.

And so I think the best implementation is for the game to do something inefficient, but elegant. When the player makes a move (a single tile at a time), the game will simulate the whole thing, ignoring all walls, posts, spikes. It will recursively move boxes when one box pushes another (in the same direction), until all boxes affected by the move, have moved. Then, it will “save” or “record” the move, because of course that happens after every move, and finally then, after all the data has already been updated, it will check if the move was illegal (if any boxes are on walls or posts, or if the player is on spikes). If not illegal, great! The game can continue on as usual. But if the move is found to be illegal, the game will undo itself, automatically, as if the player pressed the undo button, but it’ll undo whether the player likes it or not. And all the pre existing code for undoing will run, and that will ensure that the game is back in a legal state. In theory, all this happens in a fraction of a second, and the player won’t even know that, for a moment the box was in a wall, or something.

This seems like an inefficient solution, but I think that a “clever” solution (trying to figure out legal moves ahead of time) wouldn’t be very smart. At least the inefficient solution is consistent.

Super Mailing List

Nearly the end of the month I gotta get this written quick!

Last spring… or maybe this spring of this year depending on how you look at it… the most recent spring that previously happened, I programmed Mailing List software. Maybe that doesn’t sound particularly interesting to you, but these are monthly posts! A few years ago I could give you a box of entertainment concentrated semi-yearly, but I’ve got to spread it out a bit with these monthly ones. Anyway I’ll be referring to Super Mailing List as SML for the rest of this blog post unless my word count is too low (in which cast I’ll replace it with the full name, but I don’t even know how to do a word count so that seems unlikely to happen).

Either way, the main purpose of SML (which stands for Super Mailing List… I just told you last paragraph how could you have forgotten already?!) is that it will allow you to have your very own mailing list. When it’s running on your computer people will be able to subscribe to your mailing list by sending a message with the subject SUBSCRIBE to SML’s email address and SML will add them to the subscribers file. Then, if a moderator sends a message to SML’s email address the programme will rebroadcast it to all the subscribers.

You can download SML here: https://www.gartekstudios.ca/downloads/superMailingList.zip

It’s being updated frequently so if you have any suggestions they might get added!

Do I have a sign off? I don’t think so…

Pumpkins and penguins, bye!

Video Game Hints

Oh dear! I haven’t done a blog post in ages. I’m going to try to do one at the start of each month, but I feel like I’ve said something similar to that before and not really succeeded.

Anyway, in my video game that I’m programming, (called No Anglerfish, which I’ve already talked a bit about in this post) there are Sokoban type puzzles that you must solve to progress. Unfortunately it’s impossible to design a puzzle that is the same difficulty for everyone. One player might see where the “soko blocks” need to be moved right away and solve it in two minutes, another player might take ten minutes or twenty minutes or even give up entirely : (

So that’s why I decided to add hints for the puzzles. If a player is stuck on one puzzle for more than about five minutes, text will appear at the bottom of the screen saying “Press H for hint”.

Then if the player did press H it would display what they needed to press to solve the puzzle. But this was NOT a good system. First off, the hint would just be displayed as a long list of directions that the player needed to press (for example: ↓↓→→→→↑↓←←←←←↓↓↓↓↓→→↑↑↑↑↑). Second, the “hint” would be covering up the puzzle so you couldn’t solve it while looking at the hint – you had to write down the hint and then close the hint screen and then solve the puzzle. This was meant to discourage people from using the hint too often. And the third reason why this wasn’t great is that the “hints” just tell you exactly what to do! They weren’t even hints, just instructions on what to do to solve the puzzle. I don’t know but I suspect that if a player is having trouble understanding what a new puzzle mechanic does, telling them exactly what to press to solve it might not actually teach them very well how the mechanics work. In short, thumbs down to hint version 1.0.

Now after I decided to reprogramme the hint system, I had to find a better way to guide players into solving a puzzle if they were stuck (and I wanted it to be something that didn’t require me to reprogramme massive chunks of code to get it to work). I think it was my Mother’s idea to show the player an image of the puzzle almost solved if they asked for a hint. That idea was what I decided to use! Now in the new and improved hint system version 2.0, after about five minutes of being stuck on a puzzle the game will say that you can have a hint if you want it and if the player does request a hint it will show them a dark image of where the blocks need to be before the puzzle can be solved – or sometimes an image showing how a new mechanic works or anything that can guide them to the solution without making it too obvious.

Hopefully that helps them realise the trick to solving the puzzle and the player can close the hint and then win the puzzle.

And that’s the end of the post.

Modules in Python

When I programmed Factory512 all of the code was in one long file (1897 lines in fact) which meant that it took a while to scroll through. When I started my next game I did the same but by the time it was over 3000 lines I started to wonder if there was was a better way to deal with lots of code. Daddy looked it up and told me about modules. Modules allow you to have code in separate files that all run together. You just have to import the module at the start of the larger programme and then you can treat it like function (Except that that you must go into another file to see it). And it gets compiled too!(Compiled python runs faster) Yay!

The Post in Which I Explain The Post in Which Daddy Helps me With Arrays.

Several people have indicated that my last post was pretty technical, so let me see if I can explain it differently…

It’s like this: Imagine that Daddy and I are walking down the road. I have a notebook that I can write stuff in.

First Daddy and I walk past house number 64. Daddy tells me to “Write down the number of the house we just walked past”, so I write “…the number of the house we just walked past”.

Then we walk past house number 66 and Daddy tells me to “write down the number of the house we just walked past”, so again I write “…the number of the house we just walked past”.

THEN we walk past house number 68 and Daddy tells me again to “write down the number of the house we just walked past”, so then there’s a plot twist and I write “…the number of the house we just walked past”.

Finally we walk past house number 70 and Daddy asks what I’ve written down so I look at the notebook and see:

  • …the number of the house we just walked past.
  • …the number of the house we just walked past.
  • …the number of the house we just walked past.

so I look at the number of the house we just walked past and see that it’s 70. I say to Daddy “70 70 70” and he gets annoyed.

Now replace me with my computer and Daddy with me and that is what I was talking about in the last post.

The Post in Which Daddy Helps Me With Arrays.

I am making a grid based game where you have to move big blocks around and onto buttons and stuff like that. I also wanted the player to be able to undo their moves if they made a mistake, so I needed a big array that would remember the positions of the blocks and then if the player pressed the undo button, it would move the blocks (and the player) back to their earlier positions. However, the position of the block was also an array because some blocks could be odd shapes and I needed to store all of that information as well. So basically I had a huge array of all the information that ever was in a smaller array that was the position and shape of oddly shaped blocks.

It didn’t work.

I tried to fix it but it just made the code messier and I really couldn’t figure it out. I decided to do another, better and simpler version of it and that didn’t work ether. It seemed like while the actual position of the block moved, it would change bits of the array that saved previous positions, but it would only do it in specific spots. I figured out that it would only do it when I undid moves. I found the exact line that would change one list and for some reason the other one changed. I stared at that line for quite awhile until Daddy looked at it. He went online and found out that somehow instead of the code putting the data of the array at that time in the other array, it was REFERRING to the array of the current position. So instead of reading data of the array at the time when I wanted to go back to, the code was just looking at what the blocks current position is.

I fixed it by adding [:] to the right lines and it worked!…almost. I just had to write a bit more code and fix a few more glitches, and then it worked. The end.

Blog and a Videogame.

Recently I have been working on my blog and making it look a bit better. I want to write more posts by myself and more often.

About a month ago I finished programming one of my longest videogames yet and Daddy posted it to a site called Itch.io for me. The game is called Factory 512 and I made it with Python 2. It’s the first platformer that I made with all my own code.

The hardest part was making gravity work properly and the player stop when they collide with solid objects. I made my own physics for the game because I wanted more control over it. I know that when the player jumps, they go up exactly 7 pixels on the first frame and the distance they go up decreases every frame after that (even into negatives) until they hit the ground (or they get to terminal velocity which is -14 pixels per frame). Not only does the programme check collisions every frame but it also checks in between frames to prevent a fast moving object from flying right through a wall or something (although sometimes it doesn’t bother if the player is in between tiles and has no chance of hitting anything).

At first the wires between the levers and gates were very thin but after people tested the game I realized that they needed to be thicker. Unfortunately I couldn’t make them light up when powered. Maybe next time I do something similar I’ll have interactive wires.

The game is about a robot escaping from a factory – for freedom and happiness! But it is very challenging.

Click here to go to Itch.io to download the game.

Next time I may or may not be talking about what I am programming now.

Programming

Yesterday at the library I demonstrated my latest programme on the projector at the library and then described how I coded it.  Question and answer followed where I was able to explain how and why I did the manipulations I did.


Tech Club

Yesterday there were two more new introductions to our coding club.  It was exciting to spend time tweaking the computers.

I spent most of my Minecraft time perfecting an igloo with my friend S!

Tech Club

Today at our weekly Tech Club we had probably the most other kids come out ever!  Hard to imagine that the first many weeks it was just Daddy and me.

Daddy thinks we had at least eleven other kids playing Minecraft and Scratch!
Afterwards Daddy had an appointment, so I went with my friend C! and his Grandma to Chapters, where Mama caught up with us and brought me home.

It was almost overwhelming!  Whew!