diff options
Diffstat (limited to 'tris')
-rw-r--r-- | tris/core.go | 2 | ||||
-rw-r--r-- | tris/hold.go | 23 |
2 files changed, 25 insertions, 0 deletions
diff --git a/tris/core.go b/tris/core.go index 6963294..089dca4 100644 --- a/tris/core.go +++ b/tris/core.go @@ -20,6 +20,7 @@ type Piece [4]uint16 // A table that represents each piece from https://tetris.fandom.com/wiki/SRS // in binary starting with 1 top left going per row, here in hexadecimal shorthand. var ( + EmptyPiece = Piece{} IPiece = Piece{0x0F00, 0x4444, 0x00F0, 0x2222} JPiece = Piece{0x1700, 0x6220, 0x0740, 0x2230} LPiece = Piece{0x4700, 0x2260, 0x0710, 0x3220} @@ -130,6 +131,7 @@ func (b Bag) Randomize() Bag { } func (b Bag) Pick() (Bag, Placement) { + Swapped = false if len(b) == 0 { b = NewBag() } diff --git a/tris/hold.go b/tris/hold.go new file mode 100644 index 0000000..6a82f5b --- /dev/null +++ b/tris/hold.go @@ -0,0 +1,23 @@ +package tris + +var HoldPiece Piece + +var HoldBox Field + +var Swapped bool + +func (b Bag) Swap(p Placement) (Bag, Placement) { + if Swapped { + return b, p + } + var tempp Placement + if HoldPiece == EmptyPiece { + b, tempp = b.Pick() + HoldPiece = tempp.piece + } + p.piece, HoldPiece = HoldPiece, p.piece + Swapped = true + HoldBox, _ = Placement{piece: HoldPiece, X: 0, Y:0}.Field(2,4) + p.Rot, p.X, p.Y = 0, 3, -2 + return b, p +} |