-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathline.go
46 lines (35 loc) · 869 Bytes
/
line.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
package ddskgen
import (
"fmt"
"io"
)
// Line outputs a part of lines that Mikihisa Azuma might say.
type Line struct {
writer io.Writer
rand Rand
}
// NewLine returns a new Line instance.
func NewLine(w io.Writer, rand Rand) *Line {
return &Line{w, rand}
}
// TryDodosuko3 tries to output a part of lines that Mikihisa Azuma might say, and returns true if suceeded.
func (l *Line) TryDodosuko3() bool {
words := []string{"ドド", "スコ"}
expectedIdxs := []int{0, 1, 1, 1}
idxs := l.indices(len(words), len(expectedIdxs))
succeeded := true
for i, wi := range idxs {
fmt.Fprint(l.writer, words[wi])
if expectedIdxs[i] != wi {
succeeded = false
}
}
return succeeded
}
func (l *Line) indices(maxValue int, length int) []int {
ret := make([]int, length)
for i := 0; i < length; i++ {
ret[i] = l.rand.Intn(maxValue)
}
return ret
}