An issue with my game logic

I’m sure there are several other ways of doing this, but here’s one option. I see where you’re coming from with the extra list, but I think it’s unnecessary. You’re essentially doing a breadth first search (the link shows a simple code implementation, but there are plenty of explanations online), except you want to keep all the nodes you pass along the way. You could do this with a list and an index. Start with the tile that was swapped, which you’re presumably already doing, and i = 0. Then just loop over code that adds neighboring pieces for list[i] and increments i. Now you have a list that’s somewhere between 1 and 5 long, and i is 1. If i ever reaches the end of your list (i >= list.Count) then you can break out and check the length of your list.

Also with checking neighbors, I’m not sure how your grid is set up, but there should be a faster way than iterating through every tile. Consider if you get the x,y coordinates of the one you’re looking at, you can add and subtract 1 to x and to y to get the 4 neighboring tiles.

EDIT: Since you said you just started learning, I thought I’d clarify in case you didn’t know: there’s only a problem with changing a list while iterating over it when you use a foreach loop because it creates the enumerator. If you use a for loop and track the index yourself (which also creates less garbage), then you can arbitrarily access any element you want.