Facebook
From dimusnail, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 249
  1. You might know that there already is a guide on this topic, but I found it very hard to understand, so after looking at the code and figuring things out myself, I've decided to try writing a simplified, but hopefully completely accurate summary of how the Giga Snail AI works. I'll also try to avoid programming terms as much as possible.
  2. Here's the code that Auriplane shared if you want to look at it yourself: https://www.auriplane.net/Boss4SecondForm.as
  3. Firstly, all Giga Snail's RNG is based on a table that contains 100 static "random" numbers between 0 and 1, which you can find at the bottom of the linked code. Each of these numbers has an index, which corresponds to the position of that number on the list – the first number's index is 0, but the last number has the index 99.  Although these numbers in the list were probably generated randomly at first, they never change, so if we can force the game to always choose the same "random" numbers, we can force Giga Snail to always act in the same way.
  4. So how does the game choose which numbers to use from the table? The first random number is chosen at the moment you kill Moon Snail's first form, and its index corresponds to the last two digits of Snaily's x position at that moment. Now, whenever the game needs a random number to decide an action of the boss, it uses *the next* random number on the list after the currently selected one, and when it needs another random number, it always uses the one after the previously used number. When the last number of the list is used, the next number is the first one on the list.
  5. So if we want to make Giga Snail act the same way each time, first of all, Snaily's x postition needs to always have the same last two digits at the moment Moon Snail is killed, which is most easily achievable if there's a setup that guarantees Snaily to always have the same x coordinate – for example, pressing against a wall. Secondly, there are other player actions that can influence which random numbers the boss uses, but to understand that, we need to learn how exactly do the random numbers influence each state of the boss.
  6. The boss always starts out in the Stomp state, which is the state where Giga Snail jumps around and is vulnerable, and, as we want to have as many stomp phases and as few other states as possible, it makes sense to study this state the most.
  7. The first random thing the boss has to decide is where to move on the screen before coming out of its shell. There are seven different positions where Giga Snail can go, and each of them is numbered with numbers 0 - 7. All the positions are arranged in the boss room roughly like this:
  8. 3 67 2
  9. 5    4
  10. 1    0
  11. Now you might be wondering what's up with the "67". Numbers 6 and 7 actually stand for the same place, it's simply a small mistake in the code that led to the top middle position having two numbers, but the bottom middle having none.
  12. So, to decide where to go, the boss takes the current random number, multiplies it by 8, rounds it down to the nearest integer and then tries to move to the corresponding position. For example, if the random number is 0.3263779227, it gets multiplied by 8, resulting in 2.6110233816, which then gets rounded down to 2, so the boss tries to move to the position with the number 2, which in this case is the top right corner.
  13. But Auriplane thought it would be unfair if the boss could move to a position that's close to Snaily, dealing damage to him without really any time to react. So she decided to make the code check if Snaily is within 130 pixel distance from the position where Giga Snail would move, and if Snaily is within that distance, Giga Snail doesn't go to that position, instead taking *the next* random number and checking if it can go to its corresponding position. And if it can't, the code keeps checking the next numbers one after another until a plausible location is found. Ultimately, this is the main way we can influence Giga Snail's behaviour during the bossfight, as we can "block" certain parts of the room to force the boss to skip forward the exact amount of random numbers needed for the best outcome afterwards.
  14. After finding and moving to a place that's not too close to Snaily, the next random number is used to decide Giga Snail's gravity direction – if the random number is greater than 0.5, the gravity direction is down, otherwise it's up.
  15. After that, Giga Snail has to decide which state will be his next one, and this is the part where it's crucial that the random numbers are aligned exactly in such a way that the next state turns out to be Stomp again.
  16. Here the code behaves a bit differently whether Giga Snail is in panic phase(<40% health) or not, as he can't go into the sleep state if he's not in panic phase. If he hasn't reached panic phase, at first the game checks the current random number to see if it's larger than 0.7, and if it is, Giga Snail goes into smash state(red background). If it isn't, the game checks the next random number to see if it is larger than 0.8, and if it is, Giga Snail goes into Stomp phase. If both of these checks fail, the boss goes into the strafe state(purple background, shooting multiple streams of bullets). As you can see, before the boss has reached panic phase, we ideally want the next number after the one that decides the gravity direction to be smaller than 0.7, but the next after that – larger than 0.8.
  17. If the boss has reached panic phase, it at first checks if the current random number is larger than 0.7, and if it is, it goes into the sleep phase. If the number isn't larger than 0.7, the game uses the random numbers after it to decide in which state to go just as before. However, as the developer yet again doesn't want the boss to be able to deal damage without the player having the time to react, the sleep phase has a very, very fortunate check: if the player is below the boss when Giga Snail would go into the sleep phase and fall down on top of poor Snaily, the boss instead goes into... stomp phase, without any influence from random numbers! So we can also let Giga Snail go into sleep phase, provided that we can manage to be under him at the right moment while also potentially blocking certain parts of the screen.
  18. As it turns out that it doesn't seem possible to do the whole bossfight with only stomp and sleep states, we should also quickly look how other phases use the random values. If the strafe state is selected, the first random number decides the direction of the strafe(>0.5 – clockwise, else anti-clockwise), then the next number(s) are used to decide the following state like so: if it's panic phase and the first number > 0.74, go to sleep mode, else if the next number(if it isn't panic phase, the same number that would be used in the first comparison) < 0.77, go into stomp state, else go into smash state.
  19. Talking about the smash state... it is not only a complicated mess in enough itself, it even uses random numbers outside the table that are impossible to predict and that can influence how many table random numbers are used, making it potentially inconsistent. It doesn't mean there certainly couldn't be any more or less viable strategies that have a smash state, but I still think it's best to avoid it as much as possible. That's why I won't waste time trying to explain it here, you can try to figure it out from the code yourself(look at the functions updateAiShellSmash and pickSmashDir), or I might explain it somewhere separately if you really want to.
  20. Finally, although the sleep state should most often be skipped by being below the boss, if for any reason it doesn't get skipped, at the end of it the next state gets decided like so: if random number > 0.5, go into stomp state, else go into strafe state.
  21. ---
  22. With all this knowledge, you can finally start searching for good Giga Snail patterns! However, just going through the raw random numbers in the table can be pretty tough, as they contain a lot of redundant information – as we're most interested in stomp phases, we most often just need to know the position on the screen that each number would correspond to, or which numbers are larger than 0.7 and which – larger 0.8, so that the stomp phase would be continuously selected. That's why I turned the 100 random number table into these two strings:
  23. 1301430172032013166515363505662261701021521444242120765675674021222722202556132165172534555552661761
  24. --------&--------&&--|-|-|--&&--|-&-----------------&||&&||&-------&-----|-&----|--&-----|----&&-&&-
  25. The first string shows which position each of the random numbers(in the order as they are in the table) would correspond to if said number was used to choose a position to move to, but in the second row each "&" represents a number that's larger than 0.8, each "|" – a number between 0.7 and 0.8, but "-" are numbers smaller than 0.7. The number and the symbol that are in the same column represent the same random number from the table, so you can just go along both rows, looking at the top row if you need to know where the random number would make Giga Snail move and looking at the bottom row if you want to know if these random numbers would make the boss turn into stomp phase. You can also use the top row to understand which gravity direction this number would achieve – numbers with 0 to 3 on the top row are less than 0.5, but 4 to 7 are larger, resulting in upside down and normal gravity repectively.
  26.  
  27. Now, as an example, I'll show you what happens in the pattern I found and use in runs(a tutorial of it can be found at the end of this video: https://youtu.be/EeAWEbHv2y0). I'll quickly copy the position layout and the same two rows that I showed earlier, plus add an extra row on the top and bottom with some letters so that I can reference each position that we're at in any moment.
  28. 3 67 2
  29. 5    4
  30. 1    0
  31.    ABCDEFGHIJKLMNOPQRSTUVW
  32. 1301430172032013166515363505662261701021521444242120765675674021222722202556132165172534555552661761
  33. --------&--------&&--|-|-|--&&--|-&-----------------&||&&||&-------&-----|-&----|--&-----|----&&-&&-
  34.    ABCDEFGHIJKLMNOPQRSTUVW
  35. At the start, when standing on the right wall, the last two digits of Snaily's x position(apparently) are 03, so we start at the position A. Then, as it's stomp phase automatically at the beginning, the game uses the next number, which is at position B, to see if Giga Snail can move to that position in the room. Position number 4 is middle right, but as Snaily is standing on the right wall at the beginning, the boss can't go to this position and instead tries to go to the position 3 signified by the next random number at C. As 3 is on the top left corner but Snaily is on the right wall, it isn't blocked, so Giga Snail moves to this spot.
  36. Then he uses the next number at D to see if his gravity should be up or down. As the number is smaller than 0.5(which we can see by the fact that the top number is 0), the up direction is selected. Then, after jumping around for a bit, he checks the next number at E to see if the next phase should be smash, but as this number is smaller than 0.7, he checks if the next number at F is bigger than 0.8, and as it is, the next phase is yet again stomp.
  37. Then, using the number at G, he tries to go to the position 2 that's in the top right corner, and as this corner is free, he can move there. Then the number at H decides that the gravity should be up, the number at I decides that the next phase shouldn't be smash, but as this time the number at J is not larger than 0.8, Giga Snail also doesn't go into stomp phase, instead choosing strafe.
  38. The next number at K decides that the strafe should turn counter-clockwise, and the number at L, which is smaller than 0.77, decides that the next phase should be stomp. Then Giga Snail successfully goes to position 3, chooses gravity up because of the number at N, and, as by the end of this phase the boss should be in panic phase, now the first check decides if the boss should go into sleep state. As the number at O is indeed larger than 0.7, Giga Snail tries to go into sleep state, but as the player is directly below him, he goes back into stomp state.
  39. At this same moment the player should also have jumped in the air so that they're blocking the position 6 but not the position 5, so that the boss skips the number at P and chooses the go to the posititon signified by Q. Then the number at R decides that the gravity should be up, and the number at S, as it's bigger than 0.7, makes Giga Snail go into sleep state, which again gets cancelled by the player standing below him. Now the player also must have jumped in the air so that they're blocking the position 3, but not the position 6. Then the number at V decides that the direction of gravity should be up, and finally, the number at W decides that the next phase should be sleep phase, which again gets cancelled, and then the boss gets killed in the final stomp phase.
  40. Thanks for reading. It's probably been hard to remember and understand everything from this massive amount of text, so I'd recommend going through the pattern on your own until you get a more intuitive sense of how everything works and what is needed for a good pattern. So I hope you've now got some understanding about how the RNG manipulation for the last boss works, and hopefully can also now try finding other possible strategies!