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 cs 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 cslab;
public class Gomoku implements GomokuInterface
private Square board;
private Square turn;
private Square currentTurn;
private static final int NUMOFCOLUMNS ;
private static final int NUMOFROWS ;
private static final int POINTSTOWIN ;
public static void mainString args
Gomoku game new Gomoku;
if argslength
game.initComputerPlayerargs;
GomokuGUI.showGUIgame;
@Override
public int getNumCols
return NUMOFCOLUMNS;
@Override
public int getNumRows
return NUMOFROWS;
@Override
public int getNumInLineForWin
return POINTSTOWIN;
@Override
public TurnResult handleClickAtint row, int colthis is what changes the board
if row row NUMOFROWS col col NUMOFCOLUMNS
throw new MyCustomExceptionIllegal move!";
Square turn new SquareNUMOFROWSNUMOFCOLUMNS;
turnrowcol Square.CROSS;
String currentBoard getCurrentBoardAsString;
System.out.printlnCurrent board:
currentBoard;
turnrowcol turnrowcolRING;
getCurrentBoardAsString;
return new TurnResultTurnResultTypeVALIDMOVE, currentBoard;
@Override
public void initializeGame
this.board new SquareNUMOFROWSNUMOFCOLUMNS;
this.currentTurn Square.EMPTY;
@Override
public String getCurrentBoardAsString
StringBuilder squareThing new StringBuilder;
for int i ; i NUMOFCOLUMNS; i
for int z ; z NUMOFROWS; z
squareThing.appendboardiz;
return squareThing.toString;
@Override
public Square getCurrentTurn
return currentTurn;
@Override
public void initComputerPlayerString s
Assuming s represents the opponent eg "human" or AI
if sequalsIgnoreCasehuman
Initialize a human player
System.out.printlnHuman player selected.";
Add any other necessary logic for human player setup
else if sequalsIgnoreCaseAI
Initialize an AI player
System.out.printlnAI player selected.";
Add any other necessary logic for AI player setup
else
System.out.printlnInvalid player type. Please choose 'human' or AI;
Handle other cases or error messages as needed
public class MyCustomException extends RuntimeException
public MyCustomExceptionString message
supermessage;
public boolean hasWinningMoveSquare board, int row, int col, Square playerMarker
Check horizontally
int count ;
for int c Math.max col ; c Math.minNUMOFCOLUMNS col ; c
if boardrowc playerMarker
count;
if count POINTSTOWIN
return true;
else
count ;
Check vertically
count ;
for int r Math.max row ; r Math.minNUMOFROWS row ; r
if boardrcol playerMarker
count;
if count POINTSTOWIN
return true;
else
count ;
Check diagonals both directions
Lefttoright diagonal
count ;
for int i ; i ; i
int r row i;
int c col i;
if r && r NUMOFROWS && c && c NUMOFCOLUMNS
if boardrc playerMarker
count;
if count POINTSTOWIN
return true;
else
count ;
Righttoleft diagonal
count ;
for int i ; i ; i
int r row i;
int c col i;
if r && r NUMOFROWS && c && c NUMOFCOLUMNS
if boardrc playerMarker
count;
if count POINTSTOWIN
return true;
else
count ;
return false
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
