Question: JAVA: Connect Four - Implement Connect Four for both 2 human players and single human and computer opponent. You should use the following template to

JAVA: Connect Four - Implement Connect Four for both 2 human players and single human and computer opponent. You should use the following template to implement the game:

import java.util.Scanner; /** * Connect Four is is a two-player game in which the players 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 * objective of the game is to be the first to form a horizontal, * vertical, or diagonal line of four of one's own discs. */ public class Connect4 { String[][] board = new String[ 6 ][ 7 ]; /** * Constructor Method * Initialize the board array. */ public Connect4 ( ) { // YOUR CODE HERE } /** * Print the game board. 0 1 2 3 4 5 6 +-+-+-+-+-+-+-+ | | | | | | | | +-+-+-+-+-+-+-+ | | | | | | | | +-+-+-+-+-+-+-+ | | | | | | | | +-+-+-+-+-+-+-+ | | | | | | | | +-+-+-+-+-+-+-+ | | | | | | | | +-+-+-+-+-+-+-+ | | | | | | | | +-+-+-+-+-+-+-+ 0 1 2 3 4 5 6 */ public void printBoard ( ) { // YOUR CODE HERE } /** * Add a piece to the board for the specified player * in the specified column. * * Drops the piece into the column. * The piece drops in the column until it either reaches the bottom * or rests above an existing piece. * * The move should fail if the column is already full * or the indicated column is out of range. * * @param player - the player making the move * @param column - the columns the piece is dropped in. * @return true if the move is successful */ public boolean move ( int player, int column ) { // YOUR CODE HERE } /** * @return false if the board is completely full, thus no moves are possible. */ public boolean isMovePossible( ) { // YOUR CODE HERE } /** * Returns true if the player has won the game. * * The player wins the game if they have 4 neighboring pieces * in a row, column, or diagonal. * * If no moves are possible, the game ends in a tie. * * @param player - player number * @return - true if the player has for connected pieces */ public boolean isWinner ( int player ) { // YOUR CODE HERE } /** * Asks the player which column they want to place their piece in. * Then makes the move. * If the move is invalid, tells the player to try again and repeats. * * @param player - the player number */ public void makeHumanMove( int player ) { // YOUR CODE HERE } /** * The computer makes a move as the specified player. * * @param player - player number */ public void makeComputerMove( int player ) { // YOUR CODE HERE } /** * The main program loop. * Determine how many human players. * Alternate printing the board, getting player moves until * someone wins the game or the game ends in a tie. */ public static void main ( String[] args ) { Connect4 game = new Connect4 ( ); // YOUR CODE HERE } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!