chess

package module
v0.0.0-...-3bccb7e Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2016 License: MIT Imports: 14 Imported by: 0

README

YeerChess

It's a pet project which implement the chess game invented by me when I was 13 years old.

Demo & Screenshot

http://yeerchess.github.io

How to Play?

Visit the demo site and see the help section.

Installation

	go get "github.com/athom/chess"
Run it on the geek way

Go to the cmd/yeerchessserver direcotry

go install .

Go to the cmd/yeerchessclient diretory

go install .

Then start a server in your terminal

yeerchessserver

Start a client in the terminal

yeerchessclient

Start another client in the terminal

yeerchessclient

You can have fun in the console now.

Run it as a web service.

First go to the cmd/yeerchesswebserver directory

go install .

Then start the server

yeerchesswebserver

It will start a webserver on port 3000.

Then check out another the HTML5 client repo. Change WS_HOST in the file app/app.js to your localhost or any server you run the chess server. Then open the index.html in your browser and you can see the App is playable.

How to play in the console mode?

The input use coordinate since mouse is not available. The format looks like this

x,y:m,n

The idea is Point1:Point2, means move piece from Point1 to Point2.

All possible poits on the board are:

(0,5) (1,5) (2,5) (3,5) (4,5) (5,5)

(0,4) (1,4) (2,4) (3,4) (4,4) (5,4)

(0,3) (1,3) (2,3) (3,3) (4,3) (5,3)

(0,2) (1,2) (2,2) (3,2) (4,2) (5,2)

(0,1) (1,1) (2,1) (3,1) (4,1) (5,1)

(0,0) (1,0) (2,0) (3,0) (4,0) (5,0)

So, for example, if you want to move your piece 3 from (2,0) to (2,3), you just type

2,0:2,3

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIllegalMove      = errors.New("illegal move")
	ErrGameOverWhiteWin = errors.New("game over, white win")
	ErrGameOverBlackWin = errors.New("game over, black win")
)
View Source
var CommandError = errors.New("wrong command")

Functions

This section is empty.

Types

type BoardInfo

type BoardInfo struct {
	Units
	Size int
}

type ConsoleMailBox

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

func (*ConsoleMailBox) Receive

func (this *ConsoleMailBox) Receive() (r *PlayerState)

func (*ConsoleMailBox) Send

func (this *ConsoleMailBox) Send(gs *GameState)

type Game

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

func NewGame

func NewGame(size int) (r *Game)

func (*Game) BoardInfo

func (this *Game) BoardInfo() (r BoardInfo)

func (*Game) LoadBoardInfo

func (this *Game) LoadBoardInfo(bi BoardInfo) (err error)

func (*Game) Move

func (this *Game) Move(srcPos, desPos Pos, side Side) (err error)

func (*Game) Select

func (this *Game) Select(pos Pos) (r []Pos)

type GameState

type GameState struct {
	State       OutState     `json:"state"`
	MyBoardInfo *MyBoardInfo `json:"boardInfo"`
}

func (GameState) ToJson

func (this GameState) ToJson() (r []byte)

type Hall

type Hall struct {
	sync.Mutex

	Joins chan MailBox
	// contains filtered or unexported fields
}

func NewHall

func NewHall() (r *Hall)

func (*Hall) Join

func (this *Hall) Join(conn MailBox)

func (*Hall) JoinRoom

func (this *Hall) JoinRoom(conn MailBox, slug string)

func (*Hall) Players

func (this *Hall) Players() []*Player

func (*Hall) Rooms

func (this *Hall) Rooms() []*Room

type InState

type InState int
const (
	IN_READY InState = 0
	IN_MOVE  InState = iota
	IN_ABORT
	IN_GIVEUP
	IN_ILLEAGLE_OPERATION
)

func (InState) String

func (this InState) String() string

type MailBox

type MailBox interface {
	Receive() *PlayerState
	Send(*GameState)
}

func NewConsoleMailBox

func NewConsoleMailBox(conn net.Conn) (r MailBox)

type Move

type Move struct {
	FromPos Pos `json:"from_pos"`
	ToPos   Pos `json:"to_pos"`
}

type MoveInfo

type MoveInfo struct {
	FromPos Pos `json:"from_pos"`
	ToPos   Pos `json:"to_pos"`
}

func NewMoveInfo

func NewMoveInfo(fromPos, toPos Pos) (r *MoveInfo)

type MyBoardInfo

type MyBoardInfo struct {
	BoardInfo
	Side    Side `json:"side"`
	Movable bool `json:"movable"`
}

func GameOverBoardInfo

func GameOverBoardInfo(bi BoardInfo, side Side) (r *MyBoardInfo)

func NewMyBoardInfo

func NewMyBoardInfo(bi BoardInfo, side Side) (r *MyBoardInfo)

func (*MyBoardInfo) FindUnit

func (this *MyBoardInfo) FindUnit(pos Pos) (r UnitInfo)

func (*MyBoardInfo) ToJson

func (this *MyBoardInfo) ToJson() (r []byte)

type OutState

type OutState int
const (
	OUT_WAIT  OutState = 0
	OUT_READY OutState = iota
	OUT_ILLEGAL_OPERATION
	OUT_BOARD_UPDATED
	OUT_OPPOENENT_ABORT
	OUT_OPPOENENT_GIVEUP
	OUT_GAMEOVER_WIN
	OUT_GAMEOVER_LOSE
	OUT_GAMEOVER_FOR_WATCHER
	OUT_WATCHER_LEAVE
)

func (OutState) String

func (this OutState) String() string

type Player

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

func NewPlayer

func NewPlayer(mb MailBox) (r *Player)

func (*Player) AbortGame

func (this *Player) AbortGame()

func (*Player) GiveUp

func (this *Player) GiveUp()

func (*Player) IsWatcher

func (this *Player) IsWatcher() bool

func (*Player) Move

func (this *Player) Move()

func (*Player) Ready

func (this *Player) Ready()

type PlayerState

type PlayerState struct {
	Id       string    `json:"id"`
	Side     Side      `json:"side"`
	State    InState   `json:"state"`
	MoveInfo *MoveInfo `json:"moveInfo"`
}

type PlayerStateParser

type PlayerStateParser struct {
}

func NewPlayerStateParser

func NewPlayerStateParser() (r *PlayerStateParser)

func (*PlayerStateParser) Parse

func (this *PlayerStateParser) Parse(msg string) (r *PlayerState)

type Pos

type Pos struct {
	X int `json:"x"`
	Y int `json:"y"`
}

func (*Pos) IsOutside

func (p *Pos) IsOutside(length int) bool

func (*Pos) Move

func (p *Pos) Move(x, y int) Pos

type Room

type Room struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewRoom

func NewRoom(players ...*Player) (r *Room)

func NewRoomWithSlug

func NewRoomWithSlug(slug string, players ...*Player) (r *Room)

func (*Room) BlackPlayer

func (this *Room) BlackPlayer() *Player

func (*Room) Join

func (this *Room) Join(player *Player)

func (*Room) JoinableForPlay

func (this *Room) JoinableForPlay() (r bool)

func (*Room) Leave

func (this *Room) Leave(player *Player)

func (*Room) Watchers

func (this *Room) Watchers() []*Player

func (*Room) WhitePlayer

func (this *Room) WhitePlayer() *Player

type Side

type Side int
const (
	NONE  Side = 0
	BLACK Side = iota
	WHITE
)

func (Side) String

func (this Side) String() string

type Unit

type Unit struct {
	Side      Side `json:"side"`
	Value     int  `json:"value"`
	JustMoved bool `json:"just_moved"`
}

func NewUnit

func NewUnit(side Side, v int) (r *Unit)

func (*Unit) Name

func (this *Unit) Name() string

func (*Unit) Set

func (this *Unit) Set(info UnitInfo)

func (*Unit) SetNone

func (this *Unit) SetNone()

func (*Unit) Turn

func (this *Unit) Turn(other *Unit)

type UnitInfo

type UnitInfo struct {
	Unit
	Pos Pos `json:"pos"`
}

type Units

type Units []UnitInfo

type WebsocketMailBox

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

func NewWebsocketMailBox

func NewWebsocketMailBox(ws *websocket.Conn) (r *WebsocketMailBox)

func (*WebsocketMailBox) Receive

func (this *WebsocketMailBox) Receive() (r *PlayerState)

func (*WebsocketMailBox) Run

func (this *WebsocketMailBox) Run()

func (*WebsocketMailBox) Send

func (this *WebsocketMailBox) Send(gs *GameState)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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