-
Notifications
You must be signed in to change notification settings - Fork 0
/
aiplan_vector_gen.go
120 lines (107 loc) · 2.31 KB
/
aiplan_vector_gen.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Code generated by "genenum.exe -typename=AIPlan -packagename=aiplan -basedir=enum -vectortype=int"
package aiplan_vector_int
import (
"bytes"
"fmt"
"html/template"
"net/http"
"github.com/kasworld/goguelike-single/enum/aiplan"
)
type AIPlanVector_int [aiplan.AIPlan_Count]int
func (es AIPlanVector_int) String() string {
var buf bytes.Buffer
fmt.Fprintf(&buf, "AIPlanVector_int[")
for i, v := range es {
fmt.Fprintf(&buf,
"%v:%v ",
aiplan.AIPlan(i), v)
}
buf.WriteString("]")
return buf.String()
}
func (es *AIPlanVector_int) Dec(e aiplan.AIPlan) {
es[e] -= 1
}
func (es *AIPlanVector_int) Inc(e aiplan.AIPlan) {
es[e] += 1
}
func (es *AIPlanVector_int) Add(e aiplan.AIPlan, v int) {
es[e] += v
}
func (es *AIPlanVector_int) SetIfGt(e aiplan.AIPlan, v int) {
if es[e] < v {
es[e] = v
}
}
func (es AIPlanVector_int) Get(e aiplan.AIPlan) int {
return es[e]
}
// Iter return true if iter stop, return false if iter all
// fn return true to stop iter
func (es AIPlanVector_int) Iter(fn func(i aiplan.AIPlan, v int) bool) bool {
for i, v := range es {
if fn(aiplan.AIPlan(i), v) {
return true
}
}
return false
}
// VectorAdd add element to element
func (es AIPlanVector_int) VectorAdd(arg AIPlanVector_int) AIPlanVector_int {
var rtn AIPlanVector_int
for i, v := range es {
rtn[i] = v + arg[i]
}
return rtn
}
// VectorSub sub element to element
func (es AIPlanVector_int) VectorSub(arg AIPlanVector_int) AIPlanVector_int {
var rtn AIPlanVector_int
for i, v := range es {
rtn[i] = v - arg[i]
}
return rtn
}
func (es *AIPlanVector_int) ToWeb(w http.ResponseWriter, r *http.Request) error {
tplIndex, err := template.New("index").Funcs(IndexFn).Parse(`
<html>
<head>
<title>AIPlan Vector int</title>
</head>
<body>
<table border=1 style="border-collapse:collapse;">` +
HTML_tableheader +
`{{range $i, $v := .}}` +
HTML_row +
`{{end}}` +
HTML_tableheader +
`</table>
<br/>
</body>
</html>
`)
if err != nil {
return err
}
if err := tplIndex.Execute(w, es); err != nil {
return err
}
return nil
}
func Index(i int) string {
return aiplan.AIPlan(i).String()
}
var IndexFn = template.FuncMap{
"AIPlanIndex": Index,
}
const (
HTML_tableheader = `<tr>
<th>Name</th>
<th>Value</th>
</tr>`
HTML_row = `<tr>
<td>{{AIPlanIndex $i}}</td>
<td>{{$v}}</td>
</tr>
`
)