I am doing a tile based game. I try make a method that return an array that my character can move based on x,y coordinate and move limit.
For example, if I input currentPosition:(3,3) moveLimit:1
then it should give me back ((3,2),(3,2),(3,4),(4,3))
and if I input currentPosition:(3,3) moveLimit:2
then it should back ((3,1),(2,2),(3,2),(4,2),(1,3),(2,3),(4,3),(5,3),(2,4),(3,4),(4,4),(3,5))
I planning to use recursive method by making all possible of -1 and +1 on both x and y. but it is quite inefficient, since a lot of repeated case may occur such as +1 then -1 compared to -1 then +1.
Anyone know if there is any good pattern for this?
Thank you a lot.