C
C#16mo ago
Dahyerin

✅ Tic-Tac-Toe validation outputting wrong values

I have a validation loop that checks whether a box is appropriate or not. Whilst the validator checks and throws an error if the square is already occupied, requesting another input from the user (or AI). When it gets an valid input, it will output the incorrect one instead of the new one. In the case for the AI, it outputs all of the incorrect variations it tried when it receives a valid one, which results in it overriding anything and everything there. I have included the two pics of the validation method and the human Make move function in hopes this will help. Thanks.
8 Replies
SinFluxx
SinFluxx16mo ago
$paste
MODiX
MODiX16mo ago
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
SinFluxx
SinFluxx16mo ago
As it's hard to figure out what's going on with incomplete cropped screenshots In your ValidateMove method though, shouldn't your loop be while (correctInput == false)?
Dahyerin
DahyerinOP16mo ago
This is just the player class, I changed the while loop to what you said, but now it just endlessly loops on the first error. https://paste.mod.gg/ujixrhqrdacc/0
BlazeBin - ujixrhqrdacc
A tool for sharing your source code with the world!
TheBoxyBear
TheBoxyBear16mo ago
What does the boardSpot array represent? If it's mapping a number to a space on the board, how about finding the range of valid numbers mathematically and get XY to check if it's occupied? I thought you were doing recursion to handle errors but there actually seems to be circular calls between valdiateMove and makeMove Right so makeMove prompts the player and valdiateMove makes the validation so it's effectively recursion but across two methods. When you're doing recursion, you need actually need a loop to repeat the instructions, you just need an exit condition. In your case since its based on user user action, I would stick to a loop over recursion to avoid ballooning. A user could break the app by spamming invalid input.
Dahyerin
DahyerinOP16mo ago
Thanks. I ended up figuring it out. \close
SinFluxx
SinFluxx16mo ago
$close
MODiX
MODiX16mo ago
Use the /close command to mark a forum thread as answered
Want results from more Discord servers?
Add your server