squares

package module
v0.0.0-...-f419d28 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 9, 2020 License: BSD-3-Clause Imports: 2 Imported by: 0

README

Avoid the Square

go-squares is an engine for the game of Avoid the Squares. The point of the game is to avoid making a square with your pieces. Each player takes turns placing a piece on the board, and the first person to make a square using their own pieces loses.

Examples

This is a square

Image of Trivial Square

This is a non-trivial square

Image of Non-Trivial Square

In both of these situations, red loses.

Documentation

Index

Constants

View Source
const (
	//SIZE is the size of the nxn board
	SIZE = 5
)

Variables

View Source
var (
	//ErrMoveInvalid is the base error for invalid moves.
	ErrMoveInvalid = errors.New("squares: move is invalid")
)

Functions

This section is empty.

Types

type Game

type Game struct {
	// contains filtered or unexported fields
}

Game is the game state

func NewGame

func NewGame() Game

NewGame returns a new game of Squares.

func (Game) ApplyAction

func (g Game) ApplyAction(p Position) (Game, error)

ApplyAction generates a new game state by placing a piece p on the board If p is an invalid action, an error is returned with an unchanged board.

func (Game) GetActions

func (g Game) GetActions() []Position

GetActions returns the list of y,x positions that can be made from this game state.

func (Game) IsTerminal

func (g Game) IsTerminal() bool

IsTerminal returns true on a terminal state.

func (Game) PieceAt

func (b Game) PieceAt(p Position) Piece

func (Game) Player

func (g Game) Player() Piece

Player returns the player that is currently considering a move.

func (Game) String

func (b Game) String() string

func (Game) Winner

func (g Game) Winner() Piece

Winner returns the piece type of the winner Returns NILPIECE on draw and non-terminal states.

type Piece

type Piece byte

Piece represents the colored piece on the board

const (
	NILPIECE Piece = iota
	RED
	GREEN
)

func (Piece) Opponent

func (p Piece) Opponent() Piece

Opponent returns the opposite piece. An empty piece's opponent is the empty piece.

func (Piece) String

func (p Piece) String() string

type Position

type Position struct {
	// contains filtered or unexported fields
}

Position represents the position of a move

func (Position) Add

func (p Position) Add(p2 Position) Position

Add takes 2 positions and performs a vector addition

func (Position) InBounds

func (p Position) InBounds() bool

InBounds checks if the position is on the board

func (Position) String

func (p Position) String() string

func (Position) Sub

func (p Position) Sub(p2 Position) Position

Sub takes 2 positions and performs a vector subtraction

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL