MP3: ConnectN
Maybe you play them, maybe you don’t, maybe you carry your gaming desktop with you at all times—but regardless of how you feel about it, a fair number of people use computers to play games. Some of those games can be instructive, some can be fun. But an MP where you get to build a fun game is both fun and instructive! For MP3 you’ll be learning Java class design and object-oriented programming as you complete a simple Connect-4-like game.
MP3 is our first two (plus) week MP and due Monday 10/15/2018 @ 5PM. To receive full credit, you must submit by this deadline. In addition, 10% of your grade on MP3 is for submitting code that earns at least 40 points by Monday 10/8/2018 @ 5PM. Note that, unlike MP2, you have to do a bit more work on MP3 to get to 40 points—but the early deadline is also later to accommodate that.
As usual, late submissions will be subject to the MP late submission policy.
1. Learning Objectives
The purpose of MP3 is to begin introducing you to object-oriented programming. MP3 does not explore more advanced topics like inheritance, interfaces, or polymorphism. It sticks to the basics: instance and class variables, getters and setters, constructors, and instance and class methods. You’ll begin to learn how to:
-
design a class that meets a given specification
-
implement that class including both properly-protected variables and appropriate methods
2. Assignment Structure
MP3 consists of a simple client-server system. The HTML, CSS, and JavaScript for the client are provided for you. But it relies on your backend to work properly.
Your job is to create and complete ConnectN.java
.
These functions are called by the web server that is set up using WebServer.java
.
MP3 provides a bit less scaffolding than previous MPs. This is intentional. Eventually you’ll need to write code from scratch, and frequently you’ll need to follow a specification written by other developers or a project manager.
For MP3, the official specification is our
MP3 online documentation.
It should precisely define what each public method in ConnectN.java
should do.
If you believe that the documentation is unclear, please post on
the forum and we’ll offer a clarification if needed.
2.1. Obtaining MP3
Use this GitHub Classroom invitation link to fork your copy of MP3. Once your repository has been created, import it into IntelliJ following our assignment Git workflow guide.
2.2. Your Goal
At this point you should be familiar with the requirements from previous MPs. See the grading description below.
2.3. Running MP3
To experiment with the web interface, do the following:
-
Run
WebServer.java
as a Java application. You’ll need to at least createConnectN.java
and get a few things working before the web server will run at all. -
Open your web browser and navigate to
http://localhost:8126
.
At first, nothing will work because you have not implemented any of the required game transformation functions yet.
As far as browser support, we have confirmed that Chrome works. Other browsers may or may not—but Chrome definitely does.
3. Approaching MP3
While the concepts are new, MP3 is not a lot of code to write, and you have two weeks. But here are the bits that are likely to trip you up.
3.1. Read the Fine Manual
To complete MP3 you must understand the specification. That’s your starting point, and your returning point when you get confused.
Writing code to a specification is an important skill to learn. In many software companies, designing code and implementing it are not always done by the same group. A project manager or program manager may write a specification, which is provided to developers to implement. Or a team of developers may come up with a specification, and then divide up the implementation work between them.
Regardless of where it comes from, writing code in groups almost always requires a specification to be successful—unlike when you do independent projects and can make up things as you go. A lot of the design work and high-level decisions end up going in to the specification, so by the time the implementation begins the hard and interesting choices have been made. That’s not to say it still isn’t fun at that point—even developing to a spec provides huge opportunities for simultaneous creativity and correctness in that unique programming way.
3.2. Getters and Setters
MP3 requires you to implement some simple getters and setters (just return or change the variable), and some ones with more complicated behavior. Be sure to read the documentation carefully.
3.3. Game Logic
You will need to do a bit of work to implement the game board. ConnectN is a Connect-4-like game. Tiles fall in the top (large Y values) and sit at the bottom. We’re in the proper first quadrant of 2D space, with X values going left to right and Y values going down to up:
|
|
|
|
|
|
|
|
|
A ConnectN game ends when either player plays N consecutive tiles in either a single row or column 1. Tiles always have to be played at the lowest possible location in each column—in a real Connect-4 board they fall downward and rest on the tiles below them. Consult the Wikipedia page for more details.
3.4. Class Variables and Methods
Classes can define methods and variables that are not attached to instances.
See Player.java
for an example of a class variable used to provide each
instance with a unique ID.
You’ll need to implement some of these for ConnectN.java
.
3.5. Equality
Be careful about varying definitions of equality.
You’ll need to implement ConnectN.equals
, but its definition of equality is
quite strict.
On the other hand, the class comparison methods use a different definition of
equality.
Passing all of the tests requires distinguishing between the two and
implementing each correctly.
3.6. Getting Help
The course staff is ready and willing to help you every step of the way! Please come to office hours, or post on the forum when you need help. You should also feel free to help each other, as long as you do not violate the academic integrity requirements.
4. Grading
MP3 is worth 100 points total, broken down as follows:
-
80 points:
ConnectN.java
-
15 points total for completing the width, height, and N value getters and setters
-
10 points for completing the constructors
-
15 points for completing the get and set board functions
-
10 points for determining the game winner properly
-
10 points for calculating equality correctly
-
10 points for class static methods, including equality checks and factory creation methods
-
10 points for maintaining the game count and ID properly
-
-
10 points for no
checkstyle
violations -
10 points for submitting code that earns at least 40 points before Monday 10/8/2018 @ 5PM.
4.1. Test Cases
As in previous MPs, we have provided exhaustive test cases for each part of MP3. Please review the MP0 testing instructions.
4.2. Autograding
Like MP0 and MP1, we have provided you with an autograding script that you can use to estimate your current grade as often as you want. Please review the MP0 autograding instructions.
5. Submitting Your Work
Follow the instructions from the submitting portion of the CS 125 workflow instructions.
And remember, you must submit something that earns 40 points before Monday 10/15/2018 @ 5PM to earn 10 points on the assignment.
6. Academic Integrity
Please review the MP0 academic integrity guidelines.
Here’s how we’ll feel if we catch you cheating in CS 125: