Skip to content

Commit

Permalink
Dictionary lookup words and test to validate
Browse files Browse the repository at this point in the history
  • Loading branch information
Pheebs32 committed Apr 13, 2023
1 parent a6607c2 commit 34821bb
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 16 deletions.
15 changes: 12 additions & 3 deletions Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ public class Game {
HashMap tileBag;
HashSet dict;

public Game(int numberOfPlayers) {
public Game() {
this.scrabbleBoard = new char[15][15];
this.tileBag = new HashMap<Character, Integer>();
this.dict = new HashSet<String>();

this.initTileBag();
System.out.println("tile bag init done\n");
try { this.initDict(); }
catch (FileNotFoundException e) {
System.err.println("FileNotFoundExpectation: "+ e);
Expand Down Expand Up @@ -71,22 +72,30 @@ private void initTileBag() {
}
}

//Initializes the dictionary
//Initializes the dictionary - text file from 'https://github.com/redbo/scrabble/blob/master/dictionary.txt'
private void initDict() throws FileNotFoundException {
System.out.println("entered initDict()");
BufferedReader dictReader = new BufferedReader(new FileReader(("words.txt")));
try {
String line = dictReader.readLine();
System.out.println("first line : "+ line);

//add all words from web2 to hashset
//add all words from words.txt to hashset
while (line != null) {
dict.add(line);
line = dictReader.readLine();
}
System.out.println("done reading entire file");
} catch (IOException e) {
System.err.println("IOException : "+ e);
e.printStackTrace();
}

}
/*
@param word input to be validated
@return boolean if word is valid
*/
public boolean validateWord(String word) {
return this.dict.contains(word);
}
Expand Down
26 changes: 13 additions & 13 deletions application.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ public static void main(String[] args) {
System.out.println(" ");

//Loop to create players
for (int i = 0; i < 2; i++) {

System.out.println("Enter the name of player "+ (i + 1) +" : ");
String playerName = scanner.next();
System.out.println(playerName);

//create an array to store players?
//call player class
}
// for (int i = 0; i < 2; i++) {
//
// System.out.println("Enter the name of player "+ (i + 1) +" : ");
// String playerName = scanner.next();
// System.out.println(playerName);
//
// //create an array to store players?
// //call player class
// }

//test methods for Game class
System.out.println("begin board initialization");
Game game = new Game(2);
Game game = new Game();
System.out.println("board initialization complete");

game.validateWord("HELLO");
game.validateWord("PILOT");
game.validateWord("DDEINUBIUYISVY");
System.out.println(game.validateWord("HELLO"));
System.out.println(game.validateWord("PILOT"));
System.out.println(game.validateWord("DDEINUBIUYISVY"));

}
}
Binary file modified out/production/Scrabble-Project/Game.class
Binary file not shown.
Binary file modified out/production/Scrabble-Project/application.class
Binary file not shown.
1 change: 1 addition & 0 deletions out/production/Scrabble-Project/words.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
A
AA
AAH
AAHED
Expand Down
1 change: 1 addition & 0 deletions words.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
A
AA
AAH
AAHED
Expand Down

0 comments on commit 34821bb

Please sign in to comment.