There are many ways to do it, but this is actually the simplest, especially without completely revamping the code from the ground up. Which is what I did in my tic tac toe game.
I can't remember exactly how it works, because I haven't looked at my code in years, but I created a "line" object, and then just check a method in each line object. It's a little more complex as a whole, but makes that main logic look simpler and easier to read.
This creates a set of unique numbers from the three spaces, which is then checked against two sets that correspond to winning states (all 1 or all 2 in line).
View all comments
Show parent comment
2
u/havens1515 May 20 '22
There are many ways to do it, but this is actually the simplest, especially without completely revamping the code from the ground up. Which is what I did in my tic tac toe game.
I can't remember exactly how it works, because I haven't looked at my code in years, but I created a "line" object, and then just check a method in each line object. It's a little more complex as a whole, but makes that main logic look simpler and easier to read.