checkers

package module
v0.2.3 Latest Latest
Warning

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

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

Documentation

Overview

Package checkers is a checkers board game engine.

Index

Constants

View Source
const (
	//ROWS is the number of rows in a checkers board
	ROWS = 8

	//COLS is the number of cols in a checkers board
	//this variable is represented as half the amount of the columns
	//on a typical checkers board as half of the slots on the board are
	//unused. This implementation takes use of that to save on memory
	COLS = 4
)
View Source
const (
	//TurnsBeforeDraw is the number of turns the engine
	//wil consider before resulting in a draw if a piece
	//capture has not occurred in that alloted time.
	TurnsBeforeDraw = 100
)

Variables

View Source
var (
	//ErrGameNotOver error
	ErrGameNotOver = errors.New("Game is not finished")

	//ErrInvalidGameState error
	ErrInvalidGameState = errors.New("Invalid game state")

	//ErrMoveNotInBounds error
	ErrMoveNotInBounds = errors.New("Move is not in bounds")
)

Functions

This section is empty.

Types

type Game

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

Game is the base struct that holds game state information.

func NewGame

func NewGame() Game

NewGame returns a new valid game of checkers.

func (Game) ApplyAction

func (g Game) ApplyAction(m Move) (Game, error)

ApplyAction takes a Move and applies the action to the current game state.

Returns the new game state and ErrMoveNotInBounds if the Move m is invalid.

func (Game) GetActions

func (g Game) GetActions() []Move

GetActions returns a list of moves that can be made by the current player.

func (Game) IsTerminalState

func (g Game) IsTerminalState() bool

IsTerminalState returns whether the game is finished or not.

func (Game) Player

func (g Game) Player() byte

Player returns the ascii value of the player that is currently deciding a move.

Player returns 'o' if player o is making a move. Otherwise, Player return 'x'.

func (Game) String

func (b Game) String() string

func (Game) Winner

func (g Game) Winner() (byte, error)

Winner returns the winner's ascii value.

If the game results in a draw, this method returns '_' as the winner.

Returns ErrGameNotOver if the game is not over.

Returns ErrInvalidGameState if the game is in an invalid game state.

type Move

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

Move represents an action in checkers

func (Move) String

func (m Move) String() string

String returns a string representation of the move

The string returned is of the form "s -> e {p}" such that...

s is the starting position of the piece being moved

e is the ending position of the piece being moved,

p is the piece captured by the move

Jump to

Keyboard shortcuts

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