• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Need help to improve coding skills (Trying Tic Tac Toe game)

 
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everyone, I have completed my core java course and needs to improve my coding and logical skills.. So as suggested by earlier in previous posts i am trying to build Tic-Tac-Toe game.

I am hoping you guys will help me to improve my skills as you all supported me earlier... To start the game i thought below requirement, please let me know what else is required :

requirement:

1 board having 3 rows and 3 columns , 2 players , 1 dot and 1 cross

rule:
1) players needs to wait for its turn till other player tick
2) continous row , column and diagonal entry of same type (dot or cross) is winner
3) if point 2 is not satisfied than match is draw

To check the winner i thought to compare each user entry with the possible position through which match can be won but that includes several if-else statements. Is there any alternative to improve? I also thought to make list of list which stores all the possible combination through which user can win and then compare the position with that but then i also thought it may also not work as for every input i need to compare all the entries...

Any idea how to move forward???
 
Marshal
Posts: 79969
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please search this forum and you will find several threads on the same subject. I think they will be helpful.


Some of them are very long.
 
Tushar Goel
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah Thanks Campbell, but i thought if some one review my code than it will help to improve it.. Is there any other way to do that?
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tushar Goel wrote:Yeah Thanks Campbell, but i thought if some one review my code than it will help to improve it.. Is there any other way to do that?


You could sign up to the Cattle Drive
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tushar Goel wrote:1 board having 3 rows and 3 columns , 2 players , 1 dot and 1 cross


That's a good start, but don't go thinking of these things as Strings, because they're objects, and objects require classes.

At the very least, I can see three: Board, Player and Square, and it's the Square that will contain your "dot" or "cross" (probably depending on which Player filled it).

You might want to read the StringsAreBad page; particularly the example at the end.

HIH

Winston
 
Tushar Goel
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Winston, for Dot and Cross i thought to use ENUM.

So should i start thinking about class and flow of the programe or am i missing something else?
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tushar Goel wrote:Thanks Winston, for Dot and Cross i thought to use ENUM.


Sound pefectly reasonable to me.

So should i start thinking about class and flow of the programe or am i missing something else?


Not that I can see, but do your thinking ON PAPER, not in your IDE or editor. The code itself should simply be a translation of what you already know.

Winston
 
Tushar Goel
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

but do your thinking ON PAPER



Yeah will do that... I will get back once i make some progress on paper.. Thanks..
 
Tushar Goel
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Winston, while thinking about it i thought of 2 things about type of game and it is procedure:

I am starting with basic game for 2 players on different computers/sessions, later i will improved it with computer vs player.

Right now i am creating a console based application in which it receive input between 1 - 9 exactly once from each player.

To control all this operation, i am thinking to use central server which stores all the movement of both players, available squares , assign "O" or "X" whenever new player is connected, check whether player move is valid and check if player is won or game is draw.
I will user socket which receive a signal from particular format and revert on particular value.

at the client side i will validate that user cannot enter same input again.
 
Tushar Goel
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried to make server version, here is prepCode for the same:



variables:
1) Declare a variable of type Symbols to store both players symbols
2) Declare a variable to store all the available squares 1 to 9
3) Declare a variable to store all the winning moves. There are 8 such moves through which player can win.
4) Declare a variable to store the state about player. Like one player is use its turn then it should wait till other player is moved
5) Declare a variable to store server socket
6) Declare a variable to store port number
7) Declare a variable to create thread pool of 2 threads one for each player


Methods:

 
Tushar Goel
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can any one suggest above prep code are good and i should go ahead of coding or do i need to modify it?
 
My first bit of advice is that if you are going to be a mime, you shouldn't talk. Even the tiny ad is nodding:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic