Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help use good code for task five. This code very hard so many thankyou. I need to complete the function getCovered() here: int []

Please help use good code for task five. This code very hard so many thankyou. I need to complete the function getCovered() 

here:

 int[] getCovered(char column, char row, char orientation) { //  implement code that correctly creates an array of integers specifying the indices of the covered spaces  return new int[]{}; } 

 // FIXME Task 5: implement code that correctly creates an array of integers specifying the indices of the covered spaces 
* This class represents a game of 'IQPuzzlerPro', which is based directly on the puzzle * from 'SmartGames' called "IQPuzzlerPro" *  

* http://www.smartgames.eu/en/smartgames/iq-puzzler-pro *

* The class and the those that it refer to provide the core logic of * the puzzle, which is used by the GUI, which runs the game in a window. *

* The board is composed of spaces arranged in a 11x5 grid. * Each space is assigned an index using row-major order, starting at the * top left of the board. * Thus the top-left space has an index of 0; * the top-right space has an index of 10; * the bottom-left space has an index of 44; and * the bottom-right space has an index of 54. *

* There are twelve puzzle pieces which are composed of various numbers of linked * balls, arranged in a planar manner so that they may be laid flat on the grid * Each piece's position is described in terms of its origin, which is the * top-left-most ball when in its unrotated state (as illustrated above). *

* The puzzle uses a 'placement string' to represent the state of the board. * A placement string is composed of zero or more 'piece placement strings', * indicating the location of each piece that has already been placed on the board. *

* A piece placement string consists of four characters: * - The first character identifies which of the 12 pieces is being placed ('A' to 'L'). * - The second character identifies the column in which the origin of the tile is placed ('A' to 'K'). * - The third character identifies the row in which the origin of the tile is placed ('A' to 'E'). * - The fourth character identifies which orientation the tile is in ('A' to 'H'). *

* The default (unrotated) orientation is 'A'. * Orientation 'B' means the piece is rotated 90 degrees clockwise; * 'C' means the piece is rotated 180 degrees; and * 'D' means the piece is rotated 270 degrees clockwise. * Rotations 'E' through 'H' mean the piece is flipped horizontally * (i.e. reflected about the y-axis) before rotating clockwise. *

* Assume that in its default orientation, a piece is M columns wide and * N rows tall. * After a 90 degree rotation, it will be N columns wide and M rows tall. * To make rotation regular and ensure that rotated pieces correctly align * with the quilt board squares, rotation is performed so that the top-left * hand corner of the MxN bounding box is always in the same place. */

 import java.lang.reflect.Array; /**  * An enumeration representing the twelve pieces in the IQPuzzlerPro game.  *  

* You may want to look at the 'Planet' example in the Oracle enum tutorial for * an example of an enumeration. *

* http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html */ public enum Piece { A(new Square[]{new Square(0, 0), new Square(1, 0), new Square(0, 1)}), B(new Square[]{new Square(0, 0), new Square(1, 0), new Square(2, 0), new Square(1, 1)}), C(new Square[]{new Square(0, 0), new Square(1, 0), new Square(2, 0), new Square(0, 1), new Square(0, 2)}), D(new Square[]{new Square(0, 0), new Square(1, 0), new Square(2, 0), new Square(0, 1), new Square(2, 1)}), E(new Square[]{new Square(1, 0), new Square(2, 0), new Square(0, 1), new Square(1, 1), new Square(0, 2)}), F(new Square[]{new Square(0, 0), new Square(1, 0), new Square(2, 0), new Square(0, 1)}), G(new Square[]{new Square(0, 0), new Square(1, 0), new Square(2, 0), new Square(0, 1), new Square(1, 1)}), H(new Square[]{new Square(0, 0), new Square(1, 0), new Square(1, 1), new Square(2, 1)}), I(new Square[]{new Square(0, 0), new Square(0, 1), new Square(1, 1), new Square(2, 1), new Square(1, 2)}), J(new Square[]{new Square(0, 0), new Square(1, 0), new Square(2, 0), new Square(3, 0), new Square(0, 1)}), K(new Square[]{new Square(0, 0), new Square(1, 0), new Square(2, 0), new Square(3, 0), new Square(1, 1)}), L(new Square[]{new Square(1, 0), new Square(2, 0), new Square(3, 0), new Square(0, 1), new Square(1, 1)}); public static final int MAX_PIECE_WIDTH = 4; public static class Square { public static final int NUM_COLUMNS = 11; public static final int NUM_ROWS = 5; final int col; final int row; Square(int col, int row) { this.col = col; this.row = row; } @Override public boolean equals(Object obj) { if (obj instanceof Square) { Square s = (Square) obj; return s.col == this.col && s.row == this.row; } return false; } @Override public int hashCode() { return col * 37 + row; } public String toString() { return col + "," + row; } } /** * A list of spaces covered by this piece in its default rotation. * Each space in the list is given as an offset from the origin (0,0). */ public final Square[] shape; Piece(Square[] shape) { this.shape = shape; } public char getId() { return this.name().charAt(0); } /** * Return indices corresponding to which board spaces would be covered * by this piece, given a correct provided placement. *

* Examples: * Given the piece placement string 'GACA' would return the indices: {22,23,24,33,34}. * Given the piece placement string 'HGBF' would return the indices: {17,28,29,40}. *

* Hint: You can associate values with each entry in the enum using a constructor, * so you could use that to somehow encode the properties of each of the twelve pieces. * Then in this method you could use the value to calculate the required indices. *

* See the 'Grade' enum given in the O2 lecture as part of the lecture code (live coding), * for an example of an enum with associated state and constructors. *

* The tutorial here: http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html * has an example of a Planet enum, which includes two doubles in each planet's * constructor representing the mass and radius. Those values are used in the * surfaceGravity() method, for example. * * @param column the column in which the origin of the piece is placed ('A' to 'K') * @param row the row in which the origin of the tile is placed ('A' to 'E') * @param orientation which orientation the tile is in ('A' to 'H') * @return A set of indices corresponding to the board positions that would be covered by this piece */ int[] getCovered(char column, char row, char orientation) { // FIXME Task 5: implement code that correctly creates an array of integers specifying the indices of the covered spaces return new int[]{}; } public int getColumnExtent() { int xMax = 0; for (Square square : shape) { xMax = Math.max(xMax, square.col); } return xMax + 1; } public int getRowExtent() { int yMax = 0; for (Square square : shape) { yMax = Math.max(yMax, square.row); } return yMax + 1; } }

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

Students also viewed these Databases questions