From ac3196415d5d87a745d339f1548573b0b5745c41 Mon Sep 17 00:00:00 2001 From: Joop Kiefte Date: Sat, 12 Sep 2020 08:25:24 +0200 Subject: Creating move routine to implement kicks in --- tris/core.go | 12 ++---------- tris/move.go | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 tris/move.go (limited to 'tris') diff --git a/tris/core.go b/tris/core.go index af46311..0b5afff 100644 --- a/tris/core.go +++ b/tris/core.go @@ -44,19 +44,10 @@ type Placement struct { Lock time.Time } -func (p Placement) Drop(f Field) (Placement, bool) { - newp := p - newp.Y++ - if !newp.Collide(f) { - return newp, true - } - return p, false -} - func (p Placement) Collide(f Field) bool { //TODO: Fix first piece collision bug pf, ok := p.Field() for x := 0; x < 9; x++ { - for y := 0; y < 19; y++ { + for y := 0; y < 20; y++ { if f[y][x] && pf[y][x] { return true } @@ -130,6 +121,7 @@ func (f Field) Add(p Placement) Field { fn[point.Y][point.X] = true } return fn + } func (f Field) String() (output string) { diff --git a/tris/move.go b/tris/move.go new file mode 100644 index 0000000..0e081ef --- /dev/null +++ b/tris/move.go @@ -0,0 +1,18 @@ +package tris + +func (p Placement) Move(f Field, rot Rotation, x, y int) (np Placement, floor, topout bool) { + np = p + np.Rot = rot + np.X = x + np.Y = y + if !np.Collide(f) { // free air + return np, false, false + } + np = p // last resort reset p + fp := np + fp.Y++ + if fp.Collide(f) && np.Y < 0 { + return np, true, true + } + return np, fp.Collide(f), false +} -- cgit v1.2.3-70-g09d2