diff options
author | Joop Kiefte <ikojba@gmail.com> | 2020-09-12 09:05:28 +0200 |
---|---|---|
committer | Joop Kiefte <ikojba@gmail.com> | 2020-09-12 09:05:28 +0200 |
commit | 3edb4c1779ae23dd976c067622f2aaee9ac98f5d (patch) | |
tree | 9289f2b2a674ab11bb6eed6dbead64810d567497 /tris | |
parent | ac3196415d5d87a745d339f1548573b0b5745c41 (diff) |
Mostly playable now -- kicks still missing and problem with floor detection L piece
Diffstat (limited to 'tris')
-rw-r--r-- | tris/lines.go | 27 | ||||
-rw-r--r-- | tris/move.go | 12 |
2 files changed, 35 insertions, 4 deletions
diff --git a/tris/lines.go b/tris/lines.go new file mode 100644 index 0000000..5cb6981 --- /dev/null +++ b/tris/lines.go @@ -0,0 +1,27 @@ +package tris + +func (f Field) Lines() (int, Field) { + full := [10]bool{true, true, true, true, true, true, true, true, true, true} + empty := [10]bool{false, false, false, false, false, false, false, false, false, false} + var n int + var nf [][10]bool + + // count and collect + for _, line := range f { + if line == full { + n++ + } else { + nf = append(nf, line) + } + } + + // compress + for i := 0; i < 20; i++ { + if i < n { + f[i] = empty + } else { + f[i] = nf[i-n] + } + } + return n, f +} diff --git a/tris/move.go b/tris/move.go index 0e081ef..29140b8 100644 --- a/tris/move.go +++ b/tris/move.go @@ -1,5 +1,11 @@ package tris +func (p Placement) Floor(f Field) bool { + fp := p + fp.Y++ + return fp.Collide(f) +} + func (p Placement) Move(f Field, rot Rotation, x, y int) (np Placement, floor, topout bool) { np = p np.Rot = rot @@ -9,10 +15,8 @@ func (p Placement) Move(f Field, rot Rotation, x, y int) (np Placement, floor, t return np, false, false } np = p // last resort reset p - fp := np - fp.Y++ - if fp.Collide(f) && np.Y < 0 { + if np.Floor(f) && np.Y < 0 { return np, true, true } - return np, fp.Collide(f), false + return np, np.Floor(f), false } |