Hello, this is a simplified version of code that I'm working on for a school project. This is meant to be a Chess-related program. To briefly explain what this snippet is supposed to do, it is supposed to ask what specific square any piece is on, and the program is simply supposed to return whether that square exists or not, based on hashmapped int values going from 1 to 64 (since there is 64 squares on a chess board). However, whenever I DO input a valid square option (such as "c1" for example), it claims that the square does not exist, even though it's supposed to match a value in the Hashmap. I simply cannot find the problem. (btw I'm a bit of a Java noob)
#Code not working as intended
1 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @placid coral! Please use
/closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
The problem is that you're only checking if the first square is matching your input
ohhhhh, I see. That else statement is not being used correctly then, yes?
yeah you probably don't want that there
Also is there a reason as to why you're using a HashMap rather than an ArrayList
Well I'm not sure. All I really need is for those specific numbers to represent its respective square (so 1 MUST be a1, 64 MUST be h8, etc.,). But should an ArrayList be able to do this better? I might switch it to that if so.
They're 0 indexed so 0 will be A1 but that's easily fixable by adding one to the output
or subtracting one from the input
Okay then, this was very helpful. Thank You!
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.