]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - test/knight.c
ncurses 5.9 - patch 20130112
[ncurses.git] / test / knight.c
index 2835cd8b8d4689707dc07de372b6ef1c38b304ba..91c1ba36bbb805d5523e42376b16e10a624331c5 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2008,2010 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2012,2013 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -33,7 +33,7 @@
  * Eric S. Raymond <esr@snark.thyrsus.com> July 22 1995.  Mouse support
  * added September 20th 1995.
  *
- * $Id: knight.c,v 1.32 2012/11/17 23:46:31 tom Exp $
+ * $Id: knight.c,v 1.34 2013/01/13 00:40:33 tom Exp $
  */
 
 #include <test.priv.h>
@@ -123,9 +123,9 @@ init_program(void)
        (void) init_pair(PLUS_COLOR, (short) COLOR_RED, (short) bg);
        (void) init_pair(MINUS_COLOR, (short) COLOR_GREEN, (short) bg);
 
-       trail |= COLOR_PAIR(TRAIL_COLOR);
-       plus |= COLOR_PAIR(PLUS_COLOR);
-       minus |= COLOR_PAIR(MINUS_COLOR);
+       trail |= (chtype) COLOR_PAIR(TRAIL_COLOR);
+       plus |= (chtype) COLOR_PAIR(PLUS_COLOR);
+       minus |= (chtype) COLOR_PAIR(MINUS_COLOR);
     }
 #ifdef NCURSES_MOUSE_VERSION
     (void) mousemask(BUTTON1_CLICKED, (mmask_t *) NULL);
@@ -300,7 +300,7 @@ mark_possibles(int prow, int pcol, chtype mark)
     }
 }
 
-static void
+static bool
 find_next_move(int *y, int *x)
 {
     unsigned j, k;
@@ -309,6 +309,7 @@ find_next_move(int *y, int *x)
     int next = 0;
     int oldy, oldx;
     int newy, newx;
+    bool result = FALSE;
 
     if (movecount > 1) {
        oldy = history[movecount - 1].y;
@@ -335,9 +336,27 @@ find_next_move(int *y, int *x)
            *y = oldy + offsets[next].y;
            *x = oldx + offsets[next].x;
        }
-    } else {
-       beep();
+       result = TRUE;
     }
+    return result;
+}
+
+static void
+count_next_moves(int y, int x)
+{
+    int count = 0;
+    unsigned j;
+
+    wprintw(msgwin, "\nMove %d", movecount);
+    for (j = 0; j < SIZEOF(offsets); j++) {
+       int newy = y + offsets[j].y;
+       int newx = x + offsets[j].x;
+       if (chksqr(newy, newx)) {
+           ++count;
+       }
+    }
+    wprintw(msgwin, ", gives %d choices", count);
+    wclrtoeol(msgwin);
 }
 
 static void
@@ -652,7 +671,10 @@ play(void)
            case 'a':
                nx = col;
                ny = rw;
-               find_next_move(&ny, &nx);
+               if (find_next_move(&ny, &nx))
+                   count_next_moves(ny, nx);
+               else
+                   beep();
                break;
 
            case 'F':