package comp1110.ass1;
import java.util.Random;
public class Objective {
private final int problemNumber; // The problem number from the original board game
private final String initialState; // The list of initial tile placements
/**
* This array defines a set of 80 pre-defined puzzle objectives.
*
* There are 4 categories of objective, according to 4 difficulty levels,
* with 20 objectives per difficulty level, organized within the array as
* follows:
*
* Starter: 0-19
* Junior: 20-39
* Expert: 40-59
* Master: 60-79
*
* Each objective is encoded in terms of:
* 1 – A string representing the initial state of the board (see README for
* further details).
* 2 – An objective problemNumber corresponding to the objective problem
* number used in the original game.
*/
public static Objective[] OBJECTIVES = {
new Objective(“C0131D20120333O103223”, 1),
new Objective(“D00300233O011032”, 2),
new Objective(“T00D01202332O021030”, 3),
new Objective(“T30C0321D00122332O011020”, 4),
new Objective(“T22C31D01122303O001020”, 5),
new Objective(“C1222D30010333O103132”, 6),
new Objective(“T11C3001D21322303O100233”, 7),
new Objective(“T01C2033D11310213O003032”, 8),
new Objective(“T13C30D02112332O001020”, 9),
new Objective(“T00C32D01031220O102233”, 10),
new Objective(“D21O000210”, 11),
new Objective(“C03D0133O1020”, 12),
new Objective(“D010330O1020”, 13),
new Objective(“D000331O1030”, 14),
new Objective(“D0120O1121”, 15),
new Objective(“D33O001121”, 16),
new Objective(“C1113O1012”, 17),
new Objective(“C21O001030”, 18),
new Objective(“C10D0232O33”, 19),
new Objective(“C2122O1030”, 20),
new Objective(“T33D01122132O00”, 21),
new Objective(“T10D2022O1113”, 22),
new Objective(“T00D011220O103011”, 23),
new Objective(“T12D3033O031121”, 24),
new Objective(“T21D3032O1323”, 25),
new Objective(“T02D3033O1121”, 26),
new Objective(“T12C3113D0222O03”, 27),
new Objective(“T03D0020O1121”, 28),
new Objective(“T12C01D3320O1102”, 29),
new Objective(“T00D0333O1012”, 30),
new Objective(“D23O102132”, 31),
new Objective(“T11C20D03O101233”, 32),
new Objective(“T10D200112O1113”, 33),
new Objective(“C33D02132231O23”, 34),
new Objective(“T10C3320D0002O30”, 35),
new Objective(“C21D02O1012”, 36),
new Objective(“C32D02O2011”, 37),
new Objective(“C0311D30O01”, 38),
new Objective(“T01D3123O0002”, 39),
new Objective(“T32C0103D123133”, 40),
new Objective(“T02D0022O1120”, 41),
new Objective(“T00C1233O30”, 42),
new Objective(“T22D0002O1121”, 43),
new Objective(“T20D300121O1012”, 44),
new Objective(“T11D010322O1020”, 45),
new Objective(“C3233O0321”, 46),
new Objective(“C32D2013O0003”, 47),
new Objective(“T11C0123D21O2002”, 48),
new Objective(“T31C1011D0223”, 49),
new Objective(“C11O003320”, 50),
new Objective(“T22C30O1011”, 51),
new Objective(“T03C0012O11”, 52),
new Objective(“T33C10D3002O21”, 53),
new Objective(“T20C0013O11”, 54),
new Objective(“T01C31O0002”, 55),
new Objective(“T22D0220O1131”, 56),
new Objective(“T20D0132O1012”, 57),
new Objective(“T03C2131O01”, 58),
new Objective(“T21D0030O1122”, 59),
new Objective(“T10D0222O0020”, 60),
new Objective(“T00C1233O30”, 61),
new Objective(“T23C0132O00”, 62),
new Objective(“T33C20D0132O00”, 63),
new Objective(“T12C20D00O301102”, 64),
new Objective(“T21C2001O32”, 65),
new Objective(“T11C0223O01”, 66),
new Objective(“C1133O0012”, 67),
new Objective(“T21D1113O0020”, 68),
new Objective(“T22C0131O33”, 69),
new Objective(“T03C12O1023”, 70),
new Objective(“T12C0021O0233”, 71),
new Objective(“T11C1030D0223O31”, 72),
new Objective(“T31C1022O01”, 73),
new Objective(“T33D0002O1021”, 74),
new Objective(“C0003O11”, 75),
new Objective(“T21C32D13O0311”, 76),
new Objective(“T13C1123O10”, 77),
new Objective(“T22D0133O1012”, 78),
new Objective(“T10C1213O21”, 79),
new Objective(“T31C1002O23”, 80),
};
/**
* Given the initialState of the objective and a problem number, constructs
* an `Objective` object.
*
* @param initialState A string representing the list of initial tile
* placements
*
* @param problemNumber The problem number from the original board game,
* a value from 1 to 80.
*/
public Objective(String initialState, int problemNumber) {
assert problemNumber >= 1 && problemNumber <= 80;
this.initialState = initialState;
this.problemNumber = problemNumber;
}
/**
* Choose a new objective, given a difficulty level.
*
* The method should select a randomized objective from the 80 pre-defined
* solutions, being sure to select an objective with the correct level of
* difficulty.
*
* (See the comments above the declaration of the OBJECTIVES array.)
*
* So, for example, if the difficulty is 0 (starter), then this function
* should use a randomized index between 0 and 19 (inclusive) to return an
* objective from the OBJECTIVES array that is level 0 difficulty. On the
* other hand, if the difficulty is 3 (master), then this function should
* use a randomized index between 60 and 79 (inclusive) to return an
* objective from the OBJECTIVES array that is level 3 difficulty.
*
* The original code below simply returns OBJECTIVES[0], which neither
* respects the difficulty (it always returns a level 0 objective), nor is
* it randomized (it always returns the same objective).
*
* @param difficulty The difficulty of the game (0 - starter, 1 - junior,
* 2 - expert, 3 - master)
*
* @return An objective at the appropriate level of difficulty.
*/
public static Objective newObjective(int difficulty) {
assert difficulty >= 0 && difficulty <= 3;
return OBJECTIVES[0]; // FIXME Task 4 (P)
}
public String getInitialState() {
return initialState;
}
public int getProblemNumber() {
return problemNumber;
}
public static Objective getObjective(int index) {
return OBJECTIVES[index];
}
public static Objective[] getOBJECTIVES() {
return OBJECTIVES;
}
}