engine

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package engine is a generated GoMock package.

Package engine is a generated GoMock package.

Index

Constants

View Source
const MAXX = 7

MAXX maximum coordinate value

View Source
const MAXY = 7

MAXY maximum coordinate value

Variables

This section is empty.

Functions

This section is empty.

Types

type Board

type Board interface {
	Squares() Squares
	WhitePlayer() *Player
	BlackPlayer() *Player
	// EatPiece removes a piece from Board location return Piece
	EatPiece(loc SquareIdentifier) Piece
	// Fill a square with a piece
	FillSquare(SquareIdentifier, Piece)
	String() string
}

Board chess playable board

func LoadBoard

func LoadBoard(whitePlayer, blackPlayer *Player, squares Squares) Board

LoadBoard loads board

func NewBoard

func NewBoard(whitePlayer, blackPlayer *Player) Board

NewBoard creates a new Board to play

type Color

type Color uint8

Color type

const (

	// BlackColor color identifier black
	BlackColor Color
	// WhiteColor color identifier white
	WhiteColor
)

type Coordinate

type Coordinate struct {
	X uint8
	Y uint8
}

Coordinate a coordinate within the Board, starting at 0,0 = A1, 8,8 = H8

func SquareIdentifierToCoordinate

func SquareIdentifierToCoordinate(i SquareIdentifier) Coordinate

SquareIdentifierToCoordinate returns Coordinate equals to SquareIdentifier

type Game

type Game interface {
	// Move moves a piece in the Board, returns true if moved
	Move(player Player, from, to SquareIdentifier) (bool, error)
	// Turn returns player turn
	Turn() Player
	// IsCheckBy returns true if Player makes check
	IsCheckBy(Player) bool
	// IsCheckmateBy returns true if Player makes checkmate
	IsCheckmateBy(Player) bool
	// Board get board
	Board() Board
	// Movements get all historic movements
	Movements() []Movement
	// Rollback returns to a previous stage, weight means how many steps back
	Rollback(weight int)

	WhitePieces() PiecesList
	BlackPieces() PiecesList

	String() string
}

Game playable game

func LoadGame

func LoadGame(
	name string,
	board Board,
	turn Player,
	white, black Player,
	whitePieces PiecesList,
	blackPieces PiecesList,
	movements []Movement,
) (Game, error)

LoadGame loads in game being played

func NewGame

func NewGame(name string, black, white Player) (Game, error)

NewGame creates new Game

type MockBoard

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

MockBoard is a mock of Board interface.

func NewMockBoard

func NewMockBoard(ctrl *gomock.Controller) *MockBoard

NewMockBoard creates a new mock instance.

func (*MockBoard) BlackPlayer

func (m *MockBoard) BlackPlayer() *Player

BlackPlayer mocks base method.

func (*MockBoard) EXPECT

func (m *MockBoard) EXPECT() *MockBoardMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockBoard) EatPiece

func (m *MockBoard) EatPiece(loc SquareIdentifier) Piece

EatPiece mocks base method.

func (*MockBoard) FillSquare

func (m *MockBoard) FillSquare(arg0 SquareIdentifier, arg1 Piece)

FillSquare mocks base method.

func (*MockBoard) Squares

func (m *MockBoard) Squares() Squares

Squares mocks base method.

func (*MockBoard) String

func (m *MockBoard) String() string

String mocks base method.

func (*MockBoard) WhitePlayer

func (m *MockBoard) WhitePlayer() *Player

WhitePlayer mocks base method.

type MockBoardMockRecorder

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

MockBoardMockRecorder is the mock recorder for MockBoard.

func (*MockBoardMockRecorder) BlackPlayer

func (mr *MockBoardMockRecorder) BlackPlayer() *gomock.Call

BlackPlayer indicates an expected call of BlackPlayer.

func (*MockBoardMockRecorder) EatPiece

func (mr *MockBoardMockRecorder) EatPiece(loc interface{}) *gomock.Call

EatPiece indicates an expected call of EatPiece.

func (*MockBoardMockRecorder) FillSquare

func (mr *MockBoardMockRecorder) FillSquare(arg0, arg1 interface{}) *gomock.Call

FillSquare indicates an expected call of FillSquare.

func (*MockBoardMockRecorder) Squares

func (mr *MockBoardMockRecorder) Squares() *gomock.Call

Squares indicates an expected call of Squares.

func (*MockBoardMockRecorder) String

func (mr *MockBoardMockRecorder) String() *gomock.Call

String indicates an expected call of String.

func (*MockBoardMockRecorder) WhitePlayer

func (mr *MockBoardMockRecorder) WhitePlayer() *gomock.Call

WhitePlayer indicates an expected call of WhitePlayer.

type MockPiece

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

MockPiece is a mock of Piece interface.

func NewMockPiece

func NewMockPiece(ctrl *gomock.Controller) *MockPiece

NewMockPiece creates a new mock instance.

func (*MockPiece) CanMove

func (m *MockPiece) CanMove(board Board, movements []Movement, from, to Square) bool

CanMove mocks base method.

func (*MockPiece) Color

func (m *MockPiece) Color() Color

Color mocks base method.

func (*MockPiece) EXPECT

func (m *MockPiece) EXPECT() *MockPieceMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockPiece) Identifier

func (m *MockPiece) Identifier() PieceIdentifier

Identifier mocks base method.

func (*MockPiece) String

func (m *MockPiece) String() string

String mocks base method.

type MockPieceMockRecorder

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

MockPieceMockRecorder is the mock recorder for MockPiece.

func (*MockPieceMockRecorder) CanMove

func (mr *MockPieceMockRecorder) CanMove(board, movements, from, to interface{}) *gomock.Call

CanMove indicates an expected call of CanMove.

func (*MockPieceMockRecorder) Color

func (mr *MockPieceMockRecorder) Color() *gomock.Call

Color indicates an expected call of Color.

func (*MockPieceMockRecorder) Identifier

func (mr *MockPieceMockRecorder) Identifier() *gomock.Call

Identifier indicates an expected call of Identifier.

func (*MockPieceMockRecorder) String

func (mr *MockPieceMockRecorder) String() *gomock.Call

String indicates an expected call of String.

type Movement

type Movement struct {
	Player     Player
	PieceMoved Piece
	PieceEaten Piece
	From       SquareIdentifier
	To         SquareIdentifier
}

Movement a movement made

type Piece

type Piece interface {
	// Name Piece name
	Identifier() PieceIdentifier
	// Color piece color
	Color() Color
	// CanMove check if piece can be moved from, to Square,
	// returns true if it's possible, even if a piece can be eaten
	CanMove(board Board, movements []Movement, from, to Square) bool

	String() string
}

Piece piece type

func NewBishop

func NewBishop(color Color) Piece

NewBishop creates Bishop piece

func NewKing

func NewKing(color Color) Piece

NewKing creates King piece

func NewKnight

func NewKnight(color Color) Piece

NewKnight creates knight piece

func NewPawn

func NewPawn(color Color) Piece

NewPawn creates Pawn piece

func NewQueen

func NewQueen(color Color) Piece

NewQueen creates Queen piece

func NewRook

func NewRook(color Color) Piece

NewRook creates Rook piece

func PieceFromPieceIdentifier

func PieceFromPieceIdentifier(i PieceIdentifier, color Color) Piece

PieceFromPieceIdentifier returns the corresponding Piece associated to PieceIdentifier

type PieceIdentifier

type PieceIdentifier uint8

PieceIdentifier identifier id piece

const (
	PawnIdentifier PieceIdentifier
	BishopIdentifier
	KnightIdentifier
	RookIdentifier
	QueenIdentifier
	KingIdentifier
)

PIECES

type PiecesList

type PiecesList map[PieceIdentifier]uint8

PiecesList is a map of pieces, each value contains number of pieces left in board

type Player

type Player struct {
	Name  string
	Color Color
}

Player gammer

type Square

type Square struct {
	Empty            bool
	Piece            Piece
	Coordinates      Coordinate
	SquareIdentifier SquareIdentifier
}

Square type val

func (*Square) String

func (s *Square) String() string

type SquareIdentifier

type SquareIdentifier uint8

SquareIdentifier square location identifier

const (
	A1 SquareIdentifier
	B1
	C1
	D1
	E1
	F1
	G1
	H1

	A2
	B2
	C2
	D2
	E2
	F2
	G2
	H2

	A3
	B3
	C3
	D3
	E3
	F3
	G3
	H3

	A4
	B4
	C4
	D4
	E4
	F4
	G4
	H4

	A5
	B5
	C5
	D5
	E5
	F5
	G5
	H5

	A6
	B6
	C6
	D6
	E6
	F6
	G6
	H6

	A7
	B7
	C7
	D7
	E7
	F7
	G7
	H7

	A8
	B8
	C8
	D8
	E8
	F8
	G8
	H8
)

Square unique names

func CoordinateToSquareIdentifier

func CoordinateToSquareIdentifier(c Coordinate) SquareIdentifier

CoordinateToSquareIdentifier returns equivalent value from Coordinate to Square Identifier

func StringToSquareIdentifier

func StringToSquareIdentifier(str string) (SquareIdentifier, bool)

StringToSquareIdentifier returns SquareIdentifier from string. i.e. str = F("A1") = A1, true

type Squares

type Squares map[SquareIdentifier]Square

Squares board squares, total of 8*8

func PristineSquares

func PristineSquares() Squares

PristineSquares returns Squares at game initialization

Jump to

Keyboard shortcuts

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