blob: 37ec35cb27ac8d7f8abff0ceeb4cc7b6fa5ddf40 (
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
|
package tris
// Lines counts the number of lines that is completed and returns a Field with them removed
func (f Field) Lines() (int, Field) {
var n int
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 full(line) {
n++
} else {
nf = append(nf, line)
}
}
// compress
for i := 0; i < 20; i++ {
if i < n {
f[i] = make([]int, len(f[0]))
} else {
f[i] = nf[i-n]
}
}
return n, f
}
|