aboutsummaryrefslogtreecommitdiff
path: root/tris/core.go
diff options
context:
space:
mode:
Diffstat (limited to 'tris/core.go')
-rw-r--r--tris/core.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/tris/core.go b/tris/core.go
new file mode 100644
index 0000000..41d1beb
--- /dev/null
+++ b/tris/core.go
@@ -0,0 +1,57 @@
+package tris
+
+type PieceType int
+
+const (
+ IPiece PieceType = iota
+ JPiece
+ LPiece
+ SPiece
+ ZPiece
+ TPiece
+ OPiece
+)
+
+type Point struct {
+ X, Y int
+}
+
+type Piece struct {
+ Type PieceType
+ RelX int
+ RelY int
+ Layout []Point
+ Lock int
+}
+
+type Bag []Piece
+
+type Field [20][10]bool
+
+func (f Field) String() (output string) {
+ var toprow [10]bool
+ var top bool
+ for _, row := range f {
+ top = !top
+ for i, block := range row {
+ if top {
+ toprow[i] = block
+ continue
+ }
+ switch {
+ case toprow[i] && block:
+ output += "\u2588"
+ case toprow[i] && !block:
+ output += "\u2580"
+ case !toprow[i] && block:
+ output += "\u2584"
+ default:
+ output += " "
+ }
+ }
+ if !top {
+ output += "\n"
+ }
+ }
+ return output
+}