Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

Can the model parameters of interest be estimated?

Answered: 1 week ago