static void GetInput() { // first line - current pool radius string[] radiusLine = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); double radius = double.Parse(radiusLine[0]); Frog.PoolRadus = radius; // second line - my frog: <x position> <y position> <time to reload gun if shooted previously > string[] frogLine = Console.ReadLine().Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries); MyFrog = new Frog(double.Parse(frogLine[0]), double.Parse(frogLine[1]), int.Parse(frogLine[2])); // third line - enemy frog: <x position> <y position> <time to reload gun if shooted previously > frogLine = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); EnemyFrog = new Frog(double.Parse(frogLine[0]), double.Parse(frogLine[1]), int.Parse(frogLine[2])); // fourth line - number of bullets shooted string[] bulletsCountLine = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); int bulletsCount = int.Parse(bulletsCountLine[0]); Bullets = new Bullet[bulletsCount]; // next bullets count line - bullets coordinates and target position for the next move for (int i = 0; i < bulletsCount; i++) { string[] bulletsline = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); Bullets[i] = new Bullet(double.Parse(bulletsline[0]), double.Parse(bulletsline[1]), double.Parse(bulletsline[2]), double.Parse(bulletsline[3])); } }
public bool RunFromBullets(Bullet[] bullets) { foreach (var bullet in bullets) { // get bullet distance to the front of the frog double distanceToBullet = Calc.GetDistance(this.Pos, bullet.Pos) - Frog.FrogRadius; // check if my frog is in range (in 2 moves bullet can reach the frog, but we can run away in these 2 moves) if (distanceToBullet <= 2 * Bullet.BulletSpeed) { // get bullet direction Position bulletVector = Calc.GetVector(bullet.Pos, bullet.Target); // detect possible collision - check the bullet movement vector scaled by distance + frog diameter for (double i = 0; i <= 2 * Frog.FrogRadius; i += Bullet.BulletLandingDistance) { Position bulletPos = bullet.Pos.Add(bulletVector.Scale(distanceToBullet + i)); if (Calc.HasImpact(this.Pos, Frog.FrogRadius, bulletPos)) { // we have found a collision - run away immediately // go to opposite side, i.e. rotate bullet vector to 90 degrees clockwise or counter-clockwise and jump //TODO: select appropriate vector //if (true) //{ this.NextMovePos = this.Pos.Add(Calc.RotateVectorCounterClockwise(bulletVector).Scale(Frog.MaxJumpDistance)); //} //else //{ // this.NextMovePos = this.Pos.Add(Calc.RotateVectorClockwise(bulletVector).Scale(Frog.MaxJumpDistance)); //} return true; // return with movement indication } } } } return false; // there is no dangerous bullets }
public void TakeDecision(Frog enemy, Bullet[] bullets) { bool frogMoved = false; // Take care of the incoiming bullets if (!frogMoved) { frogMoved = this.RunFromBullets(bullets); } // Watch out for the collapsing pool if (!frogMoved) { frogMoved = this.RunFromPoolBorder(); } // Watch out of the enemy frog if (!frogMoved) { frogMoved = this.RunFromEnemy(enemy); } // Aggresive mode - predict enemy move and shoot this.ShootAtWill(enemy); }