Exemplo n.º 1
0
        public IndexPaar GetNeighbour(Direction _Dir)
        {
            IndexPaar Neighbour = this;

            switch (_Dir)
            {
            case Direction.Left:
                Neighbour.spalte -= 1;
                break;

            case Direction.Right:
                Neighbour.spalte += 1;
                break;

            case Direction.Up:
                Neighbour.zeile -= 1;
                break;

            case Direction.Down:
                Neighbour.zeile += 1;
                break;
            }

            return(Neighbour);
        }
Exemplo n.º 2
0
 public GameObject GetKachel(IndexPaar _Pair)
 {
     if (IsValid(_Pair) == false)
     {
         return(null);
     }
     return(board[_Pair.spalte, _Pair.zeile]);
 }
Exemplo n.º 3
0
 List<IndexPaar> GetNeighbours(IndexPaar _Node)
 {
     List<IndexPaar> Neighbours = new List<IndexPaar>();
     foreach(Direction dir in System.Enum.GetValues(typeof(Direction)))
     {
         IndexPaar Neighbour = _Node.GetNeighbour(dir);
         if (IsValid(Neighbour) && IsKachelBlocked(Neighbour) == false)
             Neighbours.Add(Neighbour);
     }
     return Neighbours;
 }
Exemplo n.º 4
0
    List <IndexPaar> GetNeighbours(IndexPaar _Node)
    {
        List <IndexPaar> Neighbours = new List <IndexPaar>();

        foreach (Direction dir in System.Enum.GetValues(typeof(Direction)))
        {
            IndexPaar Neighbour = _Node.GetNeighbour(dir);
            if (IsValid(Neighbour) && IsKachelBlocked(Neighbour) == false)
            {
                Neighbours.Add(Neighbour);
            }
        }
        return(Neighbours);
    }
Exemplo n.º 5
0
    void StartBreitensuche(IndexPaar _Start)
    {
        ResetBreitensuche();

        if (IsKachelBlocked(_Start))
        {
            return;
        }

        warteschlange.Enqueue(_Start);
        distance[_Start.zeile, _Start.spalte] = 0;

        while (warteschlange.Count > 0)
        {
            IndexPaar This = warteschlange.Dequeue();

            List <IndexPaar> Neighbours = GetNeighbours(This);

            foreach (IndexPaar Neigh in Neighbours)
            {
                if (distance[Neigh.zeile, Neigh.spalte] == int.MaxValue)
                {
                    distance[Neigh.zeile, Neigh.spalte] = 1 + distance[This.zeile, This.spalte];
                    warteschlange.Enqueue(Neigh);
                    print("new dist: " + distance[Neigh.zeile, Neigh.spalte]);
                }
            }

            // TODO Übungsaufgabe: erstmal hard-coded neighbours benutzen
            // TODO Übungsaufgabe: dann getneighbours funktion erstellen
            // TODO Übungsaufgabe: dann funktionen left(indexpair _node) right(indexpair _node) etc für indexpaar definieren
            // TODO Übungsaufgabe: dann diese funktionen in die indexpair-klasse verschieben
            // TODO Übungsaufgabe: dann isvalid() funktion in indexpair-klasse
            // TODO Übungsaufgabe: dann enum directions definieren und getneighbour(dir)
        }
    }
Exemplo n.º 6
0
 public bool IsValid(IndexPaar _Pair)
 {
     return(0 <= _Pair.zeile && _Pair.zeile < iSize &&
            0 <= _Pair.spalte && _Pair.spalte < iSize);
 }
Exemplo n.º 7
0
    public bool IsKachelBlocked(IndexPaar _Pair)
    {
        GameObject Kachel = GetKachel(_Pair);

        return(Kachel == null || Kachel.renderer.material.color == Color.blue);
    }
Exemplo n.º 8
0
    void StartBreitensuche(IndexPaar _Start)
    {
        ResetBreitensuche();

        if (IsKachelBlocked(_Start))
        return;

        warteschlange.Enqueue(_Start);
        distance[_Start.zeile, _Start.spalte] = 0;

        while (warteschlange.Count > 0)
        {
            IndexPaar This = warteschlange.Dequeue();

            List<IndexPaar> Neighbours = GetNeighbours(This);

            foreach (IndexPaar Neigh in Neighbours)
            {
                if (distance[Neigh.zeile, Neigh.spalte] == int.MaxValue)
                {
                    distance[Neigh.zeile, Neigh.spalte] = 1 + distance[This.zeile, This.spalte];
                    warteschlange.Enqueue(Neigh);
                    print ("new dist: " + distance[Neigh.zeile, Neigh.spalte]);
                }
            }

            // TODO Übungsaufgabe: erstmal hard-coded neighbours benutzen
            // TODO Übungsaufgabe: dann getneighbours funktion erstellen
            // TODO Übungsaufgabe: dann funktionen left(indexpair _node) right(indexpair _node) etc für indexpaar definieren
            // TODO Übungsaufgabe: dann diese funktionen in die indexpair-klasse verschieben
            // TODO Übungsaufgabe: dann isvalid() funktion in indexpair-klasse
            // TODO Übungsaufgabe: dann enum directions definieren und getneighbour(dir)
        }
    }
Exemplo n.º 9
0
 public bool IsValid(IndexPaar _Pair)
 {
     return (0 <= _Pair.zeile && _Pair.zeile < iSize &&
             0 <= _Pair.spalte && _Pair.spalte < iSize);
 }
Exemplo n.º 10
0
 public bool IsKachelBlocked(IndexPaar _Pair)
 {
     GameObject Kachel = GetKachel(_Pair);
     return (Kachel == null || Kachel.renderer.material.color == Color.blue);
 }
Exemplo n.º 11
0
 public GameObject GetKachel(IndexPaar _Pair)
 {
     if (IsValid(_Pair) == false)
         return null;
     return board[_Pair.spalte, _Pair.zeile];
 }