CS173: Intro to Computer Science - Four in a Row (3 Points)

Developed by Professor Tralie and Professor Mongan.

Exercise Goals

The goals of this exercise are:
  1. To iterate over a 2-dimensional array
Modify the FourInARow.java file to return whether a given array contains a winning configuration. Specifically, if any column has four consecutive items with the same value, they are a winner.
Welcome to our online modules system! Be sure to log in with your Urinus ID before you proceed. For example, Professor Tralie's ID is ctralie. If you are not an Ursinus student, that's fine! Just make something up, and you can still run everything

                    



In this exercise, you will fill in a function to determine the winner of a game of Four-in-a-Row. A game board (a 2D array of ints) initially contains all 0s. Each player (team 1 and 2) places a value into a column of the game board, and it falls to the bottom of the board. The game ends with a winner if the board contains four consecutive items down a column (only the vertical column - you don’t need to worry about the rows or diagonals). For example, this board represents a game won by team 2:

int[][] board = new int[][] {
    { 0, 2, 2, 0 },
    { 0, 2, 1, 1 },
    { 0, 2, 1, 1 },
    { 0, 2, 1, 1 }
};