From 790bdf144ea31a1fc5f1f4d9fa90ed086520e458 Mon Sep 17 00:00:00 2001 From: foo Date: Sun, 18 Dec 2016 20:55:35 +0000 Subject: [PATCH] working web --- Makefile | 31 ++++++++++++++++++++ war/about.html | 22 +++++++++++++++ war/build.jsp | 77 +++++++++++++++++++++++++++++++++++++------------- war/index.jsp | 4 ++- 4 files changed, 114 insertions(+), 20 deletions(-) create mode 100755 Makefile create mode 100755 war/about.html diff --git a/Makefile b/Makefile new file mode 100755 index 0000000..332549c --- /dev/null +++ b/Makefile @@ -0,0 +1,31 @@ +JAVA = /usr/bin/java +# JAVAFLAGS = -version # -classpath $(LIBS) +JAVAC = /usr/bin/javac +JFLAGS = -g # -classpath $(LIBS) + +SRCS = uk/org/mafoo/wordsearch/GridFactory.java \ + uk/org/mafoo/wordsearch/Bounds.java \ + uk/org/mafoo/wordsearch/CouldNotPlaceWordException.java \ + uk/org/mafoo/wordsearch/Direction.java \ + uk/org/mafoo/wordsearch/DistributedRandomNumberGenerator.java + +OBJS = ${SRCS:.java=.class} + +.SUFFIXES: .java .class + +all: build wordsearch.jar + +run: all + $(JAVA) uk.org.mafoo.wordsearch.GridFactory 10 10 + +.java.class: + $(JAVAC) $(JFLAGS) $< + +build: $(OBJS) + +clean: + rm -f $(OBJS) wordsearch.jar wordsearch.war + +wordsearch.jar: build + jar cf $@ $(OBJS) + cp wordsearch.jar war/WEB-INF/lib diff --git a/war/about.html b/war/about.html new file mode 100755 index 0000000..a49f653 --- /dev/null +++ b/war/about.html @@ -0,0 +1,22 @@ + + + About + + + +

Wordsearch Builder: About

+ Wordsearch Builder takes a list of words and places them on a grid in any direction allowing the to cross-over where possible then fills in the remaining empty spaces with semi-random letters. +

Basic algorithm

+
    +
  1. Foreach word +
      +
    1. Pick a direction at random
    2. +
    3. Compute possible start points based on word length, direction and grid size
    4. +
    5. Begin placing word. If an occupied cell is encountered which contains a different character than would go in for this word, then abort and start this word again.
    6. +
    +
  2. +
  3. When all words are placed, infill the remaining cells with random characters weighted by standard English letter frequencies
  4. +
+ The abort-and-retry word placement to try 500 times before giving up. + + \ No newline at end of file diff --git a/war/build.jsp b/war/build.jsp index f07358e..299e845 100755 --- a/war/build.jsp +++ b/war/build.jsp @@ -7,10 +7,28 @@ border-collapse: collapse; padding: 2px 4px; } + + #grid { + font-family: monospace; font-size: 16; + } + + #wrapper { + width: 80%; + margin: 0 auto; + } + #wordsearch { + float: left; + } + + #words { + float: right; + width: 200px; + } <%@ page import="uk.org.mafoo.wordsearch.*" %> <%@ page import="java.util.*" %> +<%@ page import="org.apache.commons.lang.StringUtils" %> <%@ page errorPage="error.jsp" %> <% @@ -24,31 +42,52 @@ for ( String line : request.getParameter("words").split("\r\n")) { words.add(line.trim()); } - + Collections.sort(words); + + char[][] grid = GridFactory.makeGrid(words, height, width); + + String csv = ""; %>

Wordsearch builder

-

Words

- -
- +Download CSV +
-

Grid

- -<% for(char[] row : grid) { %> - - <% for(char c : row) { %> - - <% } %> - -<% } %> -
<%= c %>
+
+
+

Grid

+ + <% for(char[] row : grid) { %> + + <% for(char c : row) { + csv += "" + c + ','; + %> + + <% } %> + + <% + csv += "\\n"; + } + %> +
<%= c %>
+
+
+

Words

+
    + <% for (String word : words) { %> +
  • <%= word.trim() %>
  • + <% } %> +
+
+
+
+
diff --git a/war/index.jsp b/war/index.jsp index 85b8808..8e81840 100755 --- a/war/index.jsp +++ b/war/index.jsp @@ -2,8 +2,10 @@ Wordsearch builder

Wordsearch builder

+About +

Words

-
+