void SpawnTanker(Player player) { TankerSpawn spawn = player.tankers.Dequeue(); double angle = (player.index + spawn.angle) * Math.PI * 2.0 / ((double)playerCount); double cos = Math.Cos(angle); double sin = Math.Sin(angle); Tanker tanker = new Tanker(spawn.size, player); double distance = TANKER_SPAWN_RADIUS + tanker.radius; bool safe = false; while (!safe) { tanker.Move(cos * distance, sin * distance); safe = units.TrueForAll(u => tanker.Distance(u) > tanker.radius + u.radius); distance += TANKER_MIN_RADIUS; } tanker.thrust(WATERTOWN, TANKER_START_THRUST); units.Add(tanker); tankers.Add(tanker); }
// Play a collision void playCollision(Collision collision) { if (collision.b == null) { // Bounce with border addToFrame(collision.a); collision.a.bounce(); } else { Tanker dead = collision.Dead(); if (dead != null) { // A destroyer kill a tanker addDeadToFrame(dead); deadTankers.Add(dead); tankers.Remove(dead); units.Remove(dead); Wreck wreck = dead.die(); // If a tanker is too far away, there's no wreck if (wreck != null) { wrecks.Add(wreck); addToFrame(wreck); } } else { // Bounce between two units addToFrame(collision.a); addToFrame(collision.b); collision.a.bounce(collision.b); } } }
private static void Main(string[] args) { // game loop while (true) { _units.Clear(); _myReaper = null; _myDestroyer = null; _myDoof = null; int myScore = int.Parse(Console.ReadLine()); int enemyScore1 = int.Parse(Console.ReadLine()); int enemyScore2 = int.Parse(Console.ReadLine()); int myRage = int.Parse(Console.ReadLine()); int enemyRage1 = int.Parse(Console.ReadLine()); int enemyRage2 = int.Parse(Console.ReadLine()); int unitCount = int.Parse(Console.ReadLine()); for (int i = 0; i < unitCount; i++) { string[] inputs = Console.ReadLine().Split(' '); int unitId = int.Parse(inputs[0]); int unitType = int.Parse(inputs[1]); int player = int.Parse(inputs[2]); float mass = float.Parse(inputs[3]); int radius = int.Parse(inputs[4]); int x = int.Parse(inputs[5]); int y = int.Parse(inputs[6]); int vx = int.Parse(inputs[7]); int vy = int.Parse(inputs[8]); int extra = int.Parse(inputs[9]); int extra2 = int.Parse(inputs[10]); var unit = _units.FirstOrDefault(u => u.Id == unitId); if (unit == null) { switch (unitType) { case (int)UnitType.Wreck: unit = new Wreck { Water = extra }; break; case (int)UnitType.Tanker: unit = new Tanker { Water = extra2 }; break; default: unit = new Unit(); break; } unit.Id = unitId; unit.UnitType = (UnitType)unitType; unit.Radius = radius; unit.Mass = mass; unit.Player = player; _units.Add(unit); if (_myReaper == null && player == 0 && unitType == (int)UnitType.Reaper) { _myReaper = unit; } if (_myDestroyer == null && player == 0 && unitType == (int)UnitType.Destroyer) { _myDestroyer = unit; } if (_myDoof == null && player == 0 && unitType == (int)UnitType.Doof) { _myDoof = unit; } } unit.Velocity = new Point(vx, vy); unit.Position = new Point(x, y); if (unit is Wreck) { ((Wreck)unit).Water = extra; } if (unit is Tanker) { ((Tanker)unit).Water = extra2; } } int thrust = 300; string message = "."; var wreck = _units.OfType <Wreck>() //.OrderByDescending(w => w.Water) .OrderBy(w => w.Position.Distance2(_myReaper.Position) / w.Water) .FirstOrDefault(); var tanker = _units.OfType <Tanker>() .OrderByDescending(t => t.Position.Distance2(_myDestroyer.Position) / t.Water) .FirstOrDefault(); bool foundWreck = false; if (wreck != null) { Console.WriteLine($"{wreck.Position.X - _myReaper.Velocity.X} {wreck.Position.Y - _myReaper.Velocity.Y} {thrust} {message}"); foundWreck = true; } string tankerMessage = "SMASH"; var oilPools = _units.Where(o => o.UnitType == UnitType.Oil); var enemyTarget = _units.FirstOrDefault(u => u.Player == (enemyScore1 > enemyScore2 ? 1 : 2)); var enemyWreck = _units.OfType <Wreck>() .FirstOrDefault(w => w.Position.Distance(enemyTarget.Position) < w.Radius); if (enemyWreck != null && oilPools.Any(o => o.Position.Distance(enemyWreck.Position) < o.Radius)) { enemyWreck = null; } //no wreck, go after same tanker as destroyer double v = 1d; if (!foundWreck) { Console.WriteLine($"{enemyTarget.Position.X - _myReaper.Velocity.X * v} {enemyTarget.Position.Y - _myReaper.Velocity.Y * v} {thrust} troll"); } if (myRage > 250 && enemyTarget.Position.Distance(_myDoof.Position) < 1000) { Console.WriteLine($"SKILL {enemyTarget.Position.X + enemyTarget.Velocity.X} {enemyTarget.Position.Y + enemyTarget.Velocity.Y} FIRE"); } else { Console.WriteLine($"{tanker.Position.X - _myDestroyer.Velocity.X} {tanker.Position.Y - _myDestroyer.Velocity.Y} 300 {tankerMessage}"); } if (enemyWreck == null || enemyWreck.Position.Distance(_myDoof.Position) > 2000) { Console.WriteLine($"{enemyTarget.Position.X - _myDoof.Velocity.X} {enemyTarget.Position.Y - _myDoof.Velocity.Y} 300"); } else { Console.WriteLine($"SKILL {enemyTarget.Position.X} {enemyTarget.Position.Y} OIL"); } } }