aboutsummaryrefslogtreecommitdiff
path: root/pkg/field/step.go
blob: eee6f959b84774d70c45122e4e537097edeacd8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package field

func (f Field) Step(x, y, dx, dy int) (int, int) {
	x2, y2 := x+dx, y+dy
	if f.isIn(x2, y2) {
		return x2, y2
	}
	// We are stepping outside, we need to wrap the Lahey-space
	for {
		x2, y2 := x-dx, y-dy
		if !f.isIn(x2, y2) {
			return x, y
		}
		x, y = x2, y2
	}
}