Skip to editor
File
New File Ctrl+N
New Folder

Save Ctrl+S
Upload File…
Download as ZIP

Delete File

Reset Files…
View
Toggle Sidebar Ctrl+B
Toggle Terminal Ctrl+`

Word Wrap Alt+Z

Exercise Info
Run
Run Code Ctrl+Enter
Save & Run F5

Clear Output
CS173: Intro to Computer Science - Four in a Row (3 pts)
Explorer
GitHub

Connect to GitHub to push and pull your project files to a repository.

On the page that opens, create a token with repo scope, copy it, then paste it below.

Paste the personal access token you created on GitHub with repo scope.

Click Refresh to load commit history
Exercise Info

Goals

  1. To iterate over a 2-dimensional array

Instructions

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.

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 }
};     

The Ursinus-WebIDE by Chris Tralie (opens in new tab) and Bill Mongan (opens in new tab)

Your browser does not support WebGL. A graphical rendering canvas would appear here.


          
No suggestions. Code quality feedback will appear here.
Not logged in java
Ln 1, Col 1