2023-06-12 20:32:31 +00:00
|
|
|
package types
|
|
|
|
|
2023-06-20 21:53:54 +00:00
|
|
|
// coordinates starting at 1:1 and end at 8:8
|
2023-06-12 20:32:31 +00:00
|
|
|
type Coordinate struct {
|
|
|
|
Col int `json:"col"`
|
|
|
|
Row int `json:"row"`
|
|
|
|
}
|
|
|
|
|
2023-06-20 21:53:54 +00:00
|
|
|
const (
|
|
|
|
RangeLastValid = 8
|
|
|
|
RangeFirstValid = 1
|
|
|
|
|
|
|
|
RangeUpperInvalid = 9
|
|
|
|
RangeLowerInvalid = 0
|
|
|
|
)
|
|
|
|
|
|
|
|
func (c Coordinate) Up(number int) *Coordinate {
|
|
|
|
check := c.Row + number
|
|
|
|
if check <= RangeLastValid {
|
|
|
|
return &Coordinate{Row: check, Col: c.Col}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
func (c Coordinate) Down(number int) *Coordinate {
|
|
|
|
check := c.Row - number
|
|
|
|
if check >= RangeFirstValid {
|
|
|
|
return &Coordinate{Row: check, Col: c.Col}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Right and left is seen from a board where row 1 is on the bottom
|
|
|
|
func (c Coordinate) Right(number int) *Coordinate {
|
|
|
|
check := c.Col + number
|
|
|
|
if check >= RangeFirstValid {
|
|
|
|
return &Coordinate{Row: c.Row, Col: check}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
func (c Coordinate) Left(number int) *Coordinate {
|
|
|
|
check := c.Col - number
|
|
|
|
if check >= RangeFirstValid {
|
|
|
|
return &Coordinate{Row: c.Row, Col: check}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-06-12 20:32:31 +00:00
|
|
|
type ChessColor string
|
|
|
|
|
|
|
|
const (
|
|
|
|
White ChessColor = "white"
|
|
|
|
Black ChessColor = "black"
|
|
|
|
)
|
|
|
|
|
2023-06-14 17:46:46 +00:00
|
|
|
func (c ChessColor) Opposite() ChessColor {
|
|
|
|
if c == White {
|
|
|
|
return Black
|
|
|
|
} else {
|
|
|
|
return White
|
|
|
|
}
|
|
|
|
}
|