Scroll to see replies
'Get the player's move by asking and reading their response as co-ordinates
Function GetHumanPlayerMove(ByVal PlayerName As String) As Integer
'MY FIX: Crash if non-integer was entered
'Dim Coordinates As Integer
Dim Coordinates As String 'Changed from Integer
Console.Write(PlayerName & " enter the coordinates of the square where you want to place your piece: ")
Coordinates = Console.ReadLine
Try
Return Int(Coordinates)
Catch ex As Exception
Return 0
End Try
End Function
I also changed CheckIfMoveIsValid to return False if the co-ordinates are out of range:'Check if a move is valid - cell is empty
'MY FIX: Add BoardSize attribute
Function CheckIfMoveIsValid(ByVal Board(,) As Char, ByVal BoardSize As Integer, ByVal Move As Integer) As Boolean
Dim Row As Integer
Dim Column As Integer
Dim MoveIsValid As Boolean
'Get row and col from move co-ordinates
Row = Move Mod 10
Column = Move \ 10
MoveIsValid = False
'BEGIN MY FIX
'Return false if Row or Col < 0
'OutOfRangeException occurs if Row or Column is greater than the board size, or < 0
If Row < 0 Or Column < 0 Or Row > BoardSize Or Column > BoardSize Then
Return False
End If
'END MY FIX
'If the cell at the given co-ordinates is empty, the move is valid
If Board(Row, Column) = " " Then
MoveIsValid = True
End If
Return MoveIsValid
End Function
Last reply 2 days ago
Is MathsFM French Alevels good for a CS degree at top uni (OX, UCL, Durham etc)Last reply 4 days ago
OCR A-level Computer Science Paper 1 (H446/01) - 12th June 2023 [Exam Chat]Last reply 2 weeks ago
OCR A-level Computer Science Paper 2 (H446/02) - 19th June 2023 [Exam Chat]Last reply 3 weeks ago
AQA A-level Computer Science Paper 1 (7517 1A - 1E) - 12th June 2023 [Exam Chat]Last reply 1 month ago
Not receiving any response from University of Birmingham.Last reply 3 months ago
OCR GCSE Computer Science Paper 1 (J277/01) - 19th May 2023 [Exam Chat]Last reply 3 months ago
AQA GCSE Computer Science Paper 2 (8525/2) - 25th May 2023 [Exam Chat]Last reply 2 days ago
Is MathsFM French Alevels good for a CS degree at top uni (OX, UCL, Durham etc)Last reply 4 days ago
OCR A-level Computer Science Paper 1 (H446/01) - 12th June 2023 [Exam Chat]Last reply 2 weeks ago
OCR A-level Computer Science Paper 2 (H446/02) - 19th June 2023 [Exam Chat]Last reply 3 weeks ago
AQA A-level Computer Science Paper 1 (7517 1A - 1E) - 12th June 2023 [Exam Chat]Last reply 1 month ago
Not receiving any response from University of Birmingham.Last reply 3 months ago
OCR GCSE Computer Science Paper 1 (J277/01) - 19th May 2023 [Exam Chat]Last reply 3 months ago
AQA GCSE Computer Science Paper 2 (8525/2) - 25th May 2023 [Exam Chat]