Controlling the barrels in Donkey KongBy Don Hodges Posted July 20, 2008 Last updated 8/14/2015
Jeff Kulczycki’s web site has some very good information on how to control the barrels in Donkey Kong. However, I believe that his information is incomplete. For example, he mentions probabilities X and Y but does not state what these are. Also, Jeff writes that "It will not work for the first barrel that comes down." The very first barrel of every stage is a "crazy" barrel; these crazy barrels never go down ladders, and they can never be controlled.
As we shall see, the second barrel will always take the first few ladders it
encounters, until the oil can is on fire. After that, this barrel can be
controlled with the same chances as any other.
The higher the modified difficulty, the higher the chance of being able to
control the barrel: the modified difficulty is compared to this random
number. If the random number is greater or equal, then the subroutine returns
and the barrel will never
go down the ladder. If the random number is less than the modified difficulty, then the
following checks are done. The bottom line:On level 4 and above, all non"crazy" barrels thrown after the oil fire is lit, and are above jumpman, have a 25% chance of completely ignoring the ladder and a 75% chance of being controlled to come down. Those that could be controlled but aren’t, have a 25% chance of taking the ladder anyway. For levels below 4, consult the following table: Table1: The chance that a player is able to control a barrel in Donkey Kong
// A barrel has reached a ladder. Decide whether or not to go down it. // Decompiled from Z80 Assembly by Don Hodges // July, 2008 Take_ladder = false ; If oil_fire == not_lit then { Take_ladder = true; Return ; } End if ; If Mario_height >= barrel_height then Return ; R = random(255) ; // random number between 0 and 255 inclusive R2 = R mod 3 ; // random number between 0 and 3 inclusive, based on R If R2 >= ((difficulty div 2 ) + 1) then Return ; If (barrel_x_position == Mario_x_position) or ((barrel_x_position < Mario_x_position) and (joystick_direction == left)) or ((barrel_x_position > Mario_x_position) and (joystick_direction == right)) then { Take_ladder = true; Return ; } End if ; If (R & 0x18) != 0 then Return ; // 75% chance of return without ladder Take_ladder = true; // 25% chance of taking ladder Return // original Z80 assembly code of the subroutine 2178 3A4863 LD A,(#6348) ; get status of the oil can fire 217B A7 AND A ; is the fire lit ? 217C CAB221 JP Z,#21B2 ; no, always take ladders before oil is lit 217F 3A0562 LD A,(#6205) ; else load A with Mario's Y position + 5 2182 D604 SUB #04 ; subtract 4 2184 BA CP D ; is the barrel already below or same level as Mario ? 2185 D8 RET C ; yes, return without taking ladder 2186 3A8063 LD A,(#6380) ; else load A with difficulty from 1 to 5. 2189 1F RRA ; divide by 2, result can be 0, 1, or 2 218A 3C INC A ; increment. result is now 1, 2, or 3 218B 47 LD B,A ; store into B 218C 3A1860 LD A,(#6018) ; load A with random timer 218F 4F LD C,A ; store into C for later use 2190 E603 AND #03 ; mask bits. result now random number between 0 and 3 2192 B8 CP B ; is it greater than modified difficulty? 2193 D0 RET NC ; yes, return without taking ladder 2194 211060 LD HL,#6010 ; else load HL with player input. 2197 3A0362 LD A,(#6203) ; load A with Mario's X position 219A BB CP E ; compare with barrel's X position 219B CAB221 JP Z,#21B2 ; if equal, then go down ladder 219E D2A921 JP NC,#21A9 ; if barrel is to right of Mario, check for moving to left 21A1 CB46 BIT 0,(HL) ; else is Mario trying to move right ? 21A3 CAAE21 JP Z,#21AE ; no, skip ahead 21A6 C3B221 JP #21B2 ; yes, make barrel take ladder 21A9 CB4E BIT 1,(HL) ; is Mario trying to move left ? 21AB C2B221 JP NZ,#21B2 ; yes, make barrel take ladder 21AE 79 LD A,C ; else load A with random timer computed above 21AF E618 AND #18 ; mask with #18. 25% chance of being zero 21B1 C0 RET NZ ; if not zero, return without taking ladder 21B2 DD3407 INC (IX+#07) ; else increase barrel animation 21B5 DDCB02C6 SET 0,(IX+#02) ; set barrel to take the ladder 21B9 C9 RET ; return 
In accordance with Title 17 U.S.C. Section 107, some of the material on this site is distributed without profit to those who have expressed a prior interest in receiving the included information for research and educational purposes. For more information go to: http://www.law.cornell.edu/uscode/17/107.shtml. If you wish to use copyrighted material from this site for purposes of your own that go beyond 'fair use', you must obtain permission from the copyright owner. 


