Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class ChessBoard
- Public Enum ChessPieces
- WHITE_PAWN = 1
- BLACK_PAWN = -1
- WHITE_KNIGHT = 3
- BLACK_KNIGHT = -3
- WHITE_BISHOP = 3
- BLACK_BISHOP = -3
- WHITE_ROOK = 5
- BLACK_ROOK = -5
- WHITE_QUEEN = 9
- BLACK_QUEEN = -9
- WHITE_KING = 200
- BLACK_KING = -200
- End Enum
- Private board As String
- Private arr As Array = New Char(8, 8) {}
- Public Sub New()
- board = "RKBQDBKR/PPPPPPPP/8/8/8/8/pppppppp/rkbqdbkr"
- parseFromString()
- End Sub
- Public Sub New(ByVal initial_board As String)
- board = initial_board
- parseFromString()
- End Sub
- Private Sub parseFromString()
- Dim tmp As String = board.Replace("8"c, "NNNNNNNN")
- Dim rows As Array = tmp.Split(New String() {"/"c}, StringSplitOptions.RemoveEmptyEntries)
- For i As Integer = 0 To 7
- For j As Integer = 0 To 7
- arr(i, j) = rows(i)(j)
- Next
- Next
- End Sub
- Private Sub parseToString(Optional ByVal boardrep As Boolean = False)
- Dim tmp As String = ""
- For i As Integer = 7 To 0 Step -1
- For j As Integer = 7 To 0 Step -1
- tmp += arr(i, j)
- Next
- If i <> 7 Then
- If Not boardrep Then tmp += "/" Else tmp += Environment.NewLine
- End If
- Next
- board = tmp
- End Sub
- Public ReadOnly Property StringRepresentation
- Get
- parseToString()
- Return board
- End Get
- End Property
- Public ReadOnly Property BoardRepresentation
- Get
- parseToString(True)
- Return board
- End Get
- End Property
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement