Advertisement
Just_Tom

Untitled

Mar 24th, 2024
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VisualBasic 1.19 KB | Source Code | 0 0
  1. Private Function GenerateKnightMoves(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 XDirection() As SByte = {-2, -1, 1, 2, 2, 1, -1, -2}
  6.     Dim YDirection() As SByte = {-1, -2, -2, -1, 1, 2, 2, 1}
  7.     Dim SideBitboard As ULong = CurrentGame.GetSetComputerBitboard()
  8.     If GenTurn = Turn.Player Then
  9.         SideBitboard = CurrentGame.GetSetPlayerBitboard()
  10.     End If
  11.     For XYIndex = 0 To 7
  12.         Dim EndFile As SByte = StartFile + XDirection(XYIndex)
  13.         Dim EndRank As SByte = StartRank + YDirection(XYIndex)
  14.         If (EndFile > -1 And EndFile < 8) And (EndRank > -1 And EndRank < 8) Then
  15.             Dim TargetSquare64 As ULong = (1UL << (EndRank * 8 + EndFile))
  16.             If ControlledSquares = True Then
  17.                 TargetSquares = TargetSquares Or TargetSquare64
  18.             ElseIf (SideBitboard And TargetSquare64) = 0 Then
  19.                 TargetSquares = TargetSquares Or TargetSquare64
  20.             End If
  21.         End If
  22.     Next
  23.     Return TargetSquares
  24. End Function
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement