game

package
v0.0.0-...-6d3abe3 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const BotActivityName = "play"

Variables

View Source
var ChessNotation = chess.UCINotation{}

Functions

This section is empty.

Types

type Bot

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

func NewBot

func NewBot() (*Bot, error)

func (*Bot) Play

func (b *Bot) Play(fen string, dur time.Duration) (*chess.Move, error)

func (*Bot) Stop

func (b *Bot) Stop()

type BotActivity

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

func NewBotActivity

func NewBotActivity(bot *Bot) *BotActivity

func (*BotActivity) Execute

func (b *BotActivity) Execute(ctx context.Context, fen string) (string, error)

type Color

type Color chess.Color

Color is a wrap of chess.Color with JSON-encoding compatibility.

const (
	NoColor Color = Color(chess.NoColor)
	White   Color = Color(chess.White)
	Black   Color = Color(chess.Black)
)

func (Color) Chess

func (c Color) Chess() chess.Color

func (Color) MarshalJSON

func (c Color) MarshalJSON() ([]byte, error)

func (Color) String

func (c Color) String() string

func (*Color) UnmarshalJSON

func (c *Color) UnmarshalJSON(blob []byte) error

type GameInfo

type GameInfo struct {
	FEN        string        // Position of the board.
	Outcome    chess.Outcome // Result of the game ("*" means "in progress").
	Method     chess.Method  // Method that generated the outcome.
	Board      string        // Simple viz of the board using Unicode chess symbols.
	Turn       Turn          // Current turn.
	Color      Color         // User's color.
	ValidMoves []string      // Valid moves when it is the user's turn.
}

GameInfo is the data structure that this workflow is going to return from query handlers or as the final return value describing the state of the game

func GameWorkflow

func GameWorkflow(ctx workflow.Context, params GameWorkflowParams) (*GameInfo, error)

GameWorkflow is the game workflow function.

func NewInfoFromGame

func NewInfoFromGame(g *chess.Game, c Color, t Turn) *GameInfo

NewInfoFromGame creates a new GameInfo.

type GameWorkflowParams

type GameWorkflowParams struct {
	Color Color  `json:"color"` // Color chosen by the user, leave empty for a random pick.
	FEN   string `json:"fen"`   // Initial state of the game in Forsysth-Edwards notation.
}

func (*GameWorkflowParams) PickColor

func (params *GameWorkflowParams) PickColor(ctx workflow.Context)

type Turn

type Turn uint8

Turn of the game.

const (
	User    Turn = 0
	Machine Turn = 1
)

func (Turn) MarshalJSON

func (t Turn) MarshalJSON() ([]byte, error)

func (*Turn) Shift

func (t *Turn) Shift()

func (Turn) String

func (t Turn) String() string

func (*Turn) UnmarshalJSON

func (t *Turn) UnmarshalJSON(blob []byte) error

Jump to

Keyboard shortcuts

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