Skip to content

Comments

Solved Issue #551 regarding input validation in Connect Four#552

Open
shrutidoshi94 wants to merge 2 commits intowasmerio:mainfrom
shrutidoshi94:Connect-Four-Input-Validation
Open

Solved Issue #551 regarding input validation in Connect Four#552
shrutidoshi94 wants to merge 2 commits intowasmerio:mainfrom
shrutidoshi94:Connect-Four-Input-Validation

Conversation

@shrutidoshi94
Copy link

@shrutidoshi94 shrutidoshi94 commented Feb 24, 2026

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant