working web

This commit is contained in:
foo 2016-12-18 20:55:35 +00:00
parent 947dd5fcd9
commit 790bdf144e
4 changed files with 114 additions and 20 deletions

31
Makefile Executable file
View File

@ -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

22
war/about.html Executable file
View File

@ -0,0 +1,22 @@
<html>
<head>
<title>About</title>
</head>
<body>
<h1>Wordsearch Builder: About</h1>
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.
<h2>Basic algorithm</h2>
<ol>
<li>Foreach word
<ol>
<li>Pick a direction at random</li>
<li>Compute possible start points based on word length, direction and grid size</li>
<li>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.</li>
</ol>
</li>
<li>When all words are placed, infill the remaining cells with random characters weighted by <a href="https://www.math.cornell.edu/~mec/2003-2004/cryptography/subs/frequencies.html">standard English letter frequencies</a></li>
</ol>
The abort-and-retry word placement to try 500 times before giving up.
</body>
</html>

View File

@ -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;
}
</style>
</head>
<%@ 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 = "";
%>
<body>
<h1>Wordsearch builder</h1>
<h2>Words</h2>
<div style="float: right; padding: 15px;">
<ul>
<% for (String word : words) { %>
<li><%= word.trim() %></li>
<% } %>
</ul>
<a id='csvdownload'>Download CSV</a>
<script>
var csv = '<%= csv %>';
var csvdownload = document.getElementById('csvdownload');
csvdownload.href='data:text/csv;base64,' + btoa(csv);
</script>
</div>
<h2>Grid</h2>
<table style="font-family: monospace; font-size: 16;">
<% for(char[] row : grid) { %>
<tr>
<% for(char c : row) { %>
<td><%= c %></td>
<% } %>
</tr>
<% } %>
</table>
<div id="wrapper">
<div id="wordsearch">
<h2>Grid</h2>
<table id="grid">
<% for(char[] row : grid) { %>
<tr>
<% for(char c : row) {
csv += "" + c + ',';
%>
<td><%= c %></td>
<% } %>
</tr>
<%
csv += "\\n";
}
%>
</table>
</div> <!-- end wordsearch -->
<div id="words">
<h2>Words</h2>
<ul>
<% for (String word : words) { %>
<li><%= word.trim() %></li>
<% } %>
</ul>
</div> <!-- end words -->
</div> <!-- end wrapper -->
<br />
<div>
</body>
</html>

View File

@ -2,8 +2,10 @@
<head><title>Wordsearch builder</title></head>
<body>
<h1>Wordsearch builder</h1>
<a href="about.html">About</a>
<h2>Words</h2>
<form action="build.jsp">
<form action="build.jsp" method="post">
<textarea name="words" rows="10">
Kitchen
Lounge