The purpose of this assignment is to practice:

  • using dimensional arrays
  • develop a model for a “real world game
  • writing methods given a specification
  • testing your code

This assignment simulates play of Connect4, a popular strategy game. Here s an overview of the game:

Connect Four (also known as Captain's Mistress, Four Up, Plot Four, Find Four, Fourplay, Four in a Row and Four in a Line) is a two‐player game in which the players first choose a color and then take turns dropping colored discs from the top into a seven‐column, six‐row vertically‐suspended grid. The pieces fall straight down, occupying the next available space within the column. The object of the game is to connect four of one's own discs of the same color next to each other vertically, horizontally, or diagonally before your opponent. Source: http://en.wikipedia.org/wiki/Connect_Four

For this assignment, the Connect4 game will be modeled using a Grid class. The Grid class defines the game board. A Connect 4 grid has 6 rows and 7 columns. The Grid class represents the game board with a 2 dimensional array of chars. There are three values that will be used for the chars: B (for black), R (for red), and * for an empty cell.

Your Grid class will need the following methods.

  • A constructor that Creates the dimensional array of chars and initializes each “cell with *
  • A fullBoard method that returns true if the board has no more vacant cells, false otherwise
  • An isColValid method that returns true if a column falls on the Grid false otherwise
  • A firstEmpty method that given a column returns the row of the first empty cell, or ‐1 if there is no empty row in this column.
  • A showBoard method that displays the board
  • A checkForWin method that returns true if there are 4 in row, diagonal or column, false otherwise

Your game board must be scalable. In other words, the constructor accepts arguments for the number of rows and columns and all methods work properly with any size board.

I am providing methods that control the game play. You MUST NOT change any of the code that I provide or your program will not compile when it is submitted.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.