Esempio n. 1
0
    public SquareGraphElem FindFirstSave(Square square)
    {
        SquareGraphElem save = LookAround(square, IsThisSquareNotSave, ReturnSquare);

        //save.mySquare.GetComponent<Image>().color = (Color.blue + Color.red) / 2; //przenosc target niech pokazuje
        return(save);
    }
Esempio n. 2
0
    public SquareGraphElem Connect(SquareGraphElem current, SquareGraphElem origin)
    {
        current.stepBack = origin;
        origin.stepForward.Add(current);

        return(current);
    }
Esempio n. 3
0
    public SquareGraphElem LookAround(Square square, LookAroundFunc BreakPoint, LookAroundFuncReturn Return, bool ignorePlayers = false, bool dangerIsNotWalkable = false)
    {
        ExtraSquareInfo squareInfo = square.GetComponent <ExtraSquareInfo>();

        currentStep = new List <SquareGraphElem>();
        currentStep.Add(new SquareGraphElem(square));

        MarkDanger();

        for (int x = 0; x < 10; x++)
        {
            int loopCount = currentStep.Count;
            for (int i = loopCount - 1; i >= 0; i--)
            {
                SquareGraphElem currentSquare = currentStep[i];
                squareInfo = currentSquare.mySquare.GetComponent <ExtraSquareInfo>();
                if (squareInfo.visited)
                {
                    currentStep.RemoveAt(i);
                    continue;
                }

                squareInfo.visited = true;

                if (!BreakPoint(currentSquare))
                {
                    //print("break");
                    ClearBoard();
                    return(Return(currentSquare));
                }
            }

            loopCount = currentStep.Count;
            for (int i = 0; i < loopCount; i++)
            {
                SquareGraphElem currentSquare = currentStep[i];

                foreach (Square neighbour in currentSquare.mySquare.Neighbours)
                {
                    if (!neighbour.Walkable(ignorePlayers, !dangerIsNotWalkable) || neighbour.info.visited)
                    {
                        continue;
                    }
                    SquareGraphElem newSquareGraphElem = new SquareGraphElem(neighbour);
                    currentStep.Add(newSquareGraphElem);
                    Connect(newSquareGraphElem, currentSquare);
                }
            }
        }

        ClearBoard();

        //print("no break");
        return(new SquareGraphElem(square));
    }
Esempio n. 4
0
    public SquareGraphElem ReturnNextStepSquare(SquareGraphElem graphElem)
    {
        SquareGraphElem last    = graphElem;
        SquareGraphElem current = graphElem;

        while (current.stepBack != null)
        {
            last    = current;
            current = current.stepBack;
        }

        return(last);
    }
Esempio n. 5
0
    public bool AddPointsToValue(SquareGraphElem square)
    {
        if (square.mySquare.info.danger)
        {
            return(true);
        }

        value += 1;
        foreach (Square neighbour in square.mySquare.Neighbours)
        {
            if (neighbour.Walkable(false, true) && (square.stepBack == null || !Board.main.InLine(square.stepBack.mySquare, square.mySquare, neighbour))) //to chyba nei dziala
            {
                value += 1;
            }
        }
        return(true);
    }
    void LookAroundStep(bool ignorePlayers = false, bool ignoreDanger = true, bool ignoreDestructable = false, bool ignoreBombs = false)
    {
        int loopCount = currentStep.Count;

        for (int i = loopCount - 1; i >= 0; i--)
        {
            SquareGraphElem currentSquare = currentStep[i];
            if (currentSquare.mySquare == null)
            {
                print("no square!");
                continue;
            }

            ExtraSquareInfo squareInfo = currentSquare.mySquare.info;
            if (squareInfo.visited)
            {
                currentStep.RemoveAt(i);
                continue;
            }

            squareInfo.visited = true;
        }

        loopCount = currentStep.Count;
        for (int i = 0; i < loopCount; i++)
        {
            SquareGraphElem currentSquare = currentStep[i];

            foreach (Square neighbour in currentSquare.mySquare.Neighbours)
            {
                if (!neighbour.Walkable(ignorePlayers, ignoreDanger, ignoreDestructable, ignoreBombs) || neighbour.info.visited)
                {
                    continue;
                }
                SquareGraphElem newSquareGraphElem = new SquareGraphElem(neighbour);
                currentStep.Add(newSquareGraphElem);
                Connect(newSquareGraphElem, currentSquare);
            }
        }
    }
Esempio n. 7
0
 public SquareGraphElem ReturnSquare(SquareGraphElem graphElem)
 {
     return(graphElem);
 }
Esempio n. 8
0
 public bool IsThisSquareGoal(SquareGraphElem square)
 {
     return(square.mySquare != squareGoal);
 }
Esempio n. 9
0
 public bool IsThisSquareNotSave(SquareGraphElem square)
 {
     return(square.mySquare.info.danger);
 }