Exemplo n.º 1
0
        private static bool ExpandConnection(PositionedConnection conn, char[,] artChars)
        {
            Position currentPos            = conn.track[conn.track.Count - 1];
            List <Position.Direction> dirs = new List <Position.Direction>();

            foreach (var direction in PositionedConnection.GetContainedDirections(conn.tailDirection))
            {
                Position newPos = currentPos + direction;
                if (newPos.IsWithin(artChars))
                {
                    Position.Direction thisDir = CharFits(artChars[newPos.x, newPos.y], direction);
                    if (thisDir != Position.Direction.None)
                    {
                        dirs.Add(direction);
                    }
                }
            }
            if (dirs.Count == 0)
            {
                throw new InvalidOperationException("Connection reaches dead end");
            }
            if (dirs.Count > 1)
            {
                throw new InvalidOperationException("Connection reaches splitting point: not allowed");
            }
            Position newPoint = currentPos + dirs[0];

            conn.track.Add(newPoint);
            conn.tailDirection = CharFits(artChars[newPoint.x, newPoint.y], dirs[0]);
            return(!TailAtEnd(artChars[newPoint.x, newPoint.y]));
        }
Exemplo n.º 2
0
        private static int GetStreamNumber(PositionedConnection conn, char[,] artChars)
        {
            Position startPoint = conn.track[conn.track.Count - 2];
            char     c          = artChars[startPoint.x, startPoint.y];

            if (c >= '0' && c <= '9')
            {
                return(int.Parse(c.ToString()));
            }
            return(0);
        }
Exemplo n.º 3
0
        private static void ExtractConnectionEndFor(Position pos, char[,] artChars, Position.Direction dir, char pointerSymbol, List <PositionedConnection> pointers)
        {
            int difX = (dir == Position.Direction.East ? 1 : (dir == Position.Direction.West ? -1 : 0));
            int difY = (dir == Position.Direction.South ? 1 : (dir == Position.Direction.North ? -1 : 0));

            pos.x += difX; pos.y += difY;
            if (pos.x < 0 || pos.y < 0 || pos.x >= artChars.GetLength(0) || pos.y >= artChars.GetLength(1))
            {
                return;
            }
            if (artChars[pos.x, pos.y] == pointerSymbol)
            {
                PositionedConnection newConn = new PositionedConnection()
                {
                    tailDirection = dir
                };
                newConn.track.Add(pos);
                pointers.Add(newConn);
            }
        }
Exemplo n.º 4
0
        internal static void ExtractNodesAndConnections(string art, IDictionary <char, TaskNode> nodes, Flow f)
        {
            char[,] artChars = ExtractMatrix(art);
            f.Art            = artChars;
            List <PositionedTask>       tasks       = GetTasks(artChars, nodes);
            List <PositionedConnection> connections = new List <PositionedConnection>();

            foreach (var task  in tasks)
            {
                f.AddNode(task.task, task.pos);
            }
            int totalUsed = 0;

            foreach (var task in tasks)
            {
                PositionedConnection conn = FindConnectionEnd(task, artChars);
                if (conn != null)
                {
                    while (ExpandConnection(conn, artChars))
                    {
                    }
                    ;
                    Position startPos = conn.track[conn.track.Count - 1];
                    char     start    = artChars[startPos.x, startPos.y];
                    conn.startPoint = new PositionedTask()
                    {
                        task = nodes[start], pos = startPos
                    };
                    int outNr = GetStreamNumber(conn, artChars);
                    BoundedBlockingQueue stream = f.ConnectNodes(conn.startPoint.task, conn.endPoint.task, outNr);
                    stream.InPoint = conn.track[1];
                    connections.Add(conn);
                    totalUsed += conn.track.Count - 1;
                }
            }
            foreach (Position p in GetJoinPosition(artChars))
            {
                PositionedConnection        joinedWith = connections.Where((PositionedConnection c) => c.track.Contains(p)).Single();
                List <PositionedConnection> conns      = FindConnectionJoin(p, artChars);
                foreach (var conn in conns)
                {
                    conn.endPoint = joinedWith.endPoint;
                    while (ExpandConnection(conn, artChars))
                    {
                    }
                    ;
                    Position startPos = conn.track[conn.track.Count - 1];
                    char     start    = artChars[startPos.x, startPos.y];
                    conn.startPoint = new PositionedTask()
                    {
                        task = nodes[start], pos = startPos
                    };
                    int outNr = GetStreamNumber(conn, artChars);
                    f.ConnectNodeByJoin(conn.startPoint.task, conn.endPoint.task, outNr);
                    connections.Add(conn);
                    totalUsed += conn.track.Count - 1; // both the end and begin point are already counted
                }
            }



            // after finding all connections, the total number of +, |, -, digits and letters should sum to the
            // total tracks + nr of tasks
            int usedSpots = art.ToCharArray().Count(c => { return("1234567890abcdefghijklmnopqrstuvwxyz-+#|<>^V".Contains(c)); });

            if (usedSpots != totalUsed + tasks.Count)
            {
                throw new InvalidOperationException("loose ends!");
            }
        }
Exemplo n.º 5
0
 private static int GetStreamNumber(PositionedConnection conn, char[,] artChars)
 {
     Position startPoint = conn.track[conn.track.Count-2];
     char c = artChars[startPoint.x, startPoint.y];
     if (c >= '0' && c <= '9')
     {
         return int.Parse(c.ToString());
     }
     return 0;
 }
Exemplo n.º 6
0
 private static void ExtractConnectionEndFor(Position pos, char[,] artChars, Position.Direction dir, char pointerSymbol, List<PositionedConnection> pointers)
 {
     int difX = (dir == Position.Direction.East ? 1 : (dir == Position.Direction.West ? -1 : 0));
     int difY = (dir == Position.Direction.South ? 1 : (dir == Position.Direction.North ? -1 : 0));
     pos.x += difX; pos.y += difY;
     if (pos.x < 0 || pos.y < 0 || pos.x >= artChars.GetLength(0) || pos.y >= artChars.GetLength(1))
     {
         return;
     }
     if (artChars[pos.x, pos.y] == pointerSymbol)
     {
         PositionedConnection newConn = new PositionedConnection() { tailDirection = dir };
         newConn.track.Add(pos);
         pointers.Add(newConn);
     }
 }
Exemplo n.º 7
0
 private static bool ExpandConnection(PositionedConnection conn, char[,] artChars)
 {
     Position currentPos = conn.track[conn.track.Count - 1];
     List<Position.Direction> dirs = new List<Position.Direction>();
     foreach (var direction in PositionedConnection.GetContainedDirections(conn.tailDirection))
     {
         Position newPos = currentPos + direction;
         if (newPos.IsWithin(artChars))
         {
             Position.Direction thisDir = CharFits(artChars[newPos.x, newPos.y], direction);
             if (thisDir != Position.Direction.None)
             {
                 dirs.Add(direction);
             }
         }
     }
     if (dirs.Count == 0)
     {
         throw new InvalidOperationException("Connection reaches dead end");
     }
     if (dirs.Count > 1)
     {
         throw new InvalidOperationException("Connection reaches splitting point: not allowed");
     }
     Position newPoint = currentPos + dirs[0];
     conn.track.Add(newPoint);
     conn.tailDirection = CharFits(artChars[newPoint.x, newPoint.y], dirs[0]);
     return !TailAtEnd(artChars[newPoint.x, newPoint.y]);
 }