[SOLVED]Unexpected results
void GeneratePath(List<Vector2> currentPath,List<Vector2> notOccupiedList)
{
Vector2 currentBlock = currentPath[currentPath.Count - 1];
Vector2 top = new Vector2(currentBlock.x, currentBlock.y + 1);
Vector2 bottom = new Vector2(currentBlock.x, currentBlock.y - 1);
//Vector2 left = new Vector2(currentBlock.x - 1, currentBlock.y);
//Vector2 right = new Vector2(currentBlock.x + 1, currentBlock.y);
List<Vector2> checkList = new List<Vector2>() { top , bottom };
if (currentBlock.x == 0 || currentBlock.y == 0 || currentBlock.x == 4 || currentBlock.y == 4)
{
testlist.Add(new TestClas() { testlis = currentPath });
}
else
{
foreach (Vector2 checkPos in checkList)
{
if (notOccupiedList.Contains(checkPos) && currentPath.Contains(checkPos) == false)
{
List<Vector2> newPath = currentPath;
newPath.Add(checkPos);
GeneratePath(newPath, notOccupiedList);
}
Hey guys as you can see I have a code that checks top and bottom of a vector2 and if it is available then move to top / bottom , however it is returning unexpected results.
Note : second element in picture is exactly the same as the first one
as you can see it goes to the bottom then the top when it is supposed to go in only 1 direction and it also doesn't stop when it reached 0 / 4 like I wrote in the code , I was expecting to have 2 elements in the list like this
top - element 0 = 2,2 , element 1 = 2,3 , element 2 = 2,4 bottom - element 0 = 2,2 , element 1 = 2,1 , element 2 = 2,0
however though if I only used one direction "either top or bottom" and comment out the others, it returns perfect result
http://pasteboard.co/5kRJNTKWd.png
sorry I used another website but no more attachments were allowed
Edit: if anybody is looking for the solution look at my thread "same code returning different results"