Advertisement
Just_Tom

Untitled

Mar 24th, 2024
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VisualBasic 3.23 KB | Source Code | 0 0
  1. Private Function GeneratePawnMoves(CurrentGame As GameInstance, StartSquare As Byte, GenTurn As Turn, ControlledSquares As Boolean) As ULong
  2.     Dim TargetSquares As ULong = 0
  3.     Dim StartRank As Byte = Math.Floor(StartSquare / 8)
  4.     Dim StartFile As Byte = StartSquare Mod 8
  5.     Dim Direction As SByte = -1
  6.     Dim DoublePawnPush As Byte = 6
  7.     Dim EnpassantPlay As Byte = 3
  8.     Dim PawnLocationEnpassant As ULong = CurrentGame.GetSetGameBitboard(5) And CurrentGame.GetSetPlayerBitboard()
  9.     Dim SideTakingBitboard As ULong = CurrentGame.GetSetPlayerBitboard()
  10.     Dim EnpassantTaking() = {-7, -9}
  11.     If GenTurn = Turn.Player Then
  12.         Direction = 1
  13.         DoublePawnPush = 1
  14.         EnpassantPlay = 4
  15.         PawnLocationEnpassant = CurrentGame.GetSetGameBitboard(5) And CurrentGame.GetSetComputerBitboard()
  16.         SideTakingBitboard = CurrentGame.GetSetComputerBitboard()
  17.         EnpassantTaking = {9, 7}
  18.     End If
  19.     Dim TargetSquareF() As ULong = {1UL << ((StartRank + Direction) * 8 + StartFile), 1UL << ((StartRank + 2 * Direction) * 8 + StartFile)}
  20.     Dim TargetSquareT() As ULong = {1UL << ((StartRank + Direction) * 8 + StartFile + 1), 1UL << ((StartRank + Direction) * 8 + StartFile - 1)}
  21.     If StartFile = 0 Then
  22.         TargetSquareT(1) = 0
  23.     ElseIf StartFile = 7 Then
  24.         TargetSquareT(0) = 0
  25.     End If
  26.     If ControlledSquares = False Then
  27.         'Moving forward one and two spaces
  28.        If (CurrentGame.GetPieceBitboard() And TargetSquareF(0)) = 0 Then
  29.             TargetSquares = TargetSquares Or TargetSquareF(0)
  30.             If (CurrentGame.GetPieceBitboard() And TargetSquareF(1)) = 0 And StartRank = DoublePawnPush Then
  31.                 TargetSquares = TargetSquares Or TargetSquareF(1)
  32.             End If
  33.         End If
  34.         'Taking opponent pieces
  35.        If (SideTakingBitboard And TargetSquareT(0)) > 0 Then
  36.             TargetSquares = TargetSquares Or TargetSquareT(0)
  37.         End If
  38.         If (SideTakingBitboard And TargetSquareT(1)) > 0 Then
  39.             TargetSquares = TargetSquares Or TargetSquareT(1)
  40.         End If
  41.         'En passant
  42.        Dim MostRecentMovePosition As ULong = 1UL << CurrentGame.GetSetMostRecentMove.TargetSquare
  43.         Dim StartRankMostRecentMove As Byte = Math.Floor(CurrentGame.GetSetMostRecentMove.StartSquare / 8)
  44.         Dim MostRecentMoveDifference As Byte = Math.Abs(CurrentGame.GetSetMostRecentMove.StartSquare - CurrentGame.GetSetMostRecentMove.TargetSquare)
  45.         If (PawnLocationEnpassant And MostRecentMovePosition) > 0 And StartRank = EnpassantPlay And (StartRankMostRecentMove = 6 Or StartRankMostRecentMove = 1) And MostRecentMoveDifference = 16 Then
  46.             If MostRecentMovePosition And (1UL << (StartRank * 8 + StartFile + 1)) Then
  47.                 TargetSquares = TargetSquares Or (1UL << (StartRank * 8 + StartFile + EnpassantTaking(0)))
  48.             ElseIf MostRecentMovePosition And (1UL << (StartRank * 8 + StartFile - 1)) Then
  49.                 TargetSquares = TargetSquares Or (1UL << (StartRank * 8 + StartFile + EnpassantTaking(1)))
  50.             End If
  51.         End If
  52.     Else
  53.         TargetSquares = TargetSquares Or TargetSquareT(0)
  54.         TargetSquares = TargetSquares Or TargetSquareT(1)
  55.     End If
  56.     Return TargetSquares
  57. End Function
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement