public static TileKey GetDestination(Tile start, FPGATypes.Direction direction, int stepWidth) { TileKey targetKey; if (direction.Equals(FPGATypes.Direction.North)) { targetKey = new TileKey(start.TileKey.X, start.TileKey.Y - stepWidth); return(targetKey); //return FPGA.FPGA.Instance.GetTile(targetKey); } else if (direction.Equals(FPGATypes.Direction.South)) { targetKey = new TileKey(start.TileKey.X, start.TileKey.Y + stepWidth); return(targetKey); //return FPGA.FPGA.Instance.GetTile(targetKey); } else if (direction.Equals(FPGATypes.Direction.East)) { targetKey = new TileKey(start.TileKey.X + stepWidth, start.TileKey.Y); return(targetKey); //return FPGA.FPGA.Instance.GetTile(targetKey); } else if (direction.Equals(FPGATypes.Direction.West)) { targetKey = new TileKey(start.TileKey.X - stepWidth, start.TileKey.Y); return(targetKey); //return FPGA.FPGA.Instance.GetTile(targetKey); } else { throw new Exception("Unknown direction: " + direction); } }
public static IEnumerable <Location> GetDestination(Tile where, Port exit) { //SE5BEG2 //SL2BEG1 //SL5BEG2 String portName = exit.ToString(); if (Regex.IsMatch(portName, "(E|N|S|W)(E|N|S|W|L|R)(2|5)BEG") && !Regex.IsMatch(portName, "_")) { int distance = int.Parse(portName.Substring(2, 1)); //int index = int.Parse(portName.Substring(6, portName.Length - 6)); //mid FPGATypes.Direction dir1 = FPGA.FPGATypes.GetDirectionFromString(portName.Substring(0, 1)); int startX = where.LocationX; int startY = where.LocationY; int midX; int midY; //double lines if (dir1.Equals(FPGATypes.Direction.East) && distance == 2) { midX = startX + 1; midY = startY; } else if (dir1.Equals(FPGATypes.Direction.North) && distance == 2) { midX = startX; midY = startY + 1; } else if (dir1.Equals(FPGATypes.Direction.South) && distance == 2) { midX = startX; midY = startY - 1; } else if (dir1.Equals(FPGATypes.Direction.West) && distance == 2) { midX = startX - 1; midY = startY; } //pent lines else if (dir1.Equals(FPGATypes.Direction.East) && distance == 5) { midX = startX + 3; midY = startY; } else if (dir1.Equals(FPGATypes.Direction.North) && distance == 5) { midX = startX; midY = startY + 3; } else if (dir1.Equals(FPGATypes.Direction.South) && distance == 5) { midX = startX; midY = startY - 3; } else if (dir1.Equals(FPGATypes.Direction.West) && distance == 5) { midX = startX - 3; midY = startY; } else { throw new ArgumentException("Can not handle port " + exit); } String locationFirstPart = Regex.Split(where.Location, "_")[0]; String midTargetLocation = locationFirstPart + "_X" + midX.ToString() + "Y" + midY.ToString(); if (FPGA.FPGA.Instance.Contains(midTargetLocation)) { Tile midTarget = FPGA.FPGA.Instance.GetTile(midTargetLocation); Port midEnter = new Port(Regex.Replace(portName, "BEG", "MID")); //return mid yield return(new Location(midTarget, midEnter)); } int endX; int endY; FPGATypes.Direction dir2; String dir2String = portName.Substring(1, 1); if (Regex.IsMatch(dir2String, "(R|L)")) { dir2 = dir1; } else { dir2 = FPGA.FPGATypes.GetDirectionFromString(dir2String); } //double lines if (dir2.Equals(FPGATypes.Direction.East) && distance == 2) { endX = midX + 1; endY = midY; } else if (dir2.Equals(FPGATypes.Direction.North) && distance == 2) { endX = midX; endY = midY + 1; } else if (dir2.Equals(FPGATypes.Direction.South) && distance == 2) { endX = midX; endY = midY - 1; } else if (dir2.Equals(FPGATypes.Direction.West) && distance == 2) { endX = midX - 1; endY = midY; } //pent lines else if (dir2.Equals(FPGATypes.Direction.East) && distance == 5) { endX = midX + 2; endY = midY; } else if (dir2.Equals(FPGATypes.Direction.North) && distance == 5) { endX = midX; endY = midY + 2; } else if (dir2.Equals(FPGATypes.Direction.South) && distance == 5) { endX = midX; endY = midY - 2; } else if (dir2.Equals(FPGATypes.Direction.West) && distance == 5) { endX = midX - 2; endY = midY; } else { throw new ArgumentException("Can not handle port " + exit); } String endTargetLocation = locationFirstPart + "_X" + endX.ToString() + "Y" + endY.ToString(); if (FPGA.FPGA.Instance.Contains(endTargetLocation)) { Tile endTarget = FPGA.FPGA.Instance.GetTile(endTargetLocation); Port endEnter = new Port(Regex.Replace(portName, "BEG", "END")); //return mid yield return(new Location(endTarget, endEnter)); } } else if (Regex.IsMatch(portName, "^L(V|H)(0|18)$")) { /* * foreach (Tuple<String, String> nextWire in where.GetAllConnectedWires(portName)) * { * if (Regex.IsMatch(nextWire.Value, "^L(V|H)(0|6|12|18)")) * { * if (FPGA.FPGA.Instance.Contains(nextWire.Key)) * { * Tile targetTile = FPGA.FPGA.Instance.GetTile(nextWire.Key); * Port targetPort = new Port(nextWire.Value); * yield return new Location(targetTile, targetPort); * } * else * { * } * * } * } * */ } }