/// <summary> /// Calculates what damage a unit will receive from lasers at a given location. /// </summary> /// <param name="map">The game map.</param> /// <param name="location">Where the unit is located.</param> /// <returns>The amount of damage. Will be 0 or 1.</returns> public static int CalcLaserDamage(GameMap map, BoardLocation location) { int damage = 0; damage += _CalcLaserDamage(map, location.MapPosition, 0, -1, MapSquare.DIRECTION.SOUTH, MapSquare.SIDE.NORTH, MapSquare.SIDE.SOUTH); damage += _CalcLaserDamage(map, location.MapPosition, 0, 1, MapSquare.DIRECTION.NORTH, MapSquare.SIDE.SOUTH, MapSquare.SIDE.NORTH); damage += _CalcLaserDamage(map, location.MapPosition, -1, 0, MapSquare.DIRECTION.EAST, MapSquare.SIDE.WEST, MapSquare.SIDE.EAST); damage += _CalcLaserDamage(map, location.MapPosition, 1, 0, MapSquare.DIRECTION.WEST, MapSquare.SIDE.EAST, MapSquare.SIDE.WEST); return damage; }
/// <summary> /// Destination for a movement. Ignores all robots on the map but does take into account walls, conveyor belts and gears. Returns /// every step of the move. /// </summary> /// <param name="map">The game map.</param> /// <param name="startLocation">Where the unit starts.</param> /// <param name="cards">The cards to apply.</param> /// <returns>Every step of the move.</returns> public static List<MovePoint> CardPath(GameMap map, BoardLocation startLocation, IEnumerable<Card> cards) { // if we can't move, we end up where we started List<MovePoint> points = new List<MovePoint> {new MovePoint(startLocation)}; foreach (Card cardOn in cards) { // move robot MovePoint endLocation = Move(map, startLocation, cardOn.Move); if (endLocation.Dead) { points.Add(endLocation); return points; } if (! endLocation.Location.Equals(startLocation)) { startLocation = endLocation.Location; points.Add(new MovePoint(startLocation)); } // conveyor belt - may cause a 1/4 turn. MapSquare sq = map.GetSquare(startLocation.MapPosition); for (int speed=1; (sq.Conveyor != null) && (speed <= sq.Conveyor.Speed); speed++) { endLocation = Move(map, startLocation.MapPosition, sq.Conveyor.Direction); BoardLocation locMove = new BoardLocation(endLocation.Location.MapPosition, startLocation.Direction); sq = map.GetSquare(endLocation.Location.MapPosition); if (sq.Conveyor != null) { MapSquare.DIRECTION dirEnter = MoveDirection(startLocation.MapPosition, endLocation.Location.MapPosition); locMove = locMove.Rotate((int)sq.Conveyor.Direction - (int)dirEnter); } startLocation = locMove; points.Add(new MovePoint(startLocation)); } // gears if (sq.Type == MapSquare.TYPE.ROTATE_CLOCKWISE) { startLocation = startLocation.Rotate(1); points.Add(new MovePoint(startLocation)); } if (sq.Type == MapSquare.TYPE.ROTATE_COUNTERCLOCKWISE) { startLocation = startLocation.Rotate(-1); points.Add(new MovePoint(startLocation)); } // damage int damage = CalcLaserDamage(map, startLocation); if (damage != 0) points[points.Count - 1].Damage = damage; } return points; }
/// <summary> /// Called each time the system needs another turn. If you do not return a valid turn, the game will randomly move one of your units. /// This call must return in under 1 second. If it has not returned in 1 second the call will be aborted and a random move will be assigned. /// </summary> /// <param name="map">The game map with all units on it.</param> /// <param name="you">Your player object. This is created for each call.</param> /// <param name="cards">The cards you get to pick from. This does not include locked cards.</param> /// <returns>Your requested turn.</returns> public PlayerTurn Turn(GameMap map, Player you, List<Card> cards) { // get 40 sets, pick the one that's closest to the flag - center of map if flags all done List<Card> best = null; int bestDiff = int.MaxValue; int okDiff = rand.Next(0, 3); FlagState fs = you.FlagStates.FirstOrDefault(fsOn => !fsOn.Touched); Point ptFlag = fs == null ? new Point(map.Width / 2, map.Height / 2) : fs.Position; for (int turnOn = 0; turnOn < 40; turnOn++) { // pick 5 (or fewer if locked) random cards List<Card> moveCards = new List<Card>(); bool[] cardUsed = new bool[cards.Count]; for (int ind = 0; ind < Framework.NUM_PHASES - you.NumLockedCards; ind++) for (int iter = 0; iter < 100; iter++) // in case can't work it with these cards { Trap.trap(iter > 20); int index = rand.Next(cards.Count); if (cardUsed[index]) continue; moveCards.Add(cards[index]); cardUsed[index] = true; break; } // add in the locked cards for (int ind = Framework.NUM_PHASES - you.NumLockedCards; ind < Framework.NUM_PHASES; ind++) moveCards.Add(you.Cards[ind]); // If all we have are rotates, we add in a move forward 1 so that a card that is a turn can then take into account next time we get a forward 1. bool addMove = moveCards.All(card => card.IsRotate); if (addMove) moveCards.Add(new Card(Card.ROBOT_MOVE.FORWARD_ONE, 500)); // run it Utilities.MovePoint mp = Utilities.CardDestination(map, you.Robot.Location, moveCards); // if it kills us we don't want it if (mp.Dead) continue; // if better than before, use it if (addMove) moveCards.RemoveAt(moveCards.Count - 1); int diff = Math.Abs(ptFlag.X - mp.Location.MapPosition.X) + Math.Abs(ptFlag.Y - mp.Location.MapPosition.Y); if (diff <= okDiff) return new PlayerTurn(moveCards, false); if (diff < bestDiff) { bestDiff = diff; best = moveCards; } } return new PlayerTurn(best, false); }
/// <summary> /// Destination for a movement. Ignores all robots on the map but does take into account walls, conveyor belts and gears. Returns /// the final location of the move. /// </summary> /// <param name="map">The game map.</param> /// <param name="startLocation">Where the unit starts.</param> /// <param name="cards">The cards to apply.</param> /// <returns>The final location of the move.</returns> public static MovePoint CardDestination(GameMap map, BoardLocation startLocation, IEnumerable<Card> cards) { List<MovePoint> points = CardPath(map, startLocation, cards); if ((points == null) || (points.Count == 0)) { Trap.trap(); return null; } return points[points.Count - 1]; }
/// <summary> /// Destination for a movement. Ignores all robots on the map but does take into account walls, conveyor belts and gears. Returns /// the final location of the move. /// </summary> /// <param name="map">The game map.</param> /// <param name="startLocation">Where the unit starts.</param> /// <param name="cards">The cards to apply.</param> /// <returns>The final location of the move.</returns> public static MovePoint CardDestination(GameMap map, BoardLocation startLocation, Card[] cards) { MovePoint[] points = CardPath(map, startLocation, cards); if ((points == null) || (points.Length == 0)) { Trap.trap(); return null; } return points[points.Length - 1]; }
/// <summary> /// Create the map. /// </summary> /// <returns></returns> public static GameMap CreateMap() { // build map - all standard tiles GameMap map = new GameMap { Squares = new MapSquare[MAP_SQUARE_WIDTH][] }; for (int x = 0; x < MAP_SQUARE_WIDTH; x++) { map.Squares[x] = new MapSquare[MAP_SQUARE_HEIGHT]; for (int y=0; y<MAP_SQUARE_HEIGHT; y++) map.Squares[x][y] = new MapSquare(MapSquare.TYPE.NORMAL); } // walls map.Squares[2][0] = new MapSquare(MapSquare.SIDE.NORTH); map.Squares[4][0] = new MapSquare(MapSquare.SIDE.NORTH); map.Squares[7][0] = new MapSquare(MapSquare.SIDE.NORTH); map.Squares[9][0] = new MapSquare(MapSquare.SIDE.NORTH); map.Squares[0][2] = new MapSquare(MapSquare.SIDE.WEST); // pit - map.Squares[3][2] = new MapSquare(MapSquare.SIDE.SOUTH); map.Squares[11][2] = new MapSquare(MapSquare.SIDE.EAST); map.Squares[5][3] = new MapSquare(MapSquare.SIDE.WEST); // laser - map.Squares[6][3] = new MapSquareInternal(MapSquare.SIDE.EAST); map.Squares[0][4] = new MapSquare(MapSquare.SIDE.WEST); map.Squares[11][4] = new MapSquare(MapSquare.SIDE.EAST); // laser - map.Squares[8][5] = new MapSquareInternal(MapSquare.SIDE.NORTH); // laser - map.Squares[3][6] = new MapSquareInternal(MapSquare.SIDE.SOUTH); map.Squares[0][7] = new MapSquare(MapSquare.SIDE.WEST); map.Squares[11][7] = new MapSquare(MapSquare.SIDE.EAST); // laser - map.Squares[5][8] = new MapSquareInternal(MapSquare.SIDE.WEST); map.Squares[6][8] = new MapSquare(MapSquare.SIDE.EAST); map.Squares[0][9] = new MapSquare(MapSquare.SIDE.WEST); // pit - map.Squares[8][9] = new MapSquare(MapSquare.SIDE.NORTH); map.Squares[11][9] = new MapSquare(MapSquare.SIDE.EAST); map.Squares[2][11] = new MapSquare(MapSquare.SIDE.SOUTH); map.Squares[4][11] = new MapSquare(MapSquare.SIDE.SOUTH); map.Squares[7][11] = new MapSquare(MapSquare.SIDE.SOUTH); map.Squares[9][11] = new MapSquare(MapSquare.SIDE.SOUTH); map.Squares[2][12] = new MapSquare(MapSquare.SIDE.NORTH); map.Squares[4][12] = new MapSquare(MapSquare.SIDE.NORTH | MapSquare.SIDE.WEST); map.Squares[7][12] = new MapSquare(MapSquare.SIDE.NORTH | MapSquare.SIDE.EAST); map.Squares[9][12] = new MapSquare(MapSquare.SIDE.NORTH); map.Squares[1][13] = new MapSquare(MapSquare.SIDE.WEST); map.Squares[2][13] = new MapSquare(MapSquare.SIDE.WEST); map.Squares[9][13] = new MapSquare(MapSquare.SIDE.EAST); map.Squares[10][13] = new MapSquare(MapSquare.SIDE.EAST); map.Squares[6][14] = new MapSquare(MapSquare.SIDE.WEST); map.Squares[6][15] = new MapSquare(MapSquare.SIDE.WEST); // 4 square conveyor belts map.Squares[1][1] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.EAST, MapSquare.SIDE.NORTH)); map.Squares[2][1] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.EAST, MapSquare.SIDE.NONE)); map.Squares[3][1] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.EAST, MapSquare.SIDE.NONE)); map.Squares[4][1] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.SOUTH, MapSquare.SIDE.EAST)); map.Squares[4][2] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.SOUTH, MapSquare.SIDE.NONE)); map.Squares[4][3] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.SOUTH, MapSquare.SIDE.NONE)); map.Squares[4][4] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.WEST, MapSquare.SIDE.SOUTH)); map.Squares[3][4] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.WEST, MapSquare.SIDE.NONE)); map.Squares[2][4] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.WEST, MapSquare.SIDE.NONE)); map.Squares[1][4] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.NORTH, MapSquare.SIDE.WEST)); map.Squares[1][3] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.NORTH, MapSquare.SIDE.NONE)); map.Squares[1][2] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.NORTH, MapSquare.SIDE.NONE)); map.Squares[7][1] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.EAST, MapSquare.SIDE.NORTH)); map.Squares[8][1] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.EAST, MapSquare.SIDE.NONE)); map.Squares[9][1] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.EAST, MapSquare.SIDE.NONE)); map.Squares[10][1] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.SOUTH, MapSquare.SIDE.EAST)); map.Squares[10][2] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.SOUTH, MapSquare.SIDE.NONE)); map.Squares[10][3] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.SOUTH, MapSquare.SIDE.NONE)); map.Squares[10][4] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.WEST, MapSquare.SIDE.SOUTH)); map.Squares[9][4] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.WEST, MapSquare.SIDE.NONE)); map.Squares[8][4] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.WEST, MapSquare.SIDE.NONE)); map.Squares[7][4] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.NORTH, MapSquare.SIDE.WEST)); map.Squares[7][3] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.NORTH, MapSquare.SIDE.NONE)); map.Squares[7][2] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.NORTH, MapSquare.SIDE.NONE)); map.Squares[1][7] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.EAST, MapSquare.SIDE.NORTH)); map.Squares[2][7] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.EAST, MapSquare.SIDE.NONE)); map.Squares[3][7] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.EAST, MapSquare.SIDE.NONE)); map.Squares[4][7] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.SOUTH, MapSquare.SIDE.EAST)); map.Squares[4][8] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.SOUTH, MapSquare.SIDE.NONE)); map.Squares[4][9] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.SOUTH, MapSquare.SIDE.NONE)); map.Squares[4][10] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.WEST, MapSquare.SIDE.SOUTH)); map.Squares[3][10] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.WEST, MapSquare.SIDE.NONE)); map.Squares[2][10] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.WEST, MapSquare.SIDE.NONE)); map.Squares[1][10] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.NORTH, MapSquare.SIDE.WEST)); map.Squares[1][9] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.NORTH, MapSquare.SIDE.NONE)); map.Squares[1][8] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.NORTH, MapSquare.SIDE.NONE)); map.Squares[7][7] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.EAST, MapSquare.SIDE.NORTH)); map.Squares[8][7] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.EAST, MapSquare.SIDE.NONE)); map.Squares[9][7] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.EAST, MapSquare.SIDE.NONE)); map.Squares[10][7] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.SOUTH, MapSquare.SIDE.EAST)); map.Squares[10][8] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.SOUTH, MapSquare.SIDE.NONE)); map.Squares[10][9] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.SOUTH, MapSquare.SIDE.NONE)); map.Squares[10][10] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.WEST, MapSquare.SIDE.SOUTH)); map.Squares[9][10] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.WEST, MapSquare.SIDE.NONE)); map.Squares[8][10] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.WEST, MapSquare.SIDE.NONE)); map.Squares[7][10] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.NORTH, MapSquare.SIDE.WEST)); map.Squares[7][9] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.NORTH, MapSquare.SIDE.NONE)); map.Squares[7][8] = new MapSquare(new Conveyor(2, MapSquare.DIRECTION.NORTH, MapSquare.SIDE.NONE)); // 2 start conveyor belts map.Squares[0][14] = new MapSquare(new Conveyor(1, MapSquare.DIRECTION.EAST, MapSquare.SIDE.NONE)); map.Squares[1][14] = new MapSquare(new Conveyor(1, MapSquare.DIRECTION.EAST, MapSquare.SIDE.NONE)); map.Squares[2][14] = new MapSquare(new Conveyor(1, MapSquare.DIRECTION.SOUTH, MapSquare.SIDE.EAST)); map.Squares[2][15] = new MapSquare(new Conveyor(1, MapSquare.DIRECTION.EAST, MapSquare.SIDE.SOUTH)); map.Squares[3][15] = new MapSquare(new Conveyor(1, MapSquare.DIRECTION.EAST, MapSquare.SIDE.NONE)); map.Squares[4][15] = new MapSquare(new Conveyor(1, MapSquare.DIRECTION.EAST, MapSquare.SIDE.NONE)); map.Squares[7][15] = new MapSquare(new Conveyor(1, MapSquare.DIRECTION.WEST, MapSquare.SIDE.NONE)); map.Squares[8][15] = new MapSquare(new Conveyor(1, MapSquare.DIRECTION.WEST, MapSquare.SIDE.NONE)); map.Squares[9][15] = new MapSquare(new Conveyor(1, MapSquare.DIRECTION.WEST, MapSquare.SIDE.SOUTH)); map.Squares[9][14] = new MapSquare(new Conveyor(1, MapSquare.DIRECTION.SOUTH, MapSquare.SIDE.WEST)); map.Squares[10][14] = new MapSquare(new Conveyor(1, MapSquare.DIRECTION.WEST, MapSquare.SIDE.NONE)); map.Squares[11][14] = new MapSquare(new Conveyor(1, MapSquare.DIRECTION.WEST, MapSquare.SIDE.NONE)); // rotators map.Squares[2][2] = new MapSquare(MapSquare.TYPE.ROTATE_CLOCKWISE); map.Squares[8][2] = new MapSquare(MapSquare.TYPE.ROTATE_CLOCKWISE); map.Squares[3][3] = new MapSquare(MapSquare.TYPE.ROTATE_CLOCKWISE); map.Squares[9][3] = new MapSquare(MapSquare.TYPE.ROTATE_CLOCKWISE); map.Squares[2][8] = new MapSquare(MapSquare.TYPE.ROTATE_CLOCKWISE); map.Squares[8][8] = new MapSquare(MapSquare.TYPE.ROTATE_CLOCKWISE); map.Squares[3][9] = new MapSquare(MapSquare.TYPE.ROTATE_CLOCKWISE); map.Squares[9][9] = new MapSquare(MapSquare.TYPE.ROTATE_CLOCKWISE); map.Squares[5][2] = new MapSquare(MapSquare.TYPE.ROTATE_COUNTERCLOCKWISE); map.Squares[6][4] = new MapSquare(MapSquare.TYPE.ROTATE_COUNTERCLOCKWISE); map.Squares[4][5] = new MapSquare(MapSquare.TYPE.ROTATE_COUNTERCLOCKWISE); map.Squares[9][5] = new MapSquare(MapSquare.TYPE.ROTATE_COUNTERCLOCKWISE); map.Squares[2][6] = new MapSquare(MapSquare.TYPE.ROTATE_COUNTERCLOCKWISE); map.Squares[7][6] = new MapSquare(MapSquare.TYPE.ROTATE_COUNTERCLOCKWISE); map.Squares[5][7] = new MapSquare(MapSquare.TYPE.ROTATE_COUNTERCLOCKWISE); map.Squares[6][9] = new MapSquare(MapSquare.TYPE.ROTATE_COUNTERCLOCKWISE); // lasers map.Lasers.Add(new Laser(new BoardLocation(new Point(6, 3), MapSquare.DIRECTION.WEST), 2)); map.Lasers.Add(new Laser(new BoardLocation(new Point(5, 8), MapSquare.DIRECTION.EAST), 2)); map.Lasers.Add(new Laser(new BoardLocation(new Point(3, 6), MapSquare.DIRECTION.NORTH), 4)); map.Lasers.Add(new Laser(new BoardLocation(new Point(8, 5), MapSquare.DIRECTION.SOUTH), 4)); map.Squares[6][3] = new MapSquare(map.Lasers[0], MapSquare.SIDE.EAST); map.Squares[5][8] = new MapSquare(map.Lasers[1], MapSquare.SIDE.WEST); map.Squares[3][6] = new MapSquare(map.Lasers[2], MapSquare.SIDE.SOUTH); map.Squares[8][5] = new MapSquare(map.Lasers[3], MapSquare.SIDE.NORTH); // repair map.Squares[2][3] = new MapSquare(MapSquare.TYPE.REPAIR); map.Squares[8][3] = new MapSquare(MapSquare.TYPE.REPAIR); map.Squares[3][8] = new MapSquare(MapSquare.TYPE.REPAIR); map.Squares[9][8] = new MapSquare(MapSquare.TYPE.REPAIR); // pits map.Squares[3][2] = new MapSquare(MapSquare.TYPE.PIT, MapSquare.SIDE.SOUTH); map.Squares[9][2] = new MapSquare(MapSquare.TYPE.PIT); map.Squares[2][9] = new MapSquare(MapSquare.TYPE.PIT); map.Squares[8][9] = new MapSquare(MapSquare.TYPE.PIT, MapSquare.SIDE.NORTH); // flags map.Squares[5][4] = new MapSquare(1); map.Squares[10][11] = new MapSquare(2); map.Squares[1][6] = new MapSquare(3); map.Flags = new[] { new Point(5, 4), new Point(10, 11), new Point(1, 6)}; return map; }
private static int _CalcLaserDamage(GameMap map, Point position, int xAdd, int yAdd, MapSquare.DIRECTION laserDirection, MapSquare.SIDE wallExit, MapSquare.SIDE wallEnter) { int damage = 0; int x = position.X; int y = position.Y; bool startSquare = true; while ((0 <= x) && (x < map.Width) && (0 <= y) && (y < map.Height)) { MapSquare sq = map.Squares[x][y]; // can we move into this square? if ((! startSquare) && ((sq.Walls & wallEnter) != 0)) break; startSquare = false; if ((sq.Laser != null) && (sq.Laser.Location.Direction == laserDirection)) { damage++; break; } // can we move out of this square? if ((sq.Walls & wallExit) != 0) break; x += xAdd; y += yAdd; } return damage; }
/// <summary> /// Move a unit one square in the requested direction. Ignores all robots on the map but does take into account walls, conveyor belts and gears. /// </summary> /// <param name="map">The game map.</param> /// <param name="position">The map square to start the move from.</param> /// <param name="direction">The direction to move.</param> /// <returns>The final location of the move.</returns> public static MovePoint Move(GameMap map, Point position, MapSquare.DIRECTION direction) { // watch for wall in this direction MapSquare.SIDE sideExit = sideMoveOut[(int) direction]; MapSquare.SIDE sideEnter = sideMoveIn[(int) direction]; BoardLocation location = new BoardLocation(position, direction); // can we exit this square? MapSquare sq = map.GetSquare(position); if ((sq.Walls & sideExit) != 0) return new MovePoint(location); BoardLocation moveTo = location.Move(1); // did we go off the board? if ((moveTo.MapPosition.X < 0) || (map.Width <= moveTo.MapPosition.X) || (moveTo.MapPosition.Y < 0) || (map.Height <= moveTo.MapPosition.Y)) return new MovePoint(location, true); // did we go into a pit? if (map.GetSquare(moveTo.MapPosition).Type == MapSquare.TYPE.PIT) return new MovePoint(moveTo, true); // can we enter the new square? sq = map.GetSquare(moveTo.MapPosition); if ((sq.Walls & sideEnter) != 0) return new MovePoint(location); return new MovePoint(moveTo); }
/// <summary> /// Move a unit one card move. Ignores all robots on the map but does take into account walls, conveyor belts and gears. /// </summary> /// <param name="map">The game map.</param> /// <param name="startLocation">Where the unit starts.</param> /// <param name="move">The move to apply.</param> /// <returns>The final location of the move.</returns> public static MovePoint Move(GameMap map, BoardLocation startLocation, Card.ROBOT_MOVE move) { int steps = 0; switch (move) { case Card.ROBOT_MOVE.BACKWARD_ONE: steps = -1; break; case Card.ROBOT_MOVE.FORWARD_ONE: steps = 1; break; case Card.ROBOT_MOVE.FORWARD_TWO: steps = 2; break; case Card.ROBOT_MOVE.FORWARD_THREE: steps = 3; break; case Card.ROBOT_MOVE.ROTATE_LEFT: return new MovePoint(startLocation.Rotate(-1)); case Card.ROBOT_MOVE.ROTATE_RIGHT: return new MovePoint(startLocation.Rotate(1)); case Card.ROBOT_MOVE.ROTATE_UTURN: return new MovePoint(startLocation.Rotate(2)); } MapSquare.DIRECTION dir = steps >= 0 ? startLocation.Direction : startLocation.Rotate(2).Direction; Point position = startLocation.MapPosition; while (steps != 0) { MovePoint mp = Move(map, position, dir); if (mp.Dead) return new MovePoint(new BoardLocation(mp.Location.MapPosition, startLocation.Direction), true); position = mp.Location.MapPosition; int singleStep = Math.Max(-1, Math.Min(1, steps)); steps -= singleStep; } return new MovePoint(new BoardLocation(position, startLocation.Direction)); }