Results 1 to 4 of 4
Thread: Recursion Game
- 11-17-2010, 04:53 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 2
- Rep Power
- 0
Recursion Game
Hi all,
I have a work to write about a recursion game.
"matches" Game: on the table there is a pile of matches. Two players take from the stack, and off, a number of Matches at a time.The number of matches that can be taken at a time is set according to the rules of the game. The player who takes the. The last match is the winner.
In the game, we can say that a player has a winning move if and only if, he can take a number of such matches, according to Rules of the game ,leaving one of two possibilities: either he wins immediately takes all the matches, or ,is left on
Table that matches the number of opponent will not be a winning move.
He can take 1,x,y matches from the table.
The funcation should be recursive.
Example:
matches(20,2,6) will return true .
matches(17,2,6) will return false .
I worte a psy. code, I saw that in mine turn there is OR between the recursion caling and when its my a opp. turn there is a AND between the recursion caling.
I have the basic code that i really think that should be in the final code,
I missing An IF that will be a STOPING POINT.
Java Code:public static boolean matches(int numOfMatches, int x, int y) { if (numOfMatches == 0) return true; if (numOfMatches < 0 ) return false; return matches(numOfMatches-1,x,y) || matches(numOfMatches-x,x,y) || matches(numOfMatches-y,x,y); }
Tnx!
- 11-17-2010, 07:42 PM #2
Member
- Join Date
- Sep 2010
- Posts
- 21
- Rep Power
- 0
I don't want this to sound rude, but what is your mother language?
- Winners compare their achievements with their goals, while losers compare their achievements with those of other people. -
- 11-17-2010, 07:58 PM #3
Member
- Join Date
- Nov 2010
- Posts
- 2
- Rep Power
- 0
haha, it's not rude, my mother language is not English :P
it's Hebrew, I use Google Translate for this post, and the translate is a bit poor, sorry :\
- 11-17-2010, 07:59 PM #4
Member
- Join Date
- Sep 2010
- Posts
- 21
- Rep Power
- 0
Similar Threads
-
Implementing "Game Over" in Minesweeper game based on Gridworld framework.
By JFlash in forum New To JavaReplies: 2Last Post: 08-05-2010, 05:49 AM -
recursion and tail-recursion differences
By OptimusPrime in forum New To JavaReplies: 2Last Post: 12-28-2009, 07:26 PM -
Recursion help
By rjg_2186 in forum New To JavaReplies: 1Last Post: 01-02-2009, 09:03 AM -
recursion
By kdeighan in forum New To JavaReplies: 3Last Post: 01-25-2008, 10:48 PM -
Recursion
By bozovilla in forum Advanced JavaReplies: 3Last Post: 01-07-2008, 05:53 PM
Bookmarks