X-Git-Url: http://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fknight.c;h=604be1ec984fa81ab97d0ee5ad9c83e2ecdaa184;hp=f9ba1dc25bf083ea9ee73cdd40f5af87fec9c48c;hb=64f44b13d30e0a7bc2921a9d43755423f81564fd;hpb=8f527f87c0b979d9c2598ef5c3394463af288468 diff --git a/test/knight.c b/test/knight.c index f9ba1dc2..604be1ec 100644 --- a/test/knight.c +++ b/test/knight.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2006,2008 Free Software Foundation, Inc. * + * Copyright (c) 1998-2008,2010 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 July 22 1995. Mouse support * added September 20th 1995. * - * $Id: knight.c,v 1.28 2008/08/03 23:04:26 tom Exp $ + * $Id: knight.c,v 1.33 2012/12/09 00:14:28 tom Exp $ */ #include @@ -119,9 +119,9 @@ init_program(void) bg = -1; #endif - (void) init_pair(TRAIL_COLOR, COLOR_CYAN, bg); - (void) init_pair(PLUS_COLOR, COLOR_RED, bg); - (void) init_pair(MINUS_COLOR, COLOR_GREEN, bg); + (void) init_pair(TRAIL_COLOR, (short) COLOR_CYAN, (short) bg); + (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); @@ -155,8 +155,8 @@ help1(void) (void) waddstr(helpwin, "puzzle; also inform you when you run out\n"); (void) waddstr(helpwin, "of legal moves.\n\n"); - (void) mvwaddstr(helpwin, NOTIFYY - INSTRY, 0, - "Press `?' to go to keystroke help."); + MvWAddStr(helpwin, NOTIFYY - INSTRY, 0, + "Press `?' to go to keystroke help."); } static void @@ -181,8 +181,8 @@ help2(void) (void) waddstr(helpwin, "square with spacebar, Enter, or the keypad\n"); (void) waddstr(helpwin, "center key. Use F/B to review the path.\n"); - (void) mvwaddstr(helpwin, NOTIFYY - INSTRY, 0, - "Press `?' to go to game explanation"); + MvWAddStr(helpwin, NOTIFYY - INSTRY, 0, + "Press `?' to go to game explanation"); } static void @@ -226,7 +226,7 @@ dosquares(void) { int i, j; - mvaddstr(0, 20, "KNIGHT'S MOVE -- a logical solitaire"); + MvAddStr(0, 20, "KNIGHT'S MOVE -- a logical solitaire"); move(BOARDY, BOARDX); waddch(boardwin, ACS_ULCORNER); @@ -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; @@ -319,12 +320,12 @@ find_next_move(int *y, int *x) newx = oldx + offsets[k].x; if (chksqr(newy, newx)) { if (first < 0) - first = k; + first = (int) k; if (newy == *y && newx == *x) { - found = k; + found = (int) k; } else if (found >= 0) { - next = k; + next = (int) k; break; } } @@ -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 @@ -586,8 +605,8 @@ play(void) history[movecount - 1].y, history[movecount - 1].x, rw, col); - history[movecount].y = rw; - history[movecount].x = col; + history[movecount].y = (short) rw; + history[movecount].x = (short) col; movecount++; trialcount++; @@ -614,8 +633,8 @@ play(void) ny = history[movecount].y; nx = history[movecount].x; if (nx < 0 || ny < 0) { - ny = lastrow; - nx = lastcol; + ny = (lastrow >= 0) ? lastrow : 0; + nx = (lastcol >= 0) ? lastcol : 0; } movecount = 0; board[ny][nx] = FALSE; @@ -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':