From c0fc2eb3a13da21c5f0e740fbf8729984f77c1ba Mon Sep 17 00:00:00 2001 From: Holly Jones Date: Sun, 14 Apr 2024 22:04:07 -0500 Subject: [PATCH] Just comments --- src/main/java/uta/cse3310/Board_Create | 67 +++++++++++++++++++++---- src/main/java/uta/cse3310/WordList.java | 31 ++++++++---- 2 files changed, 78 insertions(+), 20 deletions(-) diff --git a/src/main/java/uta/cse3310/Board_Create b/src/main/java/uta/cse3310/Board_Create index 5597404..520496b 100644 --- a/src/main/java/uta/cse3310/Board_Create +++ b/src/main/java/uta/cse3310/Board_Create @@ -1,43 +1,90 @@ package uta.cse3310; +/** + * Board assigns each word in Wordlist to an index in the word search. + * Also has attributes: + * Orientation - Enum class with all directions a word could be in (public so it can be reused in other classes) + * Density - total density of the word search + * Randomness - array with the density of words in each orientation (uses EnumMap for faster accessing and usability) + * Min_Letters - idk I haven't used it yet + * Handle - idk + */ public class Board_Create { - public float Density; + public enum Orientation { VERT_UP, VERT_DOWN, HORIZ, DIAG_UP, DIAG_DOWN } - // Not initializing might be an issue? - public EnumMap Randomness = new EnumMap<>(Orientation.class); + public float Density; // Store word grid's density so it can be displayed on HTML + + // Array holding the sum of valid words for each orientation + // Requirement: Each sum/ttl slots >= 0.15 + // EG: Randomness[VERT_UP] = 15; The ttl number of chars in that orientation + // : total_slots = 45; + // (cont): Randomness[VERT_UP]/total_slots == 15/45 + // Requirement: public so that it can be displayed in the HTML + public EnumMap Randomness = new EnumMap<>(Orientation.class); public int Min_Letters; public String Handle; // ??? private double MIN_GRID_DENSITY = 0.67; - private int board_size; - private char[][] grid; + private int board_size; // assuming the board is 50x50 (rows=cols), then board_size = 50; + private char[][] grid; // character grid to return in order to play the game + private int total_slots; Board_Create(){ // fill grid with periods to maybe regex match better board_size = 50; + total_slots = 50*50; grid[50][50] = '.'; Randomness[5] = 0; Density = 0; } + // Might not be needed, but just in case we need a word search NOT 50x50... Board_Create(int size){ board_size = size; grid[size][size] = '.'; Randomness[] = 0; Density = 0; } - public int create_grid(){ - // Fetch words between max grid size & 3 letters + public int create_grid(){ + // Some musts: + // Empty slots will be filled with '.' (Allows regex to find words that match params) + // slots filled/total slots >= 0.67 + /* Algorithm Idea + 1. Fetch words of different lengths from [3..board_size]. (or to max_word_size if we wanna define that) + ArrayList options = WordList.list_words(); + + (START LOOP) + 2. Choose an orientation. + assign_direction(); + 3. Stringify a random row/col/diag + 4a. Use WordList.find_word(stringified_row/col/diag) to find a word that can fit inside + A/N: WordList.find_word() can return: + a) the matching word, the index to insert it in + b) a copy of the stringified_row/col/diag with the word inserted <-- Probably this tbh + c) nothing and do the insertion itself + 4b. Insert word if there is a substring of all dots the same length as the word + 5. Meets density requirements? + no) keep looping + yes) go to next step + (END LOOP) + 6. Find all empty spots & fill them in + */ - // return 1; } - public void assign_direction(){ - case + /** Assign each direction in order + Example: previous word was given the HORIZ + the next word should NOT be HORIZ, it CAN be any of the other orientations + + ... or maybe assign based on density + */ + public Orientation assign_direction(){ + // changed from void to Orientation + return VERT_UP; } public boolean validate_word(){ return true; diff --git a/src/main/java/uta/cse3310/WordList.java b/src/main/java/uta/cse3310/WordList.java index e206e51..0f40889 100644 --- a/src/main/java/uta/cse3310/WordList.java +++ b/src/main/java/uta/cse3310/WordList.java @@ -6,14 +6,21 @@ import java.io.IOException; import java.util.Scanner; -/** Fetches words from wordlist. */ +/** + * Fetches words from wordlist. + * Attributes: + * Words - an array with random word with different lengths + */ public class WordList { public ArrayList Words = new ArrayList(); + /** + * WordOptions - extra options for Words so we don't have to reopen the word file + */ private ArrayList WordOptions = new ArrayList(); - private int max_word_options; + private int max_word_options; // We don't want to keep too much in memory private int MIN_LETTERS = 3; - private int MAX_LETTERS; + private int MAX_LETTERS; // Can be line length but most English words aren't more than 10 letters WordList(){ MAX_LETTERS = 50; @@ -22,23 +29,27 @@ public class WordList { MAX_LETTERS = grid_size; } + /** + * Populates Words and WordOptions + * @param total_slots + */ public void list_words(int total_slots){ - // Open word list - + // Open file while ((Words.size()/total_slots) < 0.67){ Words.add(word_picker()); } + // Close file } - /** Maybe query WordOptions with specific conditions? like 1st letter == 'A' */ - public String word_picker(){ + /** Takes file and fetches a certain number of words to store in Words/WordOptions */ + private String word_picker(){ return "test"; } - /** Takes file and fetches a certain number of words to store in memory */ - private void valid_words(){ - + /** Maybe query WordOptions with specific conditions? like 1st letter == 'A' */ + public String find_word(String regex_string){ + return "test"; } }