Advertisement
Just_Tom

Untitled

Mar 24th, 2024
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VisualBasic 1.79 KB | Source Code | 0 0
  1. Private Function GenerateKingMoves(CurrentGame As GameInstance, StartSquare As Byte, GenTurn As Turn, ControlledSquares As Boolean) As ULong
  2.     Dim DirectionsAvailableSliding() As SByte = {8, -8, 1, -1, 9, -9, 7, -7}
  3.     Dim TargetSquares As ULong = 0
  4.     Dim SideBitboard As ULong = CurrentGame.GetSetComputerBitboard
  5.     Dim RookNom() As Byte = {2, 3}
  6.     Dim MaskRight As ULong = &HE00000000000000UL
  7.     Dim MaskLeft As ULong = &H7000000000000000UL
  8.     Dim KingMoved As Boolean = CurrentGame.GetSetKingMoved(1)
  9.     If GenTurn = Turn.Player Then
  10.         SideBitboard = CurrentGame.GetSetPlayerBitboard
  11.         RookNom = {0, 1}
  12.         MaskRight = 14
  13.         MaskLeft = 112
  14.         KingMoved = CurrentGame.GetSetKingMoved(0)
  15.     End If
  16.     For DirectionIndex = 0 To 7
  17.         Dim DeadEnd As SByte = NumSquaresToEdgeSliding(StartSquare)(DirectionIndex) - 1
  18.         If DeadEnd <> -1 Then
  19.             Dim TargetSquare64 As ULong = 1UL << (StartSquare + DirectionsAvailableSliding(DirectionIndex))
  20.             If (SideBitboard And TargetSquare64) = 0 Then
  21.                 TargetSquares = TargetSquares Or TargetSquare64
  22.             End If
  23.         End If
  24.     Next
  25.     If KingMoved = False And ControlledSquares = False Then
  26.         'Castling right
  27.        If ((CurrentGame.GetCastleSpaces() And MaskRight) And CurrentGame.GetPieceBitboard()) = 0 And CurrentGame.GetSetRooksMoved(RookNom(0)) = False Then
  28.             TargetSquares = TargetSquares Or (1UL << (StartSquare - 2))
  29.         End If
  30.         'Castling left
  31.        If ((CurrentGame.GetCastleSpaces() And MaskLeft) And CurrentGame.GetPieceBitboard()) = 0 And CurrentGame.GetSetRooksMoved(RookNom(1)) = False Then
  32.             TargetSquares = TargetSquares Or (1UL << (StartSquare + 2))
  33.         End If
  34.     End If
  35.     Return TargetSquares
  36. End Function
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement