adversarial

package
v0.0.0-...-884cce2 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2022 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const Inf = math.MaxInt64 - 1

Variables

This section is empty.

Functions

func Negamax

func Negamax[T GameState](state T, depth, alpha, beta int, color int) int

Negamax implements depth-limited negamax with alpha-beta pruning and transposition tables. It returns the index of the optimal state from the array generated by NextMoves. This assumes the player who needs to play next will be the maximizing player.

depth is the maximum depth to examine alpha represents the minimum score that the maximizing player is assured of beta represents the maximum score that the minimizing player is assured of Initially, alpha should be set to negative infinity and beta positive infinity.

Types

type GameState

type GameState interface {
	// IsGameOver returns true when the game is over, win lose or draw.
	IsGameOver() bool
	// Evaluate returns a positive value if the color is winning, negative if losing.
	Evaluate(color int) int
	// NextMoves returns a list of all possible next moves.
	NextMoves() []int
	// Play takes a move and applies it to the state.
	Play(move, color int)
	// Undo rolls the state back before the move happened.
	Undo(move, color int)
	// Hash returns a hashable value for the game state so that
	// repeated states can be found by a map lookup. Google "Zobrist Hash".
	Hash(color int) uint64
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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