attacks

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: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttacksTo

func AttacksTo(p *position.Position, square Square, color Color) Bitboard

AttacksTo determines all attacks to the given square for the given color.

func RevealedAttacks

func RevealedAttacks(p *position.Position, square Square, occupied Bitboard, color Color) Bitboard

RevealedAttacks returns sliding attacks after a piece has been removed to reveal new attacks. It is only necessary to look at slider pieces as only their attacks can be revealed.

Types

type Attacks

type Attacks struct {

	// the position key for which the attacks have been calculated
	Zobrist position.Key
	// bitboards of attacked/defended squares for each color and each from square
	// to get attackers us &^ ownPieces or & ownPieces for defenders
	From [ColorLength][SqLength]Bitboard
	// bitboards of attackers/defenders for each color and to square
	// to get attackers us &^ ownPieces or & ownPieces for defenders
	To [ColorLength][SqLength]Bitboard
	// bitboards for all attacked/defended squares of a color
	// to get attackers us &^ ownPieces or & ownPieces for defenders
	All [ColorLength]Bitboard
	// bitboards of attacked/defended squares for each color and each piece type
	// to get attackers us &^ ownPieces or & ownPieces for defenders
	Piece [ColorLength][PtLength]Bitboard
	// sum of possible moves for each color (moves to ownPieces already excluded)
	Mobility [ColorLength]int
	// pawn attacks - squares attacked by pawn of the given color
	Pawns [ColorLength]Bitboard
	// pawn double - squares which are attacked twice by pawns of the given color
	PawnsDouble [ColorLength]Bitboard
	// contains filtered or unexported fields
}

Attacks is a data structure to store all attacks and defends of a position.

func NewAttacks

func NewAttacks() *Attacks

NewAttacks creates a new instance of Attacks.

func (*Attacks) Clear

func (a *Attacks) Clear()

Clear resets all fields of the Attacks instance without new allocation by looping through all fields This is considerably faster than creating a new instance Benchmark/New_Instance-8 1.904.764 691.0 ns/op Benchmark/Clear-8 13.043.875 91.7 ns/op.

func (*Attacks) Compute

func (a *Attacks) Compute(p *position.Position)

Compute calculates all attacks on the position. Stores the positions zobrist key to be able to check if the position is already computed. if a position is called twice the already stored attacks are untouched.

Jump to

Keyboard shortcuts

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