private List <List <IBuildingBlock> > CreateBuildingBlocks(IMazeBuilder mazeBuilder, string[] schemaLines, IBuildingBlockIdentifier wallIdentifier, IBuildingBlockIdentifier pathIdentifier) { List <List <IBuildingBlock> > buildingBlocksByRows = new List <List <IBuildingBlock> >(); for (int schemaRowIndex = 0; schemaRowIndex <= schemaLines.Length - 1; schemaRowIndex++) { List <IBuildingBlock> buildingBlocksInRow = new List <IBuildingBlock>(); buildingBlocksByRows.Add(buildingBlocksInRow); string schemaRow = schemaLines[schemaRowIndex].Trim(); string[] schemaColumns = schemaRow.Split(); int latiduteIndex = -1; //To Keep track of space which is not BuildingBlock ILongitude longitude = mazeBuilder.CreateLongitude(schemaRowIndex); for (int schemaColumnIndex = 0; schemaColumnIndex <= schemaColumns.Length - 1; schemaColumnIndex++) { BuildingBlockType?buildingBlockType = null; if (schemaColumns[schemaColumnIndex].ToString() == wallIdentifier.GetIdentifier().ToString()) { buildingBlockType = BuildingBlockType.Wall; } else if (schemaColumns[schemaColumnIndex].ToString() == pathIdentifier.GetIdentifier().ToString()) { buildingBlockType = BuildingBlockType.Path; } if (buildingBlockType.HasValue) { latiduteIndex++; ILatitude latitude = mazeBuilder.CreateLatitude(latiduteIndex); ILocation location = mazeBuilder.CreateLocation(latitude, longitude); IBuildingBlock buildingBlock; switch (buildingBlockType) { case BuildingBlockType.Wall: buildingBlock = mazeBuilder.CreateWall(location); break; case BuildingBlockType.Path: buildingBlock = mazeBuilder.CreatePath(location); break; default: throw new NotImplementedException(); } buildingBlocksInRow.Add(buildingBlock); } } } return(buildingBlocksByRows); }
public static void Main() { //Setup string schema = @" # # # # # # # # # # # # # . . . # . . . . . . # . . # . # . # # # # . # # # # . # . . . . # . # # . . . . # # # . # . . # # # # . # . # . # . # # . . # . # . # . # . # # # . # . # . # . # . # # . . . . . . . . # . # # # # # # # . # # # . # # . . . . . . # . . . # # # # # # # # # # # # #"; IMazeBuilder mazeBuilder = new RectangleMazeBuilder(); IBuildingBlockIdentifier wallIdentifier = mazeBuilder.CreateBuildingBlockIdentifier(BuildingBlockType.Wall, "#"); IBuildingBlockIdentifier pathIdentifier = mazeBuilder.CreateBuildingBlockIdentifier(BuildingBlockType.Path, "."); IMazeSchema mazeSchema = new MazeSchema ( new List <IBuildingBlockIdentifier>() { wallIdentifier, pathIdentifier }, schema ); ILatitude latitude = mazeBuilder.CreateLatitude(0); ILongitude longitude = mazeBuilder.CreateLongitude(2); ILocation startLocation = mazeBuilder.CreateLocation(latitude, longitude); IMaze maze = new RectangleMaze(mazeBuilder, mazeSchema, startLocation); IWalker walker = new WalkerWithRightHand(maze); //Execute do { walker.Walk(); } while (!walker.FoundExit()); //Finalize Console.WriteLine("Walker found the exit!"); }
public static ILatitude parseLatitude(string latitude_string, string hemisphere) { ILatitude result = null; int degrees = crackDegrees(latitude_string); int minutes = crackMinutes(latitude_string); double seconds = crackSeconds(latitude_string); Hemisphere H = Hemisphere.West; switch (hemisphere) { case "N": H = Hemisphere.North; break; case "S": H = Hemisphere.South; break; case "E": H = Hemisphere.East; break; case "W": H = Hemisphere.West; break; } result = latitude.Create(H, degrees, minutes, seconds); return(result); }
public bool Equals(ILatitude other) { return(base.Equals(other)); }
public Location(ILatitude hortizontalIdentifier, ILongitude veritcalIdentifier) { Latitude = hortizontalIdentifier; Longitude = veritcalIdentifier; }
public virtual ILocation CreateLocation(ILatitude latitude, ILongitude longitude) { return(new LocationNS.Location(latitude, longitude)); }
public static float LatitudeToRadian(ILatitude latitude) { return((latitude.Hemisphere == Hemisphere.North) ? (float)(latitude.Degrees + (latitude.Minutes / 60.0f) + (float)(latitude.Seconds / 3600.0d)) : (float)(-1.0f * (latitude.Degrees + (latitude.Minutes / 60.0f) + (float)(latitude.Seconds / 3600.0d)))); }