engine

package
v0.0.0-...-ec1b2d6 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2025 License: Unlicense Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	P1    = 1
	P2    = -1
	EMPTY = 0
)
View Source
const (
	C_VALUE = 1.41
	DEPTH   = 100
)

Variables

This section is empty.

Functions

func GetModel

func GetModel() tea.Model

Types

type AI

type AI interface {
	// Returns the best move for the current player
	Solve(board *Board) int
}

func NewMCTS

func NewMCTS(engine GameEngine, depth int) AI

type Board

type Board struct {
	Size  int
	Cells []int
}

func NewBoard

func NewBoard(size int) *Board

func (*Board) ChangePerspective

func (b *Board) ChangePerspective()

func (*Board) Copy

func (b *Board) Copy() *Board

func (*Board) GetCell

func (b *Board) GetCell(index int) (int, error)

func (*Board) GetRowCol

func (b *Board) GetRowCol(index int) (int, int, error)

func (*Board) Load

func (b *Board) Load(cells []int) error

func (*Board) Print

func (b *Board) Print()

func (*Board) SetCell

func (b *Board) SetCell(index int, player int) error

type Engine

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

func NewEngine

func NewEngine(depth int) *Engine

func (*Engine) CheckGameOver

func (e *Engine) CheckGameOver(board *Board, lastMove int) (bool, int)

func (*Engine) CheckWin

func (e *Engine) CheckWin(board *Board, lastMove int) bool

func (*Engine) GetLegalMoves

func (e *Engine) GetLegalMoves(board *Board) []int

func (*Engine) GetOpponent

func (e *Engine) GetOpponent(player int) int

func (*Engine) PlayMove

func (e *Engine) PlayMove(board *Board, player int, move int) error

type Game

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

func (Game) Init

func (g Game) Init() tea.Cmd

func (Game) Update

func (g Game) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (Game) View

func (g Game) View() string

type GameEngine

type GameEngine interface {
	// Returns gameover (bool) & a value if there's a winner
	CheckGameOver(board *Board, lastMove int) (bool, int)
	// Get all available moves
	GetLegalMoves(board *Board) []int
	// Get the opponent of a player
	GetOpponent(player int) int
	// Play a move on the board
	PlayMove(board *Board, player int, move int) error
}

type Player

type Player = int

Jump to

Keyboard shortcuts

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