# Recursion Game

• 11-17-2010, 04:53 PM
Eranbh
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.

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!
• 11-17-2010, 07:42 PM
Allspark
I don't want this to sound rude, but what is your mother language?
• 11-17-2010, 07:58 PM
Eranbh
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
Allspark
Oh ok, yeah i figured it wasn't your first language. No offense.