-
Notifications
You must be signed in to change notification settings - Fork 1
/
item.go
160 lines (140 loc) · 2.97 KB
/
item.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// Copyright © 2011 Jeffrey Davis <jeff.davis@gmail.com>
// Use of this code is governed by the GPL version 2 or later.
// See the file LICENSE for details.
package maps
import ()
// Item codes from parsing turns
type Item byte
const (
UNKNOWN Item = iota
WATER
FOOD
LAND
MY_ANT
PLAYER1
PLAYER2
PLAYER3
PLAYER4
PLAYER5
PLAYER6
PLAYER7
PLAYER8
PLAYER9
PLAYERGUESS
MY_HILL
HILL1
HILL2
HILL3
HILL4
HILL5
HILL6
HILL7
HILL8
HILL9
HILLGUESS // Not a real hill - our guess
MY_DEAD
DEAD1
DEAD2
DEAD3
DEAD4
DEAD5
DEAD6
DEAD7
DEAD8
DEAD9
MY_HILLANT
HILLANT1
HILLANT2
HILLANT3
HILLANT4
HILLANT5
HILLANT6
HILLANT7
HILLANT8
HILLANT9
EXPLORE // An explore goal - terminal
DEFEND // A defense spot - terminal
RALLY // rally point for future attack - terminal
WAYPOINT // a place to go on the way somewhere - terminal
BLOCK // A moved ant or something else preventing stepping in
OCCUPIED // An ant has moved here so it can't be moved into
MAX_ITEM
INVALID_ITEM Item = 255
)
var itemToSym = [256]byte{' ', '%', '*', '.',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', '~', // Player, ~ is a player guess
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '?', // Hill ? is guess hill
'!', 'z', 'y', 'x', 'w', 'v', 'u', 't', 's', 'r', // Dead ant
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', // Ant on hill
'X', '+', '@', '=', '|', '&', // Operational things
}
var symToItem [256]Item
var TerminalItem [256]bool
var StepableItem [256]bool
func init() {
// Set up static symbol item mappings.
for j := 0; j < 256; j++ {
symToItem[j] = INVALID_ITEM
}
for i := UNKNOWN; i < MAX_ITEM; i++ {
symToItem[itemToSym[i]] = i
}
// Make Terminal
for _, item := range []Item{EXPLORE, DEFEND, RALLY} {
TerminalItem[item] = true
}
for item := Item(HILL1); item <= HILLGUESS; item++ {
TerminalItem[item] = true
}
for item := Item(HILLANT1); item <= HILLANT9; item++ {
TerminalItem[item] = true
}
// StepableItem
for i := range StepableItem {
StepableItem[i] = true
}
for _, item := range []Item{WATER, BLOCK, FOOD} {
StepableItem[item] = false
}
}
func (o Item) String() string {
return string(o.ToSymbol())
}
// Map an Item code to a character
func (o Item) ToSymbol() byte {
return itemToSym[o]
}
// Map a character to an Item code
func ToItem(c byte) Item {
return symToItem[c]
}
func (o Item) IsHill() bool {
if (o >= MY_HILL && o <= HILLGUESS) || (o >= MY_HILLANT && o <= HILLANT9) {
return true
}
return false
}
func (o Item) IsEnemyHill(player int) bool {
if o == LAND || o == WATER {
return false
}
if o >= MY_HILL && o <= HILLGUESS {
return player != int(o-MY_HILL)
}
if o >= MY_HILLANT && o <= HILLANT9 {
return player != int(o-MY_HILLANT)
}
return false
}
func (o Item) IsEnemyAnt(player int) bool {
if o == LAND || o == WATER {
return false
}
if o >= MY_ANT && o <= PLAYERGUESS {
return player != int(o-MY_ANT)
}
if o >= MY_HILLANT && o <= HILLANT9 {
return player != int(o-MY_HILLANT)
}
return false
}