go-atari-models, v1.1
Posted on

The library that implements checking and generating of Atari Go moves.
Adding basic checkings of moves.
Change Log
- adding basic checkings of moves.
Features
- representing the board as an associative array of stones with their positions as keys;
- immutable applicating moves to the board via copying the latter;
- basic checkings of moves.
Examples
atarimodels.Board.CheckMove() with a legal move:
package main
import (
"fmt"
models "github.com/thewizardplusplus/go-atari-models"
)
func main() {
// +-+-+-+-+-+
// | | | | | |
// +-+-+-+-+-+
// | |B|W| | |
// +-+-+-+-+-+
// |B|W|X|W| |
// +-+-+-+-+-+
// | |B|W| | |
// +-+-+-+-+-+
// | | | | | |
// +-+-+-+-+-+
board := models.NewBoard(models.Size{Width: 5, Height: 5})
for _, move := range []models.Move{
{Color: models.Black, Point: models.Point{Column: 1, Row: 1}},
{Color: models.White, Point: models.Point{Column: 2, Row: 1}},
{Color: models.Black, Point: models.Point{Column: 0, Row: 2}},
{Color: models.White, Point: models.Point{Column: 1, Row: 2}},
{Color: models.White, Point: models.Point{Column: 3, Row: 2}},
{Color: models.Black, Point: models.Point{Column: 1, Row: 3}},
{Color: models.White, Point: models.Point{Column: 2, Row: 3}},
} {
board = board.ApplyMove(move)
}
move := models.Move{
Color: models.Black,
Point: models.Point{Column: 2, Row: 2},
}
fmt.Printf("%+v: %v\n", move, board.CheckMove(move))
// Output: {Color:0 Point:{Column:2 Row:2}}: <nil>
}
atarimodels.Board.CheckMove() with an illegal move:
package main
import (
"fmt"
models "github.com/thewizardplusplus/go-atari-models"
)
func main() {
// +-+-+-+-+-+
// | | | | | |
// +-+-+-+-+-+
// | |B|W| | |
// +-+-+-+-+-+
// |B|W| |W| |
// +-+-+-+-+-+
// | |B|W| | |
// +-+-+-+-+-+
// | | | | | |
// +-+-+-+-+-+
board := models.NewBoard(models.Size{Width: 5, Height: 5})
for _, move := range []models.Move{
{Color: models.Black, Point: models.Point{Column: 1, Row: 1}},
{Color: models.White, Point: models.Point{Column: 2, Row: 1}},
{Color: models.Black, Point: models.Point{Column: 0, Row: 2}},
{Color: models.White, Point: models.Point{Column: 1, Row: 2}},
{Color: models.White, Point: models.Point{Column: 3, Row: 2}},
{Color: models.Black, Point: models.Point{Column: 1, Row: 3}},
{Color: models.White, Point: models.Point{Column: 2, Row: 3}},
} {
board = board.ApplyMove(move)
}
move := models.Move{
Color: models.Black,
Point: models.Point{Column: 3, Row: 2},
}
fmt.Printf("%+v: %v\n", move, board.CheckMove(move))
// Output: {Color:0 Point:{Column:3 Row:2}}: occupied point
}
Repository
Link: https://github.com/thewizardplusplus/go-atari-models/tree/v1.1.
Content: code.
License: MIT.