Fix king moves and fix formatting.
This commit is contained in:
parent
2d5eacb351
commit
63e973a3be
@ -181,9 +181,9 @@ func (b Board) getLastMove() types.Move {
|
|||||||
|
|
||||||
func (b Board) getCopyOfBoard() Board {
|
func (b Board) getCopyOfBoard() Board {
|
||||||
return Board{
|
return Board{
|
||||||
position: b.position.getCopyOfPosition(),
|
position: b.position.getCopyOfPosition(),
|
||||||
history: b.history,
|
history: b.history,
|
||||||
colorToMove: b.colorToMove,
|
colorToMove: b.colorToMove,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,12 +200,11 @@ func (b *Board) handleSpecialMove(move types.Move) bool {
|
|||||||
var was bool
|
var was bool
|
||||||
var pieceAtStartSquare = b.getPieceAt(move.StartSquare)
|
var pieceAtStartSquare = b.getPieceAt(move.StartSquare)
|
||||||
|
|
||||||
switch pieceAtStartSquare.(type) {
|
switch piece := pieceAtStartSquare.(type) {
|
||||||
case Pawn:
|
case Pawn:
|
||||||
pawn := pieceAtStartSquare.(Pawn)
|
was = piece.HandlePossiblePromotion(b, move)
|
||||||
was = pawn.HandlePossiblePromotion(b, move)
|
|
||||||
if !was {
|
if !was {
|
||||||
was = pawn.HandleEnPassant(b, move, b.getLastMove())
|
was = piece.HandleEnPassant(b, move, b.getLastMove())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return was
|
return was
|
||||||
|
@ -31,14 +31,15 @@ func (b *Board) GetNonBlockedDiagonals(fromSquare types.Coordinate) []types.Coor
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *Board) GetNonBlockedKingMoves(fromSquare types.Coordinate) []types.Coordinate {
|
func (b *Board) GetNonBlockedKingMoves(fromSquare types.Coordinate) []types.Coordinate {
|
||||||
return b.getNonBlockedConsecutive(fromSquare.GetAllKingMoves(), fromSquare)
|
return b.getNonBlockedRaw(fromSquare.GetAllKingMoves(), fromSquare)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Board) GetNonBlockedKnightMoves(fromSquare types.Coordinate) []types.Coordinate {
|
func (b *Board) GetNonBlockedKnightMoves(fromSquare types.Coordinate) []types.Coordinate {
|
||||||
allKnightMoves := fromSquare.GetAllKnightMoves()
|
return b.getNonBlockedRaw(fromSquare.GetAllKnightMoves(), fromSquare)
|
||||||
return b.getNonBlockedForKnights(allKnightMoves, fromSquare)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// returns only those squares in a straight/diagonal that are not blocked
|
||||||
|
// until it hits a blocking piece (excluding same color, including diff color)
|
||||||
func (b *Board) getNonBlockedConsecutive(
|
func (b *Board) getNonBlockedConsecutive(
|
||||||
squaresToCheck []types.Coordinate,
|
squaresToCheck []types.Coordinate,
|
||||||
sourceSquare types.Coordinate,
|
sourceSquare types.Coordinate,
|
||||||
@ -50,8 +51,8 @@ func (b *Board) getNonBlockedConsecutive(
|
|||||||
piece := b.getPieceAt(square)
|
piece := b.getPieceAt(square)
|
||||||
if piece != nil {
|
if piece != nil {
|
||||||
if piece.GetColor() == pieceOnSourceSquare.GetColor() {
|
if piece.GetColor() == pieceOnSourceSquare.GetColor() {
|
||||||
//We do not append squares with same-colored pieces
|
//We do not append squares with same-colored pieces
|
||||||
//and also not the squares behind it
|
//and also not the squares behind it
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
// if there is an opposite colored piece we append it but
|
// if there is an opposite colored piece we append it but
|
||||||
@ -64,18 +65,19 @@ func (b *Board) getNonBlockedConsecutive(
|
|||||||
return nonBlocked
|
return nonBlocked
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Board) getNonBlockedForKnights(
|
// returns any square in squaresToCheck that are not blocked
|
||||||
|
func (b *Board) getNonBlockedRaw(
|
||||||
squaresToCheck []types.Coordinate,
|
squaresToCheck []types.Coordinate,
|
||||||
sourceSquare types.Coordinate,
|
sourceSquare types.Coordinate,
|
||||||
) []types.Coordinate {
|
) []types.Coordinate {
|
||||||
pieceOnSourceSquare := b.getPieceAt(sourceSquare)
|
pieceOnSourceSquare := b.getPieceAt(sourceSquare)
|
||||||
nonBlocked := []types.Coordinate{}
|
nonBlocked := []types.Coordinate{}
|
||||||
|
|
||||||
for _, square := range squaresToCheck {
|
for _, square := range squaresToCheck {
|
||||||
piece := b.getPieceAt(square)
|
piece := b.getPieceAt(square)
|
||||||
if piece == nil || piece.GetColor() != pieceOnSourceSquare.GetColor() {
|
if piece == nil || piece.GetColor() != pieceOnSourceSquare.GetColor() {
|
||||||
nonBlocked = append(nonBlocked, square)
|
nonBlocked = append(nonBlocked, square)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nonBlocked
|
return nonBlocked
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user