• Post Reply Bookmark Topic Watch Topic
  • New Topic

Work for school  RSS feed

 
tiago santos
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So this is my code , I am getting started on java , and I this is a NIM game .. the rules of the game are basically : 1- the game starts with 21 matches | 2-each player can only take 1 to 4 matche at the time | 3-the last player to take the matche loses...

So I already did that , and its working, but there is one problem, my teacher also ask for some things that I ont know how to do it :/ ... I think it works with arrays, but I ont know how to work with that.

1-Every move must always be visible the total number of moves and the
number of moves made ​​by each player.

2- At the end of the game there should be a message that states who the
winning player and how many moves made ​​.

3- At the end of each game should be allowed to review all the moves that
They were made ( game history ) .

4- the possibility that, at the end of each game, there is the
possibility of restarting .

Can someone help me fast as they can ? I dont need the code done ( I would be thankfull if someone give that, tho x) ) , I need someone to explain me how to do this 4 points ... thanks

 
Les Morgan
Rancher
Posts: 768
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tiago santos wrote:
1-Every move must always be visible the total number of moves and the
number of moves made ​​by each player.

You have to keep a count of how many moves are made by each player and print out the sum of those and the individual counts each round. (can be done with int variables)

tiago santos wrote:
2- At the end of the game there should be a message that states who the
winning player and how many moves made ​​.

Well according to your game explanation, there are N-1 winners, and only 1 loser. So this only makes sense where you have 2 players. You would have to keep track of who won and print out what ever the winning move is, but that does not make sense either--there is a losing move so I guess you would have to print the K-1 move--the second to last move because it would, in effect, be the winning move.

tiago santos wrote:
3- At the end of each game should be allowed to review all the moves that
They were made ( game history ) .

You have to record every move in the game, save it in a structure so you can recall it at the end of the game. I prefer an ArrayList to do this over an Array because you don't need to define how big the ArrayList is, but for an Array you have to have a bound.

tiago santos wrote:
4- the possibility that, at the end of each game, there is the
possibility of restarting .

You have this all implemented in a loop, like a while loop with something like a condition of while(!WantToContinue) where WantToContinue is a Boolean
 
tiago santos
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, let me warning you again xD, I am only working on java for 2 weeks, so I dont know almost nothing ..
I know INT,if,while,switch ...

thanks for the answer , but , I need better explanation, because even after I read, I dont understand what to do :S

"You have to keep a count of how many moves are made by each player and print out the sum of those and the individual counts each round. (can be done with int variables)..."

Can you be more specific? thanks :/
 
Stefan Evans
Bartender
Posts: 1836
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How many players are there in this game? Is it just two, or could it be more?
I notice you have declared two of every variable: eg humano1, humano2.

There is also a bit of a language barrier here as in I don't understand spanish, so your variable names etc don't make much sense to me. Maybe you can provide a quick translation?
For instance I think that jogada is holding how many sticks the person wants to remove on their turn, but there is jogada, jogada1 and jogador all in there...

For this level I would recommend using an array to keep track of the history.
An array of integers should be sufficient.
Figure out what is the longest possible game. For 21 matches, that would be 21 moves right? That can help figure out the maximum size of your array.

The number of moves so far can be used as the index into the array. Everytime you add one to the number of moves, store the current move in that array.

I would start simple:

- Declare the game history variable
- Print the game history (even if it starts out printing all zeroes)
- Store the values in the history as the game goes (you can check this using the print method which is why you write that first)

hope this helps,
Stefan
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!