Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Function GenerateKingMoves(CurrentGame As GameInstance, StartSquare As Byte, GenTurn As Turn, ControlledSquares As Boolean) As ULong
- Dim DirectionsAvailableSliding() As SByte = {8, -8, 1, -1, 9, -9, 7, -7}
- Dim TargetSquares As ULong = 0
- Dim SideBitboard As ULong = CurrentGame.GetSetComputerBitboard
- Dim RookNom() As Byte = {2, 3}
- Dim MaskRight As ULong = &HE00000000000000UL
- Dim MaskLeft As ULong = &H7000000000000000UL
- Dim KingMoved As Boolean = CurrentGame.GetSetKingMoved(1)
- If GenTurn = Turn.Player Then
- SideBitboard = CurrentGame.GetSetPlayerBitboard
- RookNom = {0, 1}
- MaskRight = 14
- MaskLeft = 112
- KingMoved = CurrentGame.GetSetKingMoved(0)
- End If
- For DirectionIndex = 0 To 7
- Dim DeadEnd As SByte = NumSquaresToEdgeSliding(StartSquare)(DirectionIndex) - 1
- If DeadEnd <> -1 Then
- Dim TargetSquare64 As ULong = 1UL << (StartSquare + DirectionsAvailableSliding(DirectionIndex))
- If (SideBitboard And TargetSquare64) = 0 Then
- TargetSquares = TargetSquares Or TargetSquare64
- End If
- End If
- Next
- If KingMoved = False And ControlledSquares = False Then
- 'Castling right
- If ((CurrentGame.GetCastleSpaces() And MaskRight) And CurrentGame.GetPieceBitboard()) = 0 And CurrentGame.GetSetRooksMoved(RookNom(0)) = False Then
- TargetSquares = TargetSquares Or (1UL << (StartSquare - 2))
- End If
- 'Castling left
- If ((CurrentGame.GetCastleSpaces() And MaskLeft) And CurrentGame.GetPieceBitboard()) = 0 And CurrentGame.GetSetRooksMoved(RookNom(1)) = False Then
- TargetSquares = TargetSquares Or (1UL << (StartSquare + 2))
- End If
- End If
- Return TargetSquares
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement