public static void GenerateMoves() { moveRight = new BitArray[Constants.PlayableSquares]; moveLeft = new BitArray[Constants.PlayableSquares]; moveUp = new BitArray[Constants.PlayableSquares]; moveDown = new BitArray[Constants.PlayableSquares]; for (int p = 0; p < Constants.PlayableSquares; p++) { var mapPos = BitState.GetMapIndex(p); // right var bits = new BitArray(Constants.PlayableSquares); bits[p] = true; if (mapPos.Item1 + 1 < Constants.BoardWidth && mapPos.Item2 % 2 == 0) { bits[p + 1] = true; } moveRight[p] = bits; // left bits = new BitArray(Constants.PlayableSquares); bits[p] = true; if (mapPos.Item1 - 1 >= 0 && mapPos.Item2 % 2 == 0) { bits[p - 1] = true; } moveLeft[p] = bits; // up bits = new BitArray(Constants.PlayableSquares); bits[p] = true; if (mapPos.Item2 - 1 >= 0 && mapPos.Item1 % 2 == 0) { bits[BitState.GetBitIndex(mapPos.Item1, mapPos.Item2 - 1)] = true; } moveUp[p] = bits; // down bits = new BitArray(Constants.PlayableSquares); bits[p] = true; if (mapPos.Item2 + 1 < Constants.BoardHeight && mapPos.Item1 % 2 == 0) { bits[BitState.GetBitIndex(mapPos.Item1, mapPos.Item2 + 1)] = true; } moveDown[p] = bits; } }
public static void GenerateBombs() { bombRight = new BitArray[Constants.BoardWidth, Constants.PlayableSquares]; bombLeft = new BitArray[Constants.BoardWidth, Constants.PlayableSquares]; bombUp = new BitArray[Constants.BoardWidth, Constants.PlayableSquares]; bombDown = new BitArray[Constants.BoardWidth, Constants.PlayableSquares]; for (int i = 1; i <= Constants.BoardWidth; i++) { for (int p = 0; p < Constants.PlayableSquares; p++) { var mapPos = BitState.GetMapIndex(p); // right var bits = new BitArray(Constants.PlayableSquares); if (mapPos.Item1 + i < Constants.BoardWidth && mapPos.Item2 % 2 == 0) { bits[p + i] = true; } bombRight[i - 1, p] = bits; // left bits = new BitArray(Constants.PlayableSquares); if (mapPos.Item1 - i >= 0 && mapPos.Item2 % 2 == 0) { bits[p - i] = true; } bombLeft[i - 1, p] = bits; // up bits = new BitArray(Constants.PlayableSquares); if (mapPos.Item2 - i >= 0 && mapPos.Item1 % 2 == 0) { bits[BitState.GetBitIndex(mapPos.Item1, mapPos.Item2 - i)] = true; } bombUp[i - 1, p] = bits; // down bits = new BitArray(Constants.PlayableSquares); if (mapPos.Item2 + i < Constants.BoardHeight && mapPos.Item1 % 2 == 0) { bits[BitState.GetBitIndex(mapPos.Item1, mapPos.Item2 + i)] = true; } bombDown[i - 1, p] = bits; } } }
static void Main() { int turnNumber = 0; string[] inputs; inputs = Console.ReadLine().Split(' '); int width = int.Parse(inputs[0]); int height = int.Parse(inputs[1]); int myId = int.Parse(inputs[2]); BitMaps.GenerateMoves(); BitMaps.GenerateBombs(); // game loop while (true) { turnNumber++; char[,] map = new char[width, height]; List <Robot> bots = new List <Robot>(); List <Bomb> bombs = new List <Bomb>(); for (int i = 0; i < height; i++) { var row = Console.ReadLine().ToCharArray(); for (int j = 0; j < width; j++) { map[j, i] = row[j]; } } int entities = int.Parse(Console.ReadLine()); for (int i = 0; i < entities; i++) { inputs = Console.ReadLine().Split(' '); var entityType = int.Parse(inputs[0]); if (entityType == Constants.ENTITY_ROBOT) { var r = new Robot { owner = int.Parse(inputs[1]) }; var x = int.Parse(inputs[2]); var y = int.Parse(inputs[3]); r.position = BitState.GetBitIndex(x, y); r.param1 = int.Parse(inputs[4]); r.param2 = int.Parse(inputs[5]); bots.Add(r); } else if (entityType == Constants.ENTITY_ITEM) { if (int.Parse(inputs[4]) == Constants.ITEM_RANGE) { map[int.Parse(inputs[2]), int.Parse(inputs[3])] = Constants.MAP_ITEM_RANGE; } else { map[int.Parse(inputs[2]), int.Parse(inputs[3])] = Constants.MAP_ITEM_BOMB; } } else { var r = new Bomb { owner = int.Parse(inputs[1]) }; var x = int.Parse(inputs[2]); var y = int.Parse(inputs[3]); r.position = BitState.GetBitIndex(x, y); r.param1 = int.Parse(inputs[4]); r.param2 = int.Parse(inputs[5]); bombs.Add(r); map[x, y] = Constants.MAP_BOMB; } } var bgs = new BitState(map, bots, bombs, turnNumber); var best = BitSolution.generateBestRandomSolution(bgs, myId, 20, 80); Console.WriteLine(bgs.getBot(myId).getCommand(best.moves[0]) + " " + best.score); bgs.play(best.moves[0], myId); Console.Error.WriteLine(bgs.score(myId)); } }