modify getResult function to allow any position
solve bug in generateNewPosition