# Crossoff Game

Crossoff is a simple 2-player game.

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

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

### Challenge

Code a program to play Crossoff!

Alternatively, you can try out Learneroo before signing up.

• #### Victoria Holland

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?

• #### Learneroo

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

• #### Victoria Holland

I've done it! Thanks for the hints.

• #### Kendall Ponder

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!

• #### Learneroo

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

• #### Kendall Ponder

Got it, thanks!

• #### thales

Can i get the awnser somewhere?

• #### thales

what is wrong with this code:

``````Scanner in= new Scanner(System.in);
int num;
num = in.nextInt();

return pieces-num;
``````
• #### Learneroo

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.

• #### thales

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

• #### thales

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

• #### thales

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.