Crossoff Game

Collapse Content

Crossoff is a simple 2-player game.

The game starts with a certain number of pieces. Each turn, you must remove 1 - 3 pieces. The last player to move wins the game.

Each turn, your method play will be called, and it will be given the current number of pieces as an integer. Return an integer (from 1 to 3) with the number of pieces you want to remove.


Code a program to play Crossoff!

Please sign in or sign up to submit answers.

Alternatively, you can try out Learneroo before signing up.


  • I'm confused with this challenge - is the objective to win all 4 games? The best I've ever managed to win is 2 out of 4 games. It seems that if Player 0 makes the first move, I win, otherwise I lose. Can I have a hint please?

  • You usually can win all 4 games with proper play, unless you get very unlucky. To solve this game, you need to figure out a strategy that will guarantee victory when possible. Each turn, how

  • I've done it! Thanks for the hints.

  • I get an error when I import Scanner but I copied the line of code from a previous challenge
    import java.util.Scanner; //the Scanner has been imported for you
    Why doesn't this line compile?

    Also, is the starting number of pieces up to me? Should I have the program ask for it? Thanks!

  • @Kendall, sorry in these game challenges you cannot import classes.

    You will be given the number of pieces remaining each turn, including the first (it's not up to you).

  • Got it, thanks!

  • Can i get the awnser somewhere?

  • what is wrong with this code:

    Scanner in= new Scanner(; 
    int num;
    num = in.nextInt();
    return pieces-num;
  • You're given the number of remaining pieces each turn, so there's no need for Scanner. You need to return 1 to 3 pieced each turn. Here's an attempt that loses, but follows the rules.

  • Oh the question is very different from what i understood. I dont have to give a input but do something else i guess.

  • I got it. the goal is not to write the game itself. but the write a winning algorithm. boy stupid me.

  • jeeeeh i won all 4. you cant always win. it depends on the number of chips and if you are player one or two? if i am player 1 with 8 chips i cant win. Unless the other person does not understand it of course.

Contact Us
Sign in or email us at [email protected]