private static Command ReadFission(int b1, Stream stream) { int b2 = stream.StrictReadByte(); int n = (b1 & 0b11111000) >> 3; int m = (b2 & 0b00000000) >> 0; Delta nd = DeltaDecoder.DecodeNd(n); return(Commands.Fission(nd, m)); }
protected void LocateBots(IReadOnlyList <Coord> dests) { var commands = new List <Command>(); while (true) { if (S.Bots.Count < dests.Count) { int dx = (S.Bots.Count % 2 == 1) ? 1 : 0; int dz = (S.Bots.Count % 2 == 1) ? 0 : 1; commands.Add(Commands.Fission(Delta.Of(dx, 0, dz), 0)); } else { commands.Add(Commands.Wait()); } for (int i = 1; i < S.Bots.Count; i++) { int dx = dests[i].X - S.Bots[i].Pos.X; int dz = dests[i].Z - S.Bots[i].Pos.Z; if (dx > 0 && (i % 2 == 1 || dz == 0)) { commands.Add(Commands.SMove(Delta.LinearX(Math.Min(dx, 15)))); continue; } if (dz > 0 && (i % 2 == 0 || dx == 0)) { commands.Add(Commands.SMove(Delta.LinearZ(Math.Min(dz, 15)))); continue; } commands.Add(Commands.Wait()); } if (IsNoop(commands)) { break; } S.DoTurn(commands); commands.Clear(); } }
internal override Command DecodeText(IReadOnlyList <string> args) => Commands.Fission(Delta.Parse(args[0]), Int32.Parse(args[1]));
internal override Command Decode(int prefix, Func <int> nextByte) { Delta nd = DeltaDecoder.DecodeNd((prefix & 0b11111000) >> 3); return(Commands.Fission(nd, nextByte())); }
private static void LocateBots(State s) { var commands = new List <Command>(); int r = s.Matrix.R; while (s.Bots[0].Pos.Y < r - 1) { int dy = r - 1 - s.Bots[0].Pos.Y; s.DoTurn(new [] { Commands.SMove(Delta.LinearY(Math.Min(dy, 15))) }); } var dests = new List <Coord>(); { int[] coords = { r - 1, r - 31, r - 32, r - 62, r - 63, 0 }; var upper = new List <Coord>(); for (int i = 0; i < 6; i++) { for (int j = 0; j < i; j++) { upper.Add(Coord.Of(coords[i], r - 1, coords[j])); } } upper.Sort((c1, c2) => { int n1 = c1.X + c1.Z; int n2 = c2.X + c2.Z; return(-Comparer <Int32> .Default.Compare(n1, n2)); }); dests.Add(Coord.Of(0, r - 1, 0)); for (int i = 0; i <= 4; i++) { dests.Add(Coord.Of(coords[i], r - 1, coords[i])); } foreach (Coord c in upper) { dests.Add(c); dests.Add(Coord.Of(c.Z, c.Y, c.X)); } } while (true) { commands.Clear(); if (s.Bots.Count < dests.Count) { int dx = (s.Bots.Count % 2 == 1) ? 1 : 0; int dz = (s.Bots.Count % 2 == 1) ? 0 : 1; commands.Add(Commands.Fission(Delta.Of(dx, 0, dz), 0)); } else { commands.Add(Commands.Wait()); } for (int i = 1; i < s.Bots.Count; i++) { int dx = dests[i].X - s.Bots[i].Pos.X; int dz = dests[i].Z - s.Bots[i].Pos.Z; if (dx > 0 && (i % 2 == 1 || dz == 0)) { commands.Add(Commands.SMove(Delta.LinearX(Math.Min(dx, 15)))); continue; } if (dz > 0 && (i % 2 == 0 || dx == 0)) { commands.Add(Commands.SMove(Delta.LinearZ(Math.Min(dz, 15)))); continue; } commands.Add(Commands.Wait()); } if (IsNoop(commands)) { break; } s.DoTurn(commands); } }