aboutsummaryrefslogtreecommitdiff
path: root/tris/lines.go
diff options
context:
space:
mode:
Diffstat (limited to 'tris/lines.go')
-rw-r--r--tris/lines.go17
1 files changed, 12 insertions, 5 deletions
diff --git a/tris/lines.go b/tris/lines.go
index 7c7026b..37ec35c 100644
--- a/tris/lines.go
+++ b/tris/lines.go
@@ -2,14 +2,21 @@ package tris
// Lines counts the number of lines that is completed and returns a Field with them removed
func (f Field) Lines() (int, Field) {
- full := [10]bool{true, true, true, true, true, true, true, true, true, true}
- empty := [10]bool{false, false, false, false, false, false, false, false, false, false}
var n int
- var nf [][10]bool
+ var nf [][]int
+
+ full := func(line []int) bool {
+ for _, el := range line {
+ if el == 0 {
+ return false
+ }
+ }
+ return true
+ }
// count and collect
for _, line := range f {
- if line == full {
+ if full(line) {
n++
} else {
nf = append(nf, line)
@@ -19,7 +26,7 @@ func (f Field) Lines() (int, Field) {
// compress
for i := 0; i < 20; i++ {
if i < n {
- f[i] = empty
+ f[i] = make([]int, len(f[0]))
} else {
f[i] = nf[i-n]
}