• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Tic-tac-toe Design  RSS feed

 
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the output looks neat. Is there a way I can show you?

I think the regex is working? I've tried to break it as best I can Have I done something wrong?
 
Marshal
Posts: 64494
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried the regex with a99?
 
Prasanna Raman
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, OK! I see what you mean. Yes, I did try that and it works because I'd handled that previously in the Board class. I wanted to show you the Board class anyway to confirm that I've done it right.
 
Campbell Ritchie
Marshal
Posts: 64494
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And how are you going to handle a 99×99 board?
As far as I remember, the board class was all right before; I presume you haven't changed anything.
 
Prasanna Raman
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:And how are you going to handle a 99×99 board?

Sorry, do I need to do something different for my program to work? Does it not work already?

Campbell Ritchie wrote:As far as I remember, the board class was all right before; I presume you haven't changed anything.

Sorry, I forgot to tell you that I updated the update() method to handle negative numbers. Kindly take a look at that one.
 
Campbell Ritchie
Marshal
Posts: 64494
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That will work nicely; can it handle a size > 26, however?
 
Campbell Ritchie
Marshal
Posts: 64494
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you come across myChar % 0x20? That can handle capital letters, too.
 
Prasanna Raman
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:can it handle a size > 26, however?

No,currently I restrict the board size to 26 or less. Is that OK?
 
Campbell Ritchie
Marshal
Posts: 64494
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But what happens when you give your regex square a99?
By the way, is it possible to get negative numbers past that regex?
 
Prasanna Raman
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:But what happens when you give your regex square a99?

The regex will allow 99 but the Board will catch it and print this message: The row or column entered is greater than the size of the board.

Campbell Ritchie wrote:By the way, is it possible to get negative numbers past that regex?

No, negative numbers can't get past the regex.
 
Campbell Ritchie
Marshal
Posts: 64494
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought not. It may be unnecessary to check for negative numbers later, in that case.
 
Prasanna Raman
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, right. I've updated my update() method like this: Is this good?

Overall, do you think I've made any progress at all?
 
Campbell Ritchie
Marshal
Posts: 64494
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, to both.
 
Prasanna Raman
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much! I think I'll put this game to sleep for a while now I really cannot thank you enough for all your help through this. I definitely feel that I have improved quite a bit even though I'm still not translating everything I've learnt into design and code. I cringed yesterday looking at the very first code I posted in this thread all those months ago, so maybe that's a sign of improvement and that's thanks in no small part to you Thank you for putting up with so many daft questions along the way. Thank you to the other members who chipped in at various times as well.
 
Campbell Ritchie
Marshal
Posts: 64494
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Goodbye and “you're welcome”
 
Prasanna Raman
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could I ask a favour of you? I definitely would like not to stop with this and build more applications in the next few months. I initially had banking in mind as my next application before I started this. I am looking for your suggestion as well here since you'd now have an idea of where I'm at. What application can I work on next? Kindly suggest and I shall start working on it in a couple of days' time.
 
Campbell Ritchie
Marshal
Posts: 64494
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Database to hold details of accounts, account holders, etc.
 
Prasanna Raman
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. Do you mean a full banking application with these features as well? Could you kindly give me a little more detail?
 
Campbell Ritchie
Marshal
Posts: 64494
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could create a full banking app. Yes. I shall leave you to work out the details.
 
Prasanna Raman
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. There were a couple of questions that came to mind when I looked at my code this morning. In the Board class, you'd earlier asked me if the sameInRow, sameInColumn, sameInBend and sameInBendSinister methods needed to be public and/or static. I said public and static at the time, but I now realize that it definitely shouldn't be static thanks in part to the Campbell Ritchie classification of methods. But I think you said they needed to be public instance methods. I can't understand how these methods will be of any use to any other class outside the package - i.e., classes that don't deal with objects of this Board class. So, can't they just be package-private? Could you please help me understand?
 
Campbell Ritchie
Marshal
Posts: 64494
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you going to use those methods when you implement a GUI? If so, the GUI will be in a different package, and they ought to be public. If not, you are probably right about package private methods.
 
Prasanna Raman
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, thank you. I'm probably not going to be building a GUI anytime soon, so I'll keep those methods package-private.
 
Prasanna Raman
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
More questions:

1) When I think about a player, it seems natural to have a play() method because that's the only thing the player does in the whole game. But my Player class doesn't have a play() method. Even if I try to have it, I am not able to justify its presence. Is not having play() OK or bad? I'm sure you'd have told me if that was bad design but I am just trying to understand how to rationalise it.

2) If not having play() is OK, does it mean that sometimes what seems logical and natural when you write it on a paper may be tweaked in code in order to get it to work? Sorry, this question might be very dumb but I am not able to convince myself by giving a reasonable explanation

 
Campbell Ritchie
Marshal
Posts: 64494
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What methods does Player have? Was it takeTurn? That is equivalent to play.
 
Prasanna Raman
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No My Player has nothing in it I'm afraid, it looks like this.
 
Campbell Ritchie
Marshal
Posts: 64494
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It makes one wonder what use that class is at all.
Weren't you going to add a win field, and a record win method? Then you can count whether O or X has won the more games.
 
Prasanna Raman
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, but wouldn't that involve writing to a file or something similar? So I thought I'd do that later; You'd also suggested it as a later enhancement so I thought I'd leave it like this for now. Have I designed it the wrong way then?
 
Campbell Ritchie
Marshal
Posts: 64494
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can simply increment the win field in the Player object at the moment.
 
Prasanna Raman
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, thank you. I'll do that and post the code soon.
 
Prasanna Raman
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I've been away; will post in a day or two.
 
Prasanna Raman
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've updated my Player class. Please take a look. And I am calling that recordWin() method from the run() method in the Game class, like this:
 
Campbell Ritchie
Marshal
Posts: 64494
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is something wrong when you have to go through a List of Players to find the current Player.
 
Prasanna Raman
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have replaced the loop with this line:Is this OK?
 
Campbell Ritchie
Marshal
Posts: 64494
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
GetSquareCount? Do you always start with the same player?
 
Prasanna Raman
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, O always plays first.
 
Campbell Ritchie
Marshal
Posts: 64494
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That should work, then.
 
Prasanna Raman
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you I've written down the requirements for the banking application and posted them here:

http://www.coderanch.com/t/627551/java/java/OO-design-Banking#2871384

Please review and comment. Looking forward to working with you on that as well
 
I have gone to look for myself. If I should return before I get back, keep me here with this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!