Exemple #1
0
    /// <summary>
    /// returns a list of blocks that are accesable from the current block
    /// </summary>
    /// <param name="currentNode"> current position </param>
    /// <param name="Grid"> The grid information </param>
    /// <returns></returns>
    /// 
    List<Node> getSuccesors(Node currentNode, BlockType[,] Grid, successorCheck isSuccessor)
    {
        List<Node> successors = new List<Node>();

        int GridHeight = Grid.GetLength(0); //get the dimensions of the grid
        int GridWidth = Grid.GetLength(1);

        //for every possible add the possible successors to the list
        for (int i = 0; i < Enum.GetNames(typeof(Action)).Length; i++)
        {
            Node successor = new Node(currentNode);
            successor.pos = currentNode.pos;

            switch ((Action)i)
            {
                case Action.Left:
                    {
                        successor.pos.column--;

                        if (successor.pos.column >= 0 && isSuccessor(successor, Grid)) //if the block is not out of bounds and satisfies the conditions of isSuccessor, add it
                            successors.Add(successor);
                        break;
                    }
                case Action.Right:
                    {
                        successor.pos.column++;

                        if (successor.pos.column < GridWidth && isSuccessor(successor, Grid))
                            successors.Add(successor);
                        break;
                    }
                case Action.Up:
                    {
                        successor.pos.row--;

                        if (successor.pos.row >= 0 && isSuccessor(successor, Grid))
                            successors.Add(successor);
                        break;
                    }
                case Action.Down:
                    {
                        successor.pos.row++;

                        if (successor.pos.row < GridHeight && isSuccessor(successor, Grid))
                            successors.Add(successor);
                        break;
                    }
            }
        }

        return successors;
    }