bool FindPlayer() { if (!player) { player = FindObjectOfType <Player>(); if (player) { slowTime = player.GetComponent <SlowTime>(); cannonball = player.GetComponent <Cannonball>(); fission = player.GetComponent <Fission>(); } } return(player); }
private ICommand MoveBot(Bot bot, List <Bot> newBots, ref int numDeadBots, List <TCoord> filledCoords) { if (bot.NextCommand < (bot.MoveCommands?.Count ?? 0)) { switch (bot.MoveCommands[bot.NextCommand]) { case StraightMove m: TraceMove(bot.Coord, m, coord => interferedCells.Add(coord)); bot.Coord.Apply(m.Diff); break; case LMove m: throw new NotImplementedException(); case Wait w: break; default: throw new Exception($"WTF, unexpected command: {bot.GetType().FullName}"); } ++bot.NextCommand; if (bot.MoveTarget != null && bot.NextCommand == bot.MoveCommands.Count) { bot.MoveTarget = null; } return(bot.MoveCommands[bot.NextCommand - 1]); } if (bot.FissionTarget != null) { interferedCells.Add(bot.FissionTarget.Value); var m = bot.Seeds.Count / 2; newBots.Add( new Bot() { Id = bot.Seeds[0], Coord = bot.FissionTarget.Value, Seeds = bot.Seeds.Skip(1).Take(m).ToList(), FissionTimeout = 3, }); bot.Seeds.RemoveRange(0, m + 1); var ret = new Fission { Diff = bot.FissionTarget.Value.Diff(bot.Coord), M = m, }; bot.FissionTarget = null; return(ret); } if (bot.FusionPTarget != null) { interferedCells.Add(bot.FusionPTarget.Value); if (botPositions.TryGetValue(bot.FusionPTarget.Value, out var another)) { var ret = new FusionP { Diff = bot.FusionPTarget.Value.Diff(bot.Coord) }; bot.Seeds.Add(another.Id); bot.Seeds.AddRange(another.Seeds); bot.Seeds.Sort(); bot.ActedFusionPTarget = bot.FusionPTarget; bot.FusionPTarget = null; return(ret); } throw new InvalidOperationException("Trying to run fusion on not a bot cell!"); } else if (bot.FusionSTarget != null) { var ret = new FusionS { Diff = bot.FusionSTarget.Value.Diff(bot.Coord) }; interferedCells.Add(bot.FusionSTarget.Value); ++numDeadBots; bot.MustDie = true; bot.ActedFusionSTarget = bot.FusionSTarget; bot.FusionSTarget = null; return(ret); } if (bot.FillTarget != null) { interferedCells.Add(bot.FillTarget.Value); availablePositions.Remove(bot.FillTarget.Value); filledCoords.Add(bot.FillTarget.Value); var ret = new Fill { Diff = bot.FillTarget.Value.Diff(bot.Coord) }; bot.FillTarget = null; return(ret); } if (bot.VoidTarget != null) { interferedCells.Add(bot.VoidTarget.Value); availablePositions.Remove(bot.VoidTarget.Value); filledCoords.Add(bot.VoidTarget.Value); var ret = new Void() { Diff = bot.VoidTarget.Value.Diff(bot.Coord) }; bot.VoidTarget = null; return(ret); } throw new Exception($"WTF {numFilled} / {model.NumFilled}"); }