Advertisement
Just_Tom

Untitled

Mar 24th, 2024
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VisualBasic 1.82 KB | Source Code | 0 0
  1. Public Class Rook
  2.     Inherits Piece
  3.     Public Overrides Function CalculateMove(CurrentBoard As Board, SourcePoint As Point) As List(Of Point)
  4.         Dim DestinationLst As New List(Of Point)
  5.         Dim PDirections() As Point = {
  6.             New Point(-1, 0),  'N
  7.            New Point(0, 1),   'E
  8.            New Point(1, 0),   'S
  9.            New Point(0, -1)  'W
  10.        }
  11.         For Each Direction In PDirections
  12.             Dim NextDestination As New Point(SourcePoint.X + Direction.X, SourcePoint.Y + Direction.Y)
  13.             While CheckWithinArray(NextDestination)
  14.                 If CurrentBoard.PieceBoard(SourcePoint.X, SourcePoint.Y) > 0 Then
  15.                     If CurrentBoard.PieceBoard(NextDestination.X, NextDestination.Y) = 0 Then
  16.                         DestinationLst.Add(NextDestination)
  17.                     ElseIf CurrentBoard.PieceBoard(NextDestination.X, NextDestination.Y) < 0 Then
  18.                         DestinationLst.Add(NextDestination)
  19.                         Exit While
  20.                     Else
  21.                         Exit While
  22.                     End If
  23.                 ElseIf CurrentBoard.PieceBoard(SourcePoint.X, SourcePoint.Y) < 0 Then
  24.                     If CurrentBoard.PieceBoard(NextDestination.X, NextDestination.Y) = 0 Then
  25.                         DestinationLst.Add(NextDestination)
  26.                     ElseIf CurrentBoard.PieceBoard(NextDestination.X, NextDestination.Y) > 0 Then
  27.                         DestinationLst.Add(NextDestination)
  28.                         Exit While
  29.                     Else
  30.                         Exit While
  31.                     End If
  32.                 End If
  33.                 NextDestination.X += Direction.X
  34.                 NextDestination.Y += Direction.Y
  35.             End While
  36.         Next
  37.         Return DestinationLst
  38.     End Function
  39. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement