Question: Im doing a cs 2 5 1 assignment for a Gomoku class and I need help finishing it . This is what I have so

Im doing a cs251 assignment for a Gomoku class and I need help finishing it. This is what I have so far and I need someone to show me how to complete it:
import cs251.lab2.*;
public class Gomoku implements GomokuInterface {
private Square[][] board;
private Square[][] turn;
private Square currentTurn;
private static final int NUM_OF_COLUMNS =15;
private static final int NUM_OF_ROWS =15;
private static final int POINTS_TO_WIN =5;
public static void main(String[] args){
Gomoku game = new Gomoku();
if (args.length >0){
game.initComputerPlayer(args[0]);
}
GomokuGUI.showGUI(game);
}
@Override
public int getNumCols(){
return NUM_OF_COLUMNS;
}
@Override
public int getNumRows(){
return NUM_OF_ROWS;
}
@Override
public int getNumInLineForWin(){
return POINTS_TO_WIN;
}
@Override
public TurnResult handleClickAt(int row, int col){//this is what changes the board
if (row <0|| row >= NUM_OF_ROWS || col <0|| col >= NUM_OF_COLUMNS){
throw new MyCustomException("Illegal move!");
}
Square[][] turn = new Square[NUM_OF_ROWS][NUM_OF_COLUMNS];
turn[row][col]= Square.CROSS;
String currentBoard = getCurrentBoardAsString();
System.out.println("Current board:
"+ currentBoard);
turn[row][col]= turn[row][col].RING;
getCurrentBoardAsString();
return new TurnResult(TurnResultType.VALID_MOVE, currentBoard);
}
@Override
public void initializeGame(){
this.board = new Square[NUM_OF_ROWS][NUM_OF_COLUMNS];
this.currentTurn = Square.EMPTY;
}
@Override
public String getCurrentBoardAsString(){
StringBuilder squareThing = new StringBuilder();
for (int i =0; i < NUM_OF_COLUMNS; i++){
for (int z =0; z < NUM_OF_ROWS; z++){
squareThing.append(board[i][z]);
}
}
return squareThing.toString();
}
@Override
public Square getCurrentTurn(){
return currentTurn;
}
@Override
public void initComputerPlayer(String s){
// Assuming 's' represents the opponent (e.g., "human" or "AI")
if (s.equalsIgnoreCase("human")){
// Initialize a human player
System.out.println("Human player selected.");
// Add any other necessary logic for human player setup
} else if (s.equalsIgnoreCase("AI")){
// Initialize an AI player
System.out.println("AI player selected.");
// Add any other necessary logic for AI player setup
} else {
System.out.println("Invalid player type. Please choose 'human' or 'AI'.");
// Handle other cases or error messages as needed
}
}
public class MyCustomException extends RuntimeException {
public MyCustomException(String message){
super(message);
}
}
public boolean hasWinningMove(Square[][] board, int row, int col, Square playerMarker){
// Check horizontally
int count =0;
for (int c = Math.max(0, col -4); c <= Math.min(NUM_OF_COLUMNS -1, col +4); c++){
if (board[row][c]== playerMarker){
count++;
if (count == POINTS_TO_WIN){
return true;
}
} else {
count =0;
}
}
// Check vertically
count =0;
for (int r = Math.max(0, row -4); r <= Math.min(NUM_OF_ROWS -1, row +4); r++){
if (board[r][col]== playerMarker){
count++;
if (count == POINTS_TO_WIN){
return true;
}
} else {
count =0;
}
}
// Check diagonals (both directions)
// Left-to-right diagonal
count =0;
for (int i =-4; i <=4; i++){
int r = row + i;
int c = col + i;
if (r >=0 && r < NUM_OF_ROWS && c >=0 && c < NUM_OF_COLUMNS){
if (board[r][c]== playerMarker){
count++;
if (count == POINTS_TO_WIN){
return true;
}
} else {
count =0;
}
}
}
// Right-to-left diagonal
count =0;
for (int i =-4; i <=4; i++){
int r = row + i;
int c = col - i;
if (r >=0 && r < NUM_OF_ROWS && c >=0 && c < NUM_OF_COLUMNS){
if (board[r][c]== playerMarker){
count++;
if (count == POINTS_TO_WIN){
return true;
}
} else {
count =0;
}
}
}
return false

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!