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 }