Solved Issue #551 regarding input validation in Connect Four#552
Open
shrutidoshi94 wants to merge 2 commits intowasmerio:mainfrom
Open
Solved Issue #551 regarding input validation in Connect Four#552shrutidoshi94 wants to merge 2 commits intowasmerio:mainfrom
shrutidoshi94 wants to merge 2 commits intowasmerio:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses Issue #551, where the game would crash if a player entered a column number outside the valid range (1–7) or a non-integer value.
The fix ensures the game remains stable by implementing an input validation loop that keeps the player prompted until a valid selection is made.
Changes Made
Added Input Validation: Wrapped the column selection in a while loop to catch out-of-bounds integers.
User-Friendly Indexing: Adjusted the input logic so users can type 1–7 (human-readable) while the code processes it as 0–6 (zero-indexed).
Error Handling: Added a try-except block to handle ValueError in case a user inputs a string or symbol instead of a number.
Testing Performed
Out-of-Bounds Test: Entered 8, 0, and -1. The program correctly displayed an error message and re-prompted the user.
Type Safety Test: Entered "A" and "!" to ensure the ValueError was caught.
Boundary Test: Entered 1 and 7 to ensure the pieces were placed in the correct first and last columns of the array.