chess

package
v0.0.0-...-d7178b9 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PAWN   = 0
	KNIGHT = 1
	BISHOP = 2
	ROOK   = 3
	QUEEN  = 4
	KING   = 5
)

piece types

View Source
const (
	INFINITY   = 50000
	MATE_VALUE = 49000
	MATE_SCORE = 48000
	MAX_PLY    = 64
)
View Source
const (
	P piece = iota
	N
	B
	R
	Q
	K
)

encode pieces

Variables

View Source
var (
	UCI          = []byte("uci")
	ISREADY      = []byte("isready")
	UCINEWGAME   = []byte("ucinewgame")
	POSITION     = []byte("position")
	GO           = []byte("go")
	STARTPOS     = []byte("startpos")
	FEN          = []byte("fen")
	STARTPOS_FEN = []byte(start_position)
	MOVES        = []byte("moves")
	DEPTH        = []byte("depth")
	WINC         = []byte("winc")
	BINC         = []byte("binc")
	WTIME        = []byte("wtime")
	BTIME        = []byte("btime")
	MOVETIME     = []byte("movetime")
	MOVESTOGO    = []byte("movestogo")
)
View Source
var StringToSquare = map[string]int{
	"a1": 56, "a2": 48, "a3": 40, "a4": 32, "a5": 24, "a6": 16, "a7": 8, "a8": 0,
	"b1": 57, "b2": 49, "b3": 41, "b4": 33, "b5": 25, "b6": 17, "b7": 9, "b8": 1,
	"c1": 58, "c2": 50, "c3": 42, "c4": 34, "c5": 26, "c6": 18, "c7": 10, "c8": 2,
	"d1": 59, "d2": 51, "d3": 43, "d4": 35, "d5": 27, "d6": 19, "d7": 11, "d8": 3,
	"e1": 60, "e2": 52, "e3": 44, "e4": 36, "e5": 28, "e6": 20, "e7": 12, "e8": 4,
	"f1": 61, "f2": 53, "f3": 45, "f4": 37, "f5": 29, "f6": 21, "f7": 13, "f8": 5,
	"g1": 62, "g2": 54, "g3": 46, "g4": 38, "g5": 30, "g6": 22, "g7": 14, "g8": 6,
	"h1": 63, "h2": 55, "h3": 47, "h4": 39, "h5": 31, "h6": 23, "h7": 15, "h8": 7,
}

Functions

func GetTimeMs

func GetTimeMs() int64

get time in milliseconds

func MoveToString

func MoveToString(move Move) string

print move (for UCI purposes)

func UnmarshalAction

func UnmarshalAction(bytes []byte) (*inputEvent, error)

func UpdateClient

func UpdateClient(c *Client, update Output)

Types

type Bitboard

type Bitboard uint64

func (Bitboard) GetLs1bIndex

func (b Bitboard) GetLs1bIndex() int

get least significant 1st bit index

func (*Bitboard) PopLs1b

func (b *Bitboard) PopLs1b()

type Board

type Board struct {
	Bitboards   [12]Bitboard
	Occupancies [3]Bitboard
	Side        Side
	Enpassant   square
	Castle      castle
	HashKey     Bitboard
	Fifty       int
}

func NewBoadFromFen

func NewBoadFromFen(fen []byte) *Board

parse FEN string

func Startpos

func Startpos() Board

func (*Board) Gameover

func (board *Board) Gameover() bool

func (*Board) GetLegalMoves

func (board *Board) GetLegalMoves(capturesOnly bool) *Moves

func (*Board) GetPieces

func (b *Board) GetPieces() map[int]string

func (*Board) MakeMove

func (board *Board) MakeMove(move Move, capturesOnly bool) bool

Tries to make a move

type Client

type Client struct {
	Side Side
	// contains filtered or unexported fields
}

func NewClient

func NewClient(game *Game, conn *websocket.Conn, side Side, ctx context.Context) *Client

func (*Client) ListenInput

func (c *Client) ListenInput()

func (*Client) ListenOutput

func (c *Client) ListenOutput()

type Engine

type Engine struct {
	Board
	TimeController
	Searcher
	RepetitionTable []Bitboard
	// contains filtered or unexported fields
}

func NewEngine

func NewEngine() Engine

func (*Engine) ReceiveCommand

func (e *Engine) ReceiveCommand(message []byte)

func (*Engine) Search

func (e *Engine) Search() Move

parse UCI "go" command

type Game

type Game struct {
	Manager *Manager
	GameID  string

	Moves    pq.Int32Array
	Messages []models.Message
	// contains filtered or unexported fields
}

func NewGame

func NewGame(manager *Manager, whiteID, blackID string, timeGiven time.Duration) *Game

func (*Game) Connect

func (g *Game) Connect(w http.ResponseWriter, r *http.Request, userID string) error

func (*Game) InputEvent

func (g *Game) InputEvent(ie *inputEvent)

func (*Game) Start

func (g *Game) Start()

type Manager

type Manager struct {

	// Lock when reading or writing
	sync.RWMutex

	Storage db.Storage
	// contains filtered or unexported fields
}

func NewManager

func NewManager(storage db.Storage) *Manager

func (*Manager) GetGame

func (m *Manager) GetGame(gameID string) *Game

func (*Manager) GetUserGameID

func (m *Manager) GetUserGameID(userID string) string

func (*Manager) HandleGame

func (m *Manager) HandleGame(w http.ResponseWriter, r *http.Request)

func (*Manager) HandlePlay

func (m *Manager) HandlePlay(w http.ResponseWriter, r *http.Request)

func (*Manager) MakeGame

func (m *Manager) MakeGame(whiteID, blackID string)

func (*Manager) RemoveGame

func (m *Manager) RemoveGame(game *Game, winnerID string)

func (*Manager) UpdateRating

func (m *Manager) UpdateRating(winnerID, loserID string, isDraw bool)

type Move

type Move uint32

func (Move) GetSource

func (m Move) GetSource() int

extract source square

func (Move) GetTarget

func (m Move) GetTarget() int

extract target square

func (Move) IsCapture

func (m Move) IsCapture() bool

extract capture flag

func (Move) String

func (m Move) String() string

type Moves

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

func (*Moves) At

func (m *Moves) At(i int) Move

func (*Moves) Count

func (m *Moves) Count() int

func (*Moves) FilterSelected

func (m *Moves) FilterSelected(source int) *Moves

type Output

type Output struct {
	Type    string
	Payload interface{}
}

type Searcher

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

type Side

type Side int

type TimeController

type TimeController struct {
	// exit from engine flag
	Quit int

	// UCI "movestogo" command moves counter
	MovesToGo int

	// UCI "movetime" command time counter
	MoveTime int

	// UCI "time" command holder (ms)
	Time int

	// UCI "inc" command's time increment holder
	Inc int

	// UCI "starttime" command time holder
	StartTime int64

	// UCI "stoptime" command time holder
	StopTime int64

	// variable to flag time control availability
	Timeset int

	// variable to flag when the time is up
	Stopped int
}

func NewTimeController

func NewTimeController() TimeController

Jump to

Keyboard shortcuts

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