Sometimes when you're playing Super Mario Bros. 3, you may beat a level and then have to sit through several seconds of the roaming Hammer Brothers trying to make up their mind on where to settle next. Normally this process is only supposed to take a second--most of the time they only move one or two tiles each--but sometimes multiple Bros land on each other and they have to march around again. In tight spaces, this last ten seconds or longer! You may have wondered if it's possible for them to ever get stuck in an infinite loop and never settle down. The answer to that is yes! But it would be incredibly unlikely to happen by chance, since it does require some unorthodox play and some really lucky random number generation. The Hammer Bros at the end of world 2 merging together and running around the map for about 10 seconds before stopping [https://rgmechex.com/articles/2023-09-11/img/desert.gif]Make up your mind already! ---------------------------------------- First we need to understand how a Hammer Bro moves on the world map. Each Bro starts by grabbing a random number from the random number generator. My next video will be explain this part in more detail so I'll skip it for now. That number is then ANDed with 3 in order to get a number between 0 and 3. Each corresponding to the four cardinal directions. Then comes the process of determining if it is even valid to attempt to move in this direction. Since the level tiles in this game are actually two tiles apart from each other, there are two parts to a Hammer Bro movement: first, whether the path tile in this direction is a valid tile to traverse across; and second, whether the level tile in this direction is a valid tile to traverse onto. For the first part, a simple list of valid path tiles is used. A Hammer Bro can only traverse across nine different tiles in each direction. There are four different lists, one for each direction (although the up/down list and the left/right list are identical). A variety of path tiles, including bridges and the hand trap tile from world 8 [https://rgmechex.com/articles/2023-09-11/img/validpaths.png]Yes the normal path tile is include three times in the vertical cases--probably to simplify the code (ensuring the lists are the same length). This keeps the Hammer Bro on the intended world map paths and prevents it from wandering off into territory Mario can't reach. It also blocks Hammer Bros from walking across blockades such as rocks, locked doors, raised drawbridges, etc. For the second part, a simple list of invalid level tiles is used. There is a list of 17 tiles that Hammer Bros are forbidden to cross. A variety of level tiles, including the cleared level tiles, start, roulette game, and pipe [https://rgmechex.com/articles/2023-09-11/img/invalidtiles.png]All the copies technically have different IDs so they are all included here. The palm tree is a tile found in world 2, but I'm not sure the green hills are a tile Mario can be on anywhere. I suppose this keeps the Hammer Bros more contained. Particularly, by disallowing them from crossing over completed level tiles, it prevents them from passing over Mario after completing a level, allowing you to easily skip fighting them. If the path tile is valid and the level tile is not invalid, then the Bro will move in this direction. After completing the move, two more checks are made. First: whether the level tile is a valid tile to stay on; and second, whether there is another Hammer Bro (or really any other moving object like the N-Spade game, coin ship, airship, etc.) on this tile. Essentially, the tile is deemed to be invalid to stay on if it can be entered by Mario. Which, in practice means the Hammer Bros can't land on uncompleted level tiles. If they find themselves on a level tile like this, they start the whole moving process again with another random number. Additionally, if it is found that two Hammer Bros or other objects are occupying the same tile, then both of them get flagged to move again. This means that if there happens to be a third Hammer Bro on the same tile, it would not get flagged to move again, since by the time it is processed, the other two have already been told to move. But, if there was a fourth, then all four would move since there would be two conflicts. In addition to all of this, all moving objects including Hammer Bros keep track of which direction they are moving, and will never turn around 180 degrees unless it is the only valid direction to move. If they ever get into a situation where it is impossible to move in any direction (easily possible in two-player mode), then the object will just not move at all. ---------------------------------------- So knowing all of these rules now, can you see how two Hammer Bros could get stuck in an infinite loop, always conflicting with each other and never being able to settle down on their own tiles? Well with only two Bros, it's actually not possible. Given the two rules that Hammer Bros never turn around 180 degrees unless they have to, and that they must move if the option exists, it is actually impossible for them to always land on the same space. They may initially coincide, but they will always do so from different directions, so they will split apart right away. Additionally, if there is any ability for a Hammer Bro to pick between multiple paths, eventually two of them would choose a different direction to move thanks to the random number generator. (In theory, with a true random number generator, it would be possible for two Hammer Bros to always choose the same direction to move. This would happen with probability zero. But thankfully the random number generator in the game is just a pseudorandom number generator, so that will never happen.) A diagram showing that no matter how two Hammer Bros move, they will always find a spot to settle down [https://rgmechex.com/articles/2023-09-11/img/2way.png]Top: Hammer Bros could easily just swap positions. Bottom: If given an opportunity to move into a dead end, they will collide at first, but then settle down afterwards. Hammer Bros do remember which direction they moved last, just like the brown on here (though they do forget in between levels). Note that this is possible with the combination of a Hammer Bro and N-Spade game. This is because N-Spade games are not required to move. They will move when a Hammer Bro lands on it, but will stay put otherwise. This means that if a Hammer Bro lands on an N-Spade game while inside of a sequence of level tiles that provides no branching paths, capped off by two level tiles that are invalid to traverse across, and that the N-Spade chooses to travel in the same direction as the Hammer Bro on its first movement, the two will be stuck forever. A Hammer Bro landing on an N-Spade game and forever being attached to it [https://rgmechex.com/articles/2023-09-11/img/spade.gif]N-Spade games normally don't move, so I don't know why they made them move when a Hammer Bro lands on top of them. It would have prevented this sort of thing from happening. ---------------------------------------- However, if we bump up the number of Hammer Bros to three, then we can find a situation that will cause this to happen. In fact, it's fairly simple. If there are three Hammer Bros trapped in a sequence of three level tiles that provide no branching paths, and they are capped off by two level tiles that are invalid to traverse across, they will get stuck in an infinite loop forever. The two Bros on the ends are forced to move to the center tile, while the one in the center will move to either end. The two in the center will split apart, but one will land on the same tile as the other one, having reached that tile moving the same direction. This causes them to move in tandem, since they only turn around at the end points. Soon they collide with the third Bro, and they will forever move back and forth in this restricted area. A diagram showing that three Hammer Bros can get trapped in a cycle of moving around infinitely [https://rgmechex.com/articles/2023-09-11/img/3way.png]The only way the Hammer Bros can move in this case causes them to get stuck infinitely. Notice how the two highlighted rows are identical (other than exactly which of the three Hammer Bros are stuck together--in the game, all three take turns being the lone one each cycle). This is only possible in one area in the game: World 4. Worlds 5 and 6 also have 3 Hammer Bros, but they are on discontiguous areas of the map (World 5 due to the warp pipe, and World 6 due to a roulette game). Even so, those maps are not linear enough to allow for this to happen. The first half of World 4 works though. However, it requires getting all three Bros on the right side of the main island in the first place, which is not very easy to do (well, it's not difficult, just unlikely). By clearing 4-1, 4-Fortress 1, and the orange Toad House, you create a sequence of three tiles trapped between two non-traversable tiles (the two level tiles 4-2 and 4-3 don't affect anything). Three Hammer Bros getting stuck in an infinite cycle in world 4 [https://rgmechex.com/articles/2023-09-11/img/triple.gif]At this point you just say "whelp" and reset the game. ---------------------------------------- You can support Retro Game Mechanics Explained on Patreon here [http://patreon.rgmechex.com]! Any and all support is greatly appreciated!
The article explains how Hammer Bros’ move in the world map of Super Mario Bros. 3 with a couple of examples of how to get them stuck in infinite loops.