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 1 minute ago
JK Rowling in ‘arrest me’ challenge over hate crime lawLast reply 4 minutes ago
Lloyds Apprenticeships 2024Last reply 4 minutes ago
MSc Psychology (Conversion) course MMU or open university?Last reply 5 minutes ago
Official UCL Offer Holders Thread for 2024 entryLast reply 10 minutes ago
Official: Queen's University Belfast A100 2024 Entry ApplicantsLast reply 11 minutes ago
Participants needed for opinion on design for class!! 3-5 minutes only!Last reply 13 minutes ago
CLEARING???: KCL, QMUOL, ST Andrews, BATH , ROYAL HOLLOWAYLast reply 13 minutes ago
November 2023 Illegal Migration Intake Unit - Intake Response Team - Immigration OffiLast reply 15 minutes ago
Goldmansachs Degree Apprenticeship 2024Last reply 20 minutes ago
Standard Chartered Apprenticeships 2024Last reply 1 week ago
OCR A-level Computer Science Paper 2 (H446/02) - 19th June 2023 [Exam Chat]Last reply 2 weeks ago
AQA A-level Computer Science Paper 1 (7517 1A - 1E) - 12th June 2023 [Exam Chat]Last reply 3 weeks ago
OCR A-level Computer Science Paper 1 (H446/01) - 12th June 2023 [Exam Chat]Last reply 2 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 5 months ago
AQA GCSE Computer Science Paper 1 (8525/1A, 1B, 1C) - 19th May 2023 [Exam Chat]Last reply 5 months ago
AQA Computer Science NEA and Computer science paper 1 questionLast reply 1 week ago
OCR A-level Computer Science Paper 2 (H446/02) - 19th June 2023 [Exam Chat]Last reply 2 weeks ago
AQA A-level Computer Science Paper 1 (7517 1A - 1E) - 12th June 2023 [Exam Chat]Last reply 3 weeks ago
OCR A-level Computer Science Paper 1 (H446/01) - 12th June 2023 [Exam Chat]Last reply 2 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 5 months ago
AQA GCSE Computer Science Paper 1 (8525/1A, 1B, 1C) - 19th May 2023 [Exam Chat]Last reply 5 months ago
AQA Computer Science NEA and Computer science paper 1 question