Exemplo n.º 1
0
    private void SetCellNoneEnterRisksLevel2(int x, int y, CellNode cellNode, CellNode[] nodes, int columns)
    {
        if (cellNode.ngbrPlayerPawnsCount[0] >= 4)
        {
            bool NodeIsPlayerPawn(int nodeX, int nodeY)
            {
                return(nodes[GetCellNodeIndex(nodeX, nodeY, columns)].isPlayerPawn);
            }

            bool[] ngbrsEnterRisk = cellNode.ngbrsEnterRisk;
            for (int i = 4; i < 8; i++)
            {
                Vector2Int delta    = _cellNgbrsDeltaXY[i].Negative();
                int        signDxDy = Math.Sign(delta.x * delta.y);
                ngbrsEnterRisk[i] |=
                    NodeIsPlayerPawn(x, y - delta.y) &&
                    NodeIsPlayerPawn(x - delta.x, y) &&
                    NodeIsPlayerPawn(x - 1, y + signDxDy) &&
                    NodeIsPlayerPawn(x + 1, y - signDxDy);
            }
            ngbrsEnterRisk[1] |= ngbrsEnterRisk[7];
            ngbrsEnterRisk[3] |= ngbrsEnterRisk[7];
            ngbrsEnterRisk[0] |= ngbrsEnterRisk[4];
            ngbrsEnterRisk[2] |= ngbrsEnterRisk[4];
            ngbrsEnterRisk[1] |= ngbrsEnterRisk[5];
            ngbrsEnterRisk[2] |= ngbrsEnterRisk[5];
            ngbrsEnterRisk[0] |= ngbrsEnterRisk[6];
            ngbrsEnterRisk[3] |= ngbrsEnterRisk[6];
        }
    }
Exemplo n.º 2
0
    private List <Vector2Int> CreatePath(CellNode[] nodes, Bounds2Int bounds, Vector2Int begXY, Vector2Int endXY)
    {
        List <Vector2Int> path    = new List <Vector2Int>();
        CellNode          endNode = nodes[GetCellNodeIndex(endXY, bounds.Size)];

        if (begXY != endXY && endNode.distance < float.MaxValue / 2f)
        {
            //Debug.Log(GetType() + ".GetPath: " + begXY + "->" + endXY);
            CellNode begNode       = nodes[GetCellNodeIndex(begXY, bounds.Size)];
            bool     begNodeLocked = begNode.locked;
            begNode.locked = false;

            Vector2Int nodeXY = endXY;
            path.Add(nodeXY);
            while (nodeXY != begXY)
            {
                nodeXY = GetMinDistanceNgbrCellNodeXY(nodes, nodeXY, bounds);
                path.Add(nodeXY);
            }
            if (path.Count > 1)
            {
                path.RemoveAt(path.Count - 1);
            }
            for (int i = 0; i < path.Count; i++)
            {
                path[i] += bounds.Min;
                //Debug.Log(GetType() + ".GetPath: " + path[i]);
            }
            begNode.locked = begNodeLocked;
        }
        return(path);
    }
Exemplo n.º 3
0
        private static void FillMatrixRowsToWorksheet(WorkbookNode workbook, WfMatrix matrix, bool roleAsPerson)
        {
            NamedLocationCollection locations = workbook.Names.ToLocations();

            locations.SortByColumn();

            WorksheetNode worksheet       = workbook.Worksheets[GetWorksheet(locations)];
            int           startRowIndex   = GetStartRow(locations);
            int           currentRowIndex = -1;

            foreach (WfMatrixRow matrixRow in matrix.Rows)
            {
                RowNode row = new RowNode();

                if (currentRowIndex == -1)
                {
                    currentRowIndex = startRowIndex + 1;
                    row.Index       = currentRowIndex;
                }

                foreach (CellLocation location in locations)
                {
                    CellNode     cell  = new CellNode();
                    WfMatrixCell mCell = matrixRow.Cells.Find(c => c.Definition.DimensionKey == location.Name);

                    if (mCell != null)
                    {
                        cell.Data.Value = GetCellValue(roleAsPerson, mCell, matrixRow);
                    }
                    row.Cells.Add(cell);
                }

                worksheet.Table.Rows.Add(row);
            }
        }
Exemplo n.º 4
0
    private HashSet <Vector2Int> UpdateCellNodes(CellNode[] nodes, Bounds2Int bounds, HashSet <Vector2Int> nodesXY, Vector2Int targetXY,
                                                 ref bool targetReached)
    {
        HashSet <Vector2Int> nextNodesXY = new HashSet <Vector2Int>();
        //targetReached = false;
        Func <CellNode, int, bool> ngbrClosed = null;

        if (_cellNodeEnterRiskLevel > 0)
        {
            ngbrClosed = (ngbrNode, i) => ngbrNode.ngbrsEnterRisk[i];
        }
        else
        {
            ngbrClosed = (ngbrNode, i) => false;
        }
        foreach (var nodeXY in nodesXY)
        {
            int      nodeIndex = GetCellNodeIndex(nodeXY, bounds.Size);
            CellNode node      = nodes[nodeIndex];
            node.@checked = true;
            nextNodesXY.Remove(nodeXY);
            for (int i = 0; i < _cellNgbrsDeltaXY.Length; i++)
            {
                Vector2Int ngbrDeltaXY = _cellNgbrsDeltaXY[i];
                Vector2Int ngbrXY      = nodeXY + ngbrDeltaXY;
                if (CellNodeInBounds(ngbrXY, bounds.Size))
                {
                    int      ngbrNodeIndex = GetCellNodeIndex(ngbrXY, bounds.Size);
                    CellNode ngbrNode      = nodes[ngbrNodeIndex];
                    if (!ngbrNode.locked && !ngbrClosed(ngbrNode, i))
                    {
                        float delta = ngbrDeltaXY.x == 0 || ngbrDeltaXY.y == 0 ? 1f : SQRT2;
#if LOCKED_CELLS_HEIGHTS
                        for (int j = 0; j < 3; j++)
                        {
                            delta += 1.5f * ngbrNode.lockedNgbrsCount[j] / (8 * (i + 1));
                        }
#endif
                        float ngbrDistance = node.distance + delta * 0.25f + ngbrNode.ngbrPlayerPawnsCount[0];
                        //float ngbrDistance = node.distance + delta;
                        if ((!ngbrNode.@checked || ngbrDistance < ngbrNode.distance) && !nextNodesXY.Contains(ngbrXY))
                        {
                            nextNodesXY.Add(ngbrXY);
                        }
                        ngbrNode.distance = Mathf.Min(ngbrNode.distance, ngbrDistance);
#if DEBUG_SHOW_DISTANCES
                        SetTileMeshText(ngbrXY + bounds.Min, ngbrNode.distance.ToString("F1") + "\n" + ngbrNode.ngbrPlayerPawnsCount[0]);
#endif
                        if (ngbrXY == targetXY)
                        {
                            targetReached = true;
                            //nextNodesXY.Clear();
                            //return nextNodesXY;
                        }
                    }
                }
            }
        }
        return(nextNodesXY);
    }
Exemplo n.º 5
0
        private bool AddToRow(RowNode rowNode, CellNode entryNode)
        {
            var curr = rowNode.Right;

            if (curr == null)
            {
                rowNode.Right = entryNode;
                return(true);
            }
            var        prevOfCurr  = curr.Left;
            ColumnType entryColumn = entryNode.Value.GetColumn();
            ColumnType currColumn;
            int        comparisonResult;

            while (curr != null)
            {
                currColumn       = curr.Value.GetColumn();
                comparisonResult = currColumn.CompareTo(entryColumn);
                if (comparisonResult == 0)
                {
                    return(false);
                }
                else if (comparisonResult > 0)
                {
                    var prevNode = curr.Left;
                    var nextNode = curr;

                    if (prevNode == null)//El nodo a insertar es first
                    {
                        rowNode.Right  = entryNode;
                        entryNode.Left = null;
                    }
                    else
                    {
                        prevNode.Right = entryNode;
                        entryNode.Left = prevNode;
                    }

                    nextNode.Left   = entryNode;
                    entryNode.Right = nextNode;

                    return(true);
                }
                prevOfCurr = curr;
                curr       = curr.Right;
            }
            //Como ahora curr es null tenemos que movernos de regreso a su 'prev'
            curr             = prevOfCurr;
            currColumn       = curr.Value.GetColumn();
            comparisonResult = currColumn.CompareTo(entryColumn);
            if (comparisonResult == 0)
            {
                return(false);
            }

            curr.Right     = entryNode;
            entryNode.Left = curr;

            return(true);
        }
Exemplo n.º 6
0
        private bool AddToColumn(ColumnNode columnNode, CellNode entryNode)
        {
            var curr = columnNode.Down;

            if (curr == null)
            {
                columnNode.Down = entryNode;
                return(true);
            }
            var     prevOfCurr = curr.Up;
            RowType entryRow   = entryNode.Value.GetRow();
            RowType currRow;
            int     comparisonResult;

            while (curr != null)
            {
                currRow          = curr.Value.GetRow();
                comparisonResult = currRow.CompareTo(entryRow);
                if (comparisonResult == 0)
                {
                    return(false);
                }
                else if (comparisonResult > 0)
                {
                    var prevNode = curr.Up;
                    var nextNode = curr;

                    if (prevNode == null)//El nodo a insertar es first
                    {
                        columnNode.Down = entryNode;
                        entryNode.Up    = null;
                    }
                    else
                    {
                        prevNode.Down = entryNode;
                        entryNode.Up  = prevNode;
                    }

                    nextNode.Up    = entryNode;
                    entryNode.Down = nextNode;

                    return(true);
                }
                prevOfCurr = curr;
                curr       = curr.Down;
            }
            //Como ahora curr es null tenemos que movernos de regreso a su 'prev'
            curr             = prevOfCurr;
            currRow          = curr.Value.GetRow();
            comparisonResult = currRow.CompareTo(entryRow);
            if (comparisonResult == 0)
            {
                return(false);
            }

            curr.Down    = entryNode;
            entryNode.Up = curr;

            return(true);
        }
Exemplo n.º 7
0
 public CellNode(int x, int y, CellNode dChild, CellNode rChild)
 {
     X = x;
     Y - y;
     DChild = dChild;
     RChild = rChild;
 }
Exemplo n.º 8
0
        public bool Add(CellType entry)
        {
            if (entry is null)
            {
                throw new ArgumentNullException(nameof(entry));
            }

            var entryRow    = entry.GetRow();
            var entryColumn = entry.GetColumn();

            var matrixRowNode    = GetOrAddRowNode(entryRow);
            var matrixColumnNode = GetOrAddColumnNode(entryColumn);

            var entryNode = new CellNode(entry);

            if (!AddToRow(matrixRowNode, entryNode))
            {
                return(false);
            }

            if (!AddToColumn(matrixColumnNode, entryNode))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 9
0
        public void Add(RBTUnit unit)
        {
            if (_unitToCells.ContainsKey(unit))
            {
                return;
            }
            else
            {
                _unitToCells.Add(unit, new List <CellNode>());
            }

            var cellIndices = CalcOccupiedCells(unit);

            foreach (var cellIndex in cellIndices)
            {
                var newHead = new CellNode()
                {
                    unit = unit, cellIndex = cellIndex
                };
                if (_indexToCell.ContainsKey(cellIndex))
                {
                    var prevHead = _indexToCell[cellIndex];
                    prevHead.previous = newHead;
                    newHead.next      = prevHead;
                }

                _indexToCell[cellIndex] = newHead;
                _unitToCells[unit].Add(newHead);
            }
        }
Exemplo n.º 10
0
    private static int GetManhattenDistance(CellNode a_nodeA, CellNode a_nodeB)
    {
        int x = Mathf.Abs(a_nodeA.GridX - a_nodeB.GridX);
        int y = Mathf.Abs(a_nodeA.GridY - a_nodeB.GridY);

        return(x + y);
    }
Exemplo n.º 11
0
    private void GenerateHexagonGrid()
    {
        float offsetX = 0.38f;
        float offsetZ = 0.32f;

        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                float posX = x * offsetX;

                if (y % 2 == 1)
                {
                    posX += offsetX / 2;
                }

                GameObject _newCell = Instantiate(PrefabCell, new Vector3(posX, 0, y * offsetZ), Quaternion.identity);

                CellBase _cell = _newCell.GetComponent <CellBase>();
                CellNode _node = new CellNode();
                _node.GridX = x;
                _node.GridY = y;
                _cell.SetNode(_node);

                _newCell.transform.parent = ParentForCells;
            }
        }
    }
Exemplo n.º 12
0
        /// <summary>
        /// Generates all nodes that are adjacent to the given node. Nodes re only considered adjacent if they share a pathgroup.
        /// </summary>
        /// <param name="currentNode"></param>
        /// <returns></returns>
        private List <CellNode> GetValidNeighbors(CellNode currentNode)
        {
            IRectGrid nodeCell      = latticePathData[currentNode.Position.xPos, currentNode.Position.yPos];
            int       nodePathGroup = nodeCell.PathGroup();

            List <CellNode> neighbors = new List <CellNode>();

            //left
            if (latticePathData[currentNode.Position.xPos, currentNode.Position.yPos, Direction.West].PathGroup() == nodePathGroup)
            {
                if (currentNode.Position.xPos != 0)
                {
                    var potentialNeighbor = latticePathData[currentNode.Position.xPos - 1, currentNode.Position.yPos];
                    if (potentialNeighbor.PathGroup() == nodePathGroup)
                    {
                        neighbors.Add(new CellNode(new Position(currentNode.Position.xPos - 1, currentNode.Position.yPos), 1 * potentialNeighbor.PathModifier()));
                    }
                }
            }
            //right
            if (latticePathData[currentNode.Position.xPos, currentNode.Position.yPos, Direction.East].PathGroup() == nodePathGroup)
            {
                if (currentNode.Position.xPos < latticePathData.Width - 1)
                {
                    var potentialNeighbor = latticePathData[currentNode.Position.xPos + 1, currentNode.Position.yPos];
                    if (potentialNeighbor.PathGroup() == nodePathGroup)
                    {
                        neighbors.Add(new CellNode(new Position(currentNode.Position.xPos + 1, currentNode.Position.yPos), 1 * potentialNeighbor.PathModifier()));
                    }
                }
            }
            //down
            if (latticePathData[currentNode.Position.xPos, currentNode.Position.yPos, Direction.South].PathGroup() == nodePathGroup)
            {
                if (currentNode.Position.yPos != 0)
                {
                    var potentialNeighbor = latticePathData[currentNode.Position.xPos, currentNode.Position.yPos - 1];
                    if (potentialNeighbor.PathGroup() == nodePathGroup)
                    {
                        neighbors.Add(new CellNode(new Position(currentNode.Position.xPos, currentNode.Position.yPos - 1), 1 * potentialNeighbor.PathModifier()));
                    }
                }
            }
            //up
            if (latticePathData[currentNode.Position.xPos, currentNode.Position.yPos, Direction.North].PathGroup() == nodePathGroup)
            {
                if (currentNode.Position.yPos < latticePathData.Height - 1)
                {
                    var potentialNeighbor = latticePathData[currentNode.Position.xPos, currentNode.Position.yPos + 1];
                    if (potentialNeighbor.PathGroup() == nodePathGroup)
                    {
                        neighbors.Add(new CellNode(new Position(currentNode.Position.xPos, currentNode.Position.yPos + 1), 1 * potentialNeighbor.PathModifier()));
                    }
                }
            }

            return(neighbors);
        }
Exemplo n.º 13
0
        public void AddChild(int index, CellNode child)
        {
            if (IsLeaf)
            {
                children = new CellNode[4];
            }

            children[index] = child;
            child.parent    = this;
        }
Exemplo n.º 14
0
 public void ClearMap()
 {
     for (int y = 0; y < m_height; y++)
     {
         for (int x = 0; x < m_width; x++)
         {
             m_cells[WrapX(x), WrapY(y)] = new CellNode(x, y);
         }
     }
 }
Exemplo n.º 15
0
    void PlacePath()
    {
        //m_rootNode = m_cellMap.GetCell(0, 0);
        m_rootNode = m_cellMap.RandomCell(CellState.EMPTY);
        Carve(m_rootNode, 0);
        m_rootNode.Reduce(CellState.DOOR);

        pathNodes = new List <CellNode>();
        m_rootNode.AllChildren(ref pathNodes);
    }
Exemplo n.º 16
0
        public CellNode[] GetImmediateCellNeighbours(int x, int y)
        {
            CellNode[] neighbours = new CellNode[4];

            neighbours[0] = (y >= m_height - 1 && !wrap) ? null : m_cells[WrapX(x), WrapY(y + 1)];
            neighbours[1] = (x >= m_width - 1 && !wrap) ? null : m_cells[WrapX(x + 1), WrapY(y)];
            neighbours[2] = (y <= 1 && !wrap) ? null : m_cells[WrapX(x), WrapY(y - 1)];
            neighbours[3] = (x < 1 && !wrap) ? null : m_cells[WrapX(x - 1), WrapY(y)];

            return(neighbours);
        }
Exemplo n.º 17
0
        public void PutCellTriangleIndexesToArray(int beginPosition, int[] triangleArray, int x, int z)
        {
            CellNode cell = cells [z, x];

            triangleArray [beginPosition++] = ((IndexedFixedVertex3D)cell.bl_tr_tl.A).index;
            triangleArray [beginPosition++] = ((IndexedFixedVertex3D)cell.bl_tr_tl.C).index;
            triangleArray [beginPosition++] = ((IndexedFixedVertex3D)cell.bl_tr_tl.B).index;
            triangleArray [beginPosition++] = ((IndexedFixedVertex3D)cell.bl_tr_br.B).index;
            triangleArray [beginPosition++] = ((IndexedFixedVertex3D)cell.bl_tr_br.C).index;
            triangleArray [beginPosition++] = ((IndexedFixedVertex3D)cell.bl_tr_br.A).index;
        }
Exemplo n.º 18
0
        private static WfMatrixRow GenerateMatrixRow(WfMatrix matrix, RowNode rowNode, NamedLocationCollection locations, int index)
        {
            WfMatrixRow mRow = new WfMatrixRow(matrix);

            mRow.RowNumber = index;

            int emptyCellCount = 0;

            foreach (WfMatrixDimensionDefinition dd in matrix.Definition.Dimensions)
            {
                CellLocation location = locations[dd.DimensionKey];

                CellNode cell = rowNode.GetCellByIndex(location.Column);

                WfMatrixCell mCell = new WfMatrixCell(dd);

                mCell.StringValue = cell.Data.InnerText.Trim();

                mRow.Cells.Add(mCell);

                switch (dd.DimensionKey)
                {
                case "Operator":
                    mRow.Operator = cell.Data.InnerText;
                    break;

                case "OperatorType":
                    WfMatrixOperatorType opType = WfMatrixOperatorType.Person;
                    Enum.TryParse(cell.Data.InnerText, out opType);
                    mRow.OperatorType = opType;
                    break;

                default:
                    if (mCell.StringValue.IsNullOrEmpty())
                    {
                        emptyCellCount++;
                    }
                    break;
                }
            }

            if (emptyCellCount >= matrix.Definition.Dimensions.Count - 2)
            {
                //如果每一列都为空(不算Operator和OperatorType),那么认为整行都为空
                mRow = null;
            }
            else
            {
                matrix.Rows.Add(mRow);
            }

            return(mRow);
        }
Exemplo n.º 19
0
        private void DeleteNode(RowNode rowNode, CellNode cellNode)
        {
            //Eliminar de fila
            var left  = cellNode.Left;
            var right = cellNode.Right;

            if (left == null && right == null)//Es el unico nodo en la fila
            {
                DeleteRow(rowNode);
            }

            if (left == null)//curr es first
            {
                rowNode.Right = right;
            }
            else
            {
                left.Right = right;
            }

            if (right != null)
            {
                left.Right = right;
            }

            //Eliminar de columna
            var up   = cellNode.Up;
            var down = cellNode.Down;

            if (up == null && down == null)                                 //Es el unico nodo en la fila
            {
                var columnNode = GetColumnNode(cellNode.Value.GetColumn()); //No se va usar en todos los caso pero igual la vamos a obtener siempre
                DeleteColumn(columnNode);
            }

            if (up == null)                                                 //curr es first
            {
                var columnNode = GetColumnNode(cellNode.Value.GetColumn()); //No se va usar en todos los caso pero igual la vamos a obtener siempre
                columnNode.Down = down;
            }
            else
            {
                up.Down = down;
            }

            if (down != null)
            {
                down.Up = up;
            }
        }
Exemplo n.º 20
0
    private void SetCellNodesNgbrPlayerPawnsCount(CellNode[] nodes, Bounds2Int bounds)
    {
        Vector2Int size    = bounds.Size;
        int        columns = bounds.Size.x;

        for (int y = 1; y < size.y - 1; y++)
        {
            for (int x = 1; x < size.x - 1; x++)
            {
                CellNode cellNode = nodes[GetCellNodeIndex(x, y, columns)];
                if (!cellNode.locked)
                {
                    for (int k = 0; k < 3; k++)
                    {
                        cellNode.ngbrPlayerPawnsCount[k] = 0;
                        int   n_even = 2 + 2 * k;
                        int   n_odd  = n_even + 1; //3 + 2 * k;
                        int[] deltaJ = new int[n_odd];
                        for (int j = 1; j < n_odd - 1; j++)
                        {
                            deltaJ[j] = n_even;
                        }
                        deltaJ[0] = deltaJ[n_odd - 1] = 1;
                        //string s = "\n";
                        int offset = k + 1;
                        for (int i = 0; i < n_odd; i++)
                        {
                            int dy = i - offset;
                            for (int j = 0; j < n_odd; j += deltaJ[i])
                            {
                                int        dx     = j - offset;
                                Vector2Int ngbrXY = new Vector2Int(x + dx, y + dy);
                                //s += "(" + dx + "," + dy + ")";
                                if (CellNodeInBounds(ngbrXY, bounds.Size))
                                {
                                    int      ngbrNodeIndex = GetCellNodeIndex(ngbrXY, bounds.Size);
                                    CellNode ngbrNode      = nodes[ngbrNodeIndex];
                                    cellNode.ngbrPlayerPawnsCount[k] += ngbrNode.isPlayerPawn ? 1 : 0;
                                }
                            }
                            //s += "\n";
                        }
                        //Debug.Log(GetType() + "." + s);
                    }
                }
            }
        }
    }
Exemplo n.º 21
0
 private void CreateCells()
 {
     this.cells = new CellNode[height, width];
     for (int z = 0; z < height; z++)
     {
         for (int x = 0; x < width; x++)
         {
             cells [z, x] = new CellNode(
                 GetVertexForCell(x, z, BOT_LEF),
                 GetVertexForCell(x, z, BOT_RIG),
                 GetVertexForCell(x, z, TOP_LEF),
                 GetVertexForCell(x, z, TOP_RIG),
                 cellSize * x, cellSize * z);
         }
     }
 }
Exemplo n.º 22
0
        private static void FillWorkbook(WfMatrixDefinition definition, WorkbookNode workbook, WfMatrixDefinitionExportOptions options)
        {
            WorksheetNode worksheet = GetWorksheetFromWorkbook(workbook, options);

            worksheet.Names.Clear();
            workbook.Names.Clear();

            worksheet.Table.Rows[1].Cells.Clear();

            int row    = options.StartRow;
            int column = options.StartColumn;

            RowNode titleRow = null;

            if (worksheet.Table.Rows.Count > 0)
            {
                titleRow = worksheet.Table.Rows[1];
            }
            else
            {
                titleRow = new RowNode();
                worksheet.Table.Rows.Add(titleRow);
            }

            foreach (WfMatrixDimensionDefinition dd in definition.Dimensions)
            {
                NamedRangeNode range = new NamedRangeNode();

                range.Name = dd.DimensionKey;

                range.RefersTo = string.Format("={0}!R{1}C{2}", worksheet.Name, row, column);
                workbook.Names.Add(range);

                CellNode cell = new CellNode();

                cell.Data.Value = dd.Name;

                if (options.TitleCellStyleID.IsNotEmpty())
                {
                    cell.StyleID = options.TitleCellStyleID;
                }

                titleRow.Cells.Add(cell);

                column++;
            }
        }
Exemplo n.º 23
0
    private CellNode[] CreateCellNodes(Vector2Int begXY, Vector2Int endXY, Bounds2Int bounds,
                                       List <PawnTransition> pawnTransitions, params Transform[] contentContainers)
    {
        var nodes = new CellNode[bounds.Size.x * bounds.Size.y];

        for (int i = 0; i < nodes.Length; i++)
        {
            nodes[i] = new CellNode();
        }
        int columns = bounds.Size.x;
        int nodeIndex;

        foreach (Transform container in contentContainers)
        {
            bool isPlayerPawnsContainer = container.childCount > 0 && container.GetChild(0).GetComponent <PlayerPawn>();
            foreach (Transform child in container)
            {
                Vector2Int cell = _tilemap.WorldToCell(child.position);
                nodeIndex = GetCellNodeIndex(cell - bounds.Min, columns);
                nodes[nodeIndex].locked       = true;
                nodes[nodeIndex].isPlayerPawn = isPlayerPawnsContainer;
            }
        }
        if (pawnTransitions != null)
        {
            foreach (var pawnTransition in pawnTransitions)
            {
                nodeIndex = GetCellNodeIndex(pawnTransition.EndCell - bounds.Min, columns);
                nodes[nodeIndex].locked = true;
                nodeIndex = GetCellNodeIndex(pawnTransition.BegCell - bounds.Min, columns);
                nodes[nodeIndex].locked = false;
            }
        }
        CellNode begNode = nodes[GetCellNodeIndex(begXY, columns)];
        CellNode endNode = nodes[GetCellNodeIndex(endXY, columns)];

        begNode.distance = 0f;
        begNode.locked   = false;
        endNode.locked   = false;

        SetCellNodesNgbrPlayerPawnsCount(nodes, bounds);
        SetCellNodesEnterRisks(nodes, bounds, begXY, endXY);
        ResetCellNodesNgbrPlayerPawnsCountAroundTarged(nodes, bounds, endXY, 2);

        return(nodes);
    }
Exemplo n.º 24
0
        private SOARolePropertyRow GenerateMatrixRow(SOARole role, RowNode rowNode, NamedLocationCollection locations, int index)
        {
            SOARolePropertyRow mRow = new SOARolePropertyRow(role);

            mRow.RowNumber = index;

            int emptyCellCount = 0;

            foreach (var row in this.Definition)
            {
                CellLocation location = locations[row.Name];

                CellNode cell = rowNode.GetCellByIndex(location.Column);

                SOARolePropertyValue mCell = new SOARolePropertyValue(row);

                mCell.Value = cell.Data.InnerText.Trim();

                mRow.Values.Add(mCell);

                switch (row.Name)
                {
                case "Operator":
                    mRow.Operator = cell.Data.InnerText;
                    break;

                case "OperatorType":
                    SOARoleOperatorType opType = SOARoleOperatorType.User;
                    Enum.TryParse(cell.Data.InnerText, out opType);
                    mRow.OperatorType = opType;
                    break;

                default:
                    if (mCell.Value.IsNullOrEmpty())
                    {
                        emptyCellCount++;
                    }
                    break;
                }
            }

            role.Rows.Add(mRow);

            return(mRow);
        }
Exemplo n.º 25
0
        /// <summary>
        /// 填充Excel Xml的标题列
        /// </summary>
        /// <param name="workbook"></param>
        /// <param name="definition"></param>
        /// <param name="propertySheetName"></param>
        private static void FillWorkSheetTitle(WorkbookNode workbook, SOARolePropertyDefinitionCollection definition, string propertySheetName)
        {
            WorksheetNode worksheet = GetWorksheetFromWorkbook(workbook, propertySheetName);

            worksheet.Names.Clear();
            workbook.Names.Clear();

            worksheet.Table.Rows[1].Cells.Clear();

            int row    = 3;
            int column = 1;

            RowNode titleRow = null;

            if (worksheet.Table.Rows.Count > 0)
            {
                titleRow = worksheet.Table.Rows[1];
            }
            else
            {
                titleRow = new RowNode();
                worksheet.Table.Rows.Add(titleRow);
            }

            foreach (SOARolePropertyDefinition dd in definition)
            {
                NamedRangeNode range = new NamedRangeNode();

                range.Name = dd.Name;

                range.RefersTo = string.Format("={0}!R{1}C{2}", worksheet.Name, row, column);
                workbook.Names.Add(range);

                CellNode cell = new CellNode();

                cell.Data.Value = dd.Description.IsNotEmpty() ? dd.Description : dd.Name;

                cell.StyleID = "s17";

                titleRow.Cells.Add(cell);

                column++;
            }
        }
Exemplo n.º 26
0
    void Start()
    {
        float xInitialOffset = 0.455f;
        float yInitialOffset = -0.307f;

        float xOffset = 0.8895f;
        float yOffset = -0.578f;


        grid = new CellNode[gridHeight][];
        for (int i = 0; i < gridHeight; i++)
        {
            grid[i] = new CellNode[gridWidth];
            for (int j = 0; j < gridWidth; j++)
            {
                grid[i][j] = (Instantiate(cellPrefab, new Vector3(transform.position.x + xInitialOffset + xOffset * j, transform.position.y + yInitialOffset + yOffset * i, transform.position.z - 0.00001f), transform.rotation, transform) as GameObject).GetComponent <CellNode>();
            }
        }
    }
Exemplo n.º 27
0
            public int[][] Solve()
            {
                var start = new CellNode()
                {
                    RowConstraints    = RowRules,
                    ColumnConstraints = ColRules,
                    Current           = new Cell(0, 0, 0),
                    Previous          = Enumerable.Empty <Cell>(),
                    Seed = new Seed(_size),
                    Size = _size
                };
                var solution = start.Solve();

                if (solution.Count() > 0)
                {
                    return(GetSolution(solution));
                }
                return(null);
            }
Exemplo n.º 28
0
    void GenerateGride()
    {
        float nodeRaduis = nodeDiameter / 2f;

        grid = new CellNode[gridSizeX, gridSizeY];
        Vector3 baseButtomLeft = transform.right * (-gridSizeX * nodeRaduis) + transform.forward * (-gridSizeY * nodeRaduis);

        for (int y = 0; y < gridSizeY; y++)
        {
            for (int x = 0; x < gridSizeX; x++)
            {
                float   pointX   = baseButtomLeft.x + (x * nodeDiameter) + (nodeRaduis);
                float   pointZ   = baseButtomLeft.z + (y * nodeDiameter) + (nodeRaduis);
                Vector3 pointPos = new Vector3(pointX, 0, pointZ);
                grid[x, y] = new CellNode()
                {
                    isWalkable = true, gridX = x, gridY = y, worldPoint = pointPos
                };
            }
        }
    }
Exemplo n.º 29
0
    private Vector2Int GetMinDistanceNgbrCellNodeXY(CellNode[] nodes, Vector2Int nodeXY, Bounds2Int bounds)
    {
        float      minDistance   = float.MaxValue;
        Vector2Int minDistNgbrXY = default;

        foreach (var ngbrDeltaXY in _cellNgbrsDeltaXY)
        {
            Vector2Int ngbrXY = nodeXY + ngbrDeltaXY;
            if (CellNodeInBounds(ngbrXY, bounds.Size))
            {
                int      ngbrNodeIndex = GetCellNodeIndex(ngbrXY, bounds.Size);
                CellNode ngbrNode      = nodes[ngbrNodeIndex];
                if (!ngbrNode.locked && ngbrNode.distance < minDistance)
                {
                    minDistance   = ngbrNode.distance;
                    minDistNgbrXY = ngbrXY;
                }
            }
        }
        //Debug.Log(GetType() + ".GetMinDistanceCellNodeNgbrXY: " + minDistNgbrXY);
        return(minDistNgbrXY);
    }
Exemplo n.º 30
0
    private void ResetCellNodesNgbrPlayerPawnsCountAroundTarged(CellNode[] nodes, Bounds2Int bounds, Vector2Int endXY, int offset)
    {
        int columns = bounds.Size.x;

        for (int y = endXY.y - offset; y <= endXY.y + offset; y++)
        {
            for (int x = endXY.x - offset; x <= endXY.x + offset; x++)
            {
                if (CellNodeInBounds(x, y, bounds.Size))
                {
                    CellNode cellNode = nodes[GetCellNodeIndex(x, y, columns)];
                    if (!cellNode.locked)
                    {
                        for (int k = 0; k < 3; k++)
                        {
                            cellNode.ngbrPlayerPawnsCount[k] = 0;
                        }
                    }
                }
            }
        }
    }