Browse Source

Fix wall kicks

master v0.4.0
Joop Kiefte 9 months ago
parent
commit
e238c3df5e
3 changed files with 22 additions and 22 deletions
  1. +4
    -1
      go.mod
  2. +2
    -0
      go.sum
  3. +16
    -21
      tris/move.go

+ 4
- 1
go.mod View File

@ -2,4 +2,7 @@ module git.kiefte.eu/lapingvino/clitris
go 1.15
require github.com/pkg/term v0.0.0-20200520122047-c3ffed290a03
require (
github.com/pkg/term v0.0.0-20200520122047-c3ffed290a03
golang.org/x/sys v0.0.0-20200918174421-af09f7315aff // indirect
)

+ 2
- 0
go.sum View File

@ -1,2 +1,4 @@
github.com/pkg/term v0.0.0-20200520122047-c3ffed290a03 h1:pd4YKIqCB0U7O2I4gWHgEUA2mCEOENmco0l/bM957bU=
github.com/pkg/term v0.0.0-20200520122047-c3ffed290a03/go.mod h1:Z9+Ul5bCbBKnbCvdOWbLqTHhJiYV414CURZJba6L8qA=
golang.org/x/sys v0.0.0-20200918174421-af09f7315aff h1:1CPUrky56AcgSpxz/KfgzQWzfG09u5YOL8MvPYBlrL8=
golang.org/x/sys v0.0.0-20200918174421-af09f7315aff/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

+ 16
- 21
tris/move.go View File

@ -20,24 +20,24 @@ var LCW = Kicks{
}
// Try all possible kicks
func (ks Kicks) Try(rot Rotation, reverse bool, p Placement, f Field) (np Placement) {
orot := (rot + 3)%4
if reverse { // for going backwards, you start from one more
rot--
orot = (rot + 1)%4
func (ks Kicks) Try(p, np Placement, f Field) Placement {
direction := (np.Rot - p.Rot + 4) % 4
rot := np.Rot
factor := 1
if direction == Spawn {
factor = 0
}
if direction == CounterClockwise {
rot = (rot + 1) % 4
factor = -1
}
x, y := np.X, np.Y
for _, k := range ks[rot] {
np = p
x, y := k.X, k.Y
if reverse {
x, y = -x, -y
}
np.X, np.Y = p.X+x, p.Y+y
np.X, np.Y = x + k.X * factor, y + k.Y * factor
if !np.Collide(f) {
return np
}
}
p.Rot = orot
return p
}
@ -48,12 +48,6 @@ func (p Placement) Floor(f Field) bool {
return fp.Collide(f)
}
// CW checks if the rotation from r to nr is a Clockwise rotation
func (r Rotation) CW(nr Rotation) bool {
r += 4
return (r - nr)%4 == 1 // if nr is 1 modulo 4 higher than r, it is a CW rotation
}
// Move tries the move indicated by the parameters, applies kicks to fix when it doesn't work,
// and returns if the piece is on the floor or topping out
func (p Placement) Move(f Field, rot Rotation, x, y int) (np Placement, floor, topout bool) {
@ -67,12 +61,13 @@ func (p Placement) Move(f Field, rot Rotation, x, y int) (np Placement, floor, t
// start handling kicks
switch p.piece {
case IPiece:
np = LCW.Try(rot, np.Rot.CW(rot), np, f)
np = LCW.Try(p, np, f)
case JPiece, SPiece, ZPiece, TPiece, LPiece:
np = K3CW.Try(rot, np.Rot.CW(rot), np, f)
np = K3CW.Try(p, np, f)
default:
np = p
}
np = p // last resort reset p
if np.Floor(f) && np.Y < 0 {
return np, true, true
}


Loading…
Cancel
Save