Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. namespace Flappy
  2. {
  3. class BestController: MaximaxController
  4. {
  5. private uint _pathBinary = 3;
  6.  
  7. public override bool ShouldJump(Bird bird, Drawer drawer, long X, Deque<Pipe> pipes)
  8. {
  9. _pathBinary >>= 1;
  10.  
  11. if (_pathBinary > 1) return (_pathBinary & 1) == 0;
  12.  
  13. Pipe firstPipe = pipes.PeekFront();
  14. int maxJump = (int) (drawer.Height * 0.08 + 0.5);
  15. int maxDrop = (int) (drawer.Height * 0.12 + 0.5);
  16. int drawerHeight = drawer.Height - 1;
  17.  
  18. Test((int) X , bird.Y, firstPipe, bird.VerticalSpeed, (int) (firstPipe.X - X),
  19. firstPipe.FreeHeight + firstPipe.TopPipeHeight, true);
  20.  
  21. return (_pathBinary & 1) == 0;
  22.  
  23. bool Test(int x, int y, Pipe p, double vel, int xDiff, int yPipe, bool addPath, int actualPrediction = 1)
  24. {
  25. if (x > p.X + 3)
  26. {
  27. if (actualPrediction++ == 3) return true;
  28.  
  29. pipes.PopFront();
  30. Pipe pp = pipes.PeekFront();
  31.  
  32. if (Test(x, y, pp, vel, (int) (pp.X - x), pp.TopPipeHeight + pp.FreeHeight, false, actualPrediction)) return true;
  33.  
  34. pipes.PushFront(p);
  35. return false;
  36. }
  37.  
  38. if (xDiff > 0 && (y - maxJump * xDiff >= yPipe || y + maxDrop * xDiff < p.TopPipeHeight)) return false;
  39.  
  40. if (xDiff <= 0 && xDiff >= -2 && (y < p.TopPipeHeight || y >= p.TopPipeHeight + p.FreeHeight)) return false;
  41.  
  42. if (vel < 0.11) vel += 0.04;
  43. int yDown = (int) (y + vel * drawer.Height);
  44.  
  45. if (yDown > drawerHeight)
  46. {
  47. vel = 0;
  48. yDown = drawerHeight;
  49. }
  50.  
  51. if (Test(x + 1, yDown, p, vel, xDiff - 1, yPipe, addPath, actualPrediction))
  52. {
  53. if (addPath) _pathBinary = (_pathBinary << 1) + 1;
  54. return true;
  55. }
  56.  
  57. vel = -0.08;
  58. y = (int) (y + vel * drawer.Height);
  59.  
  60. if (y < 0)
  61. {
  62. vel = 0;
  63. y = 0;
  64. }
  65.  
  66. if (!Test(x + 1, y, p, vel, xDiff - 1, yPipe, addPath, actualPrediction)) return false;
  67.  
  68. if (addPath) _pathBinary <<= 1;
  69. return true;
  70. }
  71. }
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement