pkg

package
v0.0.0-...-37fe667 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2021 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ActionDrawOffer     Action = "Want Draw"
	ActionDrawPrompt           = "Draw?"
	ActionDrawAccept           = "Accept"
	ActionDrawReject           = "Reject"
	ActionResignPrompt         = "Resign"
	ActionResignYes            = "Yes"
	ActionResignNo             = "No"
	ActionNewGamePrompt        = "New Game?"
	ActionNewGameOffer         = "New Game"
	ActionNewGameAccept        = "Yes!"
	ActionNewGameReject        = "No~"
	ActionExit                 = "Exit"
	ActionWin                  = "Win"
	ActionLose                 = "Lose"
	ActionDraw                 = "Draw"
	ActionTimeOut              = "Time Out"
)
View Source
const (
	CommandLs       Command = "ls"
	CommandCreate           = "create"
	CommandJoin             = "join"
	CommandCallme           = "callme"
	CommandMessage          = "message"
	CommandPractice         = "practice"
)
View Source
const (
	ServerIdleTimeout = 30 * time.Minute
	ServerPort        = ":1998"
	MessageQueueSize  = 20
)
View Source
const (
	ConnQueueSize = 10
)

Variables

View Source
var (
	ChatTextView         *tview.TextView
	StatusTextView       *tview.TextView
	MenuTextView         *tview.TextView
	HistoryTextView      *tview.TextView
	OpponentTimeTextView *tview.TextView
	OurTimeTextView      *tview.TextView
)
View Source
var (
	ChesstermBinary string
	LogPath         string
	SshPort         = ":2222"
)

Functions

func Center

func Center(width, height int, p tview.Primitive) tview.Primitive

Center returns a new primitive which shows the provided primitive in its center, given the provided primitive's size.

func Decode

func Decode(data []byte, o interface{})

func Encode

func Encode(o interface{}) json.RawMessage

func GameFromFEN

func GameFromFEN(gamefen string) *chess.Game

func InitLog

func InitLog(dest, prefix string)

func NewGame

func NewGame() *chess.Game

Types

type Action

type Action string

ACTIONS

type Client

type Client struct {
	Game          *chess.Game
	App           *tview.Application
	Board         *tview.Table
	GameLayout    *tview.Grid
	MenuLayout    *tview.Grid
	OurClock      *Clock
	OpponentClock *Clock
	Conn          net.Conn
	In            chan MessageInterface
	Out           chan MessageInterface

	Role PlayerRole
	// contains filtered or unexported fields
}

func NewClient

func NewClient() *Client

func (*Client) Connect

func (cl *Client) Connect(port string)

func (*Client) Disconnect

func (cl *Client) Disconnect()

func (*Client) HandleAction

func (cl *Client) HandleAction(action Action)

func (*Client) HandleRead

func (cl *Client) HandleRead()

func (*Client) HandleWrite

func (cl *Client) HandleWrite()

func (*Client) InitGUI

func (cl *Client) InitGUI()

func (*Client) UpdateTime

func (cl *Client) UpdateTime()

type Clock

type Clock struct {
	Duration  time.Duration
	Remaining time.Duration
	Increment time.Duration
	Paused    bool
}

func NewClock

func NewClock(duration, increment time.Duration) *Clock

func (*Clock) Pause

func (cl *Clock) Pause()

func (*Clock) Reset

func (cl *Clock) Reset()

func (*Clock) Run

func (cl *Clock) Run()

func (*Clock) String

func (cl *Clock) String() string

func (*Clock) Tick

func (cl *Clock) Tick()

type Command

type Command string

COMMANDS

type Match

type Match struct {
	//Players [2]*Player
	Players       map[int]*Player
	Game          *chess.Game
	Server        Server
	Turn          PlayerRole
	In            chan MessageInterface
	Out           chan MessageInterface
	Name          string
	PracticeMode  bool
	Engine        *uci.Engine
	PracticeLevel int
	Duration      time.Duration
	Increment     time.Duration
	Clocks        map[int]*Clock
}

func NewMatch

func NewMatch(name string, practiceMode bool, duration, increment int) *Match

func (*Match) AddConn

func (m *Match) AddConn(conn net.Conn, name string)

func (*Match) GameFEN

func (m *Match) GameFEN() string

func (*Match) GameMoves

func (m *Match) GameMoves() []string

func (*Match) HandleRead

func (m *Match) HandleRead()

func (*Match) NextMove

func (m *Match) NextMove() string

func (*Match) ReMatch

func (m *Match) ReMatch()

func (*Match) WatchTime

func (m *Match) WatchTime()

type MessageConnect

type MessageConnect struct {
	Role       PlayerRole
	Fen        string
	IsTurn     bool
	BlackClock *Clock
	WhiteClock *Clock
}

Initialize connection

func (MessageConnect) Type

func (m MessageConnect) Type() MessageType

type MessageGame

type MessageGame struct {
	Fen    string
	IsTurn bool
	Moves  []string
}

Game Update

func (MessageGame) Type

func (m MessageGame) Type() MessageType

type MessageGameAction

type MessageGameAction struct {
	Action  Action
	Message string
}

func (MessageGameAction) Type

func (m MessageGameAction) Type() MessageType

type MessageGameChat

type MessageGameChat struct {
	Message string
	Name    string
	Time    time.Time
}

Chatting purpose

func (MessageGameChat) Type

func (m MessageGameChat) Type() MessageType

type MessageGameCommand

type MessageGameCommand struct {
	Command  Command
	Argument []string
}

func (MessageGameCommand) Type

type MessageGameStatus

type MessageGameStatus struct {
	Message string
}

func (MessageGameStatus) Type

func (m MessageGameStatus) Type() MessageType

type MessageInterface

type MessageInterface interface {
	Type() MessageType
}

type MessageMatchRemovePlayer

type MessageMatchRemovePlayer struct {
	PlayerId int
}

func (MessageMatchRemovePlayer) Type

type MessageMove

type MessageMove struct {
	Move string
	Msg  string
}

Move from player

func (MessageMove) Type

func (m MessageMove) Type() MessageType

type MessageTransport

type MessageTransport struct {
	MsgType  MessageType
	Data     json.RawMessage
	PlayerId int
}

A generic sturct used to transport between server-client

func (MessageTransport) Type

func (m MessageTransport) Type() MessageType

type MessageType

type MessageType int
const (
	TypeMessageGame MessageType = iota
	TypeMessageMove
	TypeMessageTransport
	TypeMessageConnect
	TypeMessageGameChat
	TypeMessageGameAction
	TypeMessageGameStatus
	TypeMessageMatchRemovePlayer
	TypeMessageGameCommand
)

func (MessageType) String

func (m MessageType) String() string

type Player

type Player struct {
	Conn net.Conn
	Role PlayerRole
	Out  chan MessageInterface
	Id   int
	Name string
}

func NewPlayer

func NewPlayer(conn net.Conn, name string) *Player

func (*Player) Disconnect

func (p *Player) Disconnect()

func (*Player) HandleRead

func (p *Player) HandleRead(In chan MessageInterface)

func (*Player) HandleWrite

func (p *Player) HandleWrite()

type PlayerRole

type PlayerRole int
const (
	White PlayerRole = iota
	Black
	Viewer
)

func (PlayerRole) String

func (pc PlayerRole) String() string

type Server

type Server struct {
	*ssh.Server
	Matches map[string]*Match
	Clients []net.Conn
	Engine  *uci.Engine
	In      chan MessageInterface
	Out     chan MessageInterface
}

func NewServer

func NewServer(binary string, sshPort string, logPath string) *Server

func (*Server) AddConn

func (s *Server) AddConn(conn net.Conn, matchId, name string, duration, increment int)

func (*Server) CleanIdleMatches

func (s *Server) CleanIdleMatches()

func (*Server) HandleConn

func (s *Server) HandleConn(sconn ServerConn)

func (*Server) IsMatchExisted

func (s *Server) IsMatchExisted(name string) bool

func (*Server) NewMatchName

func (s *Server) NewMatchName() string

type ServerConn

type ServerConn struct {
	Conn net.Conn
	Name string
}

Jump to

Keyboard shortcuts

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