Initial commit
This commit is contained in:
+10
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="module" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
</classpath>
|
||||||
+60
@@ -0,0 +1,60 @@
|
|||||||
|
.metadata
|
||||||
|
bin/
|
||||||
|
tmp/
|
||||||
|
*.tmp
|
||||||
|
*.bak
|
||||||
|
*.swp
|
||||||
|
*~.nib
|
||||||
|
local.properties
|
||||||
|
.settings/
|
||||||
|
.loadpath
|
||||||
|
.recommenders
|
||||||
|
|
||||||
|
# External tool builders
|
||||||
|
.externalToolBuilders/
|
||||||
|
|
||||||
|
# Locally stored "Eclipse launch configurations"
|
||||||
|
*.launch
|
||||||
|
|
||||||
|
# PyDev specific (Python IDE for Eclipse)
|
||||||
|
*.pydevproject
|
||||||
|
|
||||||
|
# CDT-specific (C/C++ Development Tooling)
|
||||||
|
.cproject
|
||||||
|
|
||||||
|
# CDT- autotools
|
||||||
|
.autotools
|
||||||
|
|
||||||
|
# Java annotation processor (APT)
|
||||||
|
.factorypath
|
||||||
|
|
||||||
|
# PDT-specific (PHP Development Tools)
|
||||||
|
.buildpath
|
||||||
|
|
||||||
|
# sbteclipse plugin
|
||||||
|
.target
|
||||||
|
|
||||||
|
# Tern plugin
|
||||||
|
.tern-project
|
||||||
|
|
||||||
|
# TeXlipse plugin
|
||||||
|
.texlipse
|
||||||
|
|
||||||
|
# STS (Spring Tool Suite)
|
||||||
|
.springBeans
|
||||||
|
|
||||||
|
# Code Recommenders
|
||||||
|
.recommenders/
|
||||||
|
|
||||||
|
# Annotation Processing
|
||||||
|
.apt_generated/
|
||||||
|
.apt_generated_test/
|
||||||
|
|
||||||
|
# Scala IDE specific (Scala & Java development for Eclipse)
|
||||||
|
.cache-main
|
||||||
|
.scala_dependencies
|
||||||
|
.worksheet
|
||||||
|
|
||||||
|
# Uncomment this line if you wish to ignore the project description file.
|
||||||
|
# Typically, this file would be tracked if it contains build/dependency configurations:
|
||||||
|
#.project
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>WordleSolver</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
a 1
|
||||||
|
b 1
|
||||||
|
c 1
|
||||||
|
d 1
|
||||||
|
e 1
|
||||||
|
f 1
|
||||||
|
g 1
|
||||||
|
h 1
|
||||||
|
i 1
|
||||||
|
j 1
|
||||||
|
k 1
|
||||||
|
l 1
|
||||||
|
m 1
|
||||||
|
n 1
|
||||||
|
o 1
|
||||||
|
p 1
|
||||||
|
q 1
|
||||||
|
r 1
|
||||||
|
s 1
|
||||||
|
t 1
|
||||||
|
u 1
|
||||||
|
v 1
|
||||||
|
w 1
|
||||||
|
x 1
|
||||||
|
y 1
|
||||||
|
z 1
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class depreciatedDict
|
||||||
|
{
|
||||||
|
|
||||||
|
HashMap<dictWord, Boolean> dict;
|
||||||
|
HashMap<Character, Integer> letterScores;
|
||||||
|
public depreciatedDict()
|
||||||
|
{
|
||||||
|
dict = new HashMap<dictWord, Boolean>();
|
||||||
|
letterScores = new HashMap<Character, Integer>();
|
||||||
|
populateLetterScores();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addWord(String newWord)
|
||||||
|
{
|
||||||
|
dictWord newDictWord = new dictWord(newWord, letterScores);
|
||||||
|
dict.put(newDictWord, true);
|
||||||
|
System.out.println("Added new word " + newWord + " with unique score of " + newDictWord.getUniqueScore());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cullWords(int index, char letter)
|
||||||
|
{
|
||||||
|
for(dictWord word : dict.keySet())
|
||||||
|
{
|
||||||
|
if(word.getWord().charAt(index) == letter)
|
||||||
|
{
|
||||||
|
dict.put(word, false);
|
||||||
|
System.out.println("Removed " + word);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void populateLetterScores()
|
||||||
|
{
|
||||||
|
BufferedReader bf;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
bf = new BufferedReader(new FileReader("letterScores.txt"));
|
||||||
|
String currentScore = bf.readLine();
|
||||||
|
while(currentScore != null)
|
||||||
|
{
|
||||||
|
char [] letters = currentScore.substring(0, currentScore.indexOf(' ')).toCharArray();
|
||||||
|
int score = Integer.parseInt(currentScore.substring(currentScore.indexOf(' ')).trim());
|
||||||
|
for(int i = 0; i < letters.length; i ++)
|
||||||
|
{
|
||||||
|
letterScores.put(letters[i], score);
|
||||||
|
}
|
||||||
|
currentScore = bf.readLine();
|
||||||
|
}
|
||||||
|
bf.close();
|
||||||
|
} catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class dictWord implements Comparable<Object>
|
||||||
|
{
|
||||||
|
private int uniqueScore;
|
||||||
|
private int yellowScore;
|
||||||
|
private String word;
|
||||||
|
|
||||||
|
public dictWord(String word, HashMap<Character, Integer> scores)
|
||||||
|
{
|
||||||
|
this.word = word;
|
||||||
|
uniqueScore = 0;
|
||||||
|
yellowScore = 1;
|
||||||
|
calculateUniqueScore(scores);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void calculateUniqueScore(HashMap<Character, Integer> scores)
|
||||||
|
{
|
||||||
|
String uniqueLetters = "";
|
||||||
|
for(int i = 0; i < word.length(); i++)
|
||||||
|
{
|
||||||
|
char tempChar = word.charAt(i);
|
||||||
|
if(!uniqueLetters.contains(tempChar + ""))
|
||||||
|
{
|
||||||
|
uniqueLetters += tempChar;
|
||||||
|
uniqueScore += scores.get(tempChar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void calculateYellowScore(String yellowLetters)
|
||||||
|
{
|
||||||
|
yellowScore = 1;
|
||||||
|
for(int i = 0; i < word.length(); i ++)
|
||||||
|
{
|
||||||
|
char [] yellows = yellowLetters.toCharArray();
|
||||||
|
for(char letter : yellows)
|
||||||
|
{
|
||||||
|
if(word.contains(letter + ""))
|
||||||
|
{
|
||||||
|
yellowScore++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return "Word: " + word + "\tScore: " + getTotalScore();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWord()
|
||||||
|
{
|
||||||
|
return word;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getUniqueScore()
|
||||||
|
{
|
||||||
|
return uniqueScore;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(Object compareWord)
|
||||||
|
{
|
||||||
|
return ((dictWord) compareWord).getTotalScore() - this.getTotalScore();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTotalScore()
|
||||||
|
{
|
||||||
|
return yellowScore * uniqueScore;
|
||||||
|
}
|
||||||
|
}
|
||||||
+154
@@ -0,0 +1,154 @@
|
|||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class runner
|
||||||
|
{
|
||||||
|
public static Random numGen = new Random();
|
||||||
|
public static void main(String [] args) throws IOException
|
||||||
|
{
|
||||||
|
HashMap<Character, Integer> letterScores = new HashMap<Character, Integer>();
|
||||||
|
populateLetterScores(letterScores);
|
||||||
|
wordleDict dict = new wordleDict();
|
||||||
|
addWords(dict, letterScores);
|
||||||
|
|
||||||
|
int [] correctGuesses = new int[10];
|
||||||
|
Arrays.fill(correctGuesses,0);
|
||||||
|
|
||||||
|
//for(int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
correctGuesses[playGame(dict)] ++;
|
||||||
|
addWords(dict, letterScores);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for(int thing : correctGuesses)
|
||||||
|
{
|
||||||
|
System.out.println(thing);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int playGame(wordleDict dict)
|
||||||
|
{
|
||||||
|
boolean stillGoing = true;
|
||||||
|
String wordleWord = "lemon";
|
||||||
|
String guessResult;
|
||||||
|
String guess;
|
||||||
|
int guessNum = 0;
|
||||||
|
while(stillGoing)
|
||||||
|
{
|
||||||
|
guess = dict.getBestWord().trim();
|
||||||
|
guessResult = guessWord(guess, wordleWord);
|
||||||
|
if(guessResult.equals("GGGGG") || guessNum == 9)
|
||||||
|
{
|
||||||
|
stillGoing = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
guessNum ++;
|
||||||
|
for(int i = 0; i < guessResult.length(); i ++)
|
||||||
|
{
|
||||||
|
switch(guessResult.charAt(i))
|
||||||
|
{
|
||||||
|
case('G'):
|
||||||
|
dict.greenCullWords(i, guess.charAt(i));
|
||||||
|
break;
|
||||||
|
case('E'):
|
||||||
|
dict.yellowCullWords(-1, guess.charAt(i));
|
||||||
|
break;
|
||||||
|
case('Y'):
|
||||||
|
dict.yellowCullWords(i, guess.charAt(i));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// System.out.println("Correct word: " + wordleWord);
|
||||||
|
// System.out.println("Guessed word: " + guess);
|
||||||
|
// System.out.println("Result: " + guessResult);
|
||||||
|
}
|
||||||
|
if(guessNum == 0)
|
||||||
|
{
|
||||||
|
System.out.println("Correct word: " + wordleWord);
|
||||||
|
}
|
||||||
|
return guessNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String chooseWordle(wordleDict dict)
|
||||||
|
{
|
||||||
|
return dict.getRandomWord(numGen);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String guessWord(String guess, String correctWord)
|
||||||
|
{
|
||||||
|
String output = "";
|
||||||
|
for(int i = 0; i < guess.length(); i++)
|
||||||
|
{
|
||||||
|
char c = guess.charAt(i);
|
||||||
|
if(correctWord.charAt(i) == c)
|
||||||
|
{
|
||||||
|
output += "G";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if(correctWord.contains(Character.toString(c)))
|
||||||
|
{
|
||||||
|
output += "Y";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
output += "E";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addWords(wordleDict dict, HashMap<Character, Integer> letterScores) throws IOException
|
||||||
|
{
|
||||||
|
dict.clear();
|
||||||
|
BufferedReader bf;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
boolean hasNext = true;
|
||||||
|
bf = new BufferedReader(new FileReader("words.txt"));
|
||||||
|
String newWord = bf.readLine();
|
||||||
|
while(hasNext)
|
||||||
|
{
|
||||||
|
dict.addWord(newWord, letterScores);
|
||||||
|
newWord = bf.readLine();
|
||||||
|
if(newWord == null)
|
||||||
|
hasNext = false;
|
||||||
|
}
|
||||||
|
bf.close();
|
||||||
|
} catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void populateLetterScores(HashMap<Character, Integer> letterScores)
|
||||||
|
{
|
||||||
|
BufferedReader bf;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
bf = new BufferedReader(new FileReader("letterScores.txt"));
|
||||||
|
String currentScore = bf.readLine();
|
||||||
|
while(currentScore != null)
|
||||||
|
{
|
||||||
|
char [] letters = currentScore.substring(0, currentScore.indexOf(' ')).toCharArray();
|
||||||
|
int score = Integer.parseInt(currentScore.substring(currentScore.indexOf(' ')).trim());
|
||||||
|
for(int i = 0; i < letters.length; i ++)
|
||||||
|
{
|
||||||
|
letterScores.put(letters[i], score);
|
||||||
|
}
|
||||||
|
currentScore = bf.readLine();
|
||||||
|
}
|
||||||
|
bf.close();
|
||||||
|
} catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class wordleDict
|
||||||
|
{
|
||||||
|
ArrayList <dictWord> dict;
|
||||||
|
String yellowLetters;
|
||||||
|
|
||||||
|
public wordleDict()
|
||||||
|
{
|
||||||
|
yellowLetters = "";
|
||||||
|
dict = new ArrayList<dictWord>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRandomWord(Random numGen)
|
||||||
|
{
|
||||||
|
return dict.get(numGen.nextInt(dict.size())).getWord();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addWord(String newWord, HashMap<Character, Integer> letterScores)
|
||||||
|
{
|
||||||
|
dictWord newDictWord = new dictWord(newWord, letterScores);
|
||||||
|
dict.add(newDictWord);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBestWord()
|
||||||
|
{
|
||||||
|
sortWords();
|
||||||
|
return dict.get(0).getWord();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sortWords()
|
||||||
|
{
|
||||||
|
Collections.sort(dict);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void calculateWordScores()
|
||||||
|
{
|
||||||
|
if(yellowLetters.equals(""))
|
||||||
|
return;
|
||||||
|
|
||||||
|
for(dictWord word : dict)
|
||||||
|
{
|
||||||
|
word.calculateYellowScore(yellowLetters);
|
||||||
|
}
|
||||||
|
yellowLetters = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void greenCullWords(int index, char letter)
|
||||||
|
{
|
||||||
|
ArrayList<dictWord> removalList = new ArrayList<dictWord>();
|
||||||
|
for(dictWord word : dict)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(word.getWord().charAt(index) != letter)
|
||||||
|
{
|
||||||
|
removalList.add(word);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dict.removeAll(removalList);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void yellowCullWords(int index, char letter)
|
||||||
|
{
|
||||||
|
ArrayList<dictWord> removalList = new ArrayList<dictWord>();
|
||||||
|
if(index > -1)
|
||||||
|
{
|
||||||
|
yellowLetters += letter;
|
||||||
|
for(dictWord word : dict)
|
||||||
|
{
|
||||||
|
if(word.getWord().charAt(index) == letter)
|
||||||
|
{
|
||||||
|
removalList.add(word);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(dictWord word : dict)
|
||||||
|
{
|
||||||
|
if(word.getWord().contains(letter + ""))
|
||||||
|
{
|
||||||
|
removalList.add(word);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dict.removeAll(removalList);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
String output = "";
|
||||||
|
for(dictWord word : dict)
|
||||||
|
{
|
||||||
|
output += word.toString() + "\n";
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear()
|
||||||
|
{
|
||||||
|
dict.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
words
|
||||||
Reference in New Issue
Block a user