Results 1 to 4 of 4

Thread: Recursion Game

  1. #1
    Eranbh is offline Member
    Join Date
    Nov 2010
    Posts
    2
    Rep Power
    0

    Post 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. #2
    Allspark is offline Member
    Join Date
    Sep 2010
    Posts
    21
    Rep Power
    0

    Default

    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. -

  3. #3
    Eranbh is offline Member
    Join Date
    Nov 2010
    Posts
    2
    Rep Power
    0

    Default

    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. #4
    Allspark is offline Member
    Join Date
    Sep 2010
    Posts
    21
    Rep Power
    0

    Default

    Oh ok, yeah i figured it wasn't your first language. No offense.
    - Winners compare their achievements with their goals, while losers compare their achievements with those of other people. -

Similar Threads

  1. Replies: 2
    Last Post: 08-05-2010, 05:49 AM
  2. recursion and tail-recursion differences
    By OptimusPrime in forum New To Java
    Replies: 2
    Last Post: 12-28-2009, 07:26 PM
  3. Recursion help
    By rjg_2186 in forum New To Java
    Replies: 1
    Last Post: 01-02-2009, 09:03 AM
  4. recursion
    By kdeighan in forum New To Java
    Replies: 3
    Last Post: 01-25-2008, 10:48 PM
  5. Recursion
    By bozovilla in forum Advanced Java
    Replies: 3
    Last Post: 01-07-2008, 05:53 PM

Tags for this Thread

Posting Permissions

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