Skip to content

Commit

Permalink
Merge pull request #53 from utastudents/luke
Browse files Browse the repository at this point in the history
Stats for grid making in terminal
  • Loading branch information
LToothbrush authored May 1, 2024
2 parents 0c3edfb + 435f293 commit cca761f
Show file tree
Hide file tree
Showing 28 changed files with 8,280 additions and 8,410 deletions.
65 changes: 52 additions & 13 deletions src/main/java/com/cse3310/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import java.util.ArrayList;
import java.util.Random;

public class Game {
public class Game
{

public int GameId;
public char[][] grid;
Expand All @@ -28,7 +29,8 @@ public Game(ArrayList<String> words, int GameId) {
this.grid = generateGrid(words, wordBank);
}

public int isEnd(int id) {
public int isEnd(int id)
{
for (int endId : endIds) {
if (id == endId) {
return 0;
Expand Down Expand Up @@ -105,11 +107,14 @@ public char[][] generateGrid(ArrayList<String> words, ArrayList<String> wordbank
int[][] directions = { { 1, 1 }, { -1, 1 }, { 0, 1 }, { -1, 0 }, { 1, 0 } };
double density = .67; // density of grid
int maxLength = 10;
float diagUp,diagDown,horizontals,vertUp,vertDown; // stats to see orientations
diagUp = diagDown = horizontals = vertUp = vertDown = 0;
// Input words into the array
// Take random words from the word list to put inside a word bank
int index = 0;
while (((double) validWordsLetters / (length * width)) < density) {

while (((double) validWordsLetters / (length * width)) < density)
{
//Grab a word and add it to a word length
String word = words.get(rand.nextInt(words.size())).toUpperCase();
while (word.length() > maxLength) {
word = words.get(rand.nextInt(words.size())).toUpperCase();
Expand All @@ -122,7 +127,7 @@ public char[][] generateGrid(ArrayList<String> words, ArrayList<String> wordbank
fits = true;
startX = rand.nextInt(length);
startY = rand.nextInt(width);
orientation = rand.nextInt(4);
orientation = rand.nextInt(5);
dX = directions[orientation][1];
dY = directions[orientation][0];
int secondCheck = 0;
Expand All @@ -147,8 +152,11 @@ public char[][] generateGrid(ArrayList<String> words, ArrayList<String> wordbank
}
}
}

} while (fits == false && tries < 100);
if (tries >= 100) {

if (tries >= 100)
{
fits = false;
wordBank.remove(index);
}
Expand All @@ -169,24 +177,53 @@ public char[][] generateGrid(ArrayList<String> words, ArrayList<String> wordbank

System.out.println("Start: " + startId + "\n" + "End: " + endId);


if(dY == 0)
{
horizontals++;
}
else if(dY == 1)
{
if(dX == 1)
diagUp++;
else
vertUp++;
}
else if(dY == -1)
{
if(dX == 1)
diagDown++;
else
vertDown++;
}
System.out.println(index + "." + wordBank.get(index));
validWordsLetters = validWordsLetters + wordBank.get(index).length();
index++;
}

}
System.out.println(" Actual Density: " + (double) validWordsLetters / (length * width));

System.out.println("Actual Density: " + (double)validWordsLetters / (length * width));
System.out.println("Upward Diagonals: " + (diagUp/index));
System.out.println("Downward Diagonals: " + (diagDown/index));
System.out.println("Horizontals: " + (horizontals/index));
System.out.println("Downward verticals: " + (vertDown/index));
System.out.println("Upward verticals:" + (vertUp/index));

// Fill in rest of the grid with random letters
// Print grid
// Print grid to console for debugging
for (int i = 0; i < width; i++) {
for (int j = 0; j < length; j++) {
if (grid[i][j] == 0) {
if (grid[i][j] == 0)
{

grid[i][j] = alphabet.charAt(rand.nextInt(alphabet.length()));
}

System.out.printf("" + grid[i][j] + "|");



System.out.printf("" + grid[i][j] + "|");


}
System.out.println();
}
Expand All @@ -197,6 +234,7 @@ public char[][] generateGrid(ArrayList<String> words, ArrayList<String> wordbank

}


public void checkWin(User user) {

}
Expand All @@ -209,3 +247,4 @@ public void Tick() {

}
}

Binary file removed target/classes/com/cse3310/App$LetterTimer.class
Binary file not shown.
Binary file removed target/classes/com/cse3310/App.class
Binary file not shown.
Binary file removed target/classes/com/cse3310/Error.class
Binary file not shown.
Binary file removed target/classes/com/cse3310/Game.class
Binary file not shown.
Binary file removed target/classes/com/cse3310/HttpServer$1.class
Binary file not shown.
Binary file removed target/classes/com/cse3310/HttpServer.class
Binary file not shown.
Binary file removed target/classes/com/cse3310/Lobby.class
Binary file not shown.
Binary file removed target/classes/com/cse3310/PlayerList.class
Binary file not shown.
Binary file removed target/classes/com/cse3310/ServerEvent.class
Binary file not shown.
Binary file removed target/classes/com/cse3310/User.class
Binary file not shown.
Binary file removed target/classes/com/cse3310/UserEvent.class
Binary file not shown.
Binary file removed target/classes/com/cse3310/Version.class
Binary file not shown.
Binary file removed target/classes/com/cse3310/Winner.class
Binary file not shown.
Binary file removed target/classes/com/cse3310/timerEvent.class
Binary file not shown.
Binary file removed target/cse3310-wordsearch.jar
Binary file not shown.
4 changes: 0 additions & 4 deletions target/maven-archiver/pom.properties

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

65 changes: 0 additions & 65 deletions target/surefire-reports/TEST-com.cse3310.AppTest.xml

This file was deleted.

62 changes: 0 additions & 62 deletions target/surefire-reports/TEST-com.cse3310.UserTest.xml

This file was deleted.

Loading

0 comments on commit cca761f

Please sign in to comment.