Part I Develop a ScrabbleAgent to find the optimal initial move of a Scrabble ga
ID: 3911445 • Letter: P
Question
Part I
Develop a ScrabbleAgent to find the optimal initial move of a Scrabble game, given the following inputs:
1. An empty Scrabble board. Assume the agent knows how the premium squares work, as well as their locations on the board.
2. The complete SOWPODS word list, containing all 267,751 legal words.
3. A collection of 7 tiles in the agent’s rack, of which at most 2 may be blank (“wildcard”) tiles.
The minimum output should be:
“RACK: <tiles>”, where <tiles> represents the tiles in the agent’s rack.
“PASS”, if the agent’s choice is to pass the turn.
“EXCHANGE <tiles>”, if the agent’s choice is to exchange 1 or more tiles from the rack with tiles from the tile bag. Here, <tiles> should indicate which tiles the agent wants to exchange.
“PLACE WORD <word><starting square><point total>”, if the agent decides to place a word on the board. Here, <word> should be replaced with the word the agent wants to place; <starting square> indicates the identity of the square where the first letter of the word is to be placed (this can be in <row, col> format, or a single integer value indicating the column in which the first letter should be placed, since the identity of the row is predetermined by the game rules; <point total> indicates how many points the word is worth, based on its placement.
“ELAPSED TIME: <elapsed time>”, to indicate how much time it took for the agent to determine its move. The result can be displayed in seconds or milliseconds. If your agent requires units higher than this, you need to do some more optimization.
The goals your agent should strive to achieve are:
Find the highest scoring word that can be made from the current rack of tiles. If you want to factor in other strategies, such as retaining certain tiles that may be more useful later (e.g., ‘S’, blank tiles), feel free to do so, but be sure to note this in your narrative for Part II.
Minimize the number of computationally expensive operations. These operations include such things as generation of all permutations and combinations, complete or near complete traversals of large data structures, and comparisons.
Minimize storage requirements. This problem is complex enough that it can eat up your heap memory if you’re not careful, depending on how much memory your system has, and the programming language you’re using. Also, remember that although disk storage frees up main memory, it is very expensive in terms of running time.
Minimize running time. You can measure the running time required for an operation by sto ing the system time immediately before the operation is performed, and reading the system time again immediately after the operation is complete. The difference is the running time required for that particular instance, which by itself is of limited use.
When you measure your agent’s performance, remember that the performance for a single trial usually won’t give you much information. You need to perform multiple trials, using different data inputs, and finding the average performance, to give you a better indication of how efficient your agent is.
Specific Design Requirements
1.
2. 3. 4.
Choice of
The arrangements for the tiles in the rack should be read from a flat text file containing a list of test racks. Each rack will be represented by a String of 7 characters. Uppercase letters A-Z will be used for lettered tiles, and the underscore character ‘_’ will be used to represent blank tiles. Download an example rack data file. The point of this is to allow rapid batch testing of multiple racks without the need to enter the data for the rack anew for every test. This saves valuable time, and it will allow you to easily re-run an entire test suite if you make a change to your code.
You will need to come up with your own solution to represent the Scrabble board, which will always be empty for the initial move.
You are NOT required to construct your agent to fit with any framework code, as in the previous assignment.
Other than that, there are virtually no restrictions on how you choose to design your agent. Feel free to use any of the ideas presented in the course (including topics we have not yet discussed, if you feel confident enough). You may also use ideas you glean from researching the problem. Of course, you must ultimately design and implement your own agent, and not simply reuse code found elsewhere.
Programming Language
You have
language you choose allows you to meet the requirements listed above. The only stipulation is that I must be able to compile and run your code in Windows XP or Windows 7.
some latitude regarding the choice of programming language for this assignment, so long as the
Testing
Although e xhaustive testing for this project will be impractical, you should strive to make sure your code is designed to apply generally to any rack of 7 tiles, even if blank tiles are present. If you need an oracle to guide your testing, there are several available on the internet. Two examples are: Lexical Word Finder (http://www.lexicalwordfinder.com/) and ScrabbleSolver (http://www.scrabblesolver.net/). Although I am providing you with a sample data file for reading in the rack data, the actual test file I use will contain more inputs.
Part II
Write a brief narrative discussing your rationale for the approach you chose. Include in this narrative:
• a discussion of why you chose/rejected certain heuristics (e.g., how a heuristic reduced the size of the search space or how it improved running time)
• any potential strategic values involved (e.g., saving blanks for later turns)
• an attempt to estimate the performance in terms of code complexity; i.e., Big-Oh. You don’t have to be exactly correct in your Big-Oh estimate, but you should have a ballpark idea of how your code should theoretically perform.
• supporting data such as data from time trials (if you performed time trials)
I am looking for content rather than length for the narrative, so don’t feel pressured to write pages and pages for this. Basically all I’m asking you to do here is give a rationale for what you chose to do.
Some Advice
Keep things simple. You aren’t required to solve the entire game of Scrabble, nor are you required to design your agent to play beyond the placement of the initial word (so you won’t need to worry about implementing game play between players, using minimax trees, etc.)—you’re only being asked to build an agent that will try to find an optimal solution to the first move of the game.
Don’t worry about getting THE correct answer, because there isn’t one. There are, however, many ACCEPT- ABLE answers. There is no specific performance level I am expecting your agent to reach, especially con- sidering the variations in performance that will occur depending on your system’s hardware. As a general guide, if your agent takes more than a few seconds to decide on a move, routinely runs out of memory, or consistently returns low-scoring words, you probably need to do some more optimization.
In a similar vein to the previously listed item, don’t get so focused on trying to find the best solution that you end up with nothing to turn in. Make sure you first have a solution to turn in that works, and once you’ve accomplished that, back it up and then play around trying to optimize it as time permits.
Although there is a tremendous amount of publicly available research and data about the game of Scrab- ble, don’t become overwhelmed by trying to utilize all this information.
Explanation / Answer
ScrabbleAgent to find the optimal initial move of a Scrabble game :
Permute.java :
package scrabble;
import java.util.*;
public class Permute {
public static void main(String args[]) {
Set<String> rackSet = new HashSet<String>();
Set<String> permutedSet = new HashSet<String>();
permuteString("", "ABCD", rackSet);
for(int i=0; i < 6;i++) {
for (String s : rackSet) {
permutedSet.add(s.substring(i));
}
}
for(String s :permutedSet) {
//if(s.length() == 4)
System.out.println(s);
}
}
public static Set<String> permuteString(String beginningString, String endingString, Set<String> set) {
if (endingString.length() <= 1) {
String pString = beginningString + endingString;
set.add(pString);
}
else
for (int i = 0; i < endingString.length(); i++) {
try {
String newString = endingString.substring(0, i) + endingString.substring(i + 1);
permuteString(beginningString + endingString.charAt(i), newString, set);
} catch (StringIndexOutOfBoundsException exception) {
exception.printStackTrace();
}
}
return set;
}
}
QuestionMark .java
package scrabble;
public class QuestionMark {
public static void main(String[] args) {
StringBuilder s = new StringBuilder();
s.append("STAP");
if(s.toString().contains("?")) {
int firstIndex = s.indexOf("?");
int lastIndex = s.lastIndexOf("?");
if(firstIndex != lastIndex) {
for(char i = 'a'; i <= 'z'; i++)
{
s.setCharAt(firstIndex, i);
for(char j = 'a'; j <= 'z'; j++) {
s.setCharAt(lastIndex, j);
System.out.println(s);
}
}
}
else {
for(char i = 'a'; i <= 'z'; i++)
{
s.setCharAt(firstIndex, i);
System.out.println(s.toString().toUpperCase());
}
}
}
}
}
ScrabbleAgent.java
package scrabble;
import java.io.*;
import java.util.*;
import scrabble.ScrabbleWord;
import scrabble.ScrabbleBoard;
public class ScrabbleAgent {
private static long startTime;
private static long stopTime;
private static String pathToSOWPODS = "/Users/Justin/Documents/workspace/ScrabbleAgent/src/scrabble/SOWPODS_complete.txt";
private static String pathToRACK ="/Users/Justin/Documents/workspace/ScrabbleAgent/src/scrabble/sample_rack_file.txt";
private static BufferedReader txtReader;
private static BufferedReader consoleIn = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) {
Set<String> rackSet = new HashSet<String>();
Set<String> permutedSet = new HashSet<String>();
String input;
String rack;
List<String> list = new ArrayList<String>();
ScrabbleWord FinalWord;
Trie trie = new Trie(getDictionary());
ScrabbleBoard board = new ScrabbleBoard();
boolean done = false;
try {
txtReader = new BufferedReader(new FileReader(pathToRACK));
while ((rack = txtReader.readLine()) != null && done == false) {
do {
System.out.print("Process Next Rack?<Y/N> ");
input = consoleIn.readLine().trim().toUpperCase();
} while(!input.equals("N") && !input.equals("Y"));
if(input.equals("N")) {
done = true;
}
else if (input.equals("Y")){
startTime = System.currentTimeMillis();
permuteString("", rack, rackSet);
for(int i=0; i < rack.length()-1;i++) {
for (String s : rackSet) {
permutedSet.add(s.substring(i));
}
}
rackSet.clear();
for (String s : permutedSet) {
if (rack.isEmpty())
break;
list.addAll(wordSearch(s, trie));
}
List<ScrabbleWord> scoredWords = new ArrayList<ScrabbleWord>();
int i = 0;
for(String s :list) {
scoredWords.add(new ScrabbleWord(s));
scoredWords.get(i).computeScore();
i++;
}
list.clear();
permutedSet.clear();
Collections.sort(scoredWords);
if (scoredWords.size() >= 3) {
scoredWords = scoredWords.subList(0, 3);
for(i= 0; i <=2; i++){
scoredWords.get(i).bestBoardPos();
}
Collections.sort(scoredWords);
FinalWord = scoredWords.get(0);
if(FinalWord.toString().length() >= 4) {
stopTime = System.currentTimeMillis();
FinalWord.setScore(FinalWord.getScore()*3);
board.changeBoard(FinalWord);
System.out.println("Placed " + FinalWord + " For score of " + FinalWord.getScore());
System.out.printf("Elapsed Time: %d ms ",stopTime-startTime);
scoredWords.clear();
}
else
{
stopTime = System.currentTimeMillis();
System.out.printf("Computer Passes Elapsed Time: %d ms ",stopTime-startTime);
}
}
else if (scoredWords.isEmpty()) {
System.out.println("Computer Exchanges:" + exchangeTiles(rack).toString());
stopTime = System.currentTimeMillis();
System.out.printf("Elapsed Time: %d ms ",stopTime-startTime);
}
else {
scoredWords.get(0).bestBoardPos();
board.changeBoard(scoredWords.get(0));
scoredWords.clear();
}
}
board.clear();
}
txtReader.close();
consoleIn.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
public static List<String> getDictionary() {
List<String> dictionary = new ArrayList<String>();
BufferedReader input = null;
try {
String word;
input = new BufferedReader(new FileReader(pathToSOWPODS));
while ((word = input.readLine()) != null) {
if(word.length() > 1)
dictionary.add(word);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (input != null)input.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
return dictionary;
}
public static Set<String> permuteString(String _beginningString, String _endingString, Set<String> _set) {
if (_endingString.length() <= 1) {
String pString = _beginningString + _endingString;
_set.add(pString);
}
else
for (int i = 0; i < _endingString.length(); i++) {
try {
String newString = _endingString.substring(0, i) + _endingString.substring(i + 1);
permuteString(_beginningString + _endingString.charAt(i), newString, _set);
} catch (StringIndexOutOfBoundsException exception) {
exception.printStackTrace();
}
}
return _set;
}
public static List<String> wordSearch(String _Word, Trie _Trie) {
List<String> list = new ArrayList<String>();
StringBuilder s = new StringBuilder();
s.setLength(0);
s.append(_Word);
if(s.toString().contains("_")) {
int firstIndex = s.indexOf("_");
int lastIndex = s.lastIndexOf("_");
if(firstIndex != lastIndex) {
for(char i = 'a'; i <= 'z'; i++)
{
s.setCharAt(firstIndex, i);
for(char j = 'a'; j <= 'z'; j++) {
s.setCharAt(lastIndex, j);
if (_Trie.containsWord(s.toString()))
list.add(s.toString());
}
}
}
else {
for(char i = 'a'; i <= 'z'; i++)
{
s.setCharAt(firstIndex, i);
if (_Trie.containsWord(s.toString()))
list.add(s.toString());
}
}
}
else {
if (_Trie.containsWord(_Word))
list.add(_Word);
}
return list;
}
public static List<ScrabbleWord> exchangeTiles(String _rack){
List<ScrabbleWord> letters = new ArrayList<ScrabbleWord>();
for(char c: _rack.toCharArray()) {
letters.add(new ScrabbleWord(Character.toString(c)));
}
for(ScrabbleWord c: letters){
c.computeScore();
}
Collections.sort(letters);
return letters.subList(2, 5);
}
}
ScrabbleBoard.java
package scrabble;
import scrabble.ScrabbleWord;
public class ScrabbleBoard {
private static StringBuilder[] board = new StringBuilder[] {new StringBuilder(),new StringBuilder(),new StringBuilder(),new StringBuilder(),
new StringBuilder(),new StringBuilder(),new StringBuilder(),new StringBuilder(),new StringBuilder(),new StringBuilder(),new StringBuilder(),
new StringBuilder(),new StringBuilder(),new StringBuilder(),new StringBuilder()};
public ScrabbleBoard(){
board[0].append("#¦¦2¦¦¦#¦¦¦2¦¦#");
board[1].append("¦@¦¦¦3¦¦¦3¦¦¦@¦");
board[2].append("¦¦@¦¦¦2¦2¦¦¦@¦¦");
board[3].append("2¦¦@¦¦¦2¦¦¦@¦¦2");
board[4].append("¦¦¦¦@¦¦¦¦¦@¦¦¦¦");
board[5].append("¦3¦¦¦3¦¦¦3¦¦¦3¦");
board[6].append("¦¦2¦¦¦2¦2¦¦¦2¦¦");
board[7].append("#¦¦2¦¦¦?¦¦¦2¦¦#");
board[8].append("¦¦2¦¦¦2¦2¦¦¦2¦¦");
board[9].append("¦3¦¦¦3¦¦¦3¦¦¦3¦");
board[10].append("¦¦¦¦@¦¦¦¦¦@¦¦¦¦");
board[11].append("2¦¦@¦¦¦2¦¦¦@¦¦2");
board[12].append("¦¦@¦¦¦2¦2¦¦¦@¦¦");
board[13].append("¦@¦¦¦3¦¦¦3¦¦¦@¦");
board[14].append("#¦¦2¦¦¦#¦¦¦2¦¦#");
this.showBoard();
}
public void clear(){
board[0].replace(0,15,"#¦¦2¦¦¦#¦¦¦2¦¦#");
board[1].replace(0,15,"¦@¦¦¦3¦¦¦3¦¦¦@¦");
board[2].replace(0,15,"¦¦@¦¦¦2¦2¦¦¦@¦¦");
board[3].replace(0,15,"2¦¦@¦¦¦2¦¦¦@¦¦2");
board[4].replace(0,15,"¦¦¦¦@¦¦¦¦¦@¦¦¦¦");
board[5].replace(0,15,"¦3¦¦¦3¦¦¦3¦¦¦3¦");
board[6].replace(0,15,"¦¦2¦¦¦2¦2¦¦¦2¦¦");
board[7].replace(0,15,"#¦¦2¦¦¦?¦¦¦2¦¦#");
board[8].replace(0,15,"¦¦2¦¦¦2¦2¦¦¦2¦¦");
board[9].replace(0,15,"¦3¦¦¦3¦¦¦3¦¦¦3¦");
board[10].replace(0,15,"¦¦¦¦@¦¦¦¦¦@¦¦¦¦");
board[11].replace(0,15,"2¦¦@¦¦¦2¦¦¦@¦¦2");
board[12].replace(0,15,"¦¦@¦¦¦2¦2¦¦¦@¦¦");
board[13].replace(0,15,"¦@¦¦¦3¦¦¦3¦¦¦@¦");
board[14].replace(0,15,"#¦¦2¦¦¦#¦¦¦2¦¦#");
}
public void showBoard(){
for (StringBuilder s:board) {
System.out.println(" "+s);
}
System.out.println("=========================================");
System.out.println("* Blank Square: ¦ Triple Letter: 3 * * Triple Word: # Double Letter: 2 * * Double Word: @ Center Square: ? * * Uppercase Letters:Normal Tiles * * Lowercase Letters: Blank Tiles *");
System.out.println("=========================================");
}
public void changeBoard(ScrabbleWord _word) {
board[_word.getBoardYPos()].replace(_word.getBoardXPos(), _word.getBoardXPos()+_word.toString().length(), _word.toString());
this.showBoard();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
ScrabbleBoard board = new ScrabbleBoard();
//board.showBoard();
ScrabbleWord test = new ScrabbleWord("TEST");
test.setBoardPostion(4, 7);
board.changeBoard(test);
board.clear();
System.out.println("Board Cleared");
board.showBoard();
}
}
ScrabbleWord.java
package scrabble;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class ScrabbleWord implements Comparable<ScrabbleWord> {
final static Set<String> HashSet<String>(Arrays.asList("A","E","I","O","U","L","N","R","S","T"));
final static Set<String> twoPoint = new HashSet<String>(Arrays.asList("D","G"));
final static Set<String> threePoint = new HashSet<String>(Arrays.asList("B","C","M","P"));
final static Set<String> fourPoint = new HashSet<String>(Arrays.asList("F","H","V","W","Y"));
final static Set<String> fivePoint = new HashSet<String>(Arrays.asList("K"));
final static Set<String> eightPoint = new HashSet<String>(Arrays.asList("X","J"));
final static Set<String> tenPoint = new HashSet<String>(Arrays.asList("Q","Z"));
final static Set<String> zeroPoint = new HashSet<String>(Arrays.asList("a","b","c","d","e","f","g","h","i","j",
"k","l","m","n","o","p","q","r","s","t",
"u","v","w","x","y","z"));
private String word;
private int score;
private int boardX;
private int boardY;
public ScrabbleWord() {
this.word = "default";
this.score = -1;
}
public ScrabbleWord(String _word) {
this.word =_word;
this.score = 0;
}
public ScrabbleWord(String _word, int _score){
this.word = _word;
this.score = _score;
}
public static void main(String[] args) {
}
public int getScore() {
return this.score;
}
public void setScore(int _newScore) {
score = _newScore;
}
public void setBoardPostion(int _x, int _y) {
this.boardX = _x;
this.boardY = _y;
}
public int getBoardXPos(){
return this.boardX;
}
public int getBoardYPos(){
return this.boardY;
}
@Override
public String toString() {
return this.word;
}
public boolean equals(ScrabbleWord _comparedWord){
return this.getScore() == _comparedWord.getScore();
}
@Override //Use Descending Natural Ordering
public int compareTo(ScrabbleWord _comparedWord){
if(this.equals(_comparedWord)) {
return 0;
}
else if(this.getScore() > _comparedWord.getScore()){
return -1;
}
else
return 1;
}
public void computeScore() {
for(int c=0; c < this.toString().length(); c++) {
letterScore(this, c);
}
}
public void bestBoardPos(){
if(this.word.length() == 7) {
this.score += 50;
letterScore(this, 2);
this.setBoardPostion(1, 7);
}
else if(this.word.length() == 6) {
List<ScrabbleWord> tempWords = new ArrayList<ScrabbleWord>();
tempWords.add(new ScrabbleWord(this.word, this.score));
tempWords.add(new ScrabbleWord(this.word, this.score));
tempWords.add(new ScrabbleWord(this.word, this.score));
tempWords.add(new ScrabbleWord(this.word, this.score));
letterScore(tempWords.get(0), 0);
letterScore(tempWords.get(1), 5);
letterScore(tempWords.get(2), 1);
letterScore(tempWords.get(3), 4);
tempWords.get(0).setBoardPostion(3, 7);
tempWords.get(1).setBoardPostion(6, 7);
tempWords.get(1).setBoardPostion(2, 7);
tempWords.get(1).setBoardPostion(7, 7);
Collections.sort(tempWords);
this.score = tempWords.get(0).getScore();
this.boardX = tempWords.get(0).boardX;
this.boardY = tempWords.get(0).boardY;
}
else if(this.word.length() == 5) {
List<ScrabbleWord> tempWords = new ArrayList<ScrabbleWord>();
tempWords.add(new ScrabbleWord(this.word, this.score));
tempWords.add(new ScrabbleWord(this.word, this.score));
letterScore(tempWords.get(0), 0);
letterScore(tempWords.get(1), 4);
tempWords.get(0).setBoardPostion(3, 7);
tempWords.get(1).setBoardPostion(7, 7);
Collections.sort(tempWords);
this.score = tempWords.get(0).getScore();
this.boardX = tempWords.get(0).boardX;
this.boardY = tempWords.get(0).boardY;
}
else if(this.word.length() == 4) {
this.setBoardPostion(4, 7);
}
}
public static ScrabbleWord letterScore(ScrabbleWord _word, int c) {
if(onePoint.contains(Character.toString(_word.toString().charAt(c)))) {
_word.setScore(_word.getScore()+1);
}
else if(twoPoint.contains(Character.toString(_word.toString().charAt(c)))) {
_word.setScore(_word.getScore()+2);
}
else if(threePoint.contains(Character.toString(_word.toString().charAt(c)))) {
_word.setScore(_word.getScore()+3);
}
else if(fourPoint.contains(Character.toString(_word.toString().charAt(c)))) {
_word.setScore(_word.getScore()+4);
}
else if(fivePoint.contains(Character.toString(_word.toString().charAt(c)))) {
_word.setScore(_word.getScore()+5);
}
else if(eightPoint.contains(Character.toString(_word.toString().charAt(c)))) {
_word.setScore(_word.getScore()+8);
}
else if(tenPoint.contains(Character.toString(_word.toString().charAt(c)))) {
_word.setScore(_word.getScore()+10);
}
else if(zeroPoint.contains(Character.toString(_word.toString().charAt(c)))) {
_word.setScore(_word.getScore());
}
else {
System.out.println("Invaild Word");
_word.setScore(0);
}
return _word;
}
}
Trie.java
package scrabble;
import java.util.*;
public class Trie {
private Node root = new Node("");
public Trie() {}
public Trie(List<String> _Dictionary) {
int i = 0;
System.out.print("Loading ");
for (Iterator<String> it = _Dictionary.iterator(); it.hasNext(); i++) {
String s = it.next();
addWord(s);
it.remove();
if(i == 5000){
System.out.print(".");
System.gc();
i = 0;
}
}
System.out.println(" SOWPODS Loaded");
}
public void addWord(String _Word) {
char _Chars[] = _Word.toCharArray();
Node currentNode = root;
for (int i = 0; i < _Chars.length; i++) {
if (!currentNode.containsChildValue(_Chars[i])) {
currentNode.addChild(_Chars[i], new Node(currentNode.getValue() + _Chars[i]));
}
currentNode = currentNode.getChild(_Chars[i]);
}
currentNode.setIsWord(true);
}
public boolean containsWord(String _Word) {
return contains(_Word.toUpperCase());
}
public Node getWord(String _String) {
Node node = getNode(_String);
return node != null && node.isWord() ? node : null;
}
private boolean contains(String _String) {
Node node = getNode(_String);
return (node != null && node.isWord());
}
private Node getNode(String _String) {
Node currentNode = root;
char _Chars[] = _String.toCharArray();
for (int i = 0; i < _Chars.length && currentNode != null; i++) {
currentNode = currentNode.getChild(_Chars[i]);
if (currentNode == null) {
return null;
}
}
return currentNode;
}
}
class Node {
private final String value;
private Map<Character, Node> children = new HashMap<Character, Node>();
private boolean isValidWord;
public Node(String _Value) {
value = _Value;
}
public boolean addChild(char c, Node _Child) {
children.put(c, _Child);
return true;
}
public boolean containsChildValue(char c) {
return children.containsKey(c);
}
public String getValue() {
return value.toString();
}
public Node getChild(char c) {
return children.get(c);
}
public boolean isWord() {
return isValidWord;
}
public void setIsWord(boolean _isWord) {
isValidWord = _isWord;
}
public String toString() {
return value;
}
}
wordScore .java
package scrabble;
import java.util.*;
import scrabble.ScrabbleWord;
public class wordScore {
public static void main(String[] args) {
ScrabbleWord FinalWord;
List<String> list = Arrays.asList("TEST","PIMP","FACE","ZEBRA","QuDoBa");
List<ScrabbleWord> scoredWords = new ArrayList<ScrabbleWord>();
int i = 0;
for(String s :list) {
scoredWords.add(new ScrabbleWord(s));
scoredWords.get(i).computeScore();
i++;
}
System.out.println( scoredWords.toString());
Collections.sort(scoredWords);
scoredWords = scoredWords.subList(0, 3);
System.out.println( scoredWords.toString());
for(i= 0; i <=2; i++){
scoredWords.get(i).bestBoardPos();
}
Collections.sort(scoredWords);
System.out.println( scoredWords.toString());
FinalWord = scoredWords.get(0);
System.out.printf("%s was placed at row %d postion %d for a score of %d",FinalWord,FinalWord.getBoardYPos(),FinalWord.getBoardXPos(),FinalWord.getScore());
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.