I think that is highly unlikely. AY has tried to use that most unpredictable and unreliable idiom, “if (win==true) ...”, which is not only poor style, but is prone to the error of only hitting the = key once. That will throw all the logic off.
Daniel Demesmaecker wrote:Does your logic work correctly? . . .
Ana Yo wrote:Can someone help me? Where should I put getWinner() in the driver class?
We already have. As Junilu says, you need to break the task down into smaller pieces. I see you have followed my hint about == true from yesterday, but before that please explain why you are checking every column. That is not how the game is played in real life. You only need to check one column and one row. You might need to check a diagonal, or both, or neither. I shall leave you to work out why.
Ana Yo wrote:Can someone help me?
What makes you think the driver needs a getWinner() method at all? What is the logic and concept behind getWinner()? Why do you need to know who has won? If you watch children playing the game, they never ask who has won; they know it already. Think about it. Noughts and Crosses is not like football. In football, you have to wait until the game time finishes and calculate the score to know who has won. There is no need to look for a score in noughts and crosses, nor to try to work out who won. The same applies to games like chess and draughts (US=checkers).
Where should I put getWinner() in the driver class?
Would you want that loop in the driver class in the first place?Move the loop into the game object.
Junilu Lacar wrote:. . . Here's an example of a game loop that uses a more encapsulated TicTacToe object: . . . .
Campbell Ritchie wrote:Move the loop into the game object.
Junilu Lacar wrote:
Junilu Lacar wrote:...I would suggest a method, say iterator(), that returns an Iterator instead and that documentation be explicit about the order in which the iterator goes ...
salvin francis wrote:Also curious, why isn't a multidimensional array good for a board of rows and columns ?
Junilu Lacar wrote:...To a client, it would make more sense if I just got an iterator that I could go through all the spaces in a row-wise manner.