# Thread: Recursion Game

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);
}```
If there is someone with an Idea!

Tnx!

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?

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 :\

4. Member
Join Date
Sep 2010
Posts
21
Rep Power
0
Oh ok, yeah i figured it wasn't your first language. No offense.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•