Glitch City Laboratories Archives

Glitch City Laboratories closed on 1 September 2020 (announcement). This is an archived copy of a thread from Glitch City Laboratories Forums.

You can join Glitch City Research Institute to ask questions or discuss current developments.

You may also download the archive of this forum in .tar.gz, .sql.gz, or .sqlite.gz formats.

Generation I Glitch Discussion

How does Focus Energy really work? - Page 1

How does Focus Energy really work?

Posted by: Torchickens
Date: 2014-02-25 10:03:54
There are three conflicting explanations of how Focus Energy works in Generation I, but how does Focus Energy really work?

The first explanation is that Focus Energy will quarter the Pokémon's chance of getting a critical hit (according to Kamek's document rby-stuff.wri)

The second explanation is that Focus Energy either has no effect if the user is faster than the opponent, or will prevent you from getting a critical hit if the user is slower than the opponent (sources: Psypokes - Pokémon Games :: Critical Hits, R/B/Y move information - IIMarck.us).

The third explanation incorporates the first explanation, but only for 'non-enhanced critical hit' moves. For 'enhanced critical hit moves', including Karate Chop, Razor Leaf, Crabhammer and Slash (according to the Pokémon Red disassembly), it says that the rate of scoring a critical hit is reduced by 50% if the Pokémon is somewhat slower, and becomes 0% if the Pokémon is significantly slower.  (sources: Azure Heights - Focus Energy, Smogon - Focus Energy (R/B), our wiki)

Apparently, for explanation 3 it doesn't matter how much faster the Pokémon is. I cheated to battle a level 100 'A' with a level 3 Pidgey with infinite HP, Focus Energy and Slash and then later a level 100 Jolteon. I was still able to score a critical hit with Slash after Focus Energy.

(After SnorlaxMonster sent me the link to the Azure Heights/Smogon explanation on Bulbapedia, I wrote:)

Thanks SnorlaxMonster. That seems to be the explanation Tombstoner wrote on the Glitch City wiki, too. I notice that the Azure Heights article may still have an error. I cheated to battle a level 100 A (that has base 178 speed) with a level 3 Pidgey with infinite HP, Focus Energy and Slash. A should be many times faster than Pidgey, but I was still able to get a critical hit with Slash. Either that was an error, something about me cheating made the game think A was not that much faster, and/or the Pokémon has to be even faster (at level 100 A will have over 360 speed and my Pidgey has 8), or something else. For what it's worth, I tried it with a level 100 Jolteon too, and got the same result. –Chickasaurus (talk) 15:54, 25 February 2014 (UTC)

Re: How does Focus Energy really work?

Posted by: Stackout
Date: 2014-02-25 10:27:02
According to the Pokémon Red disassembly, Focus Energy causes a bitshift to the right (read: dividing by 2) when calculating the critical hit probability, when a bitshift to the left is meant (read: multiplying by 2). This results in 1/4 the usual critical hit probability after Focus Energy is used.

The division by 2 is done before the check for a move that gives a high critical hit (Karate Chop, Razor Leaf, Crabhammer, Slash).

Re: How does Focus Energy really work?

Posted by: Torchickens
Date: 2014-02-25 10:31:16

According to the Pokémon Red disassembly, Focus Energy causes a bitshift to the right (read: dividing by 2) when calculating the critical hit probability, when a bitshift to the left is meant (read: multiplying by 2). This results in 1/4 the usual critical hit probability after Focus Energy is used.


OK, thanks Wack0. Is it really quartered? I'm confused how if the operation is read as dividing by 2.

Does your speed or the use of high-critical hit moves, including Karate Chop, Razor Leaf, Crabhammer and Slash affect how Focus Energy works?

(I just saw the same explanation on the Skeetendo forums and asked Crystal_ the same things)

Re: How does Focus Energy really work?

Posted by: Stackout
Date: 2014-02-25 10:39:26

OK, thanks Wack0. So it's definitely quartered, then?



bit 2, a ; test for focus energy
jr nz, .focusEnergyUsed
sla b ; b=b*2
jr nc, .noFocusEnergyUsed ; if b was below 128, skip...
ld b, $ff ; a cap at 255/256
jr .noFocusEnergyUsed
.focusEnergyUsed
srl b ; whoops! b=b/2, and if you look, the jump to here is before the b=b*2, so b is effectively 1/4 of what it should be
.noFocusEnergyUsed ; no cap at 255/256 for focus energy. I wonder if, if done properly, this would have caused bugs related to integer wraparound..
; ... (check for high critical hit move here)


all but one of the comments are mine. hopefully this makes the relevant block of code easier to understand…

When this block of code is ran, b is equal to (base speed)/2.

If you want to know, if the move being used causes high critical hits, b is multiplied by 4 (two left shifts), capped to 255/256 as here (the final probability being b/256). Which of course means using Slash/Crabhammer/Razor Leaf/Karate Chop essentially cancels out this bug…

Which in turn would lead to interesting strategies: Focus Energy + Slash/Crabhammer/Razor Leaf/Karate Chop means Critical Hit probability is equal to base speed…

Re: How does Focus Energy really work?

Posted by: Torchickens
Date: 2014-02-25 11:58:01
OK, I see. Thanks for your explanation. So a relative jump happens for when bit 2 is set (Focus Energy is used) and this skips a multiplication by two (sla b) for register 'b' (which is being used for chance/256) that would otherwise follow. The program advances to the 'focus energy used' function and also skips a '255/256 cap' function and from there, the chance is divided by two (srl b; b=b/2).

The way it works means that the chance for a critical hit is multiplied by two (sla b) for when Focus Energy is not used, so the real chance would be x2.0 but the chance for a critical hit for when Focus Energy is used is x0.5 and 2.0/0.5=4.0.

Re: How does Focus Energy really work?

Posted by: Crystal_
Date: 2014-02-25 13:13:56
Ah, nice you are bringing this up Torchickens. Realted to this, I have been wondering lately whether the bug came from Focus Energy, or affects the generic critical hit calculation instead (will explain this later).

This is what I wrote in Smogon, trying to show the program flow without getting into asm code:


(the crit ratio is base speed/2 to this point)

  • Check for Focus Energy
  • Has Focus Energy been used? If so, jump to Used
  • (if not used) Multiply crit ratio by 2 (bit level left shift)
  • Jump to NotUsed



  • Used: Divide crit ratio by 2 (bit level right shift) ; fallthrough to NotUsed
  • NotUsed: (…)


(finally there is another divide by 2, or a multiply by 4 for high crit moves instead)


The cond. jump of the cap is basically to prevent the crit chance from rolling back when >255.

Which in turn would lead to interesting strategies: Focus Energy + Slash/Crabhammer/Razor Leaf/Karate Chop means Critical Hit probability is equal to base speed…
But why use Focus Energy, when without it these moves would have a crit chance equal to base speed*4!



Anyway, my theory that the bug is not just related to Focus Energy is based on the following:

If the bug was that the code had been intended to be:
.focusEnergyUsed
sla b ;

instead of
.focusEnergyUsed
srl b ;

that would mean that the crit chance would be shifted to the left regardless of whether focus energy had been used or not. Having a move do effectively nothing (outside of splash of course, which especifically says 'had no effect' upon being used) wouldn't look very logical to me.

A possible option to me, is that the bug could've been in the first relative jump to .focusEnergyUsed (right after the test for focus energy). I mean that instaed of:
jr nz, .focusEnergyUsed
it should've been:
jr z, .focusEnergyUsed

So basically, we do the opposite (meaning that the names of the labels would be the opposite). The jr z would make it jump, when focus energy has NOT been used, to the srl b (b <- b/2) and skip everythnig in between. Meanwhile, when focus energy is used, sla b (b <- b*2) is executed and eventually the non-conditional jump makes it skip the srl b.

This looks more likely to me than that they could've swapped the two shifts (which in practice would be the same anyway), or than that they wanted to make Focus Energy do nothing.

The interesting thing about this is that, if this theory is true, normal critical hit ratio would be four times lower. Note also that the critical hit ratio got heavily reduced in the next generation (except for very slow Pokemon like Snorlax). The critical hit mechanics really shape competitive rby as much as you can imagine, and that's the main reason I got intrigued by this bug.

Re: How does Focus Energy really work?

Posted by: Torchickens
Date: 2014-02-25 13:45:29

Ah, nice you are bringing this up Torchickens. Realted to this, I have been wondering lately whether the bug came from Focus Energy, or affects the generic critical hit calculation instead (will explain this later).

This is what I wrote in Smogon, trying to show the program flow without getting into asm code:


(the crit ratio is base speed/2 to this point)

  • Check for Focus Energy
  • Has Focus Energy been used? If so, jump to Used
  • (if not used) Multiply crit ratio by 2 (bit level left shift)
  • Jump to NotUsed



  • Used: Divide crit ratio by 2 (bit level right shift) ; fallthrough to NotUsed
  • NotUsed: (…)


(finally there is another divide by 2, or a multiply by 4 for high crit moves instead)



I'm glad that you are interested. With the conflicting explanations I wondered if Bulbapedia was correct, and I disproved explanation 2 and 3 on the basis of it being possible to get a critical hit with a move like Slash with Focus Energy regardless of your speed.

So far, I have wrote this as a replacement:

Focus Energy worked incorrectly in Generation I. When Focus Energy is not used, there is a multiplication by two involved in the initial critical hit ratio. When Focus Energy is used, the game will skip the multiplication, and half the chance instead of multiplying it by two, essentially dividing the critical hit ratio by 4.

As moves that are programmed to result in a critical hit more often, including {{m|Karate Chop}}, {m|Razor Leaf}}, {{m|Crabhammer}} and {{m|Slash}} multiply the critical hit ratio by 4, this will bring the factor back to two, causing the chance of a critical hit to be as if the player had used a regular move without Focus Energy, provided that the speed of the Pokémon is kept constant on both cases.


You mention above in what you wrote for Smogon that there is another divide by two though. To clarify, I ask does this happen for moves that aren't programmed to result in a critical hit more often? If so, that would mean Focus Energy and something like Slash is twice as likely to result in a critical hit than a regular move (not Slash, etc.) without Focus Energy right?

Re: How does Focus Energy really work?

Posted by: Crystal_
Date: 2014-02-25 13:57:41
Moves with high crit ratio like slash will score a crit eight times more often than normal moves. It's base speed*4 times vs base speed/2 times (in both cases, out of 256). Pokemon with base speed of 64 or higher will crit 255/256 times with a move with high crit ratio.

So using focus energy followed by slash or a similar move will output a chance of critting that is twice as high as using a normal move without the use of focus energy.

Re: How does Focus Energy really work?

Posted by: Torchickens
Date: 2014-02-25 14:19:00
Right, OK. Thanks.

On second thoughts I probably don't need to talk about Karate Chop, Razor Leaf, Crabhammer and Slash on the Bulbapedia articles because they act as would be expected, with the resulting factor being x8.

Re: How does Focus Energy really work?

Posted by: SnorlaxMonster
Date: 2014-02-26 06:11:35
So my subsequent question is how does this work in Stadium? I know Focus Energy was fixed to increase quadruple instead of quarter the rate, but did anything else change? Critical hits are already stupidly frequent: did Stadium decrease their frequency?