Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Function GeneratePawnMoves(CurrentGame As GameInstance, StartSquare As Byte, GenTurn As Turn, ControlledSquares As Boolean) As ULong
- Dim TargetSquares As ULong = 0
- Dim StartRank As Byte = Math.Floor(StartSquare / 8)
- Dim StartFile As Byte = StartSquare Mod 8
- Dim Direction As SByte = -1
- Dim DoublePawnPush As Byte = 6
- Dim EnpassantPlay As Byte = 3
- Dim PawnLocationEnpassant As ULong = CurrentGame.GetSetGameBitboard(5) And CurrentGame.GetSetPlayerBitboard()
- Dim SideTakingBitboard As ULong = CurrentGame.GetSetPlayerBitboard()
- Dim EnpassantTaking() = {-7, -9}
- If GenTurn = Turn.Player Then
- Direction = 1
- DoublePawnPush = 1
- EnpassantPlay = 4
- PawnLocationEnpassant = CurrentGame.GetSetGameBitboard(5) And CurrentGame.GetSetComputerBitboard()
- SideTakingBitboard = CurrentGame.GetSetComputerBitboard()
- EnpassantTaking = {9, 7}
- End If
- Dim TargetSquareF() As ULong = {1UL << ((StartRank + Direction) * 8 + StartFile), 1UL << ((StartRank + 2 * Direction) * 8 + StartFile)}
- Dim TargetSquareT() As ULong = {1UL << ((StartRank + Direction) * 8 + StartFile + 1), 1UL << ((StartRank + Direction) * 8 + StartFile - 1)}
- If StartFile = 0 Then
- TargetSquareT(1) = 0
- ElseIf StartFile = 7 Then
- TargetSquareT(0) = 0
- End If
- If ControlledSquares = False Then
- 'Moving forward one and two spaces
- If (CurrentGame.GetPieceBitboard() And TargetSquareF(0)) = 0 Then
- TargetSquares = TargetSquares Or TargetSquareF(0)
- If (CurrentGame.GetPieceBitboard() And TargetSquareF(1)) = 0 And StartRank = DoublePawnPush Then
- TargetSquares = TargetSquares Or TargetSquareF(1)
- End If
- End If
- 'Taking opponent pieces
- If (SideTakingBitboard And TargetSquareT(0)) > 0 Then
- TargetSquares = TargetSquares Or TargetSquareT(0)
- End If
- If (SideTakingBitboard And TargetSquareT(1)) > 0 Then
- TargetSquares = TargetSquares Or TargetSquareT(1)
- End If
- 'En passant
- Dim MostRecentMovePosition As ULong = 1UL << CurrentGame.GetSetMostRecentMove.TargetSquare
- Dim StartRankMostRecentMove As Byte = Math.Floor(CurrentGame.GetSetMostRecentMove.StartSquare / 8)
- Dim MostRecentMoveDifference As Byte = Math.Abs(CurrentGame.GetSetMostRecentMove.StartSquare - CurrentGame.GetSetMostRecentMove.TargetSquare)
- If (PawnLocationEnpassant And MostRecentMovePosition) > 0 And StartRank = EnpassantPlay And (StartRankMostRecentMove = 6 Or StartRankMostRecentMove = 1) And MostRecentMoveDifference = 16 Then
- If MostRecentMovePosition And (1UL << (StartRank * 8 + StartFile + 1)) Then
- TargetSquares = TargetSquares Or (1UL << (StartRank * 8 + StartFile + EnpassantTaking(0)))
- ElseIf MostRecentMovePosition And (1UL << (StartRank * 8 + StartFile - 1)) Then
- TargetSquares = TargetSquares Or (1UL << (StartRank * 8 + StartFile + EnpassantTaking(1)))
- End If
- End If
- Else
- TargetSquares = TargetSquares Or TargetSquareT(0)
- TargetSquares = TargetSquares Or TargetSquareT(1)
- End If
- Return TargetSquares
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement