JAVA
6) The game Othello is played on an 8×8 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: O
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. (10 marks) // 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 8×8 array where each element is O 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.
JAVA
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am