Documentation ¶
Overview ¶
mancala is a library for the game of Mancala. It includes the core game logic and added functionality like algorithmic opponents. It is designed to be used by a UI, such as the tui package in the same repository.
Index ¶
Constants ¶
const ( Player1Turn = 1 Player2Turn = 2 )
The value of Turn should always be one of these constants.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BoardSide ¶
BoardSide represents one side of a Mancala board. It contains:
- a Player,
- a slice of integers (Pits) representing the number of stones in each pit,
- and an integer (Store) representing the number of stones in the store.
func NewBoardSide ¶
NewBoardSide creates a new BoardSide with the given player, number of stones per pit, and number of pits per side.
func (*BoardSide) ArePitsEmpty ¶
ArePitsEmpty returns true if all pits are empty.
func (*BoardSide) GetOpposingPitIndex ¶
GetOpposingPitIndex returns the index of the pit on the opposing side of the board. This takes into account the pits being reversed for the opposing player.
func (*BoardSide) GetScore ¶
GetScore returns the total number of stones on this side (pits and store).
func (*BoardSide) GetStones ¶
GetStones returns the number of stones in the given pit and removes them from the pit.
func (*BoardSide) ValidatePitIndex ¶
ValidatePitIndex returns an error if the given pit index is invalid. Otherwise, it returns nil.
type Game ¶
Game represents a game of Mancala. It contains: - a BoardSide for each player (Side1, Side2), - and an unsigned integer (Turn) representing which player's turn it is.
func NewGame ¶
NewGame creates a new game of Mancala with the given players, number of stones per pit, and number of pits per side.
func (*Game) AlternateTurn ¶
func (g *Game) AlternateTurn()
AlternateTurn alternates the turn between players.
func (*Game) ExecuteMove ¶
ExecuteMove executes a move for the current player. It returns an error if the game is over or if the given pit index is invalid.
type MinimaxBot ¶
MinimaxBot represents a bot that uses the minimax algorithm to determine its next move. It contains a name and a score.
func NewMinimaxBot ¶
func NewMinimaxBot(name string) *MinimaxBot
NewMinimaxBot creates a new MinimaxBot with the given name.
func (*MinimaxBot) GetMove ¶
func (bot *MinimaxBot) GetMove(game *Game) int
GetMove returns the bot's next move using the minimax algorithm.
func (*MinimaxBot) GetName ¶
func (bot *MinimaxBot) GetName() string
GetName returns the bot's name.
func (*MinimaxBot) GetScore ¶
func (bot *MinimaxBot) GetScore() int
GetScore returns the bot's score.
func (*MinimaxBot) SetScore ¶
func (bot *MinimaxBot) SetScore(score int)
SetScore sets the bot's score.