private void Flip() { var commands = new Command[S.Bots.Count]; for (int i = 0; i < S.Bots.Count; i++) { commands[i] = (i == 0) ? Commands.Flip() : Commands.Wait(); } S.DoTurn(commands); }
private static Command ReadCommand(Stream stream) { int b1 = stream.ReadByte(); switch (b1) { case -1: return(null); case 0b11111111: return(Commands.Halt()); case 0b11111110: return(Commands.Wait()); case 0b11111101: return(Commands.Flip()); } if ((b1 & 0b11001111) == 0b00000100) { return(ReadSMove(b1, stream)); } if ((b1 & 0b00001111) == 0b00001100) { return(ReadLMove(b1, stream)); } switch (b1 & 0b00000111) { case 0b111: return(ReadFusionP(b1, stream)); case 0b100: return(ReadFusionS(b1, stream)); case 0b101: return(ReadFission(b1, stream)); case 0b011: return(ReadFill(b1, stream)); case 0b010: return(ReadVoid(b1, stream)); case 0b001: return(ReadGFill(b1, stream)); case 0b000: return(ReadGVoid(b1, stream)); } throw new IOException($"Invalid first byte: {b1}."); }
private void Execute() { Delta down = Delta.LinearY(-1); var gvoid = new Command[S.Bots.Count]; for (int i = 0; i < S.Bots.Count; i++) { int dx = (S.Bots[i].Pos.X % 31 == (R - 1) % 31) ? -30 : +30; if (S.Bots[i].Pos.X == 0) { dx = (R + 30) % 31; } dx = Math.Max(dx, -S.Bots[i].Pos.X); int dz = (S.Bots[i].Pos.Z % 31 == (R - 1) % 31) ? -30 : +30; if (S.Bots[i].Pos.Z == 0) { dz = (R + 30) % 31; } dz = Math.Max(dz, -S.Bots[i].Pos.Z); gvoid[i] = Commands.GVoid(down, Delta.Of(dx, 0, dz)); } var smove = new Command[S.Bots.Count]; for (int i = 0; i < S.Bots.Count; i++) { smove[i] = Commands.SMove(down); } var flipw = new Command[S.Bots.Count]; for (int i = 0; i < S.Bots.Count; i++) { flipw[i] = (i == 0) ? Commands.Flip() : Commands.Wait(); } while (S.Bots[0].Pos.Y > 0) { if (S.Harmonics == Low && mHarmonics[S.Bots[0].Pos.Y - 1] == High) { S.DoTurn(flipw); } S.DoTurn(gvoid); if (S.Harmonics == High && mHarmonics[S.Bots[0].Pos.Y - 1] == Low) { S.DoTurn(flipw); } S.DoTurn(smove); } }
internal override Command DecodeText(IReadOnlyList <string> args) => Commands.Flip();
internal override Command Decode(int prefix, Func <int> nextByte) => Commands.Flip();