package game import ( "fmt" ) // Position represents a zero-based position on the map. // TODO: Change to a 1-based coordinate system. // // This allows to use the zero value as invalid Position. // // The origin is the upper left corner of the map. type Position struct { X int Y int } const POSITION_FMT = "(%d, %d)" func (p Position) String() string { if p == INVALID_POSITION() { return "INVALID_POSITION" } return fmt.Sprintf(POSITION_FMT, p.X, p.Y) } func INVALID_POSITION() Position { return Position{-1, -1} } // Valid reports if a coordinate is smaller than 0. func (p Position) Valid() bool { return p.X >= 0 && p.Y >= 0 }