pkg

package
v0.0.0-...-c5bc949 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2023 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ApplicationTitle string = `[blue]chess-cli ♟️ [white]
Play locally with a [yellow]friend[white] or online with [red]Lichess!`
	LichessTitle  string = "[blue]chess-cli[white]: [red]lichess[white] client"
	LichessRibbon string = "CHESS-CLI | LICHESS CLIENT | Press 'Ctrl-c' to quit"

	OngoingRibbonstr string = "CHESS-CLI -> Ongoing Games | Press 'Ctrl-c' to quit"
	EmptyChar        string = "博"
)

Variables

View Source
var (
	Root = new(State)

	NewChessGame *chess.Game //used in online.go in the LichessGame() function to update the board position from new stream event

	CurrentChallenge api.CreateChallengeType

	StreamChannel      chan api.StreamEventType
	LastSelectedCell   PiecePosition
	GameListIDArr      []string
	OutChallengeGameID []string
	InChallengeGameID  []string
	EventStreamArr     []api.StreamEventType
	Ready              chan struct{}
)
View Source
var (
	PiecesMap = map[rune]string{
		'K': "♔",
		'Q': "♕",
		'R': "♖",
		'B': "♗",
		'N': "♘",
		'P': "♙",
		'k': "♚",
		'q': "♛",
		'r': "♜",
		'b': "♝",
		'n': "♞",
		'p': "🨾",
	}

	KnightIconMap = map[int]string{
		0: " ♞ ",
		1: " 🨇 ",
		2: " 🨓 ",
		3: " 🨜 ",
		4: " 🨨 ",
		5: " 🨱 ",
		6: " 🨽 ",
		7: " 🩆 ",
	}

	NormalLoaderMap = map[int64]string{
		0: "⠋",
		1: "⠙",
		2: "⠹",
		3: "⠸",
		4: "⠼",
		5: "⠴",
		6: "⠦",
		7: "⠧",
		8: "⠇",
		9: "⠏",
	}

	RandQuoteMap = map[int]string{
		0:  "“I have come to the personal conclusion that while all artists are not chess players, all chess players are artists.”\n – Marcel Duchamp",
		1:  "“Unlike other games in which lucre is the end and aim, [chess] recommends itself to the wise by the fact that its mimic battles are fought for no prize but honor. \nIt is eminently and emphatically the philosopher’s game.”\n – Paul Morphy",
		2:  "“The beauty of chess is it can be whatever you want it to be. \nIt transcends language, age, race, religion, politics, gender, and socioeconomic background. \nWhatever your circumstances, anyone can enjoy a good fight to the death over the chess board.”\n – Simon Williams",
		3:  "“Chess is the struggle against the error.”\n – Johannes Zukertort",
		4:  "“Every chess master was once a beginner.”\n – Irving Chernev",
		5:  "“Avoid the crowd. \nDo your own thinking independently. \nBe the chess player, not the chess piece.”\n – Ralph Charell",
		6:  "“Chess makes men wiser and clear-sighted.”\n – Vladimir Putin",
		7:  "“Chess is the gymnasium of the mind.”\n – Blaise Pascal",
		8:  "“Chess holds its master in its own bonds, shackling the mind and brain so that the inner freedom of the very strongest must suffer.”\n – Albert Einstein",
		9:  "“Chess is a war over the board. \nThe object is to crush the opponent’s mind.”\n – Bobby Fischer",
		10: "“I am convinced, the way one plays chess always reflects the player’s personality. \nIf something defines his character, then it will also define his way of playing.”\n – Vladimir Kramnik",
		11: "“The game of chess is not merely an idle amusement. \nSeveral very valuable qualities of the mind, useful in the course of human life, are to be acquired or strengthened by it… Life is a kind of Chess, in which we have often points to gain, and competitors or adversaries to contend with.”\n – Benjamin Franklin",
		12: "“As proved by evidence, [chess is] more lasting in its being and presence than all books and achievements; the only game that belongs to all people and all ages; of which none knows the divinity that bestowed it on the world, to slay boredom, to sharpen the senses, to exhilarate the spirit.”\n – Stefan Zweig",
		13: "“Chess doesn’t drive people mad, it keeps mad people sane.”\n – Bill Hartston",
		14: "“In life, as in chess, one’s own pawns block one’s way. \n A man’s very wealthy, ease, leisure, children, books, which should help him to win, more often checkmate him.”\n – Charles Buxton",
		15: "“Chess is life in miniature. \nChess is a struggle, chess battles.”\n – Garry Kasparov",
		16: "“Chess, like love, like music, has the power to make men happy.”\n – Siegbert Tarrasch",
		17: "“For in the idea of chess and the development of the chess mind we have a picture of the intellectual struggle of mankind.”\n – Richard Réti",
		18: "“I don’t believe in psychology. \nI believe in good moves.”\n – Bobby Fischer",
		19: "“Play the opening like a book, the middlegame like a magician, and the endgame like a machine.”\n – Rudolph Spielmann",
		20: "“I used to attack because it was the only thing I knew. \nNow I attack because I know it works best.”\n – Garry Kasparov",
		21: "“It is my style to take my opponent and myself on to unknown grounds. \nA game of chess is not an examination of knowledge; it is a battle of nerves.”\n – David Bronstein",
		22: "“Chess is rarely a game of ideal moves. \nAlmost always, a player faces a series of difficult consequences whichever move he makes.”\n – David Shenk",
		23: "“When you see a good move, look for a better one.”\n – Emanuel Lasker",
		24: "“After a bad opening, there is hope for the middle game. \nAfter a bad middle game, there is hope for the endgame. \nBut once you are in the endgame, the moment of truth has arrived.”\n – Edmar Mednis",
		25: "“Give me a difficult positional game, I will play it. \nBut totally won positions, I cannot stand them.”\n – Hein Donner",
		26: "“There is no remorse like the remorse of chess.”\n – H. G. Wells",
		27: "“Half the variations which are calculated in a tournament game turn out to be completely superfluous. \nUnfortunately, no one knows in advance which half.”\n – Jan Timman",
		28: "“Even a poor plan is better than no plan at all.”\n – Mikhail Chigorin",
		29: "“Tactics is knowing what to do when there is something to do; strategy is knowing what to do when there is nothing to do.”\n – Savielly Tartakower",
		30: "“In life, as in chess, forethought wins.”\n – Charles Buxton",
		31: "“You may learn much more from a game you lose than from a game you win. \nYou will have to lose hundreds of games before becoming a good player.”\n – José Raúl Capablanca",
		32: "“Pawns are the soul of the game.”\n – François-André Danican Philidor",
		33: "“The passed pawn is a criminal, who should be kept under lock and key. \nMild measures, such as police surveillance, are not sufficient.”\n – Aron Nimzowitsch",
		34: "“Modern chess is too much concerned with things like pawn structure. \nForget it, checkmate ends the game.”\n – Nigel Short",
		35: "“Pawn endings are to chess what putting is to golf.”\n – Cecil Purdy",
		36: "“Nobody ever won a chess game by resigning.”\n – Savielly Tartakower",
		37: "“The blunders are all there on the board, waiting to be made.”\n – Savielly Tartakower",
		38: "“It’s always better to sacrifice your opponent’s men.”\n – Savielly Tartakower",
		39: "“One doesn’t have to play well, it’s enough to play better than your opponent.”\n – Siegbert Tarrasch",
		40: "“Up to this point, White has been following well-known analysis. \nBut now he makes a fatal error: he begins to use his own head.”\n – Siegbert Tarrasch",
		41: "“Of chess, it has been said that life is not long enough for it, but that is the fault of life, not chess.”\n – William Napier",
		42: "“Chess is beautiful enough to waste your life for.”\n – Hans Ree",
		43: "“A chess game in progress is… a cosmos unto itself, fully insulated from an infant’s cry, an erotic invitation, or war.”\n – David Shenk",
		44: "“It will be cheering to know that many people are skillful chess players, though in many instances their brains, in a general way, compare unfavorably with the cognitive faculties of a rabbit.”\n – James Mortimer",
		45: "“The pin is mightier than the sword.”\n – Fred Reinfeld",
		46: "“The only thing chess players have in common is chess.”\n – Lodewijk Prins",
		47: "“Those who say they understand chess, understand nothing.”\n – Robert Hübner",
		48: "“One bad move nullifies forty good ones.”\n – Bernhard Horwitz",
		49: "“If your opponent offers you a draw, try to work out why he thinks he’s worse off.”\n – Nigel Short",
		50: "“A computer once beat me at chess, but it was no match for me at kick boxing.” - Emo Phillips",
		51: "“I did **** all, and it proved to be enough!” - Tony Miles",
		52: "“To win against me, you must beat me three times: in the opening, the middlegame and the endgame.”\n – Alexander Alekhine",
		53: "“There are two kinds of sacrifices; correct ones and mine.”\n – Mikhail Tal",
		54: "“After 1.e4 White”s game is in its last throes.” - Gyula Breyer.",
		55: "“The most important move in chess, as in life, is the one you just made.” - Unknown",
		56: "“I like chess.” - H.F. Witte",
	}
)

Functions

func Center

func Center(width, height int, p cv.Primitive, toFocus cv.Primitive) cv.Primitive

func DrawBoard

func DrawBoard(table *cv.Table, white bool)

func DrawMoveHistory

func DrawMoveHistory(win *cv.TextView)

func EventContainedInEventStream

func EventContainedInEventStream(a []api.StreamEventType, eventtype string) (api.StreamEventType, bool)

func FENtoBoard

func FENtoBoard(table *cv.Table, FEN string, white bool)

func GetCapturePiecesArr

func GetCapturePiecesArr(seq string) error

func GetMoveType

func GetMoveType(movestr string, g *chess.Game) (*chess.Move, error)

func GetPiece

func GetPiece(p string, g *chess.Game) chess.Piece

func GetPieceArr

func GetPieceArr(moveArr []string) ([]string, error)

func GetRandomQuote

func GetRandomQuote() string

func InitUI

func InitUI()

func LocalTableHandler

func LocalTableHandler(row, col int)

func MoveTranslationToFEN

func MoveTranslationToFEN(sequence string) (string, error)

func NewOptionWindow

func NewOptionWindow(msg, op1, op2 string, handler1, handler2 func()) *cv.Flex

func RandStringRunes

func RandStringRunes(n int) string

func RestoreGame

func RestoreGame(info SavedInfo) error

func SendChallengeRequest

func SendChallengeRequest(gchan chan<- string, errchan chan<- error)

func StreamConsumer

func StreamConsumer(EventChannel <-chan api.StreamEventType)

consumes stream events for a user after stream for a user started after login

func UpdateChessGame

func UpdateChessGame()

func WaitForLichessGameResponse

func WaitForLichessGameResponse()

func WelcomeInit

func WelcomeInit() *cv.Grid

func WriteLocal

func WriteLocal(title string, payload string)

writes to a local text file

Types

type BothInc

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

type Challenges

type Challenges struct {
	Out *cv.List
	In  *cv.List
}

func (*Challenges) Init

func (c *Challenges) Init() *cv.Grid

func (*Challenges) UpdateList

func (c *Challenges) UpdateList()

type GameScreen

type GameScreen struct {
	Board     *cv.Table
	Status    *cv.TextView
	History   *cv.TextView
	UserInfo  *cv.TextView
	UserTimer *cv.TextView
	OppInfo   *cv.TextView
	OppTimer  *cv.TextView
	List      *cv.List
}

func (*GameScreen) DoMove

func (g *GameScreen) DoMove(m string) error

func (*GameScreen) Init

func (g *GameScreen) Init() *cv.Grid

local game grid

func (*GameScreen) UpdateStatus

func (g *GameScreen) UpdateStatus()

func (*GameScreen) UpdateUserInfo

func (g *GameScreen) UpdateUserInfo()

type GameState

type GameState struct {
	Game             *chess.Game
	NextMove         string
	MoveHistoryArray []string
	LegalMoves       []string
	Status           string
	MoveCount        int
	WhiteCaptured    []string
	BlackCaptured    []string
	Started          string
	Hash             string
	LastPlayed       string
}

func (*GameState) Init

func (s *GameState) Init()

func (*GameState) SaveGame

func (gs *GameState) SaveGame(new bool)

func (*GameState) UpdateLegalMoves

func (gs *GameState) UpdateLegalMoves()

type ListSelectedFunc

type ListSelectedFunc func() //used to easily add functions to list items in initUI.go

type Loader

type Loader struct {
	Message *cv.TextView
	Icon    *cv.TextView
}

func (*Loader) DrawIcon

func (l *Loader) DrawIcon(i int) int

func (*Loader) DrawMessage

func (l *Loader) DrawMessage(msg string)

func (*Loader) Init

func (l *Loader) Init() *cv.Grid

type Login

type Login struct {
	Token              string
	Email              string
	Online             bool
	StreamStart        bool
	Name               string
	Friends            []string
	OngoingGames       []api.OngoingGameInfo
	IncomingChallenges []api.ChallengeInfo
	OutgoingChallenges []api.ChallengeInfo
}

func (*Login) GetChallenges

func (user *Login) GetChallenges() error

func (*Login) GetLichessUserInfo

func (user *Login) GetLichessUserInfo() error

func (*Login) GetOngoing

func (user *Login) GetOngoing() error

func (*Login) Init

func (user *Login) Init() error

type Ongoing

type Ongoing struct {
	List    *cv.List
	Preview *cv.Table
}

func (*Ongoing) Init

func (ong *Ongoing) Init() *cv.Grid

func (*Ongoing) UpdateList

func (ongoing *Ongoing) UpdateList()

type OnlineGame

type OnlineGame struct {
	Grid      *cv.Grid
	Board     *cv.Table
	Status    *cv.TextView
	History   *cv.TextView
	List      *cv.List
	UserInfo  *cv.TextView
	UserTimer *cv.TextView
	OppInfo   *cv.TextView
	OppTimer  *cv.TextView
	PopUp     *cv.Flex

	Full   api.StreamBoardGameFull
	State  api.StreamBoardGameState
	Resign api.StreamBoardResign
}

func (*OnlineGame) DoMove

func (og *OnlineGame) DoMove(move string) error

func (*OnlineGame) Init

func (g *OnlineGame) Init() *cv.Grid

func (*OnlineGame) InitTimeView

func (og *OnlineGame) InitTimeView()

func (*OnlineGame) LichessGame

func (online *OnlineGame) LichessGame(gameID string)

LichessGame() is called after a gameID string has been retrieved from the event stream by WaitForLichessGameResponse() This function then starts a board stream with the gameID and loops and modifies the gamestate and view based on events from the board stream.

func (*OnlineGame) LiveUpdateTime

func (og *OnlineGame) LiveUpdateTime(b int64, w int64)

func (*OnlineGame) OnlineTableHandler

func (online *OnlineGame) OnlineTableHandler(row, col int)

func (*OnlineGame) TimerLoop

func (online *OnlineGame) TimerLoop(d <-chan bool, bi <-chan BothInc)

func (*OnlineGame) UpdateAll

func (og *OnlineGame) UpdateAll()

func (*OnlineGame) UpdateList

func (og *OnlineGame) UpdateList()

func (*OnlineGame) UpdateStatus

func (og *OnlineGame) UpdateStatus()

func (*OnlineGame) UpdateUserInfo

func (og *OnlineGame) UpdateUserInfo()

type OnlinePostGame

type OnlinePostGame struct {
	Grid *cv.Grid

	Board   *cv.Table
	Result  *cv.TextView
	History *cv.TextView
	PopUp   *cv.Flex
}

func (*OnlinePostGame) Init

func (pg *OnlinePostGame) Init() *cv.Grid

func (*OnlinePostGame) UpdateResult

func (pg *OnlinePostGame) UpdateResult()

type PiecePosition

type PiecePosition struct {
	Row    int
	Col    int
	Alg    string
	Empty  bool
	Symbol string
}

type PostGameScreen

type PostGameScreen struct {
	Board   *cv.Table
	Result  *cv.TextView
	History *cv.TextView
}

func (*PostGameScreen) Init

func (p *PostGameScreen) Init() *cv.Grid

func (*PostGameScreen) UpdateResult

func (g *PostGameScreen) UpdateResult()

type SavedGameList

type SavedGameList struct {
	Games []SavedInfo `json:"games"`
}

func (*SavedGameList) Init

func (s *SavedGameList) Init()

type SavedGames

type SavedGames struct {
	List    *cv.List
	Preview *cv.Table
}

func (*SavedGames) Init

func (sg *SavedGames) Init() *cv.Grid

func (*SavedGames) UpdateList

func (sg *SavedGames) UpdateList()

type SavedInfo

type SavedInfo struct {
	FEN              string   `json:"fen"`
	MoveCount        int      `json:"move_count"`
	MoveHistoryArray []string `json:"move_history_array"`
	WhiteCaptured    []string `json:"white_captured"`
	BlackCaptured    []string `json:"black_captured"`
	Hash             string   `json:"hash"`
	LastPlayed       string   `json:"date"`
	Started          string   `json:"started"`
}

func RemoveIndex

func RemoveIndex(s []SavedInfo, index int) []SavedInfo

type State

type State struct {
	App *cv.Application

	Shell string

	User *Login
	// contains filtered or unexported fields
}

func (*State) Login

func (s *State) Login() error

func (*State) NewGame

func (s *State) NewGame()

func (*State) RefreshAll

func (s *State) RefreshAll(p ...cv.Primitive)

func (*State) Switch

func (s *State) Switch(panel string)

type WelcomeOnline

type WelcomeOnline struct {
	Title *cv.TextView
}

func (*WelcomeOnline) Init

func (w *WelcomeOnline) Init() *cv.Grid

func (*WelcomeOnline) UpdateTitle

func (w *WelcomeOnline) UpdateTitle(msg string)

Jump to

Keyboard shortcuts

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