Example #1
0
        public static void AddMove(Command command)
        {
            availableShipMoves.Remove(command.Ship);
            Safety.TwoTurnAvoider.Remove(command.TargetCell);
            usedShips[command.Ship] = command;
            collisionCells.Add(command.TargetCell);
            Log.LogMessage(command.Comment);

            if (availableShipMoves.Any(kvp => GameInfo.AvailableMoveCounts(kvp.Key, !command.Ship.OnDropoff) == 1))
            {
                var shipToMove = availableShipMoves.First(kvp => GameInfo.AvailableMoveCounts(kvp.Key, !command.Ship.OnDropoff) == 1).Key;
                var dirs       = shipToMove.OnDropoff ? DirectionExtensions.ALL_CARDINALS : DirectionExtensions.ALL_DIRECTIONS;
                if (dirs.Any(d => !CollisionCells.Contains(GameInfo.CellAt(shipToMove, d))))
                {
                    var dir = dirs.First(d => !CollisionCells.Contains(GameInfo.CellAt(shipToMove, d)));
                    AddMove(shipToMove.Move(dir, $"Moving ship {shipToMove.Id} because there were no other moves remaining"));
                }
            }
        }