aboutsummaryrefslogtreecommitdiff
path: root/tris
diff options
context:
space:
mode:
authorJoop Kiefte <ikojba@gmail.com>2020-09-12 08:25:24 +0200
committerJoop Kiefte <ikojba@gmail.com>2020-09-12 08:25:24 +0200
commitac3196415d5d87a745d339f1548573b0b5745c41 (patch)
treeb296d16875d98b965b7520797294358156ee3b08 /tris
parentbc89ff176ddf7cf9627df15e8624d94a040a1d0b (diff)
Creating move routine to implement kicks in
Diffstat (limited to 'tris')
-rw-r--r--tris/core.go12
-rw-r--r--tris/move.go18
2 files changed, 20 insertions, 10 deletions
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
+}