-
Notifications
You must be signed in to change notification settings - Fork 6
/
core.go
49 lines (38 loc) · 972 Bytes
/
core.go
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
package takuzu
import "errors"
// Create a new instance of Takuzu Core with given size
func NewCore(size int) (*Core, error) {
if size < 4 || size > 12 || size%2 != 0 {
return &Core{}, errors.New(incorrectSize)
}
return &Core{
Size: size,
}, nil
}
// Generate a new Takuzu field
func (tc *Core) Generate() {
field, err := generateField(tc.Size)
for err != nil {
field, err = generateField(tc.Size)
}
_, errVerify := verify(field)
for errVerify != nil || err != nil {
field, err = generateField(tc.Size)
_, errVerify = verify(field)
}
tc.Field = field
}
// Prepare a new Takuzu task based on already generated field with given fill factor
func (tc *Core) Prepare(fillFactor int) error {
task, err := prepareField(tc.Field, fillFactor)
if err != nil {
return err
}
tc.Task = task
return nil
}
// Verify a current Takuzu task
func (tc *Core) Verify() (*VerificationResult, error) {
result, err := verify(tc.Task)
return result, err
}