public static int DistanceTo(int fastShipPosition, int targetFastCoord) { var bowDist = FastCoord.Distance(Bow(fastShipPosition), targetFastCoord); if (bowDist == 0) { return(0); } var dist = FastCoord.Distance(Coord(fastShipPosition), targetFastCoord); if (dist == 0) { return(0); } var sternDist = FastCoord.Distance(Stern(fastShipPosition), targetFastCoord); if (sternDist == 0) { return(0); } return(bowDist); }
public static void Init() { if (initialized) { return; } initialized = true; FastCoord.Init(); for (int speed = 0; speed <= Constants.MAX_SHIP_SPEED; speed++) { for (int orientation = 0; orientation < 6; orientation++) { for (int x = 0; x < Constants.MAP_WIDTH; x++) { for (int y = 0; y < Constants.MAP_HEIGHT; y++) { foreach (var moveCommand in ShipMoveCommands.all) { var shipPosition = new ShipPosition(new Coord(x, y), orientation, speed); var nextPositions = shipPosition.Apply(moveCommand); if (nextPositions.Count != 2) { throw new InvalidOperationException("nextPositions.Count != 2"); } var fastShipPosition = Create(shipPosition); var moved = 0u; for (int phase = 0; phase < nextPositions.Count; phase++) { moved = unchecked ((moved << 16) | (uint)Create(nextPositions[phase])); } moves[fastShipPosition | ((int)moveCommand << positionBits)] = moved; } } } } } }
public static int Stern(int fastShipPosition) { return(FastCoord.Neighbor(Coord(fastShipPosition), (Orientation(fastShipPosition) + 3) % 6)); }
public static int Bow(int fastShipPosition) { return(FastCoord.Neighbor(Coord(fastShipPosition), Orientation(fastShipPosition))); }
public static int Create(int x, int y, int orientation, int speed) { return(Create(FastCoord.Create(x, y), orientation, speed)); }
public static int Mine(int fastShipPosition) { var backOrientation = (Orientation(fastShipPosition) + 3) % 6; return(FastCoord.Neighbor(FastCoord.Neighbor(Coord(fastShipPosition), backOrientation), backOrientation)); }
public static ShipPosition ToShipPosition(int fastShipPosition) { return(new ShipPosition(FastCoord.ToCoord(Coord(fastShipPosition)), Orientation(fastShipPosition), Speed(fastShipPosition))); }
public static bool IsInsideMap(int fastShipPosition) { return(FastCoord.IsInsideMap(Coord(fastShipPosition))); }
public int ToFastCoord() { return(FastCoord.Create(this)); }