private static void Main(string[] args) { string[] inputs; _laps = int.Parse(Console.ReadLine()); _checkpointCount = int.Parse(Console.ReadLine()); checkpoints = new Checkpoint[_checkpointCount]; for (int i = 0; i < _checkpointCount; i++) { inputs = Console.ReadLine().Split(' '); int checkpointX = int.Parse(inputs[0]); int checkpointY = int.Parse(inputs[1]); checkpoints[i] = new Checkpoint(i, checkpointX, checkpointY); } Pods[0].Partner = Pods[1]; Pods[1].Partner = Pods[0]; Pods[2].Partner = Pods[3]; Pods[3].Partner = Pods[2]; var meReflex = new ReflexBot(); var oppReflex = new ReflexBot(2); var opp = new SearchBot(2); opp.Opponents.Add(meReflex); var me = new SearchBot(); me.Opponents.Add(opp); me.Opponents.Add(oppReflex); while (true) { round++; for (int i = 0; i < 4; i++) { var s = Console.ReadLine(); inputs = s.Split(' '); int x = int.Parse(inputs[0]); // x position of your pod int y = int.Parse(inputs[1]); // y position of your pod int vx = int.Parse(inputs[2]); // x speed of your pod int vy = int.Parse(inputs[3]); // y speed of your pod int angle = int.Parse(inputs[4]); // angle of your pod int nextCheckPointId = int.Parse(inputs[5]); // next check point id of your pod if (round == 0 && i > 1 && angle > -1) { is_p2 = true; } if (nextCheckPointId == -1) { nextCheckPointId = 1; } Pods[i].Update(x, y, vx, vy, angle, nextCheckPointId); } //Console.Error.WriteLine("DTC: {0} {1}", Pods[0].Distance(checkpoints[Pods[2].CheckpointId]), Pods[2].CheckpointId); _stopwatch = Stopwatch.StartNew(); int timeLimit = round == 0 ? 980 : 142; opp.Solve(timeLimit * 0.15); me.Solve(timeLimit, round > 0); Console.Error.WriteLine("Moving towards {0} at angle {1} : {2}\n{3}\nRunner: {4}", me.Runner().CheckpointId, me.Runner().Angle, me.sol.Angle[0], me.sol.EndPoint(me.sol.Thrust[0], me.sol.Angle[0], Pods[0]), me.Runner().Id); if (round > 0) { Console.Error.WriteLine("Avg iterations {0}; avg sims {1}", _solutionsTried / round, _solutionsTried * Chromosones / round); } me.sol.Output(me.sol.Thrust[0], me.sol.Angle[0], Pods[0]); me.sol.Output(me.sol.Thrust[Chromosones], me.sol.Angle[Chromosones], Pods[1]); } }
private static void Main(string[] args) { string[] inputs; _myTeamId = int.Parse(Console.ReadLine()); // if 0 you need to score on the right of the map, if 1 you need to score on the left var oppReflex = new ReflexBot(_myTeamId == 0 ? 3 : 1); var meReflex = new ReflexBot(_myTeamId == 0 ? 1 : 3); var oppSearch = new ReflexBot(oppReflex.Id - 1); var meSearch = new SearchBot(meReflex.Id - 1); meSearch.Opponents = new List <Bot>() { oppReflex, meReflex, oppSearch }; // game loop while (true) { round++; _snaffles.Clear(); inputs = Console.ReadLine().Split(' '); int myScore = int.Parse(inputs[0]); int myMagic = int.Parse(inputs[1]); inputs = Console.ReadLine().Split(' '); int opponentScore = int.Parse(inputs[0]); int opponentMagic = int.Parse(inputs[1]); int entities = int.Parse(Console.ReadLine()); // number of entities still in game int wizCount = 0; int oppWizCount = 0; for (int i = 0; i < entities; i++) { inputs = Console.ReadLine().Split(' '); int entityId = int.Parse(inputs[0]); // entity identifier EntityType entityType = (EntityType)Enum.Parse(typeof(EntityType), inputs[1], true); // "WIZARD", "OPPONENT_WIZARD" or "SNAFFLE" or "BLUDGER" int x = int.Parse(inputs[2]); // position int y = int.Parse(inputs[3]); // position int vx = int.Parse(inputs[4]); // velocity int vy = int.Parse(inputs[5]); // velocity int state = int.Parse(inputs[6]); // 1 if the wizard is holding a Snaffle, 0 otherwise switch (entityType) { case EntityType.Wizard: case EntityType.Opponent_Wizard: var wiz = _wizards.FirstOrDefault(w => w.Id == entityId); if (wiz == null) { wiz = new Wizard(entityId, x, y, vx, vy, Convert.ToBoolean(state)); wiz.TeamId = entityType == EntityType.Wizard ? _myTeamId : Math.Abs(_myTeamId - 1); _wizards.Add(wiz); if (wiz.TeamId == _myTeamId) { _myWiz[wizCount++] = wiz; if (meSearch.Wizard == null) { meSearch.Wizard = wiz; } else { meReflex.Wizard = wiz; } } else { _oppWiz[oppWizCount++] = wiz; if (oppSearch.Wizard == null) { oppSearch.Wizard = wiz; } else { oppReflex.Wizard = wiz; } } } else { wiz.X = x; wiz.Y = y; wiz.Velocity.X = vx; wiz.Velocity.Y = vy; wiz.Carrying = Convert.ToBoolean(state); } wiz.MP = myMagic; if (wiz.ActiveSpell != null) { wiz.ActiveSpell.Duration--; } wiz.Save(); _entities[entityId] = wiz; break; case EntityType.Snaffle: var snaffle = new Snaffle(entityId, x, y, vx, vy, Convert.ToBoolean(state)); _snaffles.Add(snaffle); snaffle.Save(); _entities[entityId] = snaffle; break; case EntityType.Bludger: var bludger = _bludgers.FirstOrDefault(w => w.Id == entityId); if (bludger == null) { bludger = new Bludger(entityId, x, y, vx, vy); _bludgers.Add(bludger); } else { bludger.X = x; bludger.Y = y; bludger.Velocity.X = vx; bludger.Velocity.Y = vy; } bludger.LastTarget = _wizards.FirstOrDefault(w => w.Id == state); bludger.Save(); _entities[entityId] = bludger; break; } } for (int i = 0; i < 4; i++) { _wizards[i].Snaffle = _snaffles.FirstOrDefault(s => s.Distance(_wizards[i]) < _wizards[i].Radius); _wizards[i].Save(); } _stopwatch = Stopwatch.StartNew(); int time = round == 0 ? 980 : 92; meSearch.Solve(time, round > 0); Solution.Output(meSearch.Solution.Moves[0], _wizards.First(w => w.Id == meSearch.Id)); Console.Error.WriteLine("Score {0}\nNew Pos: {1}", meSearch.Solution.Score, _myWiz[0] as Point); //meSearch.Solution.Output(meSearch.Solution.Moves[Chromosones], _wizards.First(w => w.Id == meSearch.Id + 1)); Console.WriteLine("MOVE 0 0 0 " + _myWiz[0]); if (round > 0) { Console.Error.WriteLine(string.Format("Sims Per Round: {0}, Avg: {1}", _simulations / round, _simulations * Chromosones / round)); } continue; foreach (var wizard in _wizards.Where(w => w.TeamId == _myTeamId)) { // Write an action using Console.WriteLine() To debug: // Console.Error.WriteLine("Debug messages..."); // Edit this line to indicate the action for each wizard (0 ≤ thrust ≤ 150, 0 ≤ // power ≤ 500) i.e.: "MOVE x y thrust" or "THROW x y power" if (wizard.Carrying) { var x = _myTeamId == 0 ? Width : 0 - wizard.Velocity.X; var y = GoalY - wizard.Velocity.Y; Console.WriteLine(string.Format("THROW {0} {1} {2}", x, y, MaxPower)); } else { //check bludger if (myMagic >= Flipendo.Cost) { int myGoal = _myTeamId == 0 ? 0 : Width; bool cast = false; foreach (var s in _snaffles.OrderByDescending(s => s.Distance(wizard))) { var spell = new Flipendo() { Source = wizard, Target = s }; Console.Error.WriteLine("Old {0}", wizard); spell.GetPower(); // s.Thrust((int)spell.Power, new Point(myGoal, GoalY)); s.Move(1.0); Console.Error.WriteLine("New {0}", wizard); if (s.X > Width || s.X < 0) { wizard.ActiveSpell.Cast(s); myMagic -= Flipendo.Cost; cast = true; break; } s.Load(); //if ((_myTeamId == 0 && s.X < 3000 && wizard.X > s.X) || (_myTeamId == 1 && s.X > Width - 3000 && wizard.X < s.X)) //{ // wizard.ActiveSpell = new Flipendo() // { // Target = s // }; // wizard.ActiveSpell.Cast(s); // cast = true; // myMagic -= Flipendo.Cost; // break; //} } if (cast) { continue; } } /* * if (myMagic > Obliviate.Cost) * { * var minBludgerDistance = 10000.0; * Bludger minBludger = null; * for (int i = 0; i < 2; i++) * { * var d = _bludgers[i].Distance(wizard); * if (d < minBludgerDistance) * { * minBludgerDistance = d; * minBludger = _bludgers[i]; * } * } * if (minBludgerDistance < 1000 && minBludger.LastTarget != wizard) * { * wizard.ActiveSpell = new Obliviate(); * wizard.ActiveSpell.Cast(minBludger); * Console.Error.WriteLine("Oblivia D: {0}", minBludgerDistance); * myMagic -= Obliviate.Cost; * continue; * } * }*/ if (myMagic >= Accio.Cost) { bool cast = false; foreach (var s in _snaffles) { if ((_myTeamId == 0 && s.X < 2000) || (_myTeamId == 1 && s.X > Width - 2000)) { wizard.ActiveSpell = new Accio(); wizard.ActiveSpell.Cast(s); cast = true; myMagic -= Accio.Cost; break; } } if (cast) { continue; } }/* * if (myMagic >= Petrificus.Cost) * { * bool cast = false; * foreach (var enemy in _wizards.Where(w => w.TeamId != _myTeamId && !_wizards.Any(w1 => w1.ActiveSpell?.Target == w))) * { * if ((_myTeamId == 0 && enemy.X < 3000) || (_myTeamId == 1 && enemy.X > Width - 3000)) * { * wizard.ActiveSpell = new Petrificus(); * wizard.ActiveSpell.Target = enemy; * wizard.ActiveSpell.Cast(enemy); * myMagic -= Petrificus.Cost; * cast = true; * break; * } * } * if (cast) continue; * } */ var snaff = _snaffles.OrderBy(s => s.Distance2(wizard)).FirstOrDefault(s => !s.BeingCarried); if (snaff == null) { snaff = _snaffles.FirstOrDefault(); } snaff.BeingCarried = true; Console.WriteLine(string.Format("MOVE {0} {1} {2}", snaff.X, snaff.Y, MaxThrust)); } } } }