mirror of
				https://github.com/fooflington/wordsearch.git
				synced 2025-11-03 22:09:03 +00:00 
			
		
		
		
	Compare commits
	
		
			10 Commits
		
	
	
		
			20170417-1
			...
			more-modes
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 6e2767e066 | |||
| f7b05f3183 | |||
| e44b5356ab | |||
| 
						 | 
					f869de337f | ||
| 21c558950c | |||
| 
						 | 
					7d313a6baf | ||
| 
						 | 
					cce371ecb4 | ||
| 
						 | 
					d8a0ed6f5a | ||
| 
						 | 
					b02ef52f65 | ||
| 
						 | 
					cc2c7eee29 | 
							
								
								
									
										0
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										0
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										
										
										Normal file → Executable file
									
								
							
							
								
								
									
										31
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								Makefile
									
									
									
									
									
								
							@@ -1,31 +0,0 @@
 | 
				
			|||||||
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 30 30
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.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
 | 
					 | 
				
			||||||
							
								
								
									
										91
									
								
								counties.txt
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										91
									
								
								counties.txt
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,91 @@
 | 
				
			|||||||
 | 
					Aberdeenshire
 | 
				
			||||||
 | 
					Anglesey
 | 
				
			||||||
 | 
					Angus
 | 
				
			||||||
 | 
					Antrim
 | 
				
			||||||
 | 
					Argyll
 | 
				
			||||||
 | 
					Armagh
 | 
				
			||||||
 | 
					Ayrshire
 | 
				
			||||||
 | 
					Banffshire
 | 
				
			||||||
 | 
					Bedfordshire
 | 
				
			||||||
 | 
					Berkshire
 | 
				
			||||||
 | 
					Berwickshire
 | 
				
			||||||
 | 
					Brecknockshire
 | 
				
			||||||
 | 
					Buckinghamshire
 | 
				
			||||||
 | 
					Buteshire
 | 
				
			||||||
 | 
					Caernarfonshire
 | 
				
			||||||
 | 
					Caithness
 | 
				
			||||||
 | 
					Cambridgeshire
 | 
				
			||||||
 | 
					Cardiganshire
 | 
				
			||||||
 | 
					Carmarthenshire
 | 
				
			||||||
 | 
					Cheshire
 | 
				
			||||||
 | 
					Clackmannanshire
 | 
				
			||||||
 | 
					Cornwall
 | 
				
			||||||
 | 
					Cromartyshire
 | 
				
			||||||
 | 
					Cumberland
 | 
				
			||||||
 | 
					Denbighshire
 | 
				
			||||||
 | 
					Derbyshire
 | 
				
			||||||
 | 
					Devon
 | 
				
			||||||
 | 
					Dorset
 | 
				
			||||||
 | 
					Down
 | 
				
			||||||
 | 
					Dumbartonshire
 | 
				
			||||||
 | 
					Dumfriesshire
 | 
				
			||||||
 | 
					Durham
 | 
				
			||||||
 | 
					East Lothian
 | 
				
			||||||
 | 
					Essex
 | 
				
			||||||
 | 
					Fermanagh
 | 
				
			||||||
 | 
					Fife
 | 
				
			||||||
 | 
					Flintshire
 | 
				
			||||||
 | 
					Glamorgan
 | 
				
			||||||
 | 
					Gloucestershire
 | 
				
			||||||
 | 
					Hampshire
 | 
				
			||||||
 | 
					Herefordshire
 | 
				
			||||||
 | 
					Hertfordshire
 | 
				
			||||||
 | 
					Huntingdonshire
 | 
				
			||||||
 | 
					Invernessshire
 | 
				
			||||||
 | 
					Kent
 | 
				
			||||||
 | 
					Kincardineshire
 | 
				
			||||||
 | 
					Kirkcudbrightshire
 | 
				
			||||||
 | 
					Lanarkshire
 | 
				
			||||||
 | 
					Lancashire
 | 
				
			||||||
 | 
					Leicestershire
 | 
				
			||||||
 | 
					Lincolnshire
 | 
				
			||||||
 | 
					Londonderry
 | 
				
			||||||
 | 
					Merionethshire
 | 
				
			||||||
 | 
					Middlesex
 | 
				
			||||||
 | 
					Midlothian
 | 
				
			||||||
 | 
					Monmouthshire
 | 
				
			||||||
 | 
					Montgomeryshire
 | 
				
			||||||
 | 
					Morayshire
 | 
				
			||||||
 | 
					Nairnshire
 | 
				
			||||||
 | 
					Norfolk
 | 
				
			||||||
 | 
					Northamptonshire
 | 
				
			||||||
 | 
					Northumberland
 | 
				
			||||||
 | 
					Nottinghamshire
 | 
				
			||||||
 | 
					Orkney
 | 
				
			||||||
 | 
					Oxfordshire
 | 
				
			||||||
 | 
					Peeblesshire
 | 
				
			||||||
 | 
					Pembrokeshire
 | 
				
			||||||
 | 
					Perthshire
 | 
				
			||||||
 | 
					Radnorshire
 | 
				
			||||||
 | 
					Renfrewshire
 | 
				
			||||||
 | 
					Rossshire
 | 
				
			||||||
 | 
					Roxburghshire
 | 
				
			||||||
 | 
					Rutland
 | 
				
			||||||
 | 
					Selkirkshire
 | 
				
			||||||
 | 
					Shetland
 | 
				
			||||||
 | 
					Shropshire
 | 
				
			||||||
 | 
					Somerset
 | 
				
			||||||
 | 
					Staffordshire
 | 
				
			||||||
 | 
					Stirlingshire
 | 
				
			||||||
 | 
					Suffolk
 | 
				
			||||||
 | 
					Surrey
 | 
				
			||||||
 | 
					Sussex
 | 
				
			||||||
 | 
					Sutherland
 | 
				
			||||||
 | 
					Tyrone
 | 
				
			||||||
 | 
					Warwickshire
 | 
				
			||||||
 | 
					West Lothian
 | 
				
			||||||
 | 
					Westmorland
 | 
				
			||||||
 | 
					Wigtownshire
 | 
				
			||||||
 | 
					Wiltshire
 | 
				
			||||||
 | 
					Worcestershire
 | 
				
			||||||
 | 
					Yorkshire
 | 
				
			||||||
							
								
								
									
										12
									
								
								src/Makefile
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								src/Makefile
									
									
									
									
									
								
							@@ -1,12 +0,0 @@
 | 
				
			|||||||
CC=gcc
 | 
					 | 
				
			||||||
CFLAGS=-DDEBUG_GRID_MAIN -std=c99 -g
 | 
					 | 
				
			||||||
DEPS=dir.o rnd.o grid.o
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
wordsearch: $(DEPS)
 | 
					 | 
				
			||||||
	$(CC) -o wordsearch $(DEPS) $(CFLAGS)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
%.o: %.c 
 | 
					 | 
				
			||||||
	$(CC) -c -o $@ $< $(CFLAGS)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
clean:
 | 
					 | 
				
			||||||
	rm $(DEPS)
 | 
					 | 
				
			||||||
							
								
								
									
										39
									
								
								src/dir.c
									
									
									
									
									
								
							
							
						
						
									
										39
									
								
								src/dir.c
									
									
									
									
									
								
							@@ -1,39 +0,0 @@
 | 
				
			|||||||
#include "dir.h"
 | 
					 | 
				
			||||||
#include "rnd.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
int directions[] = {
 | 
					 | 
				
			||||||
	DIRECTION_N,
 | 
					 | 
				
			||||||
	DIRECTION_NE,
 | 
					 | 
				
			||||||
	DIRECTION_E,
 | 
					 | 
				
			||||||
	DIRECTION_SE,
 | 
					 | 
				
			||||||
	DIRECTION_S,
 | 
					 | 
				
			||||||
	DIRECTION_SW,
 | 
					 | 
				
			||||||
	DIRECTION_W,
 | 
					 | 
				
			||||||
	DIRECTION_NW
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
int get_direction(int simple)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	if (simple) {
 | 
					 | 
				
			||||||
		if (random_number(0, 1) == 0) {
 | 
					 | 
				
			||||||
			return DIRECTION_E;
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			return DIRECTION_S;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		return directions[random_number(0, NUM_DIRECTIONS)];
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef DEBUG_DIR_MAIN
 | 
					 | 
				
			||||||
#include <stdio.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
int main()
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	int n = 32;
 | 
					 | 
				
			||||||
	while (--n > 0) {
 | 
					 | 
				
			||||||
		printf("%d\n", get_direction(1));
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return 0;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
							
								
								
									
										19
									
								
								src/dir.h
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								src/dir.h
									
									
									
									
									
								
							@@ -1,19 +0,0 @@
 | 
				
			|||||||
#ifndef WORDSEARCH_DIR
 | 
					 | 
				
			||||||
#define WORDSEARCH_DIR
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
enum direction {
 | 
					 | 
				
			||||||
	DIRECTION_N,
 | 
					 | 
				
			||||||
	DIRECTION_NE,
 | 
					 | 
				
			||||||
	DIRECTION_E,
 | 
					 | 
				
			||||||
	DIRECTION_SE,
 | 
					 | 
				
			||||||
	DIRECTION_S,
 | 
					 | 
				
			||||||
	DIRECTION_SW,
 | 
					 | 
				
			||||||
	DIRECTION_W,
 | 
					 | 
				
			||||||
	DIRECTION_NW
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define NUM_DIRECTIONS 8
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
int get_direction(int simple);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
							
								
								
									
										197
									
								
								src/grid.c
									
									
									
									
									
								
							
							
						
						
									
										197
									
								
								src/grid.c
									
									
									
									
									
								
							@@ -1,197 +0,0 @@
 | 
				
			|||||||
#include <stdlib.h>
 | 
					 | 
				
			||||||
#include <stdio.h>
 | 
					 | 
				
			||||||
#include <string.h>
 | 
					 | 
				
			||||||
#include <stdarg.h>
 | 
					 | 
				
			||||||
#include <ctype.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include "rnd.h"
 | 
					 | 
				
			||||||
#include "dir.h"
 | 
					 | 
				
			||||||
#include "grid.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
enum exitcodes {
 | 
					 | 
				
			||||||
	EXIT_WORDTOOLONG,
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
bounds *get_bounds(int height, int width, enum direction direction, int length)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	if (length > height || length > width) {
 | 
					 | 
				
			||||||
		return NULL;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	length--;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	bounds *b = (bounds *) malloc(sizeof(bounds));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	b->min_x = 0;
 | 
					 | 
				
			||||||
	b->max_x = width-1;
 | 
					 | 
				
			||||||
	b->min_y = 0;
 | 
					 | 
				
			||||||
	b->max_y = height-1;
 | 
					 | 
				
			||||||
	if (direction == DIRECTION_N ||
 | 
					 | 
				
			||||||
	    direction == DIRECTION_NE || direction == DIRECTION_NW) {
 | 
					 | 
				
			||||||
		b->min_y = length;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (direction == DIRECTION_W ||
 | 
					 | 
				
			||||||
	    direction == DIRECTION_NW || direction == DIRECTION_SW) {
 | 
					 | 
				
			||||||
		b->min_x = length;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (direction == DIRECTION_E ||
 | 
					 | 
				
			||||||
	    direction == DIRECTION_NE || direction == DIRECTION_SE) {
 | 
					 | 
				
			||||||
		b->max_x = width - length;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (direction == DIRECTION_S ||
 | 
					 | 
				
			||||||
	    direction == DIRECTION_SW || direction == DIRECTION_SE) {
 | 
					 | 
				
			||||||
		b->max_y = height - length;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return b;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
int move_x(int x, enum direction d) {
 | 
					 | 
				
			||||||
	if(
 | 
					 | 
				
			||||||
			d == DIRECTION_E  ||
 | 
					 | 
				
			||||||
			d == DIRECTION_NE ||
 | 
					 | 
				
			||||||
			d == DIRECTION_SE
 | 
					 | 
				
			||||||
	  ) {
 | 
					 | 
				
			||||||
		x++;
 | 
					 | 
				
			||||||
	} else if (
 | 
					 | 
				
			||||||
			d == DIRECTION_W  ||
 | 
					 | 
				
			||||||
			d == DIRECTION_NW ||
 | 
					 | 
				
			||||||
			d == DIRECTION_SW
 | 
					 | 
				
			||||||
		  ) {
 | 
					 | 
				
			||||||
		x--;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return x;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
int move_y(int y, enum direction d) {
 | 
					 | 
				
			||||||
	if(
 | 
					 | 
				
			||||||
			d == DIRECTION_N  ||
 | 
					 | 
				
			||||||
			d == DIRECTION_NE ||
 | 
					 | 
				
			||||||
			d == DIRECTION_NW
 | 
					 | 
				
			||||||
	  ) {
 | 
					 | 
				
			||||||
		y--;
 | 
					 | 
				
			||||||
	} else if (
 | 
					 | 
				
			||||||
			d == DIRECTION_S  ||
 | 
					 | 
				
			||||||
			d == DIRECTION_SE ||
 | 
					 | 
				
			||||||
			d == DIRECTION_SW
 | 
					 | 
				
			||||||
		  ) {
 | 
					 | 
				
			||||||
		y++;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return y;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
char **make_grid(char **words, int height, int width, int simple, int count)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	char **grid = init_grid(NULL, height, width);
 | 
					 | 
				
			||||||
	for(int i=0; i<count; i++) {
 | 
					 | 
				
			||||||
		int tries = 0;
 | 
					 | 
				
			||||||
		int placed = 0;
 | 
					 | 
				
			||||||
		while(tries++ < WORDSEARCH_MAXTRIES && placed == 0) {
 | 
					 | 
				
			||||||
			if(place_word(words[i], grid, height, width, simple)) {
 | 
					 | 
				
			||||||
				placed = 1;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return grid;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
int place_word(char *word, char **grid, int height, int width, int simple)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	int dir = get_direction(simple);
 | 
					 | 
				
			||||||
	bounds *b;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (b = get_bounds(height, width, dir, strlen(word))) {
 | 
					 | 
				
			||||||
		/* word will probably fit... */
 | 
					 | 
				
			||||||
		int x, y;
 | 
					 | 
				
			||||||
		x = random_number(b->min_x, b->max_x);
 | 
					 | 
				
			||||||
		y = random_number(b->min_y, b->max_y);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		char** tempgrid = init_grid(grid, height, width);
 | 
					 | 
				
			||||||
		/* Now we have two copies of the grid, try to place the word... */
 | 
					 | 
				
			||||||
		int i;
 | 
					 | 
				
			||||||
		for(i=0; i<strlen(word); i++) {
 | 
					 | 
				
			||||||
			if(!isalpha(word[i])) continue;
 | 
					 | 
				
			||||||
			if(tempgrid[y][x] != '_') {
 | 
					 | 
				
			||||||
				if(tempgrid[y][x] != word[i]) {
 | 
					 | 
				
			||||||
					/* Failed to place word */
 | 
					 | 
				
			||||||
					free_grid(tempgrid, height);
 | 
					 | 
				
			||||||
					return 0;
 | 
					 | 
				
			||||||
				} else {
 | 
					 | 
				
			||||||
					/* word crossed ok! */
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			} else {
 | 
					 | 
				
			||||||
				tempgrid[y][x] = word[i];
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			x = move_x(x, dir);
 | 
					 | 
				
			||||||
			y = move_y(y, dir);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		free_grid(grid, height);
 | 
					 | 
				
			||||||
		free(b);
 | 
					 | 
				
			||||||
		grid = tempgrid;
 | 
					 | 
				
			||||||
		return 1;
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		/* word can't fit */
 | 
					 | 
				
			||||||
		printf("[ERR] Word too long to place in this grid: %s\n", word);
 | 
					 | 
				
			||||||
		exit(EXIT_WORDTOOLONG);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Clones or creates an empty grid - pass NULL in as old to get an empty grid */
 | 
					 | 
				
			||||||
char **init_grid(char** old, int height, int width)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	int row, cell;
 | 
					 | 
				
			||||||
	char **new = malloc(height * sizeof(char*));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	for (row=0; row < height; row++) {
 | 
					 | 
				
			||||||
		new[row] = malloc(width * sizeof(char));
 | 
					 | 
				
			||||||
		for (cell=0; cell < width; cell++) {
 | 
					 | 
				
			||||||
			if(old) {
 | 
					 | 
				
			||||||
				new[row][cell] = old[row][cell];
 | 
					 | 
				
			||||||
			} else {
 | 
					 | 
				
			||||||
				new[row][cell] = '_';
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}	
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return new;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void free_grid(char** grid, int height) {
 | 
					 | 
				
			||||||
	for (int i=0; i<height; i++) {
 | 
					 | 
				
			||||||
		free(grid[i]);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	free(grid);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void print_grid(char** grid, int height) {
 | 
					 | 
				
			||||||
	for(int i=0; i<height; i++) {
 | 
					 | 
				
			||||||
		if(grid[i] == NULL) {
 | 
					 | 
				
			||||||
			printf("row error\n");
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			printf("%s\n", grid[i]);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef DEBUG_GRID_MAIN
 | 
					 | 
				
			||||||
#include <stdio.h>
 | 
					 | 
				
			||||||
int main()
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	char *words[4] = {
 | 
					 | 
				
			||||||
		"test",
 | 
					 | 
				
			||||||
		"word",
 | 
					 | 
				
			||||||
		"longer",
 | 
					 | 
				
			||||||
		"verylong"
 | 
					 | 
				
			||||||
	};
 | 
					 | 
				
			||||||
	char **grid = make_grid(words, 10, 10, 0, 4);
 | 
					 | 
				
			||||||
	print_grid(grid, 4);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
							
								
								
									
										26
									
								
								src/grid.h
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								src/grid.h
									
									
									
									
									
								
							@@ -1,26 +0,0 @@
 | 
				
			|||||||
#ifndef WORDSEARCH_GRID
 | 
					 | 
				
			||||||
#define WORDSEARCH_GRID
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define WORDSEARCH_MAXTRIES 500
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
char **make_grid(char **words, int height, int width, int simple, int count);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef struct bounds {
 | 
					 | 
				
			||||||
	int min_y;
 | 
					 | 
				
			||||||
	int max_y;
 | 
					 | 
				
			||||||
	int min_x;
 | 
					 | 
				
			||||||
	int max_x;
 | 
					 | 
				
			||||||
} bounds;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* returns NULL if cannot fit word; caller needs to free() the response */
 | 
					 | 
				
			||||||
bounds *get_bounds(int height, int width, enum direction direction, int length);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
int place_word(char *word, char **grid, int height, int width, int simple);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
char **init_grid(char** old, int height, int width);
 | 
					 | 
				
			||||||
void free_grid(char** grid, int height);
 | 
					 | 
				
			||||||
int move_x(int x, enum direction d);
 | 
					 | 
				
			||||||
int move_y(int y, enum direction d);
 | 
					 | 
				
			||||||
void print_grid(char** grid, int height);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
							
								
								
									
										90
									
								
								src/rnd.c
									
									
									
									
									
								
							
							
						
						
									
										90
									
								
								src/rnd.c
									
									
									
									
									
								
							@@ -1,90 +0,0 @@
 | 
				
			|||||||
#include <stdlib.h>
 | 
					 | 
				
			||||||
#include <stdio.h>
 | 
					 | 
				
			||||||
#include <time.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include "rnd.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 /* https://www.math.cornell.edu/~mec/2003-2004/cryptography/subs/frequencies.html */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define ALPHABET_SIZE 26
 | 
					 | 
				
			||||||
#define RND_MAXINT 10000
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
struct letter_frequency {
 | 
					 | 
				
			||||||
	int p;			/* pegged to 10000 rather than 1 */
 | 
					 | 
				
			||||||
	char c;
 | 
					 | 
				
			||||||
} letter_frequencies[] = {
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
	7, 'Z'}, {
 | 
					 | 
				
			||||||
	10, 'J'}, {
 | 
					 | 
				
			||||||
	11, 'Q'}, {
 | 
					 | 
				
			||||||
	17, 'X'}, {
 | 
					 | 
				
			||||||
	69, 'K'}, {
 | 
					 | 
				
			||||||
	111, 'V'}, {
 | 
					 | 
				
			||||||
	149, 'B'}, {
 | 
					 | 
				
			||||||
	182, 'P'}, {
 | 
					 | 
				
			||||||
	203, 'G'}, {
 | 
					 | 
				
			||||||
	209, 'W'}, {
 | 
					 | 
				
			||||||
	211, 'Y'}, {
 | 
					 | 
				
			||||||
	230, 'F'}, {
 | 
					 | 
				
			||||||
	261, 'M'}, {
 | 
					 | 
				
			||||||
	271, 'C'}, {
 | 
					 | 
				
			||||||
	288, 'U'}, {
 | 
					 | 
				
			||||||
	398, 'L'}, {
 | 
					 | 
				
			||||||
	432, 'D'}, {
 | 
					 | 
				
			||||||
	592, 'H'}, {
 | 
					 | 
				
			||||||
	602, 'R'}, {
 | 
					 | 
				
			||||||
	628, 'S'}, {
 | 
					 | 
				
			||||||
	695, 'N'}, {
 | 
					 | 
				
			||||||
	731, 'I'}, {
 | 
					 | 
				
			||||||
	768, 'O'}, {
 | 
					 | 
				
			||||||
	812, 'A'}, {
 | 
					 | 
				
			||||||
	910, 'T'}, {
 | 
					 | 
				
			||||||
1202, 'E'},};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* from http://stackoverflow.com/questions/822323/how-to-generate-a-random-number-in-c */
 | 
					 | 
				
			||||||
int random_number(int min_num, int max_num)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	static int initialised = 0;
 | 
					 | 
				
			||||||
	int result = 0;
 | 
					 | 
				
			||||||
	int low_num = 0;
 | 
					 | 
				
			||||||
	int hi_num = 0;
 | 
					 | 
				
			||||||
	if (min_num < max_num) {
 | 
					 | 
				
			||||||
		low_num = min_num;
 | 
					 | 
				
			||||||
		hi_num = max_num + 1;	// this is done to include max_num in output.
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		low_num = max_num + 1;	// this is done to include max_num in output.
 | 
					 | 
				
			||||||
		hi_num = min_num;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if (!initialised) {
 | 
					 | 
				
			||||||
		srand(time(NULL));
 | 
					 | 
				
			||||||
		initialised = 1;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	result = (rand() % (hi_num - low_num)) + low_num;
 | 
					 | 
				
			||||||
	return result;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
char get_random_letter()
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	int rnd = random_number(0, RND_MAXINT);
 | 
					 | 
				
			||||||
	for (int i = 0; i < ALPHABET_SIZE; i++) {
 | 
					 | 
				
			||||||
		if (rnd < letter_frequencies[i].p) {
 | 
					 | 
				
			||||||
			return letter_frequencies[i].c;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		rnd -= letter_frequencies[i].p;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return '\0';
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef DEBUG_RND_MAIN
 | 
					 | 
				
			||||||
#include <stdio.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
int main()
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	int n = 32;
 | 
					 | 
				
			||||||
	while (--n > 0) {
 | 
					 | 
				
			||||||
		printf("%c", get_random_letter());
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return 0;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
@@ -1,7 +0,0 @@
 | 
				
			|||||||
#ifndef WORDSEARCH_RND
 | 
					 | 
				
			||||||
#define WORDSEARCH_RND
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
char get_random_letter();
 | 
					 | 
				
			||||||
int random_number(int min_num, int max_num);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
							
								
								
									
										52
									
								
								tags
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										52
									
								
								tags
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,52 @@
 | 
				
			|||||||
 | 
					!_TAG_FILE_FORMAT	2	/extended format; --format=1 will not append ;" to lines/
 | 
				
			||||||
 | 
					!_TAG_FILE_SORTED	1	/0=unsorted, 1=sorted, 2=foldcase/
 | 
				
			||||||
 | 
					!_TAG_PROGRAM_AUTHOR	Darren Hiebert	/dhiebert@users.sourceforge.net/
 | 
				
			||||||
 | 
					!_TAG_PROGRAM_NAME	Exuberant Ctags	//
 | 
				
			||||||
 | 
					!_TAG_PROGRAM_URL	http://ctags.sourceforge.net	/official site/
 | 
				
			||||||
 | 
					!_TAG_PROGRAM_VERSION	5.9~svn20110310	//
 | 
				
			||||||
 | 
					Bounds	uk/org/mafoo/wordsearch/Bounds.java	/^	protected Bounds(int min_y, int max_y, int min_x, int max_x) {$/;"	m	class:Bounds
 | 
				
			||||||
 | 
					Bounds	uk/org/mafoo/wordsearch/Bounds.java	/^class Bounds {$/;"	c
 | 
				
			||||||
 | 
					CouldNotPlaceWordException	uk/org/mafoo/wordsearch/CouldNotPlaceWordException.java	/^	protected CouldNotPlaceWordException() {$/;"	m	class:CouldNotPlaceWordException
 | 
				
			||||||
 | 
					CouldNotPlaceWordException	uk/org/mafoo/wordsearch/CouldNotPlaceWordException.java	/^class CouldNotPlaceWordException extends Exception {$/;"	c
 | 
				
			||||||
 | 
					Direction	uk/org/mafoo/wordsearch/Direction.java	/^enum Direction { N, NE, E, SE, S, SW, W, NW; };$/;"	g
 | 
				
			||||||
 | 
					DistributedRandomNumberGenerator	uk/org/mafoo/wordsearch/DistributedRandomNumberGenerator.java	/^    public DistributedRandomNumberGenerator() {$/;"	m	class:DistributedRandomNumberGenerator
 | 
				
			||||||
 | 
					DistributedRandomNumberGenerator	uk/org/mafoo/wordsearch/DistributedRandomNumberGenerator.java	/^public class DistributedRandomNumberGenerator {$/;"	c
 | 
				
			||||||
 | 
					E	uk/org/mafoo/wordsearch/Direction.java	/^enum Direction { N, NE, E, SE, S, SW, W, NW; };$/;"	e	enum:Direction	file:
 | 
				
			||||||
 | 
					GridFactory	uk/org/mafoo/wordsearch/GridFactory.java	/^public class GridFactory {$/;"	c
 | 
				
			||||||
 | 
					MAX_TRIES	uk/org/mafoo/wordsearch/GridFactory.java	/^	static final int MAX_TRIES = 500;$/;"	f	class:GridFactory
 | 
				
			||||||
 | 
					N	uk/org/mafoo/wordsearch/Direction.java	/^enum Direction { N, NE, E, SE, S, SW, W, NW; };$/;"	e	enum:Direction	file:
 | 
				
			||||||
 | 
					NE	uk/org/mafoo/wordsearch/Direction.java	/^enum Direction { N, NE, E, SE, S, SW, W, NW; };$/;"	e	enum:Direction	file:
 | 
				
			||||||
 | 
					NW	uk/org/mafoo/wordsearch/Direction.java	/^enum Direction { N, NE, E, SE, S, SW, W, NW; };$/;"	e	enum:Direction	file:
 | 
				
			||||||
 | 
					S	uk/org/mafoo/wordsearch/Direction.java	/^enum Direction { N, NE, E, SE, S, SW, W, NW; };$/;"	e	enum:Direction	file:
 | 
				
			||||||
 | 
					SE	uk/org/mafoo/wordsearch/Direction.java	/^enum Direction { N, NE, E, SE, S, SW, W, NW; };$/;"	e	enum:Direction	file:
 | 
				
			||||||
 | 
					SW	uk/org/mafoo/wordsearch/Direction.java	/^enum Direction { N, NE, E, SE, S, SW, W, NW; };$/;"	e	enum:Direction	file:
 | 
				
			||||||
 | 
					W	uk/org/mafoo/wordsearch/Direction.java	/^enum Direction { N, NE, E, SE, S, SW, W, NW; };$/;"	e	enum:Direction	file:
 | 
				
			||||||
 | 
					addNumber	uk/org/mafoo/wordsearch/DistributedRandomNumberGenerator.java	/^    public void addNumber(int value, double distribution) {$/;"	m	class:DistributedRandomNumberGenerator
 | 
				
			||||||
 | 
					chars	uk/org/mafoo/wordsearch/GridFactory.java	/^	private static char[] chars = new char[] {$/;"	f	class:GridFactory	file:
 | 
				
			||||||
 | 
					clone2d	uk/org/mafoo/wordsearch/GridFactory.java	/^	private static char[][] clone2d(char[][] source) {$/;"	m	class:GridFactory	file:
 | 
				
			||||||
 | 
					directions	uk/org/mafoo/wordsearch/GridFactory.java	/^	private static Direction[] directions = new Direction[] { Direction.N, Direction.NE, Direction.E, Direction.SE, Direction.S, Direction.SW, Direction.W, Direction.NW };$/;"	f	class:GridFactory	file:
 | 
				
			||||||
 | 
					distSum	uk/org/mafoo/wordsearch/DistributedRandomNumberGenerator.java	/^    private double distSum;$/;"	f	class:DistributedRandomNumberGenerator	file:
 | 
				
			||||||
 | 
					distribution	uk/org/mafoo/wordsearch/DistributedRandomNumberGenerator.java	/^    private HashMap<Integer, Double> distribution;$/;"	f	class:DistributedRandomNumberGenerator	file:
 | 
				
			||||||
 | 
					drng	uk/org/mafoo/wordsearch/GridFactory.java	/^	static DistributedRandomNumberGenerator drng = new DistributedRandomNumberGenerator();$/;"	f	class:GridFactory
 | 
				
			||||||
 | 
					dump2d	uk/org/mafoo/wordsearch/GridFactory.java	/^	private static void dump2d(char[][] g) {$/;"	m	class:GridFactory	file:
 | 
				
			||||||
 | 
					getBounds	uk/org/mafoo/wordsearch/GridFactory.java	/^	private static Bounds getBounds(int height, int width, Direction direction, int length) {$/;"	m	class:GridFactory	file:
 | 
				
			||||||
 | 
					getDirection	uk/org/mafoo/wordsearch/GridFactory.java	/^	private static Direction getDirection(boolean simple) {$/;"	m	class:GridFactory	file:
 | 
				
			||||||
 | 
					getDistributedRandomNumber	uk/org/mafoo/wordsearch/DistributedRandomNumberGenerator.java	/^    public int getDistributedRandomNumber() {$/;"	m	class:DistributedRandomNumberGenerator
 | 
				
			||||||
 | 
					getRandomChar	uk/org/mafoo/wordsearch/GridFactory.java	/^	private static char getRandomChar() {$/;"	m	class:GridFactory	file:
 | 
				
			||||||
 | 
					main	uk/org/mafoo/wordsearch/GridFactory.java	/^	public static void main(String[] args) throws IOException {$/;"	m	class:GridFactory
 | 
				
			||||||
 | 
					makeGrid	uk/org/mafoo/wordsearch/GridFactory.java	/^	public static char[][] makeGrid(List<String> words, int height, int width) {$/;"	m	class:GridFactory
 | 
				
			||||||
 | 
					makeGrid	uk/org/mafoo/wordsearch/GridFactory.java	/^	public static char[][] makeGrid(List<String> words, int height, int width, boolean simple) {$/;"	m	class:GridFactory
 | 
				
			||||||
 | 
					max_x	uk/org/mafoo/wordsearch/Bounds.java	/^	int max_x;$/;"	f	class:Bounds
 | 
				
			||||||
 | 
					max_y	uk/org/mafoo/wordsearch/Bounds.java	/^	int max_y;$/;"	f	class:Bounds
 | 
				
			||||||
 | 
					min_x	uk/org/mafoo/wordsearch/Bounds.java	/^	int min_x;$/;"	f	class:Bounds
 | 
				
			||||||
 | 
					min_y	uk/org/mafoo/wordsearch/Bounds.java	/^	int min_y;$/;"	f	class:Bounds
 | 
				
			||||||
 | 
					move_x	uk/org/mafoo/wordsearch/GridFactory.java	/^	private static int move_x(int x, Direction d) {$/;"	m	class:GridFactory	file:
 | 
				
			||||||
 | 
					move_y	uk/org/mafoo/wordsearch/GridFactory.java	/^	private static int move_y(int y, Direction d) {$/;"	m	class:GridFactory	file:
 | 
				
			||||||
 | 
					placeWord	uk/org/mafoo/wordsearch/GridFactory.java	/^	private static char[][] placeWord(String word, char[][] grid, boolean simple) throws CouldNotPlaceWordException {$/;"	m	class:GridFactory	file:
 | 
				
			||||||
 | 
					rnd	uk/org/mafoo/wordsearch/GridFactory.java	/^	static Random rnd = new Random();$/;"	f	class:GridFactory
 | 
				
			||||||
 | 
					toString	uk/org/mafoo/wordsearch/Bounds.java	/^	public String toString() {$/;"	m	class:Bounds
 | 
				
			||||||
 | 
					uk.org.mafoo.wordsearch	uk/org/mafoo/wordsearch/Bounds.java	/^package uk.org.mafoo.wordsearch;$/;"	p
 | 
				
			||||||
 | 
					uk.org.mafoo.wordsearch	uk/org/mafoo/wordsearch/CouldNotPlaceWordException.java	/^package uk.org.mafoo.wordsearch;$/;"	p
 | 
				
			||||||
 | 
					uk.org.mafoo.wordsearch	uk/org/mafoo/wordsearch/Direction.java	/^package uk.org.mafoo.wordsearch;$/;"	p
 | 
				
			||||||
 | 
					uk.org.mafoo.wordsearch	uk/org/mafoo/wordsearch/DistributedRandomNumberGenerator.java	/^package uk.org.mafoo.wordsearch;$/;"	p
 | 
				
			||||||
 | 
					uk.org.mafoo.wordsearch	uk/org/mafoo/wordsearch/GridFactory.java	/^package uk.org.mafoo.wordsearch;$/;"	p
 | 
				
			||||||
							
								
								
									
										0
									
								
								uk/org/mafoo/wordsearch/Direction.java
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										0
									
								
								uk/org/mafoo/wordsearch/Direction.java
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							@@ -61,8 +61,8 @@ public class GridFactory {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private static Direction[] directions = new Direction[] { Direction.N, Direction.NE, Direction.E, Direction.SE, Direction.S, Direction.SW, Direction.W, Direction.NW };
 | 
						private static Direction[] directions = new Direction[] { Direction.N, Direction.NE, Direction.E, Direction.SE, Direction.S, Direction.SW, Direction.W, Direction.NW };
 | 
				
			||||||
	private static Direction getDirection(boolean simple) {
 | 
						private static Direction getDirection(Modes mode) {
 | 
				
			||||||
		if(simple) {
 | 
							if(mode == Modes.SIMPLE || mode == Modes.CROSSWORD) {
 | 
				
			||||||
			return rnd.nextBoolean() ? Direction.E : Direction.S;
 | 
								return rnd.nextBoolean() ? Direction.E : Direction.S;
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			return directions[rnd.nextInt(directions.length-1)];
 | 
								return directions[rnd.nextInt(directions.length-1)];
 | 
				
			||||||
@@ -166,7 +166,7 @@ public class GridFactory {
 | 
				
			|||||||
			int tries = 0;
 | 
								int tries = 0;
 | 
				
			||||||
			while(true) {
 | 
								while(true) {
 | 
				
			||||||
				try {
 | 
									try {
 | 
				
			||||||
					grid = placeWord(word, grid, simple);
 | 
										grid = placeWord(word, grid, mode);
 | 
				
			||||||
					break;
 | 
										break;
 | 
				
			||||||
				} catch (CouldNotPlaceWordException e) {
 | 
									} catch (CouldNotPlaceWordException e) {
 | 
				
			||||||
					if(tries > MAX_TRIES) {
 | 
										if(tries > MAX_TRIES) {
 | 
				
			||||||
@@ -180,8 +180,8 @@ public class GridFactory {
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Fill rest of grid
 | 
							if(mode != Modes.CROSSWORD) {
 | 
				
			||||||
		if(fill) {
 | 
								// Fill rest of grid
 | 
				
			||||||
			for (int y=0; y<height; y++) {
 | 
								for (int y=0; y<height; y++) {
 | 
				
			||||||
				for (int x=0; x<width; x++) {
 | 
									for (int x=0; x<width; x++) {
 | 
				
			||||||
					if (grid[y][x] == Character.UNASSIGNED) 
 | 
										if (grid[y][x] == Character.UNASSIGNED) 
 | 
				
			||||||
@@ -194,8 +194,8 @@ public class GridFactory {
 | 
				
			|||||||
		return grid;
 | 
							return grid;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private static char[][] placeWord(String word, char[][] grid, boolean simple) throws CouldNotPlaceWordException {
 | 
						private static char[][] placeWord(String word, char[][] grid, Modes mode) throws CouldNotPlaceWordException {
 | 
				
			||||||
		Direction direction = getDirection(simple);
 | 
							Direction direction = getDirection(mode);
 | 
				
			||||||
		Bounds b = getBounds(grid.length, grid[0].length, direction, word.length());
 | 
							Bounds b = getBounds(grid.length, grid[0].length, direction, word.length());
 | 
				
			||||||
		// System.out.println("[" + word + "] bounds: " + b);
 | 
							// System.out.println("[" + word + "] bounds: " + b);
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
@@ -205,6 +205,7 @@ public class GridFactory {
 | 
				
			|||||||
		// System.out.println("[" + word + "] Placing @ " + x + "," + y + " going " + direction);
 | 
							// System.out.println("[" + word + "] Placing @ " + x + "," + y + " going " + direction);
 | 
				
			||||||
		char[][] tempgrid = clone2d(grid);
 | 
							char[][] tempgrid = clone2d(grid);
 | 
				
			||||||
		for( char c : word.toUpperCase().toCharArray() ) {
 | 
							for( char c : word.toUpperCase().toCharArray() ) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if(!Character.isLetter(c)) continue;
 | 
								if(!Character.isLetter(c)) continue;
 | 
				
			||||||
			if(grid[y][x] != Character.UNASSIGNED) {
 | 
								if(grid[y][x] != Character.UNASSIGNED) {
 | 
				
			||||||
				if (grid[y][x] != c) {
 | 
									if (grid[y][x] != c) {
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										7
									
								
								uk/org/mafoo/wordsearch/Modes.java
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										7
									
								
								uk/org/mafoo/wordsearch/Modes.java
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,7 @@
 | 
				
			|||||||
 | 
					package uk.org.mafoo.wordsearch;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public enum Modes {
 | 
				
			||||||
 | 
						NORMAL,
 | 
				
			||||||
 | 
						SIMPLE,
 | 
				
			||||||
 | 
						CROSSWORD;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										22
									
								
								uk/org/mafoo/wordsearch/Store.java
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										22
									
								
								uk/org/mafoo/wordsearch/Store.java
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,22 @@
 | 
				
			|||||||
 | 
					package uk.org.mafoo.wordsearch;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.sql.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class Store {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Connection conn = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						protected Store(String dbfile) {
 | 
				
			||||||
 | 
							try {
 | 
				
			||||||
 | 
								Class.forName("org.sqlite.JDBC");
 | 
				
			||||||
 | 
						        conn = DriverManager.getConnection("jdbc:sqlite:" + dbfile);
 | 
				
			||||||
 | 
						    } catch ( Exception e ) {
 | 
				
			||||||
 | 
						        System.err.println( e.getClass().getName() + ": " + e.getMessage() );
 | 
				
			||||||
 | 
						        System.exit(1);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						protected storeInstance()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										28
									
								
								uk/org/mafoo/wordsearch/f
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										28
									
								
								uk/org/mafoo/wordsearch/f
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,28 @@
 | 
				
			|||||||
 | 
					Letter	Frequency
 | 
				
			||||||
 | 
					E	12.02
 | 
				
			||||||
 | 
					T	9.10
 | 
				
			||||||
 | 
					A	8.12
 | 
				
			||||||
 | 
					O	7.68
 | 
				
			||||||
 | 
					I	7.31
 | 
				
			||||||
 | 
					N	6.95
 | 
				
			||||||
 | 
					S	6.28
 | 
				
			||||||
 | 
					R	6.02
 | 
				
			||||||
 | 
					H	5.92
 | 
				
			||||||
 | 
					D	4.32
 | 
				
			||||||
 | 
					L	3.98
 | 
				
			||||||
 | 
					U	2.88
 | 
				
			||||||
 | 
					C	2.71
 | 
				
			||||||
 | 
					M	2.61
 | 
				
			||||||
 | 
					F	2.30
 | 
				
			||||||
 | 
					Y	2.11
 | 
				
			||||||
 | 
					W	2.09
 | 
				
			||||||
 | 
					G	2.03
 | 
				
			||||||
 | 
					P	1.82
 | 
				
			||||||
 | 
					B	1.49
 | 
				
			||||||
 | 
					V	1.11
 | 
				
			||||||
 | 
					K	0.69
 | 
				
			||||||
 | 
					X	0.17
 | 
				
			||||||
 | 
					Q	0.11
 | 
				
			||||||
 | 
					J	0.10
 | 
				
			||||||
 | 
					Z	0.07
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										16
									
								
								war/WEB-INF/jspf/footer.jspf
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										16
									
								
								war/WEB-INF/jspf/footer.jspf
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,16 @@
 | 
				
			|||||||
 | 
					<!-- Piwik -->
 | 
				
			||||||
 | 
					<script type="text/javascript">
 | 
				
			||||||
 | 
					  var _paq = _paq || [];
 | 
				
			||||||
 | 
					  // tracker methods like "setCustomDimension" should be called before "trackPageView"
 | 
				
			||||||
 | 
					  _paq.push(['trackPageView']);
 | 
				
			||||||
 | 
					  _paq.push(['enableLinkTracking']);
 | 
				
			||||||
 | 
					  (function() {
 | 
				
			||||||
 | 
					    var u="//mafoo.org.uk/piwik/";
 | 
				
			||||||
 | 
					    _paq.push(['setTrackerUrl', u+'piwik.php']);
 | 
				
			||||||
 | 
					    _paq.push(['setSiteId', '3']);
 | 
				
			||||||
 | 
					    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
 | 
				
			||||||
 | 
					    g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
 | 
				
			||||||
 | 
					  })();
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
 | 
					<noscript><p><img src="//mafoo.org.uk/piwik/piwik.php?idsite=3&rec=1" style="border:0;" alt="" /></p></noscript>
 | 
				
			||||||
 | 
					<!-- End Piwik Code -->
 | 
				
			||||||
							
								
								
									
										0
									
								
								war/WEB-INF/lib/commons-lang.jar
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										0
									
								
								war/WEB-INF/lib/commons-lang.jar
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
								
								
									
										0
									
								
								war/WEB-INF/lib/json-simple-1.1.1.jar
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										0
									
								
								war/WEB-INF/lib/json-simple-1.1.1.jar
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
								
								
									
										
											BIN
										
									
								
								war/WEB-INF/lib/sqlite-3.20.0.jar
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								war/WEB-INF/lib/sqlite-3.20.0.jar
									
									
									
									
									
										Executable file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								war/WEB-INF/lib/wordsearch.jar
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								war/WEB-INF/lib/wordsearch.jar
									
									
									
									
									
										Executable file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										0
									
								
								war/api.jsp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										0
									
								
								war/api.jsp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
								
								
									
										0
									
								
								war/base.css
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										0
									
								
								war/base.css
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							@@ -13,7 +13,11 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	int height = Integer.parseInt(request.getParameter("height"));
 | 
						int height = Integer.parseInt(request.getParameter("height"));
 | 
				
			||||||
	int width  = Integer.parseInt(request.getParameter("width"));
 | 
						int width  = Integer.parseInt(request.getParameter("width"));
 | 
				
			||||||
	boolean simple = request.getParameter("simple") != null;
 | 
						Modes mode = Modes.NORMAL;
 | 
				
			||||||
 | 
						if(request.getParameter("mode") != null) {
 | 
				
			||||||
 | 
							if(request.getParameter("mode").equals("SIMPLE")) mode = Modes.SIMPLE;
 | 
				
			||||||
 | 
							if(request.getParameter("mode").equals("CROSSWORD")) mode = Modes.CROSSWORD;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	String name = StringEscapeUtils.escapeHtml(request.getParameter("name"));
 | 
						String name = StringEscapeUtils.escapeHtml(request.getParameter("name"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (request.getParameter("words").length() > 2048) { throw new Exception("Input too large"); }
 | 
						if (request.getParameter("words").length() > 2048) { throw new Exception("Input too large"); }
 | 
				
			||||||
@@ -25,10 +29,11 @@
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
  	Collections.sort(words);
 | 
					  	Collections.sort(words);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  	char[][] grid = GridFactory.makeGrid(words, height, width, simple);
 | 
					  	char[][] grid = GridFactory.makeGrid(words, height, width, mode);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  	String csv = "";
 | 
					  	String csv = "";
 | 
				
			||||||
%>
 | 
					%>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<body>
 | 
					<body>
 | 
				
			||||||
<h1><%= name %></h1>
 | 
					<h1><%= name %></h1>
 | 
				
			||||||
<div class="noprint">
 | 
					<div class="noprint">
 | 
				
			||||||
@@ -50,7 +55,7 @@
 | 
				
			|||||||
			<% for(char c : row) { 
 | 
								<% for(char c : row) { 
 | 
				
			||||||
				csv += "" + c + ',';
 | 
									csv += "" + c + ',';
 | 
				
			||||||
			%>
 | 
								%>
 | 
				
			||||||
			<td class="cell"><%= c %></td>
 | 
								<td class="cell"><%= c != Character.UNASSIGNED ? c : " " %></td>
 | 
				
			||||||
			<% 	} %>
 | 
								<% 	} %>
 | 
				
			||||||
		</tr>
 | 
							</tr>
 | 
				
			||||||
	<% 
 | 
						<% 
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,7 +25,9 @@ Dining Room
 | 
				
			|||||||
	<br />
 | 
						<br />
 | 
				
			||||||
	<input type="number" name="height" min="3" max="50" value="15" />
 | 
						<input type="number" name="height" min="3" max="50" value="15" />
 | 
				
			||||||
	<input type="number" name="width" min="3" max="50" value="15" />
 | 
						<input type="number" name="width" min="3" max="50" value="15" />
 | 
				
			||||||
	<input type="checkbox" name="simple" value="yes">Simple [<span class="tooltip" title="In simple mode, words are only placed Left-to-Right or Top-to-Bottom">?</span>]</span>
 | 
						<input type="radio" name="mode" value="NORMAL" checked />Normal 
 | 
				
			||||||
 | 
						<input type="radio" name="mode" value="SIMPLE" />Simple[<span class="tooltip" title="In simple mode, words are only placed Left-to-Right or Top-to-Bottom">?</span>]
 | 
				
			||||||
 | 
						<input type="radio" name="mode" value="CROSSWORD" />Crossword
 | 
				
			||||||
	<input type="submit" value="Build!" />
 | 
						<input type="submit" value="Build!" />
 | 
				
			||||||
</form>
 | 
					</form>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										
											BIN
										
									
								
								wordsearch.jar
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								wordsearch.jar
									
									
									
									
									
										Executable file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								wordsearch.war
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								wordsearch.war
									
									
									
									
									
										Executable file
									
								
							
										
											Binary file not shown.
										
									
								
							
		Reference in New Issue
	
	Block a user