diff --git a/pom.xml b/pom.xml
deleted file mode 100644
index 7e6a224..0000000
--- a/pom.xml
+++ /dev/null
@@ -1,153 +0,0 @@
-
-
- 4.0.0
- main
- TwoDee
- 4.0.1
-
-
-
-
- org.codehaus.mojo
- exec-maven-plugin
- 1.6.0
-
- discord.TwoDee
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
-
-
- 8
-
-
-
-
- maven-assembly-plugin
-
-
-
- discord.TwoDee
-
-
-
- jar-with-dependencies
-
-
-
-
-
-
-
-
-
- jitpack.io
- https://jitpack.io
-
-
-
-
-
-
- org.codehaus.mojo
- exec-maven-plugin
- 1.6.0
-
-
-
-
- com.fasterxml.jackson.core
- jackson-databind
- 2.9.6
-
-
-
- org.javacord
- javacord
- 3.0.0
- pom
-
-
-
-
- com.google.api-client
- google-api-client
- 1.23.0
-
-
-
- com.google.oauth-client
- google-oauth-client-jetty
- 1.23.0
-
-
-
- com.google.apis
- google-api-services-sheets
- v4-rev539-1.23.0
-
-
-
-
- com.esotericsoftware.yamlbeans
- yamlbeans
- 1.06
-
-
- org.junit.jupiter
- junit-jupiter-api
- 5.0.3
- test
-
-
- org.junit.platform
- junit-platform-commons
- 1.3.0
- compile
-
-
- org.apache.commons
- commons-lang3
- 3.4
-
-
-
- de.btobastian.sdcf4j
- sdcf4j-core
- v1.0.10
-
-
-
- de.btobastian.sdcf4j
-
- sdcf4j-javacord
- v1.0.10
-
-
-
- com.vdurmont
- emoji-java
- 4.0.0
-
-
-
-
diff --git a/src/main/java/logic/DiceRoller.java b/src/main/java/logic/DiceRoller.java
index 336868f..3528b3b 100644
--- a/src/main/java/logic/DiceRoller.java
+++ b/src/main/java/logic/DiceRoller.java
@@ -47,7 +47,7 @@ public EmbedBuilder generateResults(MessageAuthor author) {
//Sum up total
int total = getTotal(topTwo, plotResult);
//Build embed
- return buildResultEmbed(author, diceResults, pdResults, random, topTwo, dropped, total);
+ return buildResultEmbed(author, diceResults, pdResults, topTwo, dropped, total);
}
private int getPlotResult(ArrayList pdResults) {
@@ -60,7 +60,7 @@ private int getPlotResult(ArrayList pdResults) {
return plotResult;
}
- private EmbedBuilder buildResultEmbed(MessageAuthor author, ArrayList diceResults, ArrayList pdResults, Random random, ArrayList topTwo, ArrayList dropped, int total) {
+ private EmbedBuilder buildResultEmbed(MessageAuthor author, ArrayList diceResults, ArrayList pdResults, ArrayList topTwo, ArrayList dropped, int total) {
return new EmbedBuilder()
.setTitle(TwoDee.getRollTitleMessage())
.setAuthor(author)
diff --git a/src/main/java/logic/SnackCommand.java b/src/main/java/logic/SnackCommand.java
index e637508..e3ebf52 100644
--- a/src/main/java/logic/SnackCommand.java
+++ b/src/main/java/logic/SnackCommand.java
@@ -3,6 +3,8 @@
import org.javacord.api.entity.message.MessageAuthor;
import org.javacord.api.entity.message.embed.EmbedBuilder;
+import java.awt.image.BufferedImage;
+
public class SnackCommand {
private MessageAuthor author;
@@ -17,6 +19,6 @@ public EmbedBuilder dispenseSnack(){
.setAuthor(author)
.setTitle("A snack for " + author.getDisplayName())
.setDescription("Here is a cookie!")
- .setImage("");
+ .setImage("https://upload.wikimedia.org/wikipedia/commons/5/5c/Choc-Chip-Cookie.png");
}
}
diff --git a/src/main/java/logic/StatisticsGenerator.java b/src/main/java/logic/StatisticsGenerator.java
deleted file mode 100644
index ba4632c..0000000
--- a/src/main/java/logic/StatisticsGenerator.java
+++ /dev/null
@@ -1,224 +0,0 @@
-package logic;
-
-import discord.TwoDee;
-import org.javacord.api.entity.message.MessageAuthor;
-import org.javacord.api.entity.message.embed.EmbedBuilder;
-import statistics.DiceResult;
-
-import java.awt.*;
-import java.text.DecimalFormat;
-import java.util.*;
-
-public class StatisticsGenerator {
-
- private ArrayList resultList = new ArrayList<>();
- private HashMap statisticsMap;
- private HashMap doomMap;
- private boolean validCombo = false;
- private boolean overloaded = false;
-
- public ArrayList getDiceList() {
- return diceList;
- }
-
- private ArrayList diceList;
-
- public ArrayList getPlotDice() {
- return plotDice;
- }
-
- private ArrayList plotDice;
-
- public StatisticsGenerator(String message) {
- //Add all of the dice to the ArrayLists based on dice type
- diceList = new ArrayList<>();
- plotDice = new ArrayList<>();
- ArrayList args = new ArrayList<>(Arrays.asList(message.split(" ")));
- DiceParameterHandler diceParameterHandler = new DiceParameterHandler(args, diceList, plotDice);
- diceParameterHandler.addDiceToPools();
-
- //Check if command is valid
- if (!(diceList.isEmpty() && plotDice.isEmpty())){
- validCombo = true;
- }
- else {
- return;
- }
- if (diceList.size() + plotDice.size() > 6){
- overloaded = true;
- return;
- }
- generateResults(diceList, plotDice);
-
- HashMap resultHash = generateStatisticsTable();
- statisticsMap = generateProbabilityHash(diceList, plotDice, resultHash);
-
- HashMap doomHash = generateDoomChance();
- doomMap = generateProbabilityHash(diceList, plotDice, doomHash);
- }
-
- //Generate a HashMap with the roll as the keys and the percent as the values
- private HashMap generateProbabilityHash(ArrayList diceList, ArrayList plotDice, HashMap resultHash) {
- int totalCombos = getTotalCombos(diceList, plotDice);
- HashMap probHash = new HashMap<>();
- for (Object o : resultHash.entrySet()) {
- Map.Entry pair = (Map.Entry) o;
- probHash.put((Integer) pair.getKey(), (Integer)pair.getValue() / (double)totalCombos * 100);
- }
- return probHash;
- }
-
- //Get the total number of combinations by finding the product of all of the number of faces in all of the dice
- private int getTotalCombos(ArrayList diceList, ArrayList plotDice) {
- int totalCombos = 1;
- for (int combo : diceList) {
- totalCombos *= combo;
- }
-
- /*Plot dice have a minimum value of the die size / 2
- //This means that you need to divide it by two and add one to get the number of combinations from it if the
- value is greater than 2 */
- for (int pdCombo : plotDice) {
- if (pdCombo > 2){
- totalCombos *= pdCombo / 2 + 1 ;
- }
- }
- return totalCombos;
- }
-
- public static void main(String[] args) {
- new StatisticsGenerator("d10 d12 d12");
- }
-
- private HashMap generateDoomChance(){
- //Add information to a hashmap
- HashMap doomHash = new HashMap<>();
- for (DiceResult result: resultList) {
- int key = result.getDoom();
- if (!doomHash.containsKey(key)){
- doomHash.put(key, 1);
- }
- else {
- doomHash.put(key, doomHash.get(key) + 1);
- }
- }
- return doomHash;
- }
-
- /**
- * Generate a HashMap with keys of a number being rolled with the values as the number of combinations that would
- * result in that roll
- */
- private HashMap generateStatisticsTable() {
- //Add information to a hashmap
- HashMap resultHash = new HashMap<>();
- for (DiceResult result: resultList) {
- int key = result.getResult();
- if (!resultHash.containsKey(key)){
- resultHash.put(key, 1);
- }
- else {
- resultHash.put(key, resultHash.get(key) + 1);
- }
- }
- return resultHash;
- }
-
- //Prep method for generateResults to copy the dice list to prevent it from being modified
- private void generateResults(ArrayList diceList, ArrayList plotDice){
- ArrayList diceListCopy = new ArrayList<>(diceList);
- generateResults(diceListCopy, plotDice, new DiceResult());
- }
-
- //Recursive method to generate an ArrayList of results
- private void generateResults(ArrayList diceList, ArrayList plotDice, DiceResult result){
- if (diceList.isEmpty()){
- generatePDResults(plotDice, result);
- }
- else {
- ArrayList diceListCopy = new ArrayList<>(diceList);
- int diceNum = diceListCopy.remove(0);
- for (int i = 1; i <= diceNum; i++){
- DiceResult resultCopy = result.copy();
- resultCopy.addDiceToResult(i);
- generateResults(diceListCopy, plotDice, resultCopy);
- }
- }
- }
-
- //Recursive method for handling plot dice
- private void generatePDResults(ArrayList plotDice, DiceResult result){
- if (plotDice.isEmpty()){
- resultList.add(result);
- }
- else {
- ArrayList diceListCopy = new ArrayList<>(plotDice);
- int diceNum = diceListCopy.remove(0);
- for (int i = diceNum / 2; i <= diceNum; i++){
- DiceResult resultCopy = result.copy();
- resultCopy.addPlotDice(i);
- generatePDResults(diceListCopy, resultCopy);
- }
- }
- }
-
- //Generates a message that combines the probability of possible rolls and the probability of making a difficulty
- public EmbedBuilder generateStatistics(MessageAuthor author){
- if (overloaded){
- return new EmbedBuilder().setTitle("That's way too many dice for me to handle. Try using less dice.");
- }
- if (!validCombo){
- return new EmbedBuilder().setTitle("I can't find any dice in your command. Try again.");
- }
- String result = generateIndividualStatistics(statisticsMap);
- String difficulties = generateMeetingDifficulty();
- String doom = generateIndividualStatistics(doomMap);
-
- Random random = new Random();
- return new EmbedBuilder()
- .setTitle(TwoDee.getRollTitleMessage())
- .setAuthor(author)
- .setColor(new Color(random.nextFloat() , random.nextFloat(), random.nextFloat()))
- .addField("Chance to roll a", result, true)
- .addField("Chance to meet", difficulties, true)
- .addField("Chance to generate doom", doom, true);
- }
-
- //Loop through HashMap, check for rolls greater than difficulty, and sum their values to calculate the chance of
- //beating that difficulty. Rounds the probability to 4 decimal places.
- private String generateMeetingDifficulty() {
- StringBuilder result = new StringBuilder();
- DecimalFormat df = new DecimalFormat("0.##");
- String[] difficultyNames = {"Easy", "Average", "Hard", "Formidable", "Heroic", "Incredible", "Ridiculous", "Impossible"};
- int[] difficulty = {3, 7, 11, 15, 19, 23, 27, 31};
- double[] prob = new double[8];
- String[] probString = new String[8];
- for (int i = 0; i < difficulty.length; i++) {
- prob[i] = 0.0;
- for (Object o : statisticsMap.entrySet()) {
- Map.Entry pair = (Map.Entry) o;
- if (difficulty[i] <= (Integer) pair.getKey()){
- prob[i] += (double) pair.getValue();
- }
- }
- probString[i] = df.format(prob[i]);
- }
- for (int i = 0; i < difficultyNames.length; i++){
- result.append(difficultyNames[i]).append(": ").append(probString[i]).append("%\n");
- }
- return result.toString();
- }
-
- //Generate the probability of each possible roll and rounds it to two decimal places.
- private String generateIndividualStatistics(HashMap map) {
- //Iterate through HashMap to generate message
- StringBuilder result = new StringBuilder();
- for (Object o : map.entrySet()) {
- Map.Entry pair = (Map.Entry) o;
- DecimalFormat df = new DecimalFormat("0.#####");
- String roundedChance = df.format(Double.valueOf(pair.getValue().toString()));
- result.append(pair.getKey()).append(": ").append(roundedChance).append("%\n");
- }
- return result.toString();
- }
-}
diff --git a/src/test/java/StatisticsTest.java b/src/test/java/StatisticsTest.java
index 41bfca0..8770bed 100644
--- a/src/test/java/StatisticsTest.java
+++ b/src/test/java/StatisticsTest.java
@@ -1,21 +1,20 @@
-import logic.StatisticsGenerator;
+import org.javacord.api.entity.message.embed.EmbedBuilder;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
+import statistics.StatisticsContext;
public class StatisticsTest {
- private StatisticsGenerator generator;
+ private StatisticsContext generator;
@BeforeEach
public void setUp(){
- generator = new StatisticsGenerator("d10 2d12 pd10 pd12");
+ generator = new StatisticsContext("d10 2d12 pd10 pd12");
}
@Test
public void correctLists(){
- assertEquals(generator.getDiceList().size(), 3);
- assertEquals(generator.getPlotDice().size(), 2);
+ EmbedBuilder embed = generator.execute();
+ System.out.println(embed);
}
}