Hey,
I'm trying to make a simple noughts-and-crosses game using a 5x5 grid (
String[][]; I considered ArrayLists based on my last topic but will leave those alone for now), and am now trying to write the code that checks whether the last move made a row of three noughts or three crosses (which of these two isn't important at the moment; I just need to know if there are three adjacent identical characters). But I'm having a hard time coming up with an elegant way to do the check. The options I've thought of so far are:
- Check the whole board each time. Pro: easy to code using for-loops; con: hugely wasteful.
- Starting from the last character entered, check in all directions to see if it completes a line of three identical characters. Pro: slightly less wasteful; con: code looks like this:
- Or something else
What's the best way to go about this?