aboutsummaryrefslogtreecommitdiff
path: root/tris/core.go
blob: 41d1beb91aae19b5988549dca51c7b0c2f6d3283 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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
}