Exemple #1
0
    void PositionInner(Node n, Vector2 pos)
    {
        n.position = pos;
        positioned.Add(n);

        //Debug.Log(string.Format("Positioned node {0} at {1}", n.id, pos));

        foreach (KeyValuePair <NodeExit, NodeConnection> c in n.connections)
        {
            if (c.Value != null && !positioned.Contains(c.Value.node))
            {
                Vector2 nodePos    = pos;
                int     axisChange = 0;

                NodeExit exit    = c.Key;
                NodeExit adjExit = c.Value.localExit;
                Node     adjNode = c.Value.node;

                switch (exit.direction)
                {
                case Direction.Right:
                    //if (adjExit.direction == Direction.Up)
                    //    axisChange = (int)(Math.Abs(n.size.y - adjNode.size.y) + exit.position.y + 1);

                    nodePos += new Vector2(n.size.x + 1, axisChange);
                    break;

                case Direction.Left:
                    //if (adjExit.direction == Direction.Up)
                    //    axisChange = (int)(Math.Abs(n.size.y - adjNode.size.y) + exit.position.y + 1);

                    nodePos += new Vector2(-adjNode.size.x - 1, axisChange);
                    break;

                case Direction.Down:
                    //if (adjExit.direction == Direction.Left)
                    //    axisChange = (int)(Math.Abs(n.size.x - adjNode.size.x) + exit.position.x + 1);
                    //else if (adjExit.direction == Direction.Right)
                    //    axisChange = (int)(Math.Abs(n.size.x - adjNode.size.x) - exit.position.x - 1);

                    nodePos += new Vector2(axisChange, n.size.y + 1);
                    break;

                case Direction.Up:
                    //if (adjExit.direction == Direction.Left)
                    //    axisChange = (int)(Math.Abs(n.size.x - adjNode.size.x) + exit.position.x + 1);
                    //else if (adjExit.direction == Direction.Right)
                    //    axisChange = (int)(Math.Abs(n.size.x - adjNode.size.x) - exit.position.x - 1);

                    nodePos += new Vector2(axisChange, -adjNode.size.y - 1);
                    break;
                }

                PositionInner(c.Value.node, nodePos);
            }
        }

        //Debug.Log(string.Format("Finished node {0} children", n.id));
    }
Exemple #2
0
        private void Worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            if (!(e.UserState is NodeEvent))
            {
                return;
            }

            TreeNodeCollection nodes = null;

            if (CurrentParent != null)
            {
                nodes = CurrentParent.Nodes;
            }
            else
            {
                switch (((NodeEvent)e.UserState).Dest)
                {
                case NodeDest.From:
                    nodes = fromTreeView.Nodes;
                    break;

                case NodeDest.To:
                    nodes = toTreeView.Nodes;
                    break;
                }
            }
            NodeEnter enter = e.UserState as NodeEnter;

            if (enter != null)
            {
                TreeNode child = new TreeNode(enter.Name);
                if (enter.Sort)
                {
                    TreeNodeInsertSorted(nodes, child);
                }
                else
                {
                    nodes.Add(child);
                }
                CurrentParent = child;
            }
            NodeExit exit = e.UserState as NodeExit;

            if (exit != null)
            {
                CurrentParent = CurrentParent.Parent;
            }
            NodeData node_data = e.UserState as NodeData;

            if (node_data != null)
            {
                TreeNode child = new TreeNode(node_data.Name);
                child.Tag = node_data.Object;
                TreeNodeInsertSorted(nodes, child);
            }
        }
Exemple #3
0
        public bool Connect(Room adjacent)
        {
            List <NodeExit> curExits = AvailableExits;
            List <NodeExit> adjExits = adjacent.AvailableExits;

            NodeExit curChosen = null;
            NodeExit adjChosen = null;
            int      quality   = 0;

            foreach (NodeExit v1 in curExits)
            {
                foreach (NodeExit v2 in adjExits)
                {
                    int q = 0; // bad
                    if (v1.GetOpposite() == v2.direction)
                    {
                        q = 2; // good
                    }
                    else if (v1.direction != v2.direction)
                    {
                        q = 1; // ok
                    }

                    if (curChosen == null || q > quality)
                    {
                        curChosen = v1;
                        adjChosen = v2;
                        quality   = q;
                    }
                }
            }

            if (curChosen != null && adjChosen != null)
            {
                NodeConnection c1 = new NodeConnection(adjacent, adjChosen);
                connections[curChosen] = c1;

                NodeConnection c2 = new NodeConnection(this, curChosen);
                adjacent.connections[adjChosen] = c2;

                return(true);
            }

            return(false);
        }
Exemple #4
0
        public Room(RoomTemplate template, int id) : base()
        {
            this.template = template;
            this.id       = id;
            this.size     = new Vector2(template.width, template.height);
            this.bounds   = new Rect(0, 0, size.x, size.y);

            // sets the available exits
            foreach (Vector2 exit in template.exits)
            {
                Direction direction = Direction.Up;
                if (exit.x == 0)
                {
                    direction = Direction.Left;
                }
                else if (exit.y == 0)
                {
                    direction = Direction.Up;
                }
                else if (exit.x == template.width - 1)
                {
                    direction = Direction.Right;
                }
                else if (exit.y == template.height - 1)
                {
                    direction = Direction.Down;
                }
                else
                {
                    continue;
                }

                NodeExit nExit = new NodeExit(exit, direction);
                connections[nExit] = null;
            }
        }
		public INodeLocation Exit(NodeExit exit) {
			throw new NotImplementedException();
		}
		private static LinkedList<INodeInformation> CreateSector(string name, int sectorSideSize, IPlayer emptyPlayer) {
			LinkedList<INodeInformation> ret = new LinkedList<INodeInformation>();
			var sector = new SectorInfo();

			/* building the nodes >>> */
			int layersInSector = sectorSideSize;
			for (int layer = 0; layer < sectorSideSize; layer++) {
				int rowsInLayer = layersInSector - layer;

				int indexInLayer = 0;
				for (int row = 0; row < rowsInLayer; row++) {
					int columnsInRow = rowsInLayer - row;
					for (int column = 0; column < columnsInRow; column++) {
						var node = new SampleMockNodeInformation(layer, row, column, sector, emptyPlayer);
						node.IndexInLayer = indexInLayer;
						ret.AddLast(node);

						indexInLayer++;
					}
				}
			}
			/* <<< building the nodes */

			/* joining the nodes >>> */
			var exits = new NodeExit[] {
				NodeExit.Alpha, NodeExit.Beta, NodeExit.Delta, NodeExit.Epsilon, NodeExit.Eta, NodeExit.Gamma,
				NodeExit.Iota, NodeExit.Kappa, NodeExit.Lambda, NodeExit.Mu, NodeExit.Theta, NodeExit.Zeta
			};
			foreach (SampleMockNodeInformation node in ret) {
				int startLayer = node.Layer;
				int startRow = node.Row;
				int startColumn = node.Column;
				int startIndex = node.IndexInLayer;

				var currRow0 = startRow - 1;
				var currColumns0 = new int[]{ startColumn, startColumn + 1 };
				var currRow1 = startRow;
				var currColumns1 = new int[] { startColumn - 1, startColumn + 1 };
				var currRow2 = startRow + 1;
				var currColumns2 = new int[] { startColumn - 1, startColumn };
				var currNodes = (from n in ret
								 where n.Layer == startLayer
								 where (n.Row == currRow0 && currColumns0.Contains(n.Column))
									|| (n.Row == currRow1 && currColumns1.Contains(n.Column))
									|| (n.Row == currRow2 && currColumns2.Contains(n.Column))
								 select n).ToList();

				int nextLayer = startLayer + 1;
				var nextRow0 = startRow;
				var nextColumns0 = new int[] { startColumn };
				var nextRow1 = startRow - 1;
				var nextColumns1 = new int[] { startColumn - 1, startColumn };

				var nextNodes = (from n in ret
								 where n.Layer == nextLayer
								 where (n.Row == nextRow0 && nextColumns0.Contains(n.Column))
									|| (n.Row == nextRow1 && nextColumns1.Contains(n.Column))
								 select n).ToList();

				var nestedNodes = currNodes.Concat(nextNodes).ToList();
				//var connectedNodes = currNodes.Concat(nextNodes).ToList();
				var connectedNodes = (from n in nestedNodes
									  let currN = n.Exits.Where(kp => kp.Value == node).Select(kp => kp.Value).FirstOrDefault()
									  where null == currN
									  select n).ToList();

				var currAvailableExits = new List<NodeExit>(exits.Except(node.Exits.Keys));
				for (int i = 0; i < connectedNodes.Count; i++) {
					var nextNode = connectedNodes[i];
					var exit = currAvailableExits[i];
					node.Exits.Add(exit, nextNode);

					var connAvailableExits = new List<NodeExit>(exits.Except(nextNode.Exits.Keys));
					var nextExit = connAvailableExits.First();
					nextNode.Exits.Add(nextExit, node);
				}

			}
			/* <<< joining the nodes */

			/*
			 * 0 1 2 3
			 *				0 1 2
			 *  4 5 6				0 1
			 *				 3 4			0
			 *   7 8				 2
			 *				  5
			 *    9
			 *    
			 * 
			 * L0:0 -> L0:{1,4}			+ L1:0						= 3
			 * L0:1 -> L0:{0,2,4,5}		+ L1:{0,1}					= 6
			 * L0:2 -> L0:{1,3,5,6}		+ L1:{1,2}					= 6
			 * L0:3 -> L0:{2,6}			+ L1:2						= 3
			 * L0:4 -> L0:{0,1,5}		+ L1:{0,3}					= 5
			 * L0:5 -> L0:{1,2,4,6,7,8}	+ L1:{1,3,4}				= 9
			 * L0:6 -> L0:{2,3,5,8}		+ L1:{2,4}					= 6
			 * L0:7 -> L0:{4,5,8,9}		+ L1:{3,5}					= 6
			 * L0:8 -> L0:{5,6,7,9}		+ L1:{4,5}					= 6
			 * L0:9 -> L0:{7,8}			+ L1:5						= 3
			 * 
			 * L1:0 -> L1:{1,3}			+ L0:{0,1,4}	+ L2:0		= 6
			 * L1:1 -> L1:{0,2,3,4}		+ L0:{1,2,5}	+ L2:{0,1}	= 9
			 * L1:2 -> L1:{1,4}			+ L0:{2,3,4}	+ L2:1		= 6
			 * L1:3 -> L1:{0,1,4,5}		+ L0:{4,5,7}	+ L2:{0,2}	= 9
			 * L1:4 -> L1:{1,2,3,5}		+ L0:{5,6,8}	+ L2:{1,2}	= 9
			 * L1:5 -> L1:{3,4}			+ L0:{7,8,9}	+ L2:2		= 6
			 * 
			 * L2:0 -> L2:{1,2}			+ L1:{0,1,3}	+ L3:0		= 6
			 * L2:1 -> L2:{0,2}			+ L1:{1,2,4}	+ L3:0		= 6
			 * L2:2 -> L2:{0,1}			+ L1:{3,4,5}	+ L3:0		= 6
			 * 
			 * L3:0 -> L3:<->			+ L2:{0,1,2}				= 3
			 * 
			 * 
			 * X X X X	XXXX
			 *  X X X	XXX
			 *   X X	XX
			 *    X		X
			 *    
			 * 0 1 2 3	0123
			 *  4 5 6	456
			 *   7 8	78
			 *    9		9
			 *    
			 *    
			 *  R 0123		012		12		1
			 * C  
			 * 0  0123		012		12		1
			 * 1  456		34		3
			 * 2  78		5
			 * 3  9
			*/


			return ret;
		}
Exemple #7
0
 public NodeConnection(Node n, NodeExit conn)
 {
     node      = n;
     localExit = conn;
 }