384

While trying to get 3 stars on the more complex levels (the ones with a lot of destructible entities) I noticed that even after playing the same level over 50 times, doing always the same thing, I've never seen the same final result. Something always goes differently.

Does the same input always result in the same output, or is there a random factor in there?

Andreas Bonini
  • 3,879
  • 2
  • 16
  • 9
  • 154
    How can you be sure the input you're giving is 100% identical? –  Dec 29 '11 at 16:34
  • 6
    Perfect input can be given via emulation of a phone, special programs or, simply, the desktop version of the game with the mouse, as agent86 has done. – Ben Brocka Dec 29 '11 at 17:47
  • regarding "input", most fingers are bigger than 1 pixel wide. I suppose the OS converts your finger big input to a xy-coordinate that may even be float (mean value of the pixels your fingertip covers) – tnavidi Nov 02 '23 at 13:02

5 Answers5

480

The algorithm is deterministic, but it's arguable that the overall result of launching a bird is effectively non-deterministic because it relies on (extraordinarily sensitive) user input.

To test the algorithm and the effect user input has on it, I used the following procedure:

  • Load the Google Chrome version of Angry Birds
  • Load level 1-1
  • Pull the mouse back to a specific X-Y coordinate. (This was past the point of "full draw" for the bird.)
  • Release the bird, and wait for the game to reach a steady state.

To measure my X-Y coordinate, I opened a background Chrome window, and navigated it to this page. I aligned the two windows so that I could see the X and Y positions of the mouse while still able to cause something to happen when I released the bird. I aligned my mouse cursor with the lower left hand corner of the box around these two numbers, and then released. I noted the position of my mouse cursor then (as the display only updates when the mouse is not released and the cursor is over that window) and then noted the resulting score in Angry Birds. If you're having issues with exact mouse positioning, you might try an accessibility option offered by your OS, for instance, Mouse Keys on Windows.

I got the same score, so long as my cursor was in the exact same spot as it was on previous iterations.

Prior to coming up with an enhanced test rig that allowed me to measure my cursor's position to the pixel, I ran this experiment about 10 times, using a reference point in the background image of the game. I got scores by firing the first bird that varied between 8,000 and 11,000 points. Using the enhanced testing strategy, if I was off by a single pixel, I could expect score differences of anywhere between 150 and 500 points.

I will note that the cursor was beyond the edge of the game area, outside the browser window, far beyond the maximum distance the bird can be drawn back, and I still noticed differences when moving my cursor even a single pixel.

Further, I took screencaps for an extreme case where my cursor was on a different monitor than the game window, and ran several iterations where I kept my cursor in the same location, or moved it slightly. By my calculations (based on measuring distance from screencaps) the game was able to create a different result (score 32960 vs 31520) based on a one pixel difference in height (544 vs 545 pixels) over a distance of approximately 1,284 pixels of width. This works out to be an angular difference of 0.03 degrees.

I'd say that for any practical purposes, you can expect to employ the same general strategy on the same level repeatedly and expect wildly varying results. The level of sensitivity in the controls is so extreme that there's no practical way to get it to do the same thing twice. This is exacerbated by the fact that if you're playing on a touchscreen, it would be extraordinarily difficult to reproduce the same movements down to the individual pixel.

a cat
  • 25,880
  • 31
  • 154
  • 189
agent86
  • 118,734
  • 85
  • 395
  • 576
  • 6
    If you want to try this experiment, you can install my userscript. It adds boxes that track the exact cursor position to the Angry Birds page. A preview of the script is available here. – Royal Flush Dec 29 '11 at 22:44
  • Dear agent86, you wrote "I got scores by firing the first bird that varied between 8,000 and 11,000 points." Is it possible to run the test with the current version and see if the scores are systenatically higher? – Gil Kalai Dec 19 '12 at 23:21
  • 1
    @GilKalai You can't compare different levels like that, it entirely depends on where the test was aimed. – Matthew Read Jan 04 '13 at 17:57
206

Angry Birds uses Box2D library for physics.

Is Box2D deterministic? For the same input, and same binary, Box2D will reproduce any simulation. Box2D does not use any random numbers nor base any computation on random events (such as timers, etc).

However, people often want more stringent determinism. People often want to know if Box2D can produce identical results on different binaries and on different platforms. The answer is no. The reason for this answer has to do with how floating point math is implemented in many compilers and processors. I recommend reading this article if you are curious: http://www.yosefk.com/blog/consistency-how-to-defeat-the-purpose-of-ieee-floating-point.html

http://code.google.com/p/box2d/wiki/FAQ#Determinism

Pubby
  • 4,196
  • 3
  • 22
  • 30
  • 7
    This is great (thanks for actually checking with the source); for the sake of completeness, do you have a reference that Angry Birds uses Box2D? And where did you pull this quote from? –  Dec 29 '11 at 20:56
  • 6
    @MarkTrapp http://www.geek.com/articles/mobile/box2d-creator-asks-rovio-for-angry-birds-credit-at-gdc-2011032/ and http://en.wikipedia.org/wiki/Box2D – Royal Flush Dec 29 '11 at 21:06
  • 1
    And I bet physics FPS varies as well, due to numerous factors (not enough CPU, overheating, page faults, etc), thus affecting the 'accuracy' of the simulation. :) – Mateen Ulhaq Dec 30 '11 at 01:35
  • The second statement's kind of ambiguous; what I assume is that if you ran the same simulation on multiple architectures you might not get exactly the same result, but per-platform each simulation will run the same way each time. – agent86 Dec 30 '11 at 18:10
  • @muntoo that is not necessarily true, since developers can make the game run the same number of simulation steps even at lower frame rates. As for actual processor errors that possibility is usually ignored in games since it's so rare. If your interested in the subject of deterministic simulations you can read more in gamesfromwithin blog or just google it. :) – João Portela Dec 30 '11 at 18:33
  • 2
    @agent86 I would change your wording to "[...]but per-platform and per-Box2D release each simulation will run the same way each time." (that "same binary" part in the first paragraph seems to indicate that). – João Portela Dec 30 '11 at 18:38
  • @JoãoPortela, good point. I was assuming "release" was not a variable allowed to change in this case. – agent86 Dec 30 '11 at 19:36
  • Don't understand the first paragraph of the qoute. So is Box2D deterministic or not? – Jake May 13 '12 at 05:17
  • 3
    @Jake Yes, it is deterministic but with the limitations mentioned in the second paragraph. – Pubby May 13 '12 at 05:25
  • Still confused. Why does it say "Box2D will reproduce ANY simulation" rather than "SAME" simulation? I am writing a server client lockstep sim and running 2 of the same client.exe gives same simulation only if there are no collisions. – Jake May 13 '12 at 05:47
  • @Jake I'm not sure, perhaps try Stack Overflow. – Pubby May 13 '12 at 05:53
38

Some levels are subject to random explosions shortly after the level starts, and some bricks can fall on their own before you've ever thrown a bird. These events occur rarely but, by the time you've three-starred every level in every game (as I have!), you'll probably see it a few times.

I would expect that this occurs because of timing issues, possibly related to threading. I'm quite sure that if you loaded every level a dozen times and waited thirty seconds you'd end up with a non-zero score at least once. In light of Pubby's answer, I can only assume that the Angry Birds app does not always provide the same input to the Box2D functions at the start of a level.

Matthew Read
  • 19,267
  • 11
  • 89
  • 149
14

I played on Facebook using a macro recorder. I started the recorder, went to angry birds window, then zoomed out, and played the first two birds. I then stopped the recorder. EVERY time, the mouse went to the exact pixels and released with the exact same power etc. It had to, because the mouse movement recorded does the same thing every time, pixel for pixel. Each and every time I got a different score, and not every time the same number of pigs killed etc. This game IS inconsistent

-5

I did 10 tests, pulling to the same point every time (also Chrome Angry Birds, level 1, as in agent86's tests).

Red Crosshair of test spot

I never received the same score twice, despite being careful to pull to the exact same spot, and doing it about as soon after start of level. I believe Angry Birds is very much not deterministic.

This is rather easy to explain: it was designed to work on small touch screens. If it was deterministic, users could easily repeat moves due to the limited precision of the input device. This could be bad, in that their device could literally not have the precision necessary to aim at the exact angle and power they want. By having it slightly jiggle the results, and owing to the input of a 'finger', users would not notice the lack of precision, and they would also not be frustrated by never being able to make a desired shot.

Myrddin Emrys
  • 1,227
  • 1
  • 11
  • 19
  • agent86's additional test indicates I could well be wrong. I will re-test when I get home, because I was quite certain that I had been placing my cursor with precision. – Myrddin Emrys Dec 29 '11 at 17:12
  • 21
    I think you're wrong. The touch screen actually makes it extremely hard to get the same input each time. For example, the iphone has 614400 pixels. Each of those would produce a differing output. – Daenyth Dec 29 '11 at 18:16
  • 1
    @Daenyth: are you sure that the input resolution precision is 1 pixel? It may be, but what I'm saying is that it is not necessarily. – Andreas Bonini Dec 29 '11 at 20:13
  • 2
    @Daenyth not necessarily each of them. Once you're beyond the maximum distance, there may be a set of pixels at the same angle from the center that could reasonably be assumed to cause identical – Random832 Dec 29 '11 at 22:02
  • 4
    @AndreasBonini, Further testing seems to indicate that it's so precise that a single pixel can cause differences in the results, even over crazy distances - see the latest edits to my answer. – agent86 Dec 31 '11 at 01:29
  • 8
    This is an example of chaos (tiny changes in input leading to huge changed in outcome) rather than non determinism – Richard Tingle Jan 27 '14 at 13:38