Crossoff Game
Collapse Content
Show Content
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!
Please sign in or sign up to submit answers.
Alternatively, you can try out Learneroo before signing up.
Comments
Victoria Holland
Feb 13, 9:29 AMI'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
Feb 13, 9:47 AMYou 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
can you put the other player in a losing position? For example, if there's 5 pieces left, what should you do? Then see if you can extrapolate that back to when there's 9 pieces left, and convert it into a simple formula...
Victoria Holland
Feb 14, 4:33 AMI've done it! Thanks for the hints.
Kendall Ponder
Jun 2, 12:23 PMI 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
Jun 2, 12:28 PM@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
Jun 2, 8:07 PMGot it, thanks!
thales
Jul 13, 1:55 PMCan i get the awnser somewhere?
thales
Jul 13, 2:18 PMwhat is wrong with this code:
Learneroo
Jul 13, 2:39 PMYou'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
Jul 13, 2:44 PMOh the question is very different from what i understood. I dont have to give a input but do something else i guess.
thales
Jul 13, 2:57 PMI got it. the goal is not to write the game itself. but the write a winning algorithm. boy stupid me.
thales
Jul 13, 3:28 PMjeeeeh 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.