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])); } }
static void Main(string[] args) { Console.Write("Combatting both algorithms:\n\n..."); // initiallize pool string sendtext = "100" + Environment.NewLine + "-80 0 0" + Environment.NewLine + "80 0 0" + Environment.NewLine + "0" + Environment.NewLine; frogs[0] = new Frog(-80, 0, 0); frogs[1] = new Frog(80, 0, 0); bullets[0] = new List<Bullet>(); bullets[1] = new List<Bullet>(); Frog.PoolRadus = 100; // first algorithm string algo1file = @"..\..\algo1.exe"; string algo2file = @"..\..\algo2.exe"; string jsfile = @"..\..\data.js"; string htmlfile = @"..\..\Presentation.html"; // main loop of both algos while (algoAlive[0] && algoAlive[1]) { string getResponse = QueryAlgo(algo1file, sendtext); SaveMove(getResponse); sendtext = GetInput(); getResponse = QueryAlgo(algo2file, sendtext); SaveMove(getResponse); EvaluatePool(); TakeSnapshot(); Console.Write("."); sendtext = GetInput(); } SaveJSON(jsfile); Console.WriteLine("\nDone!\n\nStarting default browser for presentation..."); Process browser = new Process(); browser.StartInfo.FileName = htmlfile; browser.Start(); // browser.WaitForExit(); // browser.Close(); }
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); }
public void ShootAtWill(Frog enemy) { // predict enemy move using the same algorithm // shoots at enemy with a chance of 1/10 if (generator.Next(10) == 5) { ShootAtEnemy(enemy); } // calculate }
public void ShootAtEnemy(Frog enemy) { // take a shot to the enemy's center this.ShootTargetPos = new Position(enemy.Pos.X, enemy.Pos.Y); this.IsShooting = true; }
public bool RunFromEnemy(Frog enemy) { // try to keep distance to enemy as much as possible // move randomly to the left or to the right of the vector between frogs // get enemy direction Position enemyVector = Calc.GetVector(this.Pos, enemy.Pos); // hardcoded decision table with random selector Position[] moves = new Position[12]; moves[0] = Calc.GetVector(this.Pos, new Position(0, 0)); // run to center moves[1] = Calc.RotateVectorClockwise(enemyVector); // run clockwise to the enemy position moves[2] = Calc.RotateVectorCounterClockwise(enemyVector); // run counter-clockwise to the enemy position moves[3] = moves[0]; // run to center moves[4] = moves[0]; // run to center moves[5] = moves[1]; // run counter-clockwise to the enemy position moves[6] = moves[1]; // run counter-clockwise to the enemy position moves[7] = moves[0]; // run to center moves[8] = moves[2]; // run counter-clockwise to the enemy position moves[9] = moves[1]; // run counter-clockwise to the enemy position moves[10] = enemyVector; // run forward to the enemy moves[11] = new Position(0,0); // stay at current position double distanceToEnemy = Calc.GetDistance(this.Pos, enemy.Pos); double scaleFactor = generator.NextDouble() * (Frog.MaxJumpDistance - Frog.MinJumpDistance) + Frog.MinJumpDistance; // check if frogs are in range (in 2 moves bullet can reach the frog, but we can run away in these 2 moves) bool closeToEnemy = (distanceToEnemy < 2 * Bullet.BulletSpeed); // and if yes - exclude last two choices - stay and move forward int chooseMove = generator.Next(closeToEnemy ? moves.Length - 2 : moves.Length); this.NextMovePos = this.Pos.Add(moves[chooseMove].Scale(scaleFactor)); if (closeToEnemy) { ShootAtEnemy(enemy); } return (chooseMove != 3); // if stays then no move has been selected }