• Post Reply Bookmark Topic Watch Topic
  • New Topic

Win or Tie method

 
Liutauras Vilda
Marshal
Posts: 3404
131
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
john quick wrote:He is saying that because Turn is set to 9 the program will return TIE no matter what.  So basically no need to have tie in the code. -2 is never called and I need to make sure it is.
Not sure it is that.

Anyway, what is that -2 in your code? Don't understand looking to those few lines. And if you need to make sure is -2 returned as you say, why you need that if statement at all then? If statement gives you max 50% of probability to return what you want.

 
john quick
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My instructor replied and stated I do need TIE.  -2 should be returned if the winner is not NOUGHT, CROSS, or TIE
 
Liutauras Vilda
Marshal
Posts: 3404
131
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, any progress? Do we have solution to look at?
 
john quick
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



This is where I am currently at.  According to my instructor the problem lies in the code above.  I honestly am not sure exactly what to put in to correct the issue.  TIE needs to be in the code, so that stays.  Since my instructor says -2 should be returned if the winner is not NOUGHT, CROSS, or TIE, I feel -2 should not be in the code but I am 100% sure.  Honestly I'm burned out on this project.
 
Campbell Ritchie
Marshal
Posts: 53171
124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does −2 mean? You shou‍ld make symbolic constants for all those numbers, e.g.
 
john quick
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
-2 represents empty cells on the board.
 
Junilu Lacar
Marshal
Posts: 10409
125
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
john quick wrote:-2 represents empty cells on the board.

No, it doesn't.  There could be a winner even when there are still empty cells on the board. If there's a winner, you don't return -2, you return CROSS or NOUGHT, depending on which player won. You return -2 when the game can continue because there is still no winner and there are still empty spots on the board that the next player can choose to mark.
 
Junilu Lacar
Marshal
Posts: 10409
125
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I have been saying since the very beginning of this thread, this method does not make sense at all.  It's named winOrTie, which implies a boolean return value in answer to the question, "Was there a win or tie?" The question implies that the logic that uses the answer to that question will determine if the game should terminate or not. You could refactor that name to isGameOver to get rid of the "Or" in the name and just express the idea as one condition instead of either of two conditions.  The trouble with the current design is that instead of returning a boolean, it returns an int and the possible values returned represent four different states. This is a bad design and a bad requirement.
 
john quick
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my instructor says this is the only hint he can give me....





 
Junilu Lacar
Marshal
Posts: 10409
125
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This small method has been a thorn in your side for so long I'm almost tempted to just give you the code but I won't.  Here are your problems:

1. You haven't figured out how to determine when one of the players has won.
2. You haven't figured out how to determine when the game has ended in a draw

Unless you figure out these three (#1 is a combination of two outcomes: CROSS wins or NOUGHT wins) things, you won't be able to complete this method.

The structure of the code is literally:

Determining whether CROSS or NOUGHT has won is not a straightforward condition as you have tried so many times before. You need to scan all the rows, columns, and diagonals of the Tic Tac Toe board to see if any of them contain three of the same marks. Whoever has three marks in a row has won the game.  If you still don't know how to iterate over the rows, columns, and diagonals, then that's another problem you need to figure out before you can complete this method.
 
Junilu Lacar
Marshal
Posts: 10409
125
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One thing I simply cannot understand is how you still haven't seemed to learn how to align/indent your code properly, even after all the examples you've been given that show you the proper way to do it. This is not a matter of aesthetics or being anal about alignment and indentation. Properly aligned code is essential to being able to think clearly and correctly about the logic that the code represents. For me, poor alignment indicates poor understanding of the logic and organization of the program.
 
Campbell Ritchie
Marshal
Posts: 53171
124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:. . . You need to scan all the rows, columns, and diagonals of the Tic Tac Toe board . . .
You don't need to scan them all, or more precisely you wouldn't have needed to scan them all had the exercise been specified correctly in the first place. If you watch children playing noughts and crosses (=TicTacToe), they do not say, “play on,” nor, “You've won!” The only claim you will hear is, “I've won!” If the exercise hadn't required this daft method, OP could have written a gameWon method which behaves more like real‑life players.
 
Junilu Lacar
Marshal
Posts: 10409
125
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're absolutely right, Campbell, on multiple points. That's pretty much what I said at the start of this thread. It's always the last player to have moved who will win if there is, in fact, a winner and it will be a row, column, or diagonal that intersects the last cell to be marked that will have the winning series of marks.
 
john quick
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem has to do with the assignment and my instructor(s).

I know you guys have said the whole thing is sloppy looking and terrible, I realize that.  BUT...it is what I have been given and what I have to use.  No variation here is allowed. As for what is in the output when I run the project..  What I posted earlier is what my instructor WANTS to see in the output.  I'm not getting that in the output...

I sent my current code to my instructor(s).  I asked what is still wrong with for it not to show what THEY want it to show in the output. 

He replies...

Your program does not run properly because of the last few lines of code in your winOrTie( ) method:




Your program will return TIE no matter what the user enters into the cell for the first time because turn is always set to 9 so return -2 is never called.


I respond asking him to confirm that I need TIE, he replies...

You do need to have TIE in your code.  -2 should be returned if the winner is not CROSS, NOUGHT, or TIE.


Here is the only hint that I can provide you:




As for the alignment of the code, again it is in the instructions.  It looks just like that!  My instructor sends me the above with the code looking just like that!
 
Liutauras Vilda
Marshal
Posts: 3404
131
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
john quick wrote:it is what I have been given and what I have to use.
Alright.

john quick wrote:As for the alignment of the code, again it is in the instructions.
STOP right here!

Please post those 9 lines of code in a well formatted and indented form.
I think we are obliged here to override the poorly formatted and indented code instruction you have been given, otherwise that would be a disservice for the community to show it like that.

Waiting well formatted and indented code - so we could start over from there.

Example of nicely formatted code. Providing two different forms:

1.

2.
 
Liutauras Vilda
Marshal
Posts: 3404
131
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
3.
 
Campbell Ritchie
Marshal
Posts: 53171
124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, what Junilu is saying is that returning −2 every time there are < 9 turns taken is inconsistent with the rules of the game. It would mean that a board looking like this:-
OXO
   OX
   XO
which contains seven symbols would be reported as game in progress when in fact O has won.
 
Junilu Lacar
Marshal
Posts: 10409
125
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
john quick wrote:

As for the alignment of the code, again it is in the instructions.  It looks just like that!  My instructor sends me the above with the code looking just like that!

I'm sorry, but if this were a real western town and I were a real lawman, I would have to put your instructor in jail if that were true. Then I'd tar and feather him.
 
Junilu Lacar
Marshal
Posts: 10409
125
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:
john quick wrote:

As for the alignment of the code, again it is in the instructions.  It looks just like that!  My instructor sends me the above with the code looking just like that!

I'm sorry, but if this were a real western town and I were a real lawman, I would have to put your instructor in jail if that were true. Then I'd tar and feather him.

@OP However, in all fairness to your instructor, I think it's only right to ask him to clarify his requirement regarding formatting. You may be jumping to conclusions based on unintentional omissions or assumptions on his part. Can you please ask your instructor if the above formatting is what he would prefer rather than the examples we have shown you?

Preferably, you would write something like this:

Dear instructor:

Regarding code formatting, I was wondering if what you suggested is formatted the way you'd prefer, that is:

rather than what seems to be a more standard formatting like this:

---
Please make sure that the formatting is preserved in the email that you send your instructor so that it's crystal clear what you're asking and we can clear this matter up once and for all.
 
Campbell Ritchie
Marshal
Posts: 53171
124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...and also verify that you have copied the formatting correctly.
 
john quick
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will ask my instructor tomorrow.  They do not respond on the weekends.
 
Campbell Ritchie
Marshal
Posts: 53171
124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
john quick wrote:. . . .  They do not respond on the weekends.
hahahahahahahahaha
They have more sense than to respond to emails on Sundays. Good for them. Nobody is paying them to stay awake on Sunday listening for emails from students. Not like us on the Ranch; we get paid twice as much for answering posts on Sunday as we would on Monday to Friday
 
john quick
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, my instructor responded and said either way is acceptable for the Tic Tac Toe program.
 
Junilu Lacar
Marshal
Posts: 10409
125
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
john quick wrote:Okay, my instructor responded and said either way is acceptable for the Tic Tac Toe program.

That is quite disappointing.

Just so you know, given these two versions:


The first version is NOT ACCEPTABLE for *any* program in my book nor is it acceptable anywhere where people actually get paid to write code. Use your best judgement on what you want to do.
 
john quick
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd rather go with option 2 and not the one the instructor sent me.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!