AC Assignment Chef

[Solved] COMP1020 Assignment2-Multi-Dimensional Arrays and I/O

5.0 1 customer review Digital download

Digital download

$25.00

Availability
In stock
Checkout
One item

Upload assignment

Send a ZIP file

In this assignment, you will write a set of interrelated classes that will support the implementation of the board game known as Reversi or Othello. It has a fairly simple set of rules, but they wont be described here. Instead, look at Section 3 (Rules) at https://en.wikipedia.org/wiki/Reversi . (You can ignore the descriptions of time clocks, transcripts, row and column labels, and other items not part of the basic rules.) There are plenty of implementations of this game, and you can play against other people online, if youd like to try it. Here is a short video of how to play reversi (https://www.youtube.com/watch?v=Ol3Id7xYsY4) and a link to practice this game (https://cardgames.io/reversi/). Keep all of your methods short and simple. In a properly-written object-oriented program, the work is distributed among many small methods, which call each other. Make sure to call methods already created when appropriate, instead of duplicating code for no reason. Unless specified otherwise, all instance variables must be private, and all methods should be public. Also, unless specified otherwise, there should be no println statements in your classes. Objects usually do not print anything, they only return String values from methods.

Phase 1: A set of related classes

In this phase, you will create a set of four classes of objects that will represent individual moves in a Reversi game. Since a move must always flip some of the opponents pieces in up to 8 different directions, some classes to represent these directions will also be useful. The Direction class: An object of type Direction will hold two int values to represent one of the 8 possible vertical, horizontal, or diagonal directions on a game board, as shown below. (This is not only useful for Reversi, but could be used in many other games, too.) The two integers give the change to the row index, and to the column index, that would move from one square to the next in the indicated direction. These numbers will always be -1, 0, or +1. The two numbers should not both be 0 (since that wouldnt change any index at all), but the other 8 possible combinations are valid. Implement the following things in your Direction class: new Direction(-1,1).toString() should give <up right> new Direction(1,-1).toString() should give <down left> new Direction(1,0).toString() should give <down> new Direction(0,-1).toString() should give <left> The DirectionList class: An object of type DirectionList will hold a list of Directions (0 to 7). You can use an array to store them. If you know how to use an ArrayList (a topic which wont be covered until later in the course), you can use that too. Implement the following things in your DirectionList class: The Move class: An object of type Move will hold information describing one possible move in a game of Reversi. Since a move in this game will always flip opponent pieces in one or more directions, a Move object will also keep track of these directions. (This class doesnt calculate what the directions are it doesnt have any way to do that it just stores them.) Implement the following things in your Move class: (2,5) flips directions {<left>,<down left>} The MoveList class: An object of type MoveList will hold a list of 0 or more Moves. Implement the following things in your MoveList class: (1,2) flips directions {<down>} (2,0) flips directions {<right>,<down right>} (2,5) flips directions {<left>,<down left>} (4,0) flips directions {<right>} There are four test classes that you can test your Direction, DirectionList, Move and MoveList classes. Make sure your classes work properly before starting the next phase as you need those classes in the next phase.

Phase 2: Board class for a Reversi (Othello) game

In this step, you will create a Board class that will handle all of the tasks needed to play a Reversi game. This includes finding valid moves, making moves, flipping pieces, detecting the end of the game, etc. But it does not contain any user interface code for actually playing the game. Define a Board class. Objects of this type will store the current state of a Reversi board (which pieces are on the board, and where), provide relevant information about that state (e.g. what the valid moves are), and change that state (make moves and flip pieces). Implement the following things in your Board class: OOO ..X.OO ..XXOO ..XXXX .O.

Phase 3: I/O and Exceptions

In this phase we want to save the progress has been made and save it as a text file by calling saveFile(String fileName) method. This file has a special format. The first line of the file will be the dimension of the board and the following lines represent the board setup (. for Empty, O for Black, and X for White). Here is an example 4 ..o. .oo. xxxx .o.x As the second option to start the game, instead of creating a new regular board, you can also use a method with which you can import a specific board setup. To do this, you need to define a method, importBoardSetup(String fileName), which reads the data from a text file specified by fileName and set the dimension as well as set the values of the 2D array representing the board. The following is an example of an input text file: ..xxx. o.xxx. .oxox. ..o.x. .x. To get full mark for this section you need to define the following methods inside your Board class:

Test

You can use the supplied main program RandomOthello.java to test your Board class. This program plays games of Othello by selecting moves for Black and White at random. You can modify this program if you wish to allow human players to pick moves, but that is not required. (Dont hand in this program.)