chess

package module
v0.0.0-...-4885b1b Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2020 License: BSD-3-Clause Imports: 6 Imported by: 0

README

Chess

Requirements

Echo

$ go get go get -u github.com/labstack/echo/...

How to run

$ go get github.com/utatti/chess/cmd/chess-server
$ DEBUG=1 chess-server

License

BSD

Documentation

Index

Constants

View Source
const MAX_RANK = 8

Variables

This section is empty.

Functions

func NewServer

func NewServer() *echo.Echo

Types

type Board

type Board map[Location]Piece

func NewBoard

func NewBoard() Board

func (Board) Copy

func (board Board) Copy() Board

func (Board) Json

func (board Board) Json() interface{}

type Game

type Game struct {
	Id string

	Phase

	Sessions map[uint64]Player
	Players  map[Player]string

	State
}

func CreateGame

func CreateGame(id string) *Game

func (*Game) Json

func (game *Game) Json() interface{}

func (*Game) Move

func (game *Game) Move(session uint64, from Location, to Location) error

func (*Game) Promote

func (game *Game) Promote(session uint64, to PieceType) error

func (*Game) Register

func (game *Game) Register(player Player, session uint64, name string) error

func (*Game) Reset

func (game *Game) Reset() error

func (*Game) Unregister

func (game *Game) Unregister(session uint64) error

type Location

type Location struct {
	Row int8 `json:"row"`
	Col int8 `json:"col"`
}

func LocationFromInt8

func LocationFromInt8(i int8) Location

func MovableLocationsFromBishop

func MovableLocationsFromBishop(board Board, from Location) []Location

func MovableLocationsFromKing

func MovableLocationsFromKing(board Board, from Location) []Location

func MovableLocationsFromKnight

func MovableLocationsFromKnight(board Board, from Location) []Location

func MovableLocationsFromPawn

func MovableLocationsFromPawn(board Board, from Location) []Location

func MovableLocationsFromQueen

func MovableLocationsFromQueen(board Board, from Location) []Location

func MovableLocationsFromRook

func MovableLocationsFromRook(board Board, from Location) []Location

func (Location) Abs

func (loc Location) Abs() Location

func (Location) Int8

func (loc Location) Int8() int8

func (Location) IsValid

func (loc Location) IsValid() bool

func (Location) Relative

func (loc Location) Relative(row int8, col int8) Location

func (Location) RelativeTo

func (loc Location) RelativeTo(other Location) Location

type Phase

type Phase uint8
const (
	WAITING Phase
	ACTIVE
	DONE
)

type Piece

type Piece struct {
	Owner Player    `json:"owner"`
	Type  PieceType `json:"type"`
	Moved bool      `json:"moved"`
}

func (*Piece) IsOwnedBy

func (piece *Piece) IsOwnedBy(player Player) bool

type PieceType

type PieceType uint8
const (
	KING PieceType
	QUEEN
	ROOK
	BISHOP
	KNIGHT
	PAWN
)

type Player

type Player int8
const (
	P1 Player = 1
	P2        = -1
)

func (Player) RankedLocation

func (player Player) RankedLocation(rank int8, col int8) Location

func (Player) RankedRow

func (player Player) RankedRow(rank int8) int8

type State

type State struct {
	Turn Player
	Board
	Promotion   *Location
	LastUpdated int64
}

func NewState

func NewState() State

func (*State) IsChecked

func (state *State) IsChecked() bool

func (*State) IsCheckmated

func (state *State) IsCheckmated() bool

func (*State) Json

func (state *State) Json() interface{}

func (*State) TryMove

func (state *State) TryMove(from Location, to Location) error

func (*State) TryPromote

func (state *State) TryPromote(to PieceType) error

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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