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
|
package game
import (
"fmt"
"strings"
)
type TileType int
const (
neutral TileType = iota + 1
tower
house
farm
street
spawn
docks
store
)
func (t TileType) String() string {
switch t {
case neutral:
return "neutral"
case tower:
return "tower"
case house:
return "house"
case farm:
return "farm"
case street:
return "street"
case spawn:
return "spawn"
case docks:
return "docks"
case store:
return "store"
}
return ""
}
var TileTypes = struct {
Neutral TileType
Tower TileType
House TileType
Farm TileType
Street TileType
Spawn TileType
Docks TileType
Store TileType
}{
Neutral: neutral,
Tower: tower,
House: house,
Farm: farm,
Street: street,
Spawn: spawn,
Docks: docks,
Store: store,
}
var TileNames = map[string]TileType{
"neutral": neutral,
"tower": tower,
"house": house,
"farm": farm,
"street": street,
"spawn": spawn,
"docks": docks,
"store": store,
}
type Tile struct {
Position Position
Permanent Permanent
Type TileType
Water bool
Raw string
}
func (t *Tile) String() string {
return fmt.Sprintf("%v@%v", t.Type, t.Position)
}
func INVALID_TILE() Tile {
return Tile{INVALID_POSITION(), nil, 0, false, ""}
}
func NewTileFromString(t string, pos Position) (Tile, error) {
tile := strings.ToLower(t)
tokens := strings.Split(tile, " ")
tileType, found := TileNames[tokens[0]]
if !found {
if strings.Contains(tile, "spawn") {
tileType = spawn
}
}
water := strings.Contains(tile, "water")
return Tile{pos, nil, tileType, water, t}, nil
}
func (t *Tile) IsFree() bool {
return t.Permanent == nil
}
func (t *Tile) IsAvailableForCard(card *Card) bool {
if t.IsFree() {
if t.Water && !card.hasPlacementConstrain("swimming") {
return false
}
if !t.Water && card.hasPlacementConstrain("swimming") {
return false
}
return true
}
x, err := t.Permanent.Card().getXEffect("crew")
if err != nil {
return false
}
if len(t.Permanent.Pile()) == x {
return false
}
return true
}
func (t *Tile) OnDiagonal(other *Tile) bool {
p1, p2 := t.Position, other.Position
return p1.X == p2.X-1 && p1.Y == p2.Y-1 ||
p1.X == p2.X+1 && p1.Y == p2.Y-1 ||
p1.X == p2.X+1 && p1.Y == p2.Y+1 ||
p1.X == p2.X-1 && p1.Y == p2.Y+1
}
|