Robot Minefield Day 4

Date: 2018-03-17 03:13:31

Part 1 | Part 2 | Part 3 | Part 4

It is now day 4 of my Robot Minefield conversion to assembly. Last night was my first night I dreamed in assembly. I remember working on some problem, and assembly was involved. You know you have your head in the game when you dream about it. So far so good. I have the minefield randomly populating with mines and robots, and randomly placing the human somewhere on the field. Steve Bjork was kind enough to provide a random number generator in assembly, which was very easy to adapt. You can run the human around the minefield, and will die if you touch a mine or a robot. I just started working on the robot movement AI. You can view my initial post.


You can find the BASIC and C version, or the Assebmly version on github.

The robot AI will simply loop through the active robots, and move them in the direction of the player. If it moves onto a mine, the robot will be destroyed. In coding terms, that is simply setting it's flag to deactivated, and removing it from the minefield. Should be a simple process, but it does involve

  1. A loop to go through all the robots
  2. Calculations to find where in the minefield the robot is, and where the human is.
  3. Decide what direction to move.
  4. Check if that new spot is a mine or human and take appropriate action.

For such a simple process, which would involve a for loop, and a few if/else blocks in C or BASIC, has taken 7 compares and 9 branches so far. You have to break things down into such minute peaces.

I think the hardest part is learning the assembly as I go, since I have to look things up, and write small test programs to make sure I'm using the instruction correctly. But this is so much freakin fun! I should be learning Unity, but I find I can't pull myself away from writing assembly.

I'm a bit surprised at how big the game is already. A whopping 1.2K! Still that's 1/4 the size of an Atari 2600 game, and some of that bulk is because I have an off screen buffer for the minefield, which is 16x14 (224 bytes). The source code total is 18K.

$ ls -l robot2.asm robot2.bin text.asm
 1291 Mar 16 16:41 robot2.bin
13034 Mar 16 16:41 robot2.asm
 5942 Mar 13 00:13 text.asm

Next step in the process is to get that robot AI working. From there, I can get scoring, and the end game working. I'm also hoping to create my own keyboard routine, but will probably not yet bother with my own text print routine. I'm only using it to display the messages and the score. The game is also small enough that I don't have to worry about where to put it in RAM.

Copyright © 2019, Lee Patterson