bitboard

package
v0.0.0-...-4fb7718 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Left  Dir = "left"
	Right     = "right"
	Up        = "up"
	Down      = "down"
)

Variables

View Source
var BOTTOM_MASK = num.U128FromRaw(
	0b0000000000000000000000000000000000000000000000000000000000000000,
	0b0000000000000000000000000000000000000000000000000000011111111111,
)
View Source
var LEFT_MASK = num.U128FromRaw(
	0b0000000000000000010000000000100000000001000000000010000000000100,
	0b0000000010000000000100000000001000000000010000000000100000000001,
)
View Source
var RIGHT_MASK = num.U128FromRaw(
	0b0000000100000000001000000000010000000000100000000001000000000010,
	0b0000000001000000000010000000000100000000001000000000010000000000,
)
View Source
var TOP_MASK = num.U128FromRaw(
	0b1111111111111111110000000000000000000000000000000000000000000000,
	0b0000000000000000000000000000000000000000000000000000000000000000,
)

This is the 11 most sig bits + 7 unused bits

Functions

func BFS

func BFS(board *BitBoard, startIndex int, testerFn func(int) bool) int

returns the length of the path to the goal returns -1 if not found

func CartesianProduct

func CartesianProduct(movesA [][]SnakeMoveSet, movesB []SnakeMoveSet) [][]SnakeMoveSet

Types

type BasicStateWeights

type BasicStateWeights struct {
	Food   float64
	Aggr   float64
	Area   float64
	Length float64
	Health float64
	Tail   float64
}

type BitBoard

type BitBoard struct {

	// I need to makes Snakes a map so that I can remove snakes when they die.
	// Currently, removing a snake from the array could cause the ids of other snakes to change, since it's an array.
	// By converting to a map, I can just use the ID from the API
	// This way, when a snake dies and the API does not send that snake in the request, the state will match up with what I have in my tree since it is also being removed
	Snakes map[string]*snake

	Turn            int
	ShouldSpawnFood bool
	// contains filtered or unexported fields
}

func CreateBitBoard

func CreateBitBoard(state api.GameState) *BitBoard

func (*BitBoard) AdvanceTurn

func (bb *BitBoard) AdvanceTurn(allMoves []SnakeMoveSet)

func (*BitBoard) AreaControlScore

func (bb *BitBoard) AreaControlScore(snakeId string) float64

func (*BitBoard) BasicStateScore

func (bb *BitBoard) BasicStateScore(snakeId string, depth int, weights BasicStateWeights) float64

TODO: factor in depth for use during tree search

func (*BitBoard) Clone

func (bb *BitBoard) Clone() *BitBoard

func (*BitBoard) FoodScore

func (bb *BitBoard) FoodScore(snakeId string) float64

func (*BitBoard) GetCartesianProductOfMoves

func (bb *BitBoard) GetCartesianProductOfMoves() [][]SnakeMoveSet

func (*BitBoard) GetLastSnakeMoveFromExternal

func (bb *BitBoard) GetLastSnakeMoveFromExternal(snake api.Battlesnake) Dir

func (*BitBoard) GetMoves

func (bb *BitBoard) GetMoves(snakeId string) SnakeMoveSet

func (*BitBoard) GetMovesNoDefault

func (bb *BitBoard) GetMovesNoDefault(snakeId string) SnakeMoveSet

func (*BitBoard) GetNeighbors

func (bb *BitBoard) GetNeighbors(index int) moveset.MoveSet

func (*BitBoard) GetOpponents

func (bb *BitBoard) GetOpponents() []*snake

func (*BitBoard) GetSnake

func (bb *BitBoard) GetSnake(id string) *snake

func (*BitBoard) GetZobristKey

func (bb *BitBoard) GetZobristKey(zh ZobristTable) Key

func (*BitBoard) InitializeZobristTable

func (bb *BitBoard) InitializeZobristTable() ZobristTable

func (*BitBoard) IsEqual

func (bb *BitBoard) IsEqual(board *BitBoard) bool

func (*BitBoard) IsGameOver

func (bb *BitBoard) IsGameOver() bool

func (*BitBoard) IsIndexFood

func (bb *BitBoard) IsIndexFood(i int) bool

func (*BitBoard) IsIndexHazard

func (bb *BitBoard) IsIndexHazard(i int) bool

func (*BitBoard) IsIndexOccupied

func (bb *BitBoard) IsIndexOccupied(i int) bool

func (*BitBoard) IsSnakeAlive

func (bb *BitBoard) IsSnakeAlive(id string) bool

func (*BitBoard) IsSnakeOnWall

func (bb *BitBoard) IsSnakeOnWall(snakeId string) bool

func (*BitBoard) KillScore

func (bb *BitBoard) KillScore(snakeId string) float64

func (*BitBoard) Print

func (bb *BitBoard) Print()

func (*BitBoard) RandomMove

func (bb *BitBoard) RandomMove(snakeId string, rand *rand.Rand) SnakeMoveSet

func (*BitBoard) RandomPlayout

func (bb *BitBoard) RandomPlayout(length int, rand *rand.Rand)

func (*BitBoard) RandomPlayoutMonte

func (bb *BitBoard) RandomPlayoutMonte(length int, rand *rand.Rand) Dir

func (*BitBoard) SpawnFood

func (bb *BitBoard) SpawnFood()

func (*BitBoard) SpawnHazardsRoyale

func (bb *BitBoard) SpawnHazardsRoyale()

func (*BitBoard) SplitMoves

func (bb *BitBoard) SplitMoves(mset SnakeMoveSet) []SnakeMoveSet

func (*BitBoard) TailPathScore

func (bb *BitBoard) TailPathScore(snakeId string) float64

func (*BitBoard) Update

func (bb *BitBoard) Update(new *BitBoard)

updates without removing snakes

func (*BitBoard) Voronoi

func (bb *BitBoard) Voronoi() VoronoiResult

type Dir

type Dir string

func MoveSetToDir

func MoveSetToDir(ms moveset.MoveSet) Dir

returns the Dir version ("left", "right", "up", "down") of the moveset. If more than one is set, it returns the first found in the order displayed above.

type Key

type Key uint64

type SnakeMove

type SnakeMove struct {
	Id  string
	Dir Dir
}

type SnakeMoveSet

type SnakeMoveSet struct {
	Id  string
	Set moveset.MoveSet
}

func SplitSnakeMoveSet

func SplitSnakeMoveSet(moves SnakeMoveSet) []SnakeMoveSet

type VoronoiResult

type VoronoiResult struct {
	Score     map[string]int
	FoodDepth map[string]int
	Territory map[uint16]string
}

type ZobristTable

type ZobristTable [][]Key

Jump to

Keyboard shortcuts

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