Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Flappy
- {
- class BestController: MaximaxController
- {
- private uint _pathBinary = 3;
- public override bool ShouldJump(Bird bird, Drawer drawer, long X, Deque<Pipe> pipes)
- {
- _pathBinary >>= 1;
- if (_pathBinary > 1) return (_pathBinary & 1) == 0;
- Pipe firstPipe = pipes.PeekFront();
- int maxJump = (int) (drawer.Height * 0.08 + 0.5);
- int maxDrop = (int) (drawer.Height * 0.12 + 0.5);
- int drawerHeight = drawer.Height - 1;
- Test((int) X , bird.Y, firstPipe, bird.VerticalSpeed, (int) (firstPipe.X - X),
- firstPipe.FreeHeight + firstPipe.TopPipeHeight, true);
- return (_pathBinary & 1) == 0;
- bool Test(int x, int y, Pipe p, double vel, int xDiff, int yPipe, bool addPath, int actualPrediction = 1)
- {
- if (x > p.X + 3)
- {
- if (actualPrediction++ == 3) return true;
- pipes.PopFront();
- Pipe pp = pipes.PeekFront();
- if (Test(x, y, pp, vel, (int) (pp.X - x), pp.TopPipeHeight + pp.FreeHeight, false, actualPrediction)) return true;
- pipes.PushFront(p);
- return false;
- }
- if (xDiff > 0 && (y - maxJump * xDiff >= yPipe || y + maxDrop * xDiff < p.TopPipeHeight)) return false;
- if (xDiff <= 0 && xDiff >= -2 && (y < p.TopPipeHeight || y >= p.TopPipeHeight + p.FreeHeight)) return false;
- if (vel < 0.11) vel += 0.04;
- int yDown = (int) (y + vel * drawer.Height);
- if (yDown > drawerHeight)
- {
- vel = 0;
- yDown = drawerHeight;
- }
- if (Test(x + 1, yDown, p, vel, xDiff - 1, yPipe, addPath, actualPrediction))
- {
- if (addPath) _pathBinary = (_pathBinary << 1) + 1;
- return true;
- }
- vel = -0.08;
- y = (int) (y + vel * drawer.Height);
- if (y < 0)
- {
- vel = 0;
- y = 0;
- }
- if (!Test(x + 1, y, p, vel, xDiff - 1, yPipe, addPath, actualPrediction)) return false;
- if (addPath) _pathBinary <<= 1;
- return true;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement