private static Command ReadFusionS(int b1, Stream stream) { int n = (b1 & 0b11111000) >> 3; Delta nd = DeltaDecoder.DecodeNd(n); return(Commands.FusionS(nd)); }
private static void GatherBots(State s) { var commands = new List <Command>(); int r = s.Matrix.R; foreach (Nanobot bot in s.Bots) { if (bot.Pos.X < r - 1) { if (bot.Pos.X % 31 == (r - 1) % 31) { commands.Add(Commands.FusionP(Delta.LinearX(+1))); continue; } if (bot.Pos.X % 31 == (r - 0) % 31) { commands.Add(Commands.FusionS(Delta.LinearX(-1))); continue; } } commands.Add(Commands.Wait()); } s.DoTurn(commands); commands.Clear(); foreach (Nanobot bot in s.Bots) { if (bot.Pos.Z < r - 1) { if (bot.Pos.Z % 31 == (r - 1) % 31) { commands.Add(Commands.FusionP(Delta.LinearZ(+1))); continue; } if (bot.Pos.Z % 31 == (r - 0) % 31) { commands.Add(Commands.FusionS(Delta.LinearZ(-1))); continue; } } commands.Add(Commands.Wait()); } s.DoTurn(commands); commands.Clear(); while (true) { int x = 0; foreach (Nanobot bot in s.Bots) { x = Math.Max(bot.Pos.X, x); } if (x == 0) { break; } foreach (Nanobot bot in s.Bots) { if (bot.Pos.X <= x - 2) { commands.Add(Commands.Wait()); continue; } if (bot.Pos.X == x - 1) { commands.Add(Commands.FusionP(Delta.LinearX(+1))); continue; } if (x == 1 || x % 31 == r % 31) { commands.Add(Commands.FusionS(Delta.LinearX(-1))); } else { int dx = Math.Min(x - 1, 15); commands.Add(Commands.SMove(Delta.LinearX(-dx))); } } s.DoTurn(commands); commands.Clear(); } while (true) { int z = 0; foreach (Nanobot bot in s.Bots) { z = Math.Max(bot.Pos.Z, z); } if (z == 0) { break; } foreach (Nanobot bot in s.Bots) { if (bot.Pos.Z <= z - 2) { commands.Add(Commands.Wait()); continue; } if (bot.Pos.Z == z - 1) { commands.Add(Commands.FusionP(Delta.LinearZ(+1))); continue; } if (z == 1 || z % 31 == r % 31) { commands.Add(Commands.FusionS(Delta.LinearZ(-1))); } else { int dz = -Math.Min(z - 1, 15); commands.Add(Commands.SMove(Delta.LinearZ(dz))); } } s.DoTurn(commands); commands.Clear(); } }
private void Cleanup() { var commands = new List <Command>(); foreach (Nanobot bot in S.Bots) { if (bot.Pos.X < R - 1) { if (bot.Pos.X % 31 == (R - 1) % 31) { commands.Add(Commands.FusionP(Delta.LinearX(+1))); continue; } if (bot.Pos.X % 31 == (R - 0) % 31) { commands.Add(Commands.FusionS(Delta.LinearX(-1))); continue; } } commands.Add(Commands.Wait()); } S.DoTurn(commands); commands.Clear(); foreach (Nanobot bot in S.Bots) { if (bot.Pos.Z < R - 1) { if (bot.Pos.Z % 31 == (R - 1) % 31) { commands.Add(Commands.FusionP(Delta.LinearZ(+1))); continue; } if (bot.Pos.Z % 31 == (R - 0) % 31) { commands.Add(Commands.FusionS(Delta.LinearZ(-1))); continue; } } commands.Add(Commands.Wait()); } S.DoTurn(commands); commands.Clear(); while (true) { int x = 0; foreach (Nanobot bot in S.Bots) { x = Math.Max(bot.Pos.X, x); } if (x == 0) { break; } foreach (Nanobot bot in S.Bots) { if (bot.Pos.X <= x - 2) { commands.Add(Commands.Wait()); continue; } if (bot.Pos.X == x - 1) { commands.Add(Commands.FusionP(Delta.LinearX(+1))); continue; } if (x == 1 || x % 31 == R % 31) { commands.Add(Commands.FusionS(Delta.LinearX(-1))); } else { int dx = Math.Min(x - 1, 15); commands.Add(Commands.SMove(Delta.LinearX(-dx))); } } S.DoTurn(commands); commands.Clear(); } while (true) { int z = 0; foreach (Nanobot bot in S.Bots) { z = Math.Max(bot.Pos.Z, z); } if (z == 0) { break; } foreach (Nanobot bot in S.Bots) { if (bot.Pos.Z <= z - 2) { commands.Add(Commands.Wait()); continue; } if (bot.Pos.Z == z - 1) { commands.Add(Commands.FusionP(Delta.LinearZ(+1))); continue; } if (z == 1 || z % 31 == R % 31) { commands.Add(Commands.FusionS(Delta.LinearZ(-1))); } else { int dz = -Math.Min(z - 1, 15); commands.Add(Commands.SMove(Delta.LinearZ(dz))); } } S.DoTurn(commands); commands.Clear(); } }