aboutsummaryrefslogtreecommitdiff
path: root/tris/lines.go
blob: 5cb6981fcc9960288822d0d511b7c918a82b2e81 (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
package tris

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

	// count and collect
	for _, line := range f {
		if line == full {
			n++
		} else {
			nf = append(nf, line)
		}
	}

	// compress
	for i := 0; i < 20; i++ {
		if i < n {
			f[i] = empty
		} else {
			f[i] = nf[i-n]
		}
	}
	return n, f
}