@@ -17,10 +17,10 @@ public class Common
17
17
public final static String answerWordsFile = "/common.txt" ;
18
18
//file: all words file 'all.txt' in the jar
19
19
public final static String allWordsFile = "/all.txt" ;
20
- //possible answer words
21
- public static ArrayList <String > answerWordsList = new ArrayList <String >();
22
- //all accepted words
23
- public static ArrayList <String > allWordsList = new ArrayList <String >();
20
+ //possible answer words (from common.txt)
21
+ public static ArrayList <String > answerWordsList = new ArrayList <String >(2500 );
22
+ //all accepted words (from all.txt)
23
+ public static ArrayList <String > allWordsList = new ArrayList <String >(13000 );
24
24
//how many times you want the program to try to find the word. Can be overridden by command line argument
25
25
public static int maxTries = 6 ;
26
26
//wordle letter block background colors
@@ -65,34 +65,34 @@ public static void readAllWords() throws Exception
65
65
public static void calculatePossibleWords (String inputWord , int [] result )
66
66
{
67
67
String inputWordLower = inputWord .toLowerCase ();
68
- //remove this word if result isn't [1, 1, 1, 1, 1]
69
- //to prevent a possible bug
68
+ //remove the word that have been identified as not being the answer
70
69
if (!(result [0 ] == 1 && result [1 ] == 1 && result [2 ] == 1 && result [3 ] == 1 && result [4 ] == 1 ))
71
70
answerWordsList .remove (inputWordLower );
71
+ //calculation begins
72
72
for (int loc = 0 ; loc != 5 ; loc ++)
73
73
{
74
74
switch (result [loc ])
75
75
{
76
76
case 2 ://the char is in another location
77
77
{
78
78
//keep the words that have the char
79
- ArrayList <String > temp = new ArrayList <String >();
79
+ ArrayList <String > temp = new ArrayList <String >(2000 );
80
80
for (String word : answerWordsList ) if (word .contains (inputWordLower .charAt (loc )+"" )) temp .add (word );
81
81
answerWordsList = temp ;
82
82
break ;
83
83
}
84
84
case 1 ://the char is in the right location
85
85
{
86
86
//keep the words that have the same char at the same location
87
- ArrayList <String > temp = new ArrayList <String >();
87
+ ArrayList <String > temp = new ArrayList <String >(2000 );
88
88
for (String word : answerWordsList ) if (word .charAt (loc ) == inputWordLower .charAt (loc )) temp .add (word );
89
89
answerWordsList = temp ;
90
90
break ;
91
91
}
92
92
case 0 ://the char is not in the answer word
93
93
{
94
94
//remove the words that have the same char that is not matched
95
- ArrayList <String > temp = new ArrayList <String >();
95
+ ArrayList <String > temp = new ArrayList <String >(2000 );
96
96
for (String word : answerWordsList ) if (!word .contains (inputWordLower .charAt (loc )+"" )) temp .add (word );
97
97
answerWordsList = temp ;
98
98
break ;
0 commit comments