Britbot

returns the neighbors of the Node, meaning the adjacent location wich are not impassible

Returns:

Definition at line 297 of file Node.cs.

            {
                //allocating a new list
                List<Node> neighbors = new List<Node>();

                //array to help iterating over the four neighbors
                int[] coeff = {-1, 1};

                //read X and Y from this.loc
                int X = this.Loc.Col;
                int Y = this.Loc.Row;


                //going over neighbors
                for (int delata = 0; delata < 2; delata++)
                {
                    //get the iterated neighbor coordinates
                    int neighborX = X + coeff[delata];
                    int neighborY = Y;

                    //check if out of bounderie, if so, continue to next iteration
                    if ((neighborX < 0) || (neighborX >= Bot.Game.GetCols()) ||
                        (neighborY < 0) || (neighborY >= Bot.Game.GetRows()))
                        continue;

                    //check if impassable, if so, continue to next iteration
                    /*if (!Node.Map[neighborY, neighborX].IsPassable())
                        continue;*/

                    //if we are here it means that the neighbor is ok, so add him to the list
                    neighbors.Add(Node.Map[neighborY, neighborX]);
                }
                for (int delata = 0; delata < 2; delata++)
                {
                    //get the iterated neighbor coordinates
                    int neighborX = X;
                    int neighborY = Y + coeff[delata];

                    //check if out of bounderie, if so, continue to next iteration
                    if ((neighborX < 0) || (neighborX >= Bot.Game.GetCols()) ||
                        (neighborY < 0) || (neighborY >= Bot.Game.GetRows()))
                        continue;

                    //check if impassable, if so, continue to next iteration
                    /* if (!Node.Map[neighborY, neighborX].IsPassable())
                        continue;*/

                    //if we are here it means that the neighbor is ok, so add him to the list
                    neighbors.Add(Node.Map[neighborY, neighborX]);
                }
                return neighbors;
            }