[an error occurred while processing this directive]

Individual Work 7 - Connect Four

[an error occurred while processing this directive]

Description

On the last day of class we will have a Connect Four tournament. You will write code to implement your own computer player. I will assemble all of the computer players into a single tournament and we'll watch them play off against each other. The tournament winner may select a question to skip on the final examination.

Directions

If you and your partner from PW-7 created only one version of your code, and you don't have it, have your partner give you a copy.

Open the code you created in PW-7. We will now do something very similar to what we did in the second problem of PW-7.

  1. Single-Click (do not double-click) on SequentialPlayer.java in the Project Explorer Window
  2. Use keyboard shortcuts Ctrl-c and Ctrl-v to copy and paste the file
  3. Use the name XPlayer for the copy but replace X with your first name (for example, if the instructor was completing this assignment, the copy would be named HutchingsPlayer)
  4. Open the new file
  5. Update the code to use your name instead of C. Quenchell.
  6. Also, re-locate the setupTournament method in the ConnectFour2013.java file and add your player to the tournament similar to the way you did for RevSequentialPlayer in PW-7.

It's a good idea to run the code now to make sure your new player is operating in the tournament (your player has your name but currently plays just like SequentialPlayer does). At this point only, you may seek guidance from your PW-7 partner, a classmate, or a tutor, to get your player are up and running, but do not seek any additional guidance from these sources on any other aspects of the assignment.

Now that your player is playing, you should now change the code in your player's ai method to make your player as good as possible. You won't change the header of the method, just the implementation. Also, just like GUIPlayer does, you may add data elements and methods to your player if it aids game play.

Helpful Notes

The ai method has an input parameter called gb that is a GameBoard object. It models the game board at the time of your turn. The ai method must return a column in which to play. The gb object has several methods that will help you create a smarter player.

Here's a quick example. Suppose you are thinking about making a play in column 1. This code would copy the board, drop a checker in column 1 of the copy, and indicate if you won.

GameBoard myCopy = gb.getCopy(); // copy the board
boolean canPlay = myCopy.play(1, myColor);
boolean hasWinner = myCopy.hasWinner();
if (canPlay && hasWinner) {
  // I won!
}
else {
  // I did not win yet
}

Here's another helpful example. You'd like to know what color you are...

if (myColor == GameBoard.RED) {
  System.out.println("I'm Red!");
}
else if (myColor == GameBoard.BLACK) {
  System.out.println("I'm Black!");
}

Testing Your Player

If you followed the directions in the first part of this assignment, you should have a 2-player tournament of your player against you (as the GUI Player). This is a good way to see how your player reacts to "human" play.

You may also play your player against other students' players in the class, but you must take protections so that you do not expose the code to other students. If you can't figure out how to do this, or you don't trust the other student, don't use this approach.

Grading Guidelines

Grading in this assignment works in a tiered approach... as you meet stronger requirements, you qualify to accumulate more points.

Tournament Notes

As mentioned at the outset of the assignment, everyone's player will play a tournament on the last day of class. The tournament winner gets to skip a question on the final exam. To try to account for all possibilities that might arise to call into question the tournament result, here are the tournament rules and guidelines.

  1. Any player's code that causes a Java exception or returns an invalid column automatically loses the current game.
  2. The first player in any game must win outright. The second player can win by either winning outright or dropping the last possible checker on the board (see rule 1).
  3. Players must make moves in a reasonable time frame. Code that has an infinite loop or runs excessively long will result in disqualification of the player and a reset of the entire tournament (i.e. all players eliminated through normal game play are re-entered and we start over without the offending player).
  4. Any external causes of tournament disruption (power failure, network failure, etc.) void the tournament. If possible, the tournament will be reset with any players that were not disqualified via rule 3.
  5. In other situtaions not accounted for by these rules, the instructor will attempt to make the fairest possible ruling. Instructor decisions are final.

Resources

The resources below are the only resources you should use in completing this assignment, except as explicitly noted in the directions. In particular, do not use the CSC 130 tutors and do not search any electronic resources such as the Web for sample code. You may visit the tutors for general guidance, but they have been instructed not to help with the specific assignment questions.

Grading

Recall that individual work assignments are worth 50 points each. Refer to the syllabus for more course grading information.

Submission

Submit by taking one action: upload a java file. Details are below.

  1. Upload your player's java file to Moodle no later than 11:30am on the final day of class. People uploading later than this time run this risk of not being entered in the tournament.
[an error occurred while processing this directive]