moveslice

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package moveslice provides helper functionality for slices of type Move (chess moves).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MoveSlice

type MoveSlice []Move

MoveSlice represents a data structure (go slice) for Move.

func NewMoveSlice

func NewMoveSlice(cap int) *MoveSlice

NewMoveSlice creates a new move slice with the given capacity and 0 elements. Is identical to MoveSlice(make([]Move, 0, cap))

func (*MoveSlice) At

func (ms *MoveSlice) At(i int) Move

At returns the move at index i in the slice without removing the move from the slice. At(0) refers to the first move and is the same as Front(). At(Len()-1) refers to the last move and is the same as Back(). Index will be checked against bounds and panics if out of bounds

func (*MoveSlice) Back

func (ms *MoveSlice) Back() Move

Back returns the move at the back of the slice. This is the element that would be returned by ms[len[ms)-1]. This call panics if the slice is empty.

func (*MoveSlice) Cap

func (ms *MoveSlice) Cap() int

Cap returns the capacity of the slice Equivalent to cap(ms)

func (*MoveSlice) Clear

func (ms *MoveSlice) Clear()

Clear removes all moves from the slice, but retains the current capacity. This is useful when repeatedly reusing the slice at high frequency to avoid GC during reuse.

func (*MoveSlice) Clone

func (ms *MoveSlice) Clone() *MoveSlice

Clone copies the MoveSlice into a newly create MoveSlice doing a deep copy.

func (*MoveSlice) Equals

func (ms *MoveSlice) Equals(other *MoveSlice) bool

Equals returns true if all elements of the MoveSlice equals the elements of the other MoveSlice

func (*MoveSlice) Filter

func (ms *MoveSlice) Filter(f func(index int) bool)

Filter removes all elements from the MoveSlice for which the given call to func will return false. Rebuilds the data slice by looping over all elements and only re-adding elements for which the call to the given func is true. Reuses the underlying array

func (*MoveSlice) FilterCopy

func (ms *MoveSlice) FilterCopy(dest *MoveSlice, f func(index int) bool)

FilterCopy copies the MoveSlice into the given destination slice without the filtered elements. An element is filtered when the given call to func will return false for the element.

func (*MoveSlice) ForEach

func (ms *MoveSlice) ForEach(f func(index int))

ForEach simple range loop calling the given function on each element in stored order

func (*MoveSlice) ForEachParallel

func (ms *MoveSlice) ForEachParallel(f func(index int))

ForEachParallel simple loop over all elements calling a goroutine which calls the given func with the index of the current element as a parameter. Waits until all elements have been processed. There is no synchronization for the parallel execution. This needs to done in the provided function if necessary

func (*MoveSlice) Front

func (ms *MoveSlice) Front() Move

Front returns the move at the front of the slice. This is the element that would be returned by ms[0]. This call panics if the slice is empty.

func (*MoveSlice) Len

func (ms *MoveSlice) Len() int

Len returns the number of moves currently stored in the slice. Equivalent to len(ms)

func (*MoveSlice) PopBack

func (ms *MoveSlice) PopBack() Move

PopBack removes and returns the move from the back of the slice. If the slice is empty, the call panics.

func (*MoveSlice) PopFront

func (ms *MoveSlice) PopFront() Move

PopFront removes and returns the move from the front of the slice. If the slice is empty, the call panics. Shrinks the capacity of the slice as it only shifts the start of the slice within the underlying array. Might lead to earlier re-allocations

func (*MoveSlice) PushBack

func (ms *MoveSlice) PushBack(m Move)

PushBack appends an element at the end of the slice Equivalent to append(ms, m)

func (*MoveSlice) PushFront

func (ms *MoveSlice) PushFront(m Move)

PushFront prepends an element at the beginning of the slice using the underlying array (does not create a new array) Moves (copies) all elements by one index slot and adds the new move at the front.

func (*MoveSlice) Set

func (ms *MoveSlice) Set(i int, move Move)

Set puts a move at index i in the slice. Set shares the same purpose than At() but performs the opposite operation. The index i is the same index defined by At(). Index will be checked against bounds and panics if out of bounds

func (*MoveSlice) Sort

func (ms *MoveSlice) Sort()

Sort will sort moves from highest Value to lowest Value . It uses a stable InsertionSort as MoveSlices are mostly pre-sorted and small. Sorts move only on the base of their Value (Move value == move&0xFFFF0000). Otherwise the order will not be changed.

func (*MoveSlice) String

func (ms *MoveSlice) String() string

String returns a string representation of a slice of moves

func (*MoveSlice) StringUci

func (ms *MoveSlice) StringUci() string

StringUci returns a string with a space separated list of all moves in the list in UCI protocol format

Jump to

Keyboard shortcuts

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