Question: how would I code a game of connect four using StdDraw class the requirements are below The game should follow all the rules of Connect
how would I code a game of connect four using StdDraw class the requirements are below
The game should follow all the rules of Connect 4. The rules include (but are not limited to) the following: The board should have 6 rows and 7 columns. Randomly choose which player goes first. Players alternate turns. Each time a player has a turn, they must drop one piece into a column of their choice. When a piece is dropped in a column, that piece should fall to the lowest possible spot in that column. Players cannot drop pieces into columns that are already filled up. The game is over whenever the first player connects four in a row either vertically, horizontally, or diagonally (note that there are two possible diagonal directions: [1] Lower-left to upper-right, and [2] Upper-left to lower-right). No additional pieces can be played once the game is over. Ties are possible. This happens when the board is completely filled up with pieces and neither player has four in a row. Specific Coding Requirements The board must be a 2D int array called board. The 2D array board should always have one of three possible values in each spot: 0- if there is no piece at that spot. 1- if player 1's piece is at the spot. 2- if player 2's piece is at the spot. You must have the following method declaration in your code. public static int checkForWinner (int[][] board) When you call this method, you must pass board as a parameter. The method should return the following int values once you have scanned through the board: 0- if there is no winner. 1- if player 1 is the winner. 2- if player 2 is the winner. 3- if there is a tie.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
