]> git.cworth.org Git - wordgame/commitdiff
Add grid5 game in addition to grid4
authorCarl Worth <cworth@raht.cworth.org>
Fri, 29 Sep 2006 04:26:59 +0000 (21:26 -0700)
committerCarl Worth <cworth@raht.cworth.org>
Fri, 29 Sep 2006 04:32:16 +0000 (21:32 -0700)
.gitignore
Makefile
grid.c
grid5.c [new file with mode: 0644]

index cbf8982f8d657cce88a39eea664a4f6d26f3995b..2e7b69f9b5573658cf367c438e88ca6e310c31d2 100644 (file)
@@ -1,6 +1,7 @@
 Makefile.dep
 drill2
 grid4
+grid5
 rack
 *.o
 *~
index d7441aa64aabbc65f8626d065ed20f314199e1d9..79c066c94253ba00f51bd9da43c4564453683e3e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
-WGCFLAGS=-Wall -Wextra -Wmissing-prototypes -Wno-unused-parameter
+WGCFLAGS=-Wall -Wextra -Wmissing-prototypes -Wno-unused-parameter -Wno-sign-compare
 
-PROGRAMS=grid4 drill2 rack
+PROGRAMS=grid4 grid5 drill2 rack
 all: $(PROGRAMS)
 
 LIBRARY=dict.o grid.o word-game.o
diff --git a/grid.c b/grid.c
index acfee21831118ef1f1c28df7d975639b1fcee0fb..273a6e83e765cb28c2ac291a17766e3ee1249b16 100644 (file)
--- a/grid.c
+++ b/grid.c
@@ -103,7 +103,7 @@ grid_string (grid_t *grid)
            else
                *s++ = ' ';
        }
-       if (y != 3)
+       if (y != (grid->size - 1))
            *s++ = '\n';
     }
     *s = '\0';
@@ -144,7 +144,10 @@ grid_enumerate (grid_t             *grid,
        dict_cursor = dict_cursor_next (dict_cursor, 'u');
     }
 
-    if (strlen (word) > 2 &&
+    /* For the 4x4 grid any word of length 3 or more counts.
+     * For the 5x5 grid any word of length 4 or more counts.
+     */
+    if (strlen (word) >= (grid->size - 1) &&
        DICT_ENTRY_IS_WORD (dict_cursor_resolve (dict_cursor)))
     {
        dict_add_word (grid->results, word);
diff --git a/grid5.c b/grid5.c
new file mode 100644 (file)
index 0000000..18c9b0b
--- /dev/null
+++ b/grid5.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright © 2006 Carl Worth
+ *
+ * This program is free software; you can redistribute it and\/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA."
+ */
+
+#include "grid.h"
+#include "word-game.h"
+
+#include <sys/time.h>
+#include <time.h>
+
+#define GAME_LENGTH (3 * 60)
+int
+main (void)
+{
+    dict_t dict, solution;
+    grid_t grid;
+    struct timeval tv;
+
+    gettimeofday (&tv, NULL);
+    srand (tv.tv_sec ^ tv.tv_usec);
+
+    dict_init (&dict);
+    dict_add_words_from_file (&dict, "words.txt");
+
+    grid_init (&grid, 5);
+
+    dict_init (&solution);
+    grid_solve (&grid, &dict, &solution);
+
+    word_game_play (grid_string (&grid),
+                   &dict, &solution, GAME_LENGTH);
+
+    dict_fini (&solution);
+    dict_fini (&dict);
+
+    return 0;
+}