-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStandardBoardMaker.java
83 lines (70 loc) · 2.39 KB
/
StandardBoardMaker.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
/**
* Supply a random BoggleBoard that's either 4x4 or 5x5 using standard cubes
* from Boggle and Big Boggle, respectively. Uses the BoggleFactory's random
* number generator.
*
* @author Owen Astrachan
*
*/
public class StandardBoardMaker implements IBoardMaker {
private ArrayList<Cube> myDice16;
private ArrayList<Cube> myDice25;
public StandardBoardMaker() {
myDice16 = new ArrayList<Cube>();
myDice25 = new ArrayList<Cube>();
initDice();
}
/**
* Initialize Dice list with official boggle cubes for 4x4 game and 5x5 game
* (Big Boggle)
*
*/
private static String[] bigStrings = { "aafirs", "adennn", "aaafrs",
"aeegmu", "aaeeee", "aeeeem", "afirsy", "aegmnn", "bjkqxz",
"ceipst", "ceiilt", "ccnstw", "ceilpt", "ddlonr", "dhlnor",
"dhhlor", "dhhnot", "ensssu", "emottt", "eiiitt", "fiprsy",
"gorrvw", "hiprry", "nootuw", "ooottu" };
private static String[] dieStrings = { "aaeegn", "abbjoo", "achops",
"affkps", "aoottw", "cimotu", "deilrx", "delrvy", "distty",
"eeghnw", "eeinsu", "ehrtvw", "eiosst", "elrtty", "himnqu",
"hlnnrz" };
private void initDice() {
for (String s : dieStrings) {
myDice16.add(new Cube(s));
}
for (String s : bigStrings) {
myDice25.add(new Cube(s));
}
}
/**
* Returns random boggle board of specified number of rows, boards are
* square.
*
* @param rows
* is number of rows (and columns) in returned board.
*/
public BoggleBoard makeBoard(int rows) {
return new BoggleBoard(getRandomBoard(rows * rows));
}
/**
* Return an array of Strings showing the sequence of faces on a randomly
* generated board.
*/
private String[] getRandomBoard(int totalSquares) {
ArrayList<Cube> dice = myDice16;
if (totalSquares > 16) {
dice = myDice25;
}
String[] letterList = new String[totalSquares];
Random rand = BoggleBoardFactory.getRandom();
Collections.shuffle(dice, rand);
for (int i = 0; i < totalSquares; i++) {
Cube d = dice.get(i % dice.size());
letterList[i] = d.getRandomFace();
}
return letterList;
}
}