home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / zip / gnu / gchsrc31.lzh / NUXUI.CC < prev    next >
C/C++ Source or Header  |  1992-04-27  |  18KB  |  769 lines

  1. /* nuxui.c - (new) Unix user interface for CHESS
  2.  
  3.     This file was extracted from the original GNU Chess file nuxui.c
  4.     and converted to C++ by Warwick Allison.  It represents the ASCII
  5.     interface requirements to implement ui.h.
  6.  
  7.   Revision: 1990-05-09
  8.  
  9.   Copyright (C) 1986, 1987, 1988, 1989, 1990 Free Software Foundation, Inc.
  10.   Copyright (c) 1988, 1989, 1990  John Stanback
  11.  
  12.   Modified extensively Nov 1989 Christopher North-Keys
  13.     40x24 two-colour display
  14.     option for shading black squares
  15.     expanded game save, list, and restore features using $HOME
  16.     option to disable display of coordinates
  17.     optional auto-updating of positional information
  18.     optional starring of black side
  19.     mass toggle for reverse-video functions
  20.  
  21.   This file is part of CHESS.
  22.  
  23.   CHESS is distributed in the hope that it will be useful, but WITHOUT ANY
  24.   WARRANTY.  No author or distributor accepts responsibility to anyone for
  25.   the consequences of using it or for whether it serves any particular
  26.   purpose or works at all, unless he says so in writing.  Refer to the CHESS
  27.   General Public License for full details.
  28.  
  29.   Everyone is granted permission to copy, modify and redistribute CHESS, but
  30.   only under the conditions described in the CHESS General Public License.
  31.   A copy of this license is supposed to have been given to you along with
  32.   CHESS so you can know your rights and responsibilities.  It should be in a
  33.   file named COPYING.  Among other things, the copyright notice and this
  34.   notice must be preserved on all copies.
  35. */
  36.  
  37.  
  38. #include <ctype.h>
  39. #include <signal.h>
  40. #ifdef MSDOS
  41. #include <dos.h>
  42. #include <conio.h>
  43. #include <stdlib.h>
  44. #include <string.h>
  45. #include <time.h>
  46.  
  47. #define ESC 0x1B
  48. #define refresh() fflush(stdout)
  49.  
  50. int mycntl1, mycntl2;
  51. static void param (short n);
  52. #else
  53. //#define refresh() 
  54. #include <sys/param.h>
  55. #include <sys/types.h>
  56. #include <sys/file.h>
  57.  
  58. #include <curses.h>
  59. #undef bool // Curses defines it as char !!!
  60. #undef TRUE
  61. #undef FALSE
  62.  
  63. #include <bool.h>
  64.  
  65. #endif /* MSDOS */
  66. static char* ColorStr[2] = {"White", "Black"};
  67.  
  68. #include "ui.h"
  69. #include "gnuchess.h"
  70.  
  71. #define pxx " PNBRQK"
  72. #define qxx " pnbrqk"
  73. #define rxx "12345678"
  74. #define cxx "abcdefgh"
  75. #define TAB (43)
  76. /* coordinates within a square for the following are ([1,5],[1,3]) */
  77. #define SQW (5)
  78. #define SQH (3)
  79. #define VIR_C(s)  ((flag.reverse) ? 7-column(s) : column(s))
  80. #define VIR_R(s)  ((flag.reverse) ? 7-row(s) : row(s))
  81. #define VSQ_X(x)  ((flag.reverse) ? SQW + 1 - (x) : (x))
  82. #define VSQ_Y(y)  ((flag.reverse) ? SQH + 1 - (y) : (y))
  83. #define Vblack(s) (!((VIR_C(s) + VIR_R(s)) % 2))
  84. /* Squares swapped */
  85. #define Vcoord(s,x,y) \
  86.     ((SQW)*(VIR_C(s)))+(x),((SQH)*(7-VIR_R(s))+(y))
  87. #define XYcoord(X,Y,x,y) \
  88.     (((SQW)*(X))+(x)),((SQH)*(7-(Y))+(y))
  89. /* Squares and internal locations swapped */
  90. #define VcoordI(s,x,y) \
  91.     ((SQW)*(VIR_C(s)))+(VSQ_X(x)),((SQH)*(7-VIR_R(s))+(VSQ_Y(y)))
  92. /* Squares and internal rows swapped */
  93. #define VcoordR(s,x,y) \
  94.     ((SQW)*(VIR_C(s)))+(x),((SQH)*(7-VIR_R(s))+(VSQ_Y(y)))
  95.  
  96. #if defined(MSDOS) && !defined(SEVENBIT)
  97. short rv = 0;
  98. static void ONormal (void);
  99. static void OReverse (void);
  100. #else
  101. short stars = 0;
  102. short rv = 1;
  103. short shade = 0;
  104. static void ONormal (void);
  105. static void OReverse (void);
  106. #endif /* MSDOS && !SEVENBIT */
  107.  
  108. //#define standout() wstandout(stdscr)
  109. //#define standend() wstandend(stdscr)
  110. //#define clear() wclear(stdscr)
  111. //#define move(x,y) wmove(stdscr,x,y)
  112. //#define clrtoeol() wclrtoeol(stdscr)
  113.  
  114. void TerminateSearch (int);
  115.  
  116.  
  117. void ui_Initialize()
  118. {
  119. #ifndef MSDOS
  120.   initscr ();
  121.   crmode ();
  122. #else
  123.   mycntl1 = mycntl2 = 0;
  124. #endif /* MSDOS */
  125. }
  126.  
  127. void ui_Finalize()
  128. {
  129.   gotoXY (1, 24);
  130. #ifndef MSDOS
  131.   nocrmode ();
  132.   endwin ();
  133. #endif /* MSDOS */
  134. }
  135.  
  136. void ui_GiveHelp (int compiswhite,int level,int easy,int maxdep,int dither,int hash)
  137. {
  138.   ClrScreen ();
  139.   wprintw(stdscr,"CHESS command summary\n");
  140.   wprintw(stdscr,"g1f3     move from g1 to f3      quit      Exit Chess\n");
  141.   wprintw(stdscr,"Nf3      move knight to f3       beep      on/off\n");
  142.   wprintw(stdscr,"o-o      castle king side        easy      on/off\n");
  143.   wprintw(stdscr,"o-o-o    castle queen side       hash      on/off\n");
  144.   wprintw(stdscr,"bd       redraw board            reverse   board display\n");
  145.   wprintw(stdscr,"list     game to chess.lst       book      on/off\n");
  146.   wprintw(stdscr,"undo     undo last ply           remove    take back a move\n");
  147.   wprintw(stdscr,"edit     edit board              force     enter game moves\n");
  148.   wprintw(stdscr,"switch   sides with computer     both      computer match\n");
  149.   wprintw(stdscr,"white    computer plays white    black     computer plays black\n");
  150.   wprintw(stdscr,"depth    set search depth        level     select level\n");
  151.   wprintw(stdscr,"post     principle variation     hint      suggest a move\n");
  152.   wprintw(stdscr,"save     game to file            get       game from file\n");
  153.   wprintw(stdscr,"random   randomize play          new       start new game\n");
  154.   wprintw(stdscr,"rv       toggle reverse video    coords    toggle coords\n");
  155. #if !defined(MSDOS) || defined(SEVENBIT)
  156.   wprintw(stdscr,"shade    toggle shade black      stars     toggle stars\n");
  157. #endif /* !MSDOS || SEVENBIT */
  158.   wprintw(stdscr,"p        show coordinate values\n");
  159.   gotoXY (10, 21);
  160.   wprintw(stdscr,"Computer: %s", ColorStr[compiswhite]);
  161.   gotoXY (10, 22);
  162.   wprintw(stdscr,"Opponent: %s", ColorStr[!compiswhite]);
  163.   gotoXY (10, 23);
  164.   wprintw(stdscr,"Level: %ld", level);
  165.   gotoXY (10, 24);
  166.   wprintw(stdscr,"Easy mode: %s", easy ? "ON" : "OFF");
  167.   gotoXY (40, 21);
  168.   wprintw(stdscr,"Depth: %d", maxdep);
  169.   gotoXY (40, 22);
  170.   wprintw(stdscr,"Random: %s", (dither) ? "ON" : "OFF");
  171.   gotoXY (40, 23);
  172.   wprintw(stdscr,"Transposition table: %s", hash ? "ON" : "OFF");
  173.   gotoXY (40, 24);
  174.   wprintw(stdscr,"Hit <RET> to return: ");
  175.   refresh ();
  176.   fflush(stdin);
  177.   getchar();
  178.   ClrScreen ();
  179.   UpdateDisplay (0, 0, 1, 0);
  180. }
  181.  
  182. void ui_ShowEditHelp()
  183. {
  184.   ClrScreen ();
  185.   UpdateDisplay (0, 0, 1, 0);
  186.   gotoXY (TAB, 3);
  187.   wprintw(stdscr,".   Exit to main");
  188.   gotoXY (TAB, 4);
  189.   wprintw(stdscr,"#   Clear board");
  190.   gotoXY (TAB, 5);
  191.   wprintw(stdscr,"c   Change sides");
  192.   gotoXY (TAB, 7);
  193.   wprintw(stdscr,"Enter piece & location: ");
  194. }
  195.  
  196. void ui_ShowEditColor(int col)
  197. {
  198.   gotoXY (TAB, 6);
  199.   wprintw(stdscr,"Editing: %s", ColorStr[col]);
  200.   gotoXY (TAB + 24, 7);
  201.   ClrEoln ();
  202. }
  203.  
  204. void ui_GetPieceAndLocation(char *s)
  205. {
  206.   wrefresh(stdscr);
  207.   wscanw(stdscr,"%s", s);
  208. }
  209.  
  210. void ui_ShowPlayers(bool reverse,int CompIsBlack)
  211. {
  212.   gotoXY (TAB, ((reverse) ? 23 : 2));
  213.   wprintw(stdscr,"%s", (CompIsBlack) ? "Computer" : "Human   ");
  214.   gotoXY (TAB, ((reverse) ? 2 : 23));
  215.   wprintw(stdscr,"%s", (!CompIsBlack) ? "Computer" : "Human   ");
  216. }
  217.  
  218. void ui_ShowDepth(int depth, char ch)
  219. {
  220.   gotoXY (TAB, 4);
  221.   wprintw(stdscr,"Depth= %d%c ", depth, ch);
  222.   ClrEoln ();
  223. }
  224.  
  225. void ui_ShowScore(int score)
  226. {
  227.   gotoXY (TAB, 5);
  228.   wprintw(stdscr,"Score= %d", score);
  229.   ClrEoln ();
  230. }
  231.  
  232. void ui_ShowMessage(char *msg)
  233. {
  234.   gotoXY (TAB, 6);
  235.   wprintw(stdscr,"%s", msg);
  236.   ClrEoln ();
  237. }
  238.  
  239. void ui_ClearMessage()
  240. {
  241.   gotoXY (TAB, 6);
  242.   ClrEoln ();
  243. }
  244.  
  245. void ui_ShowCurrentMove(int pnt, char *move)
  246. {
  247.   gotoXY (TAB, 7);
  248.   wprintw(stdscr,"(%2d) %4s", pnt, move);
  249. }
  250.  
  251. void ui_ShowTitle()
  252. {
  253.   gotoXY (TAB, 10);
  254. #ifdef MSDOS
  255.   wprintw(stdscr,"GNU Chess display (MS-DOS, Mar 90)");
  256. #else
  257.   wprintw(stdscr,"GNU Chess display (Nov 89)");
  258. #endif /* MSDOS */
  259. }
  260.  
  261. void ui_ShowSideToMove(int movenum, int who)
  262. {
  263.   gotoXY (TAB, 14);
  264.   wprintw(stdscr,"%2d:   %s", movenum,ColorStr[who]);
  265.   ClrEoln ();
  266. }
  267.  
  268. void ui_PromptForMove()
  269. {
  270.   gotoXY (TAB, 19);
  271.   wprintw(stdscr,"Your move is? ");
  272.   ClrEoln ();
  273. }
  274.  
  275. void ui_ShowNodeCnt(long int NodeCnt, long int evrate)
  276. {
  277.   gotoXY (TAB, 21);
  278.   wprintw(stdscr,"Nodes= %8ld, Nodes/Sec= %5ld", NodeCnt, evrate);
  279.   ClrEoln ();
  280. }  
  281.  
  282. void ui_ShowPlyMove(int ply,char *move)
  283. {
  284.   if (ply % 4 == 1)
  285.     {
  286.       gotoXY (TAB, 8+ply/4);
  287.       ClrEoln ();
  288.     }
  289.   wprintw(stdscr,"%5s ", move);
  290. }
  291.  
  292. void ui_NoMorePly(int ply)
  293. {
  294.   ClrEoln ();
  295.   while (ply < 52)
  296.   {
  297.     if (ply % 4 == 1)
  298.     {
  299.       gotoXY (TAB, 8+ply/4);
  300.       ClrEoln ();
  301.     }
  302.     ply++;
  303.   }
  304. }
  305.  
  306. void ui_SearchStartStuff(int side)
  307. {
  308.   int i;
  309.   
  310.   signal (SIGINT, TerminateSearch);
  311. #ifdef MSDOS
  312.   side++;                /* shut up the compiler */
  313. #else
  314.   signal (SIGQUIT, TerminateSearch);
  315. #endif /* MSDOS */
  316.   for (i = 4; i < 14; i++)
  317.     {
  318.       gotoXY (TAB, i);
  319.       ClrEoln ();
  320.     }
  321. }
  322.  
  323. void ui_ShowComputerMove(char *move, int feature)
  324. {
  325.   gotoXY (TAB, 17);
  326.   wprintw(stdscr,"My move is: %s", move);
  327.   if (flag.beep)
  328.     putchar (7);
  329.   ClrEoln ();
  330.  
  331.   gotoXY (TAB, 24);
  332.   switch (feature)
  333.   {
  334.     case 1: wprintw(stdscr,"Drawn game!");
  335.   break; case 2: wprintw(stdscr,"Opponent mates!");
  336.   break; case 3: wprintw(stdscr,"Computer mates!");
  337.   break; case 4: wprintw(stdscr,"Opponent will soon mate!");
  338.   break; case 5: wprintw(stdscr,"Computer will soon mate!");
  339.   }
  340.  
  341.   ClrEoln ();
  342. }
  343.  
  344. void ui_ShowMaxTree(int maxtree)
  345. {
  346.   gotoXY (TAB, 22);
  347.   wprintw(stdscr,"Max Tree= %5d", maxtree);
  348.   ClrEoln ();
  349. }
  350.  
  351. void ui_ShowClock(bool OnWhiteSide, int minutes, int seconds)
  352. {
  353.   if (OnWhiteSide)
  354.     gotoXY (60, 23);
  355.   else
  356.     gotoXY (60, 2);
  357.   wprintw(stdscr,"%d:%2d   ", minutes, seconds);
  358. }
  359.  
  360. void ui_ClrScreen()
  361. {
  362. #ifdef MSDOS
  363.   putchar(ESC);
  364.   putchar('[');
  365.   putchar('2');
  366.   putchar('J');
  367. #else
  368.   clear ();
  369. #endif /* MSDOS */
  370.   refresh ();
  371. }
  372.  
  373. void ui_DrawPiece(bool used, bool isblack, int x, int y, int piece)
  374. {
  375.   gotoXY (2+SQW*x, 2+SQH*(7-y));
  376.  
  377.   if (used)
  378.     {
  379.       if (isblack) {
  380.         if (rv)
  381.       OReverse ();
  382. #if defined(MSDOS) && !defined(SEVENBIT)
  383.         wprintw(stdscr," %c ", qxx[piece]);
  384. #else
  385.         wprintw(stdscr,(stars ? "*%c*" : " %c "), qxx[piece]);
  386. #endif /* MSDOS && !SEVENBIT */
  387.         ONormal ();
  388.       } else {
  389. #if defined(MSDOS) && !defined(SEVENBIT)
  390.         if (!rv)
  391.       OReverse ();
  392.         wprintw(stdscr," %c ", qxx[piece]);
  393.         ONormal ();
  394. #else
  395.         wprintw(stdscr," %c ", qxx[piece]);
  396. #endif /* MSDOS && !SEVENBIT */
  397.       }
  398.     } else {
  399. #if defined(MSDOS) && !defined(SEVENBIT)
  400.       if (rv)
  401.         wprintw(stdscr,Vblack (sq) ? "\262\262\262" : "\260\260\260");
  402.       else
  403.         wprintw(stdscr,Vblack (sq) ? "\260\260\260" : "\262\262\262");
  404. #else
  405.       if (shade)
  406.     /*wprintw(stdscr,Vblack (sq) ? "///" : "   ");*/
  407.         wprintw(stdscr,(!((x + y) % 2)) ? "///" : "   ");
  408.       else
  409.     {
  410.       /*if (Vblack (sq))*/
  411.           if (!((x + y) % 2))
  412.         OReverse ();
  413.       wprintw(stdscr,"   ");
  414.       ONormal ();
  415.     }
  416. #endif /* MSDOS && !SEVENBIT */
  417.     }
  418. }
  419.  
  420. void ui_DrawSquare(int x, int y, bool isblack)
  421. {
  422. #if defined(MSDOS) && !defined(SEVENBIT)
  423.   if (rv)
  424.     {
  425.       gotoXY (XYcoord (x,y, 1, 1));
  426.       wprintw(stdscr,isblack ? "\262\262\262\262\262" : "\260\260\260\260\260");
  427.       gotoXY (XYcoord (x,y, 1, 2));
  428.       wprintw(stdscr,isblack ? "\262\262\262\262\262" : "\260\260\260\260\260");
  429.       gotoXY (XYcoord (x,y, 1, 3));
  430.       wprintw(stdscr,isblack ? "\262\262\262\262\262" : "\260\260\260\260\260");
  431.     }
  432.   else
  433.     {
  434.       gotoXY (XYcoord (x,y, 1, 1));
  435.       wprintw(stdscr,isblack ? "\260\260\260\260\260" : "\262\262\262\262\262");
  436.       gotoXY (XYcoord (x,y, 1, 2));
  437.       wprintw(stdscr,isblack ? "\260\260\260\260\260" : "\262\262\262\262\262");
  438.       gotoXY (XYcoord (x,y, 1, 3));
  439.       wprintw(stdscr,isblack ? "\260\260\260\260\260" : "\262\262\262\262\262");
  440.     }
  441. #else
  442.   if (shade)
  443.     {
  444.       gotoXY (XYcoord (x,y, 1, 1));
  445.       wprintw(stdscr,isblack ? "/////" : "     ");
  446.       gotoXY (XYcoord (x,y, 1, 2));
  447.       wprintw(stdscr,isblack ? "/////" : "     ");
  448.       gotoXY (XYcoord (x,y, 1, 3));
  449.       wprintw(stdscr,isblack ? "/////" : "     ");
  450.     }
  451.   else
  452.     {
  453.       if (isblack)
  454.     OReverse ();
  455.       gotoXY (XYcoord (x,y, 1, 1));
  456.       wprintw(stdscr,"     ");
  457.       gotoXY (XYcoord (x,y, 1, 2));
  458.       wprintw(stdscr,"     ");
  459.       gotoXY (XYcoord (x,y, 1, 3));
  460.       wprintw(stdscr,"     ");
  461.       ONormal ();
  462.     }
  463. #endif /* MSDOS && !SEVENBIT */
  464. }
  465.  
  466. void ui_DrawCoords()
  467. {
  468.   short z;
  469.  
  470.   for (z = 0; z <= 7; z++)
  471.     {
  472.       short sq;
  473.  
  474.       sq = z << 3;
  475.       gotoXY (VcoordI (sq, 1, 1));
  476. #if !defined(MSDOS) || defined(SEVENBIT)
  477.       if ((Vblack (sq) || shade) && rv)
  478. #endif /* !MSDOS || SEVENBIT */
  479.     OReverse ();
  480.       wprintw(stdscr,"%d", 1 + z);
  481.       ONormal ();
  482.     }
  483.  
  484.   for (z = 0; z <= 7; z++)
  485.     {
  486.       short sq;
  487.  
  488.       sq = z;
  489.       gotoXY (VcoordI (sq, SQW, SQH));
  490. #if !defined(MSDOS) || defined(SEVENBIT)
  491.       if ((Vblack (sq) || shade) && rv)
  492. #endif /* !MSDOS || SEVENBIT */
  493.     OReverse ();
  494.       wprintw(stdscr,"%c", cxx[z]);
  495.       ONormal ();
  496.     }
  497.  
  498. #if !defined(MSDOS) || defined(SEVENBIT)
  499.   for (z = 1; z <= (8 * SQH); z++)
  500.     {
  501.       gotoXY ((8 * SQW) + 1, z);
  502.       wprintw(stdscr,"|");
  503.     }
  504. #endif /* MSDOS && !SEVENBIT */
  505. }
  506.  
  507. void ui_ShowPosnValue(short sq, int score)
  508. {
  509.   gotoXY (VcoordR (sq, 2, 1));
  510. #if !defined(MSDOS) || defined(SEVENBIT)
  511.   if (Vblack (sq) && !shade)
  512.     OReverse ();
  513. #endif /* !MSDOS || SEVENBIT */
  514.  
  515.   if (color[sq] != neutral)
  516.     wprintw(stdscr,"%3d", svalue[sq]);
  517.   else
  518. #if defined(MSDOS) && !defined(SEVENBIT)
  519.     {
  520.       if (rv)
  521.          wprintw(stdscr,Vblack (sq) ? "\262\262\262" : "\260\260\260");
  522.       else
  523.         wprintw(stdscr,Vblack (sq) ? "\260\260\260" : "\262\262\262");
  524.     }
  525. #else
  526.     wprintw(stdscr,shade && Vblack (sq) ? "///" : "   ");
  527. #endif /* MSDOS && !SEVENBIT */
  528.   ONormal ();
  529. }
  530.  
  531. void ui_GetFilename(char *prompt,char *name)
  532. {
  533.   ShowMessage ("File name: ");
  534.   wrefresh(stdscr);
  535.   wscanw(stdscr,"%s", name);
  536. }
  537.  
  538. void ui_ShowFileLoading(char *name)
  539. {
  540.   ShowMessage("Loading ");
  541.   wprintw(stdscr,"%s", name);
  542. }
  543.  
  544. void ui_LoadDone()
  545. {
  546.   ShowMessage ("Load done.  Press <Ret>");
  547.   fflush (stdin);
  548.   getchar ();
  549. }
  550.  
  551. void ui_LoadFailed()
  552. {
  553.   ShowMessage ("Load failed");
  554.   return;
  555. }
  556.  
  557. void ui_ShowFileSaving(char *name)
  558. {
  559.   ShowMessage("Saving ");
  560.   wprintw(stdscr,"%s", name);
  561. }
  562.  
  563. void ui_SaveFailed()
  564. {
  565.   ShowMessage ("Not saved");
  566.   return;
  567. }
  568.  
  569. void ui_SaveDone()
  570. {
  571.   ShowMessage ("Save done.  Press <Ret>");
  572.   fflush (stdin);
  573.   getchar ();
  574. }
  575.  
  576. void ui_ChangeSearchDepth(int *newdepth)
  577. {
  578.   ShowMessage ("depth= ");
  579.   wrefresh(stdscr);
  580.   wscanw(stdscr,"%hd", newdepth);
  581. }
  582.  
  583. void ui_ChangeContempt(int *newcontempt)
  584. {
  585.   ShowMessage ("contempt= ");
  586.   wrefresh(stdscr);
  587.   wscanw(stdscr,"%hd", newcontempt);
  588. }
  589.  
  590. void ui_ChangeLevel(int *newlevel)
  591. {
  592.   ClrScreen ();
  593.   gotoXY (32, 2);
  594.   wprintw(stdscr,"CHESS");
  595.   gotoXY (20, 4);
  596.   wprintw(stdscr," 1.   60 moves in   5 minutes");
  597.   gotoXY (20, 5);
  598.   wprintw(stdscr," 2.   60 moves in  15 minutes");
  599.   gotoXY (20, 6);
  600.   wprintw(stdscr," 3.   60 moves in  30 minutes");
  601.   gotoXY (20, 7);
  602.   wprintw(stdscr," 4.   40 moves in  30 minutes");
  603.   gotoXY (20, 8);
  604.   wprintw(stdscr," 5.   40 moves in  60 minutes");
  605.   gotoXY (20, 9);
  606.   wprintw(stdscr," 6.   40 moves in 120 minutes");
  607.   gotoXY (20, 10);
  608.   wprintw(stdscr," 7.   40 moves in 240 minutes");
  609.   gotoXY (20, 11);
  610.   wprintw(stdscr," 8.    1 move  in  15 minutes");
  611.   gotoXY (20, 12);
  612.   wprintw(stdscr," 9.    1 move  in  60 minutes");
  613.   gotoXY (20, 13);
  614.   wprintw(stdscr,"10.    1 move  in 600 minutes");
  615.  
  616.   gotoXY (20, 17);
  617.   wprintw(stdscr,"Enter Level: ");
  618.   refresh ();
  619.   wrefresh(stdscr);
  620.   wscanw(stdscr,"%ld", &Level);
  621.   ClrScreen ();
  622. }
  623.  
  624. void ui_ChoosePiece(char *s)
  625. {
  626.   ShowMessage ("Enter piece: ");
  627.   wrefresh(stdscr);
  628.   wscanw(stdscr,"%s", s);
  629. }
  630.  
  631. void ui_GetMove(char *s)
  632. {
  633.   ui_PromptForMove();
  634.   wrefresh(stdscr);
  635.   wscanw(stdscr,"%s", s);
  636. }
  637.  
  638. void ui_ToggleRV()
  639. {
  640.   rv = !rv;
  641. #if !defined(MSDOS) || defined(SEVENBIT)
  642.   shade = !rv;
  643.   stars = !rv;
  644. #endif /* MSDOS && !SEVENBIT */
  645.   UpdateDisplay (0, 0, 1, 0);
  646. }
  647.  
  648. void OReverse()
  649. {
  650. #ifdef MSDOS
  651.   putchar (ESC);
  652.   putchar ('[');
  653.   param (7);
  654.   putchar ('m');
  655. #else
  656.   standout ();
  657. /* attron (A_REVERSE); */
  658. #endif /* MSDOS */
  659. }
  660.  
  661. void ONormal()
  662. {
  663. #ifdef MSDOS
  664.   putchar (ESC);
  665.   putchar ('[');
  666.   param (0);
  667.   putchar ('m');
  668. #else
  669.   standend ();
  670. /* attroff (A_REVERSE);*/
  671. #endif /* MSDOS */
  672. }
  673.  
  674.  
  675. void ui_ToggleStars()
  676. {
  677.   stars = !stars;
  678.   UpdateDisplay (0, 0, 1, 0);
  679. }
  680.  
  681. void ui_ToggleShade()
  682. {
  683.   shade = !shade;
  684.   ClrScreen ();
  685.   UpdateDisplay (0, 0, 1, 0);
  686. }
  687.  
  688. void
  689. gotoXY (short int x, short int y)
  690. {
  691. #ifdef MSDOS
  692.   putchar(ESC);
  693.   putchar('[');
  694.   param(y);
  695.   putchar(';');
  696.   param(x);
  697.   putchar('H');
  698. #else
  699.   move (y - 1, x - 1);
  700. #endif /* MSDOS */
  701. }
  702.  
  703. void
  704. ClrScreen (void)
  705. {
  706.   ui_ClrScreen();
  707. }
  708.  
  709. void
  710. ClrEoln (void)
  711. {
  712. #ifdef MSDOS
  713.   putchar(ESC);
  714.   putchar('[');
  715.   putchar('K');
  716. #else
  717.   clrtoeol ();
  718. #endif /* MSDOS */
  719.   refresh ();
  720. }
  721.  
  722. #ifdef MSDOS
  723. void
  724. param(short n)
  725. {
  726.   if (n >= 10)
  727.     {
  728.     register short d, q;
  729.     q = n/10; d = n%10;
  730.     putchar(q + '0');
  731.     putchar(d + '0');
  732.   }
  733.   else
  734.     putchar(n + '0');
  735. }
  736. #endif /* MSDOS */
  737.  
  738. int ui_AskAbort()
  739. {
  740.   char s[80];
  741.  
  742.   ShowMessage ("Abort? ");
  743.   wrefresh(stdscr);
  744.   wscanw(stdscr,"%s", s);
  745.   return (strcmp (s, "yes") == 0);
  746. }
  747.  
  748. void ui_ClearEditHelp()
  749. {
  750.   ClrScreen();
  751. }
  752.  
  753. void ui_RefreshEarly()
  754. {
  755.   wrefresh(stdscr);
  756. }
  757.  
  758. void ui_ShowHint(char *move)
  759. {
  760.   gotoXY (TAB, 6);
  761.   wprintw(stdscr,"Try: %s", move);
  762.   ClrEoln ();
  763. }
  764.  
  765. void ui_RejectMove(char *move)
  766. {
  767.     ui_ShowMessage("Illegal move");
  768. }
  769.