Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i need help finishing this gomoku assignment. import cs 2 5 1 . lab 2 . * ; public class Gomoku implements GomokuInterface { public

i need help finishing this gomoku assignment. import cs251.lab2.*;
public class Gomoku implements GomokuInterface {
public int turn =0;
private Square[][] board;
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
TurnResult gamenotover = TurnResult.GAME_NOT_OVER;
TurnResult draw = TurnResult.DRAW;
TurnResult crosswins = TurnResult.CROSS_WINS;
TurnResult ringwins = TurnResult.RING_WINS;
board[row][col]= currentTurn;
String currentBoard = getCurrentBoardAsString();
System.out.println("This is the current board: "+ currentBoard );
if (row <0|| row >= NUM_OF_ROWS || col <0|| col >= NUM_OF_COLUMNS){
throw new MyCustomException("Illegal move!");
}
if (board[row][col]!= Square.EMPTY){
System.out.println("Square at ("+ row +","+ col +") is already occupied.");
return gamenotover;
}
if( hasWinningMove( board, row, col, currentTurn )){
System.out.println("Player "+ currentTurn +" wins!");
return currentTurn == Square.CROSS ? crosswins : ringwins;
}
if( boardFull()){
System.out.println("It's a tie! The board is full.");
return draw;
}
turn++;
switchTurn();
return gamenotover;
}
@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 r =0; r < NUM_OF_COLUMNS; r++){
for (int c =0; c < NUM_OF_ROWS; c++){
board[r][c]= Square.EMPTY;
}
return squareThing.toString();
}
@Override
public Square getCurrentTurn(){
return currentTurn;
}
@Override
public void initComputerPlayer(String s){
}
public class MyCustomException extends RuntimeException {
public MyCustomException(String message){
super(message);
}
}
private void switchTurn(){
}
private boolean boardFull(){
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions

Question

1. Encourage students to set a small-step goal for one subject.

Answered: 1 week ago