aboutsummaryrefslogtreecommitdiff
path: root/tris/core.go
diff options
context:
space:
mode:
authorJoop Kiefte <ikojba@gmail.com>2020-09-12 16:37:57 +0200
committerJoop Kiefte <ikojba@gmail.com>2020-09-12 16:37:57 +0200
commit38293b6d5df68eff2794576bb64f82c2715429b6 (patch)
treec6d839a2a055be9b4045fa8acc3d426ae74580fa /tris/core.go
parentbd80439d9620f02b124b274cd79b8c8d30b69016 (diff)
Add more comments
Diffstat (limited to 'tris/core.go')
-rw-r--r--tris/core.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/tris/core.go b/tris/core.go
index 8a9c16b..087203e 100644
--- a/tris/core.go
+++ b/tris/core.go
@@ -38,6 +38,8 @@ const (
CounterClockwise
)
+// a placement is the combination of a piece and where it exactly is on the board
+// we use this both for the actual piece and for checking hypothetical positions
type Placement struct {
piece Piece
X int
@@ -46,6 +48,7 @@ type Placement struct {
Lock time.Time
}
+// Collide checks if any squares of the Placement and the Field overlap
func (p Placement) Collide(f Field) bool {
pf, ok := p.Field()
for x := 0; x < 10; x++ {
@@ -58,6 +61,8 @@ func (p Placement) Collide(f Field) bool {
return !ok
}
+// Field translates the Placement into a Field format
+// When it gets out of the board, we return that to the caller with a bool
func (p Placement) Field() (Field, bool) {
var f Field
ok := true
@@ -74,6 +79,7 @@ func (p Placement) Field() (Field, bool) {
return f, ok
}
+// Points transforms the piece to a list of coordinates
func (p Placement) Points() []Point {
piece := p.piece[p.Rot]
var points []Point
@@ -114,6 +120,7 @@ func (b Bag) Pick() (Bag, Placement) {
type Field [20][10]bool
+// Add merges the Field and Piece together
func (f Field) Add(p Placement) Field {
fn := f
for _, point := range p.Points() {
@@ -126,6 +133,7 @@ func (f Field) Add(p Placement) Field {
}
+// The command line tool uses this representation as the actual playing field
func (f Field) String() (output string) {
for _, row := range f {
for _, block := range row {