Created
September 23, 2024 21:55
-
-
Save thejhh/a2f09b918be349b485b6099ff655fd3e to your computer and use it in GitHub Desktop.
Chess pieces source code in https://github.com/hangovergames/project-chess
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2024. Hangover Games <[email protected]>. All rights reserved. | |
// Licence FSL-1.1-MIT | |
package bishop | |
import ( | |
"log" | |
"chess/internal/chesstypes" | |
) | |
var MoveMask *chesstypes.MoveMaskGrid | |
func init() { | |
var err error | |
const ( | |
// Movement flags | |
f = chesstypes.CanMoveFirstMove // f is CanMoveFirstMove | |
a = chesstypes.CanAttack // a is CanAttack | |
m = chesstypes.CanMove // m is CanMove | |
l = chesstypes.CanLeap // l is CanLeap | |
w = chesstypes.OffensiveSide // w is OffensiveSide | |
b = chesstypes.DefendingSide // b is WhenDefending | |
x = chesstypes.AvoidCheck // x is AvoidCheck | |
e = chesstypes.CanPromoteOnEdge // e is CanPromoteOnEdge | |
// Capture in passant flags | |
p = chesstypes.CanCaptureInPassant // p is CanCaptureInPassant | |
pw = chesstypes.TargetWasInPassant // pw is TargetWasInPassant | |
p1 = chesstypes.InPassantGroup1 // p1 is InPassantGroup1 | |
p2 = chesstypes.InPassantGroup2 // p2 is InPassantGroup2 | |
// Castling flags | |
h = chesstypes.CanCastleTo // h is CanCastleTo | |
u = chesstypes.HasCastleUnit // u is HasCastleUnit | |
d = chesstypes.CastleDestination // d is CastleDestination | |
g1 = chesstypes.CastleGroup1 // g1 is CastleGroup1 | |
g2 = chesstypes.CastleGroup2 // g2 is CastleGroup2 | |
// Current position flags | |
c = chesstypes.UnitPosition // c marks the current position of the unit. See UnitPosition. | |
) | |
MoveMask, err = chesstypes.NewMoveMaskGrid([]chesstypes.MoveMask{ | |
m|a, 0 , 0 , 0 , 0 , 0 , 0 , 0, 0 , 0 , 0 , 0 , 0 , 0 , m|a, | |
0 , m|a, 0 , 0 , 0 , 0 , 0 , 0, 0 , 0 , 0 , 0 , 0 , m|a, 0 , | |
0 , 0 , m|a, 0 , 0 , 0 , 0 , 0, 0 , 0 , 0 , 0 , m|a, 0 , 0 , | |
0 , 0 , 0 , m|a, 0 , 0 , 0 , 0, 0 , 0 , 0 , m|a, 0 , 0 , 0 , | |
0 , 0 , 0 , 0 , m|a, 0 , 0 , 0, 0 , 0 , m|a, 0 , 0 , 0 , 0 , | |
0 , 0 , 0 , 0 , 0 , m|a, 0 , 0, 0 , m|a, 0 , 0 , 0 , 0 , 0 , | |
0 , 0 , 0 , 0 , 0 , 0 , m|a, 0, m|a, 0 , 0 , 0 , 0 , 0 , 0 , | |
0 , 0 , 0 , 0 , 0 , 0 , 0 , c, 0 , 0 , 0 , 0 , 0 , 0 , 0 , | |
0 , 0 , 0 , 0 , 0 , 0 , m|a, 0, m|a, 0 , 0 , 0 , 0 , 0 , 0 , | |
0 , 0 , 0 , 0 , 0 , m|a, 0 , 0, 0 , m|a, 0 , 0 , 0 , 0 , 0 , | |
0 , 0 , 0 , 0 , m|a, 0 , 0 , 0, 0 , 0 , m|a, 0 , 0 , 0 , 0 , | |
0 , 0 , 0 , m|a, 0 , 0 , 0 , 0, 0 , 0 , 0 , m|a, 0 , 0 , 0 , | |
0 , 0 , m|a, 0 , 0 , 0 , 0 , 0, 0 , 0 , 0 , 0 , m|a, 0 , 0 , | |
0 , m|a, 0 , 0 , 0 , 0 , 0 , 0, 0 , 0 , 0 , 0 , 0 , m|a, 0 , | |
m|a, 0 , 0 , 0 , 0 , 0 , 0 , 0, 0 , 0 , 0 , 0 , 0 , 0 , m|a, | |
}) | |
if err != nil { | |
log.Fatal("Cannot initialize move masks for bishop: %w") | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2024. Hangover Games <[email protected]>. All rights reserved. | |
// Licence FSL-1.1-MIT | |
package elephant | |
import ( | |
"chess/internal/chesstypes" | |
"log" | |
) | |
var MoveMask *chesstypes.MoveMaskGrid | |
func init() { | |
var err error | |
const ( | |
// Movement flags | |
f = chesstypes.CanMoveFirstMove // f is CanMoveFirstMove | |
a = chesstypes.CanAttack // a is CanAttack | |
m = chesstypes.CanMove // m is CanMove | |
l = chesstypes.CanLeap // l is CanLeap | |
w = chesstypes.OffensiveSide // w is OffensiveSide | |
b = chesstypes.DefendingSide // b is WhenDefending | |
x = chesstypes.AvoidCheck // x is AvoidCheck | |
e = chesstypes.CanPromoteOnEdge // e is CanPromoteOnEdge | |
// Capture in passant flags | |
p = chesstypes.CanCaptureInPassant // p is CanCaptureInPassant | |
pw = chesstypes.TargetWasInPassant // pw is TargetWasInPassant | |
p1 = chesstypes.InPassantGroup1 // p1 is InPassantGroup1 | |
p2 = chesstypes.InPassantGroup2 // p2 is InPassantGroup2 | |
// Castling flags | |
h = chesstypes.CanCastleTo // h is CanCastleTo | |
u = chesstypes.HasCastleUnit // u is HasCastleUnit | |
d = chesstypes.CastleDestination // d is CastleDestination | |
g1 = chesstypes.CastleGroup1 // g1 is CastleGroup1 | |
g2 = chesstypes.CastleGroup2 // g2 is CastleGroup2 | |
// Current position flags | |
c = chesstypes.UnitPosition // c marks the current position of the unit. See UnitPosition. | |
) | |
MoveMask, err = chesstypes.NewMoveMaskGrid([]chesstypes.MoveMask{ | |
m|a|l , 0 , 0 , 0 , m|a|l , | |
0 , m|a|l , 0 , m|a|l , 0 , | |
0 , 0 , c , 0 , 0 , | |
0 , m|a|l , 0 , m|a|l , 0 , | |
m|a|l , 0 , 0 , 0 , m|a|l , | |
}) | |
if err != nil { | |
log.Fatal("Cannot initialize move masks for elephant: %w") | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2024. Hangover Games <[email protected]>. All rights reserved. | |
// Licence FSL-1.1-MIT | |
package king | |
import ( | |
"chess/internal/chesstypes" | |
"log" | |
) | |
var MoveMask *chesstypes.MoveMaskGrid | |
func init() { | |
var err error | |
const ( | |
// Movement flags | |
f = chesstypes.CanMoveFirstMove // f is CanMoveFirstMove | |
a = chesstypes.CanAttack // a is CanAttack | |
m = chesstypes.CanMove // m is CanMove | |
l = chesstypes.CanLeap // l is CanLeap | |
w = chesstypes.OffensiveSide // w is OffensiveSide | |
b = chesstypes.DefendingSide // b is WhenDefending | |
x = chesstypes.AvoidCheck // x is AvoidCheck | |
e = chesstypes.CanPromoteOnEdge // e is CanPromoteOnEdge | |
// Capture in passant flags | |
p = chesstypes.CanCaptureInPassant // p is CanCaptureInPassant | |
pw = chesstypes.TargetWasInPassant // pw is TargetWasInPassant | |
p1 = chesstypes.InPassantGroup1 // p1 is InPassantGroup1 | |
p2 = chesstypes.InPassantGroup2 // p2 is InPassantGroup2 | |
// Castling flags | |
h = chesstypes.CanCastleTo // h is CanCastleTo | |
u = chesstypes.HasCastleUnit // u is HasCastleUnit | |
d = chesstypes.CastleDestination // d is CastleDestination | |
g1 = chesstypes.CastleGroup1 // g1 is CastleGroup1 | |
g2 = chesstypes.CastleGroup2 // g2 is CastleGroup2 | |
// Current position flags | |
c = chesstypes.UnitPosition // c marks the current position of the unit. See UnitPosition. | |
) | |
MoveMask, err = chesstypes.NewMoveMaskGrid([]chesstypes.MoveMask{ | |
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , | |
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , | |
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , | |
0 , 0 , 0 , m|a|x , m|a|x , m|a|x , 0 , 0 , 0 , | |
u|g1 , g1 , h|x|g1 , m|a|x|g1|d , c|x , m|a|x|g2|d , h|x|g2 , g2 , u|g2 , | |
0 , 0 , 0 , m|a|x , m|a|x , m|a|x , 0 , 0 , 0 , | |
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , | |
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , | |
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , | |
}) | |
if err != nil { | |
log.Fatal("Cannot initialize move masks for king: %w") | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2024. Hangover Games <[email protected]>. All rights reserved. | |
// Licence FSL-1.1-MIT | |
package knight | |
import ( | |
"chess/internal/chesstypes" | |
"log" | |
) | |
var MoveMask *chesstypes.MoveMaskGrid | |
func init() { | |
var err error | |
const ( | |
// Movement flags | |
f = chesstypes.CanMoveFirstMove // f is CanMoveFirstMove | |
a = chesstypes.CanAttack // a is CanAttack | |
m = chesstypes.CanMove // m is CanMove | |
l = chesstypes.CanLeap // l is CanLeap | |
w = chesstypes.OffensiveSide // w is OffensiveSide | |
b = chesstypes.DefendingSide // b is WhenDefending | |
x = chesstypes.AvoidCheck // x is AvoidCheck | |
e = chesstypes.CanPromoteOnEdge // e is CanPromoteOnEdge | |
// Capture in passant flags | |
p = chesstypes.CanCaptureInPassant // p is CanCaptureInPassant | |
pw = chesstypes.TargetWasInPassant // pw is TargetWasInPassant | |
p1 = chesstypes.InPassantGroup1 // p1 is InPassantGroup1 | |
p2 = chesstypes.InPassantGroup2 // p2 is InPassantGroup2 | |
// Castling flags | |
h = chesstypes.CanCastleTo // h is CanCastleTo | |
u = chesstypes.HasCastleUnit // u is HasCastleUnit | |
d = chesstypes.CastleDestination // d is CastleDestination | |
g1 = chesstypes.CastleGroup1 // g1 is CastleGroup1 | |
g2 = chesstypes.CastleGroup2 // g2 is CastleGroup2 | |
// Current position flags | |
c = chesstypes.UnitPosition // c marks the current position of the unit. See UnitPosition. | |
) | |
MoveMask, err = chesstypes.NewMoveMaskGrid([]chesstypes.MoveMask{ | |
0 , m|a|l, 0, m|a|l, 0 , | |
m|a|l , 0 , 0, 0 , m|a|l, | |
0 , 0 , c, 0 , 0 , | |
m|a|l , 0 , 0, 0 , m|a|l, | |
0 , m|a|l, 0, m|a|l, 0 , | |
}) | |
if err != nil { | |
log.Fatal("Cannot initialize move masks for knight: %w") | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2024. Hangover Games <[email protected]>. All rights reserved. | |
// Licence FSL-1.1-MIT | |
package chesstypes | |
// | |
type MoveMask uint64 | |
const ( | |
UnitPosition MoveMask = 1 << iota // The position of the unit which is moving on a move mask map. It's always the center of the map as well. | |
CanMoveFirstMove // The unit can only move here if this is their first move | |
CanMove // The unit can move to this position, but not attack (unless it has `CanAttack` mask also) | |
CanLeap // The unit can leap over other units. Without this flag, the direct route must be unoccupied. | |
CanCaptureInPassant // The unit can capture an adjacent unit (see TargetWasInPassant) which passed by this section, moving to this sector | |
TargetWasInPassant // This unit can be captured in passant if it passed by CanCaptureInPassant section | |
InPassantGroup1 // Marks a first group modifiers for capture in passant | |
InPassantGroup2 // Marks a second group modifiers for capture in passant | |
CanAttack // The unit can only attack to this position if there is a unit | |
CanCastleTo // The unit can castle to this position | |
HasCastleUnit // This position must have a castable unit (e.g. rook) in order to castle | |
CastleDestination // This position is the destination for castable unit (e.g. the rook) | |
CastleGroup1 // Marks a first group modifiers for castling | |
CastleGroup2 // Marks a second group modifiers for castling | |
OffensiveSide // These flags are only enabled for offensive side (traditionally "white"). | |
DefendingSide // These flags are only enabled for defending side (traditionally "black"). | |
AvoidCheck // A move to or pass through this location is not possible if this location is under attack, or if this is the current position, the next move is only valid if it will solve the condition. | |
CanPromoteOnEdge // A move to this position enables promote action, if the target position is the edge of the opposite side | |
) | |
func (m MoveMask) Flag(f MoveMask) bool { | |
return (m & f) != 0 | |
} | |
// UnitPosition The position of the unit which is moving on a move mask map. | |
// It's always the center of the map as well. | |
func (m MoveMask) UnitPosition () bool { | |
return m.Flag(UnitPosition) | |
} | |
// The unit can only move here if this is their first move | |
func (m MoveMask) CanMoveFirstMove () bool { | |
return m.Flag(CanMoveFirstMove) | |
} | |
// The unit can move to this position, but not attack (unless it has `CanAttack` | |
// mask also) | |
func (m MoveMask) CanMove () bool { | |
return m.Flag(CanMove) | |
} | |
// The unit can leap over other units. Without this flag, the direct route must | |
// be unoccupied. | |
func (m MoveMask) CanLeap () bool { | |
return m.Flag(CanLeap) | |
} | |
// The unit can capture an adjacent unit which passed by this section, then | |
// moving to this section | |
func (m MoveMask) CanCaptureInPassant () bool { | |
return m.Flag(CanCaptureInPassant) | |
} | |
// This unit can be captured in passant if it passed by CanCaptureInPassant section | |
func (m MoveMask) TargetWasInPassant () bool { | |
return m.Flag(TargetWasInPassant) | |
} | |
// Marks a first group modifiers for capture in passant | |
func (m MoveMask) InPassantGroup1 () bool { | |
return m.Flag(InPassantGroup1) | |
} | |
// Marks a second group modifiers for capture in passant | |
func (m MoveMask) InPassantGroup2 () bool { | |
return m.Flag(InPassantGroup2) | |
} | |
// The unit can only attack to this position if there is a unit | |
func (m MoveMask) CanAttack () bool { | |
return m.Flag(CanAttack) | |
} | |
// The unit can castle to this position | |
func (m MoveMask) CanCastleTo () bool { | |
return m.Flag(CanCastleTo) | |
} | |
// This position must have a castable unit (e.g. rook) in order to castle | |
func (m MoveMask) HasCastleUnit () bool { | |
return m.Flag(HasCastleUnit) | |
} | |
// This position is the destination for castable unit (e.g. the rook) | |
func (m MoveMask) CastleDestination () bool { | |
return m.Flag(CastleDestination) | |
} | |
// Marks a first group modifiers for castling | |
func (m MoveMask) CastleGroup1 () bool { | |
return m.Flag(CastleGroup1) | |
} | |
// Marks a second group modifiers for castling | |
func (m MoveMask) CastleGroup2 () bool { | |
return m.Flag(CastleGroup2) | |
} | |
// These flags are only enabled for offensive side (traditionally "white"). | |
func (m MoveMask) OffensiveSide () bool { | |
return m.Flag(OffensiveSide) | |
} | |
// These flags are only enabled for defending side (traditionally "black"). | |
func (m MoveMask) DefendingSide () bool { | |
return m.Flag(DefendingSide) | |
} | |
// A move to or pass through this location is not possible if this location is | |
// under attack, or if this is the current position, the next move is only valid | |
// if it will solve the condition. | |
func (m MoveMask) AvoidCheck () bool { | |
return m.Flag(AvoidCheck) | |
} | |
// A move to this position enables promote action, if the target position is the | |
// edge of the opposite side | |
func (m MoveMask) CanPromoteOnEdge () bool { | |
return m.Flag(CanPromoteOnEdge) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2024. Hangover Games <[email protected]>. All rights reserved. | |
// Licence FSL-1.1-MIT | |
package pawn | |
import ( | |
"chess/internal/chesstypes" | |
"log" | |
) | |
var MoveMask *chesstypes.MoveMaskGrid | |
func init() { | |
var err error | |
const ( | |
// Movement flags | |
f = chesstypes.CanMoveFirstMove // f is CanMoveFirstMove | |
a = chesstypes.CanAttack // a is CanAttack | |
m = chesstypes.CanMove // m is CanMove | |
w = chesstypes.OffensiveSide // w is OffensiveSide | |
b = chesstypes.DefendingSide // b is WhenDefending | |
e = chesstypes.CanPromoteOnEdge // e is CanPromoteOnEdge | |
// Capture in passant flags | |
p = chesstypes.CanCaptureInPassant // p is CanCaptureInPassant | |
pw = chesstypes.TargetWasInPassant // pw is TargetWasInPassant | |
p1 = chesstypes.InPassantGroup1 // p1 is InPassantGroup1 | |
p2 = chesstypes.InPassantGroup2 // p2 is InPassantGroup2 | |
// Current position flags | |
c = chesstypes.UnitPosition // c marks the current position of the unit. See UnitPosition. | |
) | |
MoveMask, err = chesstypes.NewMoveMaskGrid([]chesstypes.MoveMask{ | |
0, 0 , f|e|w , 0 , 0 , | |
0, a|p|e|w|p1 , m|e|w , a|p|e|w|p2 , 0 , | |
0, pw|p1 , c , pw|p2 , 0 , | |
0, a|p|e|b|p1 , m|e|b , a|p|e|b|p2 , 0 , | |
0, 0 , f|e|b , 0 , 0 , | |
}) | |
if err != nil { | |
log.Fatal("Cannot initialize move masks for pawn: %w") | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2024. Hangover Games <[email protected]>. All rights reserved. | |
// Licence FSL-1.1-MIT | |
package queen | |
import ( | |
"chess/internal/chesstypes" | |
"log" | |
) | |
var MoveMask *chesstypes.MoveMaskGrid | |
func init() { | |
var err error | |
const ( | |
// Movement flags | |
f = chesstypes.CanMoveFirstMove // f is CanMoveFirstMove | |
a = chesstypes.CanAttack // a is CanAttack | |
m = chesstypes.CanMove // m is CanMove | |
l = chesstypes.CanLeap // l is CanLeap | |
w = chesstypes.OffensiveSide // w is OffensiveSide | |
b = chesstypes.DefendingSide // b is WhenDefending | |
x = chesstypes.AvoidCheck // x is AvoidCheck | |
e = chesstypes.CanPromoteOnEdge // e is CanPromoteOnEdge | |
// Capture in passant flags | |
p = chesstypes.CanCaptureInPassant // p is CanCaptureInPassant | |
pw = chesstypes.TargetWasInPassant // pw is TargetWasInPassant | |
p1 = chesstypes.InPassantGroup1 // p1 is InPassantGroup1 | |
p2 = chesstypes.InPassantGroup2 // p2 is InPassantGroup2 | |
// Castling flags | |
h = chesstypes.CanCastleTo // h is CanCastleTo | |
u = chesstypes.HasCastleUnit // u is HasCastleUnit | |
d = chesstypes.CastleDestination // d is CastleDestination | |
g1 = chesstypes.CastleGroup1 // g1 is CastleGroup1 | |
g2 = chesstypes.CastleGroup2 // g2 is CastleGroup2 | |
// Current position flags | |
c = chesstypes.UnitPosition // c marks the current position of the unit. See UnitPosition. | |
) | |
MoveMask, err = chesstypes.NewMoveMaskGrid([]chesstypes.MoveMask{ | |
m|a, 0 , 0 , 0 , 0 , 0 , 0 , m|a, 0 , 0 , 0 , 0 , 0 , 0 , m|a, | |
0 , m|a, 0 , 0 , 0 , 0 , 0 , m|a, 0 , 0 , 0 , 0 , 0 , m|a, 0 , | |
0 , 0 , m|a, 0 , 0 , 0 , 0 , m|a, 0 , 0 , 0 , 0 , m|a, 0 , 0 , | |
0 , 0 , 0 , m|a, 0 , 0 , 0 , m|a, 0 , 0 , 0 , m|a, 0 , 0 , 0 , | |
0 , 0 , 0 , 0 , m|a, 0 , 0 , m|a, 0 , 0 , m|a, 0 , 0 , 0 , 0 , | |
0 , 0 , 0 , 0 , 0 , m|a, 0 , m|a, 0 , m|a, 0 , 0 , 0 , 0 , 0 , | |
0 , 0 , 0 , 0 , 0 , 0 , m|a, m|a, m|a, 0 , 0 , 0 , 0 , 0 , 0 , | |
m|a, m|a, m|a, m|a, m|a, m|a, m|a, c , m|a, m|a, m|a, m|a, m|a, m|a, m|a, | |
0 , 0 , 0 , 0 , 0 , 0 , m|a, m|a, m|a, 0 , 0 , 0 , 0 , 0 , 0 , | |
0 , 0 , 0 , 0 , 0 , m|a, 0 , m|a, 0 , m|a, 0 , 0 , 0 , 0 , 0 , | |
0 , 0 , 0 , 0 , m|a, 0 , 0 , m|a, 0 , 0 , m|a, 0 , 0 , 0 , 0 , | |
0 , 0 , 0 , m|a, 0 , 0 , 0 , m|a, 0 , 0 , 0 , m|a, 0 , 0 , 0 , | |
0 , 0 , m|a, 0 , 0 , 0 , 0 , m|a, 0 , 0 , 0 , 0 , m|a, 0 , 0 , | |
0 , m|a, 0 , 0 , 0 , 0 , 0 , m|a, 0 , 0 , 0 , 0 , 0 , m|a, 0 , | |
m|a, 0 , 0 , 0 , 0 , 0 , 0 , m|a, 0 , 0 , 0 , 0 , 0 , 0 , m|a, | |
}) | |
if err != nil { | |
log.Fatal("Cannot initialize move masks for queen: %w") | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2024. Hangover Games <[email protected]>. All rights reserved. | |
// Licence FSL-1.1-MIT | |
package rook | |
import ( | |
"chess/internal/chesstypes" | |
"log" | |
) | |
var MoveMask *chesstypes.MoveMaskGrid | |
func init() { | |
var err error | |
const ( | |
// Movement flags | |
f = chesstypes.CanMoveFirstMove // f is CanMoveFirstMove | |
a = chesstypes.CanAttack // a is CanAttack | |
m = chesstypes.CanMove // m is CanMove | |
l = chesstypes.CanLeap // l is CanLeap | |
w = chesstypes.OffensiveSide // w is OffensiveSide | |
b = chesstypes.DefendingSide // b is WhenDefending | |
x = chesstypes.AvoidCheck // x is AvoidCheck | |
e = chesstypes.CanPromoteOnEdge // e is CanPromoteOnEdge | |
// Capture in passant flags | |
p = chesstypes.CanCaptureInPassant // p is CanCaptureInPassant | |
pw = chesstypes.TargetWasInPassant // pw is TargetWasInPassant | |
p1 = chesstypes.InPassantGroup1 // p1 is InPassantGroup1 | |
p2 = chesstypes.InPassantGroup2 // p2 is InPassantGroup2 | |
// Castling flags | |
h = chesstypes.CanCastleTo // h is CanCastleTo | |
u = chesstypes.HasCastleUnit // u is HasCastleUnit | |
d = chesstypes.CastleDestination // d is CastleDestination | |
g1 = chesstypes.CastleGroup1 // g1 is CastleGroup1 | |
g2 = chesstypes.CastleGroup2 // g2 is CastleGroup2 | |
// Current position flags | |
c = chesstypes.UnitPosition // c marks the current position of the unit. See UnitPosition. | |
) | |
MoveMask, err = chesstypes.NewMoveMaskGrid([]chesstypes.MoveMask{ | |
0 , 0 , 0 , 0 , 0 , 0 , 0 , m|a , 0 , 0 , 0 , 0 , 0 , 0 , 0 , | |
0 , 0 , 0 , 0 , 0 , 0 , 0 , m|a , 0 , 0 , 0 , 0 , 0 , 0 , 0 , | |
0 , 0 , 0 , 0 , 0 , 0 , 0 , m|a , 0 , 0 , 0 , 0 , 0 , 0 , 0 , | |
0 , 0 , 0 , 0 , 0 , 0 , 0 , m|a , 0 , 0 , 0 , 0 , 0 , 0 , 0 , | |
0 , 0 , 0 , 0 , 0 , 0 , 0 , m|a , 0 , 0 , 0 , 0 , 0 , 0 , 0 , | |
0 , 0 , 0 , 0 , 0 , 0 , 0 , m|a , 0 , 0 , 0 , 0 , 0 , 0 , 0 , | |
0 , 0 , 0 , 0 , 0 , 0 , 0 , m|a , 0 , 0 , 0 , 0 , 0 , 0 , 0 , | |
m|a , m|a , m|a , m|a , m|a , m|a , m|a , c , m|a , m|a , m|a , m|a , m|a , m|a , m|a , | |
0 , 0 , 0 , 0 , 0 , 0 , 0 , m|a , 0 , 0 , 0 , 0 , 0 , 0 , 0 , | |
0 , 0 , 0 , 0 , 0 , 0 , 0 , m|a , 0 , 0 , 0 , 0 , 0 , 0 , 0 , | |
0 , 0 , 0 , 0 , 0 , 0 , 0 , m|a , 0 , 0 , 0 , 0 , 0 , 0 , 0 , | |
0 , 0 , 0 , 0 , 0 , 0 , 0 , m|a , 0 , 0 , 0 , 0 , 0 , 0 , 0 , | |
0 , 0 , 0 , 0 , 0 , 0 , 0 , m|a , 0 , 0 , 0 , 0 , 0 , 0 , 0 , | |
0 , 0 , 0 , 0 , 0 , 0 , 0 , m|a , 0 , 0 , 0 , 0 , 0 , 0 , 0 , | |
0 , 0 , 0 , 0 , 0 , 0 , 0 , m|a , 0 , 0 , 0 , 0 , 0 , 0 , 0 , | |
}) | |
if err != nil { | |
log.Fatal("Cannot initialize move masks for rook: %w") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment