Games Comments


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

  • yeeh i win again !

  • It is not clear to me what is given and what we are supposed to program. Is the play method used by both players? I Am I supposed to use play to update board[][]?

  • You are just programming one side in the game, and need to return an integer from 0 to 6 for the column you're moving in. (Other code will then perform your move and do another move, and then call your play method again..)

  • Am I placing 1 or 2?

  • I developed my code with BlueJ and got it to compile and got a runtime array out of bounds error. I fixed the problem but now I get a compile error saying I can't return my integer method.

  • I found the compile problem. A change I made in the method call disappeared for some reason and I had to reenter it.

  • I don't see how I can find an array out of bounds problem when I can't see all of the code. The numbers of the runtime error don't match the numbers of my code.

  • Is there a way to print so I can see what certain values are before the program crashes. I tried System.out.println() and I don't get anything. Thanks!

  • @Kendall, as mentioned, you can see what line play() is called in the error to see how many lines of code is being added. So if play() is called 338 when it's really line 4, that means you just need to subtract 334 lines from any error line.

  • For seeing errors, you can always use the error output to print to the error box. In Java, just use System.err.println to print to the error output.

  • I thought in the following code:
    while(row<6 && board[row][col]!=0){
    The row<6 would be evaluated first so if row=6 the board[row][col]

  • @kendall, that's correct, but maybe it's col that's out of bounds? Also make sure you're checking the right ones, since the format I mentioned is board[col][row], not [row][col]. You can also use the included helper method to check if a move is legal.

  • Oops! I wrote the code with the col & row reversed! Thanks!

  • Not a question but I find how the editor highlights entire words when you click on the code annoying. I have to click three times to insert something and have accidently deleted code several

  • is the goal to write the program? is the goal to find winning moves? wat is the goal what is given?

  • You need to write an AI/program/bot that plays connect4, but doesn't run the game itself. All it does is take in a double-array board each turn and return an integer move.

  • I am sorry but i still dont understand?

  • It's the same idea as the crossoff game. Here's a simple program that plays legally but loses. The goal is to improve your program's moves so it wins.

  • I think the links is wrong, cause that is what i tried to see what would happen.

  • The game seems to have not the same behaviour as shown in the description. One example is:
    Field twelve contains 12 pieces.
    --> The computer takes all of them and puts 2 into field 13 and then 1 in field 0, 1 in field 1 and 1 in field 2.
    Why does the computer put two pieces in field two?

  • Sorry, field twelve does not contain 12, but 5 pieces.

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