Question
Multi-dimensional arrays 6) The game Othello is played on an 88 board of squares, each of which is either empty or it holds a Black
Multi-dimensional arrays
6) The game Othello is played on an 88 board of squares, each of which is either empty or it holds a Black piece or a White piece. On Black's move it is legal for them to place a new piece on an empty square x,y iff there is a straight line of one or more White pieces from x,y to another square holding a Black piece. For example, on this board:
it is legal for Black to place a piece on any of the squares marked by a small circle: (3,1), or (4,1), or (4,2), or (6,3), or (3,5), or (5,5).
Write the following method.
// returns true iff Black can place a piece at x,y on board
public boolean canPlaceAt(int x, int y, int[][] board)
board is an 88 array where each element is 0 if the corresponding square is empty, 1 if it is occupied by a Black piece, and -1 if it is occupied by a White piece. Squares are numbered 0..7 up and across from the bottom-left-hand corner.
You will probably find it helpful to define a private helper method that checks whether the new piece makes a line in one direction from x,y.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started