home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / games / volume15 / reversi / part02 < prev    next >
Encoding:
Internet Message Format  |  1993-01-26  |  9.4 KB

  1. Path: uunet!zephyr.ens.tek.com!master!saab!billr
  2. From: billr@saab.CNA.TEK.COM (Bill Randle)
  3. Newsgroups: comp.sources.games
  4. Subject: v15i008:  reversi - play a game of reversi against the computer or a human, Part02/02
  5. Message-ID: <3804@master.CNA.TEK.COM>
  6. Date: 23 Oct 92 15:38:31 GMT
  7. Sender: news@master.CNA.TEK.COM
  8. Lines: 328
  9. Approved: billr@saab.CNA.TEK.COM
  10. Xref: uunet comp.sources.games:1507
  11.  
  12. Submitted-by: elias@proxxi.se (Elias M}rtensson )
  13. Posting-number: Volume 15, Issue 8
  14. Archive-name: reversi/Part02
  15. Environment: curses
  16.  
  17.  
  18.  
  19. #! /bin/sh
  20. # This is a shell archive.  Remove anything before this line, then unpack
  21. # it by saving it into a file and typing "sh file".  To overwrite existing
  22. # files, type "sh file -c".  You can also feed this as standard input via
  23. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  24. # will see the following message at the end:
  25. #        "End of archive 2 (of 2)."
  26. # Contents:  Makefile menu.c reversi.h
  27. # Wrapped by billr@saab on Fri Oct 23 08:35:19 1992
  28. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  29. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  30.   echo shar: Will not clobber existing file \"'Makefile'\"
  31. else
  32. echo shar: Extracting \"'Makefile'\" \(1310 characters\)
  33. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  34. X#    reversi - play a game of reversi against the computer or a human
  35. X#    Copyright (C) 1992  Elias Martenson
  36. X#
  37. X#    This program is free software; you can redistribute it and/or modify
  38. X#    it under the terms of the GNU General Public License as published by
  39. X#    the Free Software Foundation; either version 2 of the License, or
  40. X#    (at your option) any later version.
  41. X#
  42. X#    This program is distributed in the hope that it will be useful,
  43. X#    but WITHOUT ANY WARRANTY; without even the implied warranty of
  44. X#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  45. X#    GNU General Public License for more details.
  46. X#
  47. X#    You should have received a copy of the GNU General Public License
  48. X#    along with this program; if not, write to the Free Software
  49. X#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  50. X#
  51. X#    Contact me by email at elias@proxxi.se
  52. X
  53. XEXEC = reversi
  54. XGAMEDIR = /usr/games
  55. X
  56. XOBJS = reversi.o graphics.o move.o comp.o menu.o
  57. X
  58. XCC = gcc
  59. X
  60. X#  Put -DHAVE_VOID_SIGNALS in OPTFLAGS if Your compiler requres it
  61. X
  62. X#OPTFLAGS = -g -DDEBUG -DHAVE_VOID_SIGNALS
  63. XOPTFLAGS = -O -DHAVE_VOID_SIGNALS
  64. X
  65. XCFLAGS = $(OPTFLAGS)
  66. X
  67. Xall:        $(EXEC)
  68. X
  69. X$(EXEC):    $(OBJS)
  70. X        $(CC) $(OPTFLAGS) -o $(EXEC) $(OBJS) -lcurses -ltermcap
  71. X
  72. Xinstall:    $(EXEC)
  73. X        cp $(EXEC) $(GAMEDIR)
  74. X
  75. Xclean:
  76. X        rm -f *.o *~ $(EXEC) core
  77. END_OF_FILE
  78. if test 1310 -ne `wc -c <'Makefile'`; then
  79.     echo shar: \"'Makefile'\" unpacked with wrong size!
  80. fi
  81. # end of 'Makefile'
  82. fi
  83. if test -f 'menu.c' -a "${1}" != "-c" ; then 
  84.   echo shar: Will not clobber existing file \"'menu.c'\"
  85. else
  86. echo shar: Extracting \"'menu.c'\" \(4269 characters\)
  87. sed "s/^X//" >'menu.c' <<'END_OF_FILE'
  88. X/*
  89. X    reversi - play a game of reversi against the computer or a human
  90. X    Copyright (C) 1992  Elias Martenson
  91. X
  92. X    This program is free software; you can redistribute it and/or modify
  93. X    it under the terms of the GNU General Public License as published by
  94. X    the Free Software Foundation; either version 2 of the License, or
  95. X    (at your option) any later version.
  96. X
  97. X    This program is distributed in the hope that it will be useful,
  98. X    but WITHOUT ANY WARRANTY; without even the implied warranty of
  99. X    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  100. X    GNU General Public License for more details.
  101. X
  102. X    You should have received a copy of the GNU General Public License
  103. X    along with this program; if not, write to the Free Software
  104. X    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  105. X
  106. X    Contact me by email at elias@proxxi.se
  107. X*/
  108. X
  109. X/*
  110. X *  These menu routines is written by Stefan Rapp (rappen@proxxi.se)
  111. X *
  112. X */
  113. X
  114. X#include <curses.h>
  115. X#include "menu.h"
  116. X
  117. X/*                      */
  118. X/*  Start: 0 = First    */
  119. X/*                      */
  120. X
  121. Xmenu (x, y, width, height, start, flags, names)
  122. Xint x, y, width, height, start, flags;
  123. XMenuEntry *names;
  124. X{
  125. X  MenuEntry *namesstart = names;
  126. X  WINDOW *menu_window;
  127. X  int max_width=0, number_names= 0, counter, names_select = FALSE;
  128. X  char ch;
  129. X  char *str;
  130. X
  131. X  do{
  132. X    if( strlen( names->name ) > max_width  ){ 
  133. X      max_width = strlen(names->name);
  134. X    }
  135. X    number_names++;
  136. X  } while((++names) -> name != NULL );
  137. X
  138. X  if( height == 0){
  139. X    height = number_names;
  140. X  }
  141. X
  142. X  if( width == 0){
  143. X    width = max_width;
  144. X  }
  145. X  
  146. X  names=namesstart;
  147. X  names+=start;
  148. X
  149. X  counter = 0;
  150. X  
  151. X  menu_window = newwin( height, width + 1, y, x );
  152. X  if( ( flags & DRAW_BOX ) == DRAW_BOX ){
  153. X    box( menu_window, DRAW_BOX_SYMBOL_VERT, DRAW_BOX_SYMBOL_HORIZ );
  154. X }
  155. X  wclear( menu_window );
  156. X  refresh_names( menu_window, 1, width, height, names+1);
  157. X  wstandout( menu_window );
  158. X  mvwaddstr(menu_window, 0, 0, (names)->name);
  159. X  wstandend( menu_window );
  160. X  do{
  161. X    wrefresh(menu_window);
  162. X    ch = wgetch( menu_window );
  163. X
  164. X    wstandend( menu_window );
  165. X    mvwaddstr( menu_window, counter, 0, names-> name);
  166. X        
  167. X    switch( ch ){
  168. X    case MV_UP:
  169. X      if(names-namesstart > 0){
  170. X    names--;
  171. X    counter--;
  172. X        if( counter < 0 ){    
  173. X      counter = 0;
  174. X      refresh_names( menu_window, 0, width, height, names);
  175. X        }
  176. X      }
  177. X      else if( (flags & WRAP) == WRAP ){
  178. X    names = namesstart;
  179. X    names += number_names -1;
  180. X        counter = height -1;
  181. X    refresh_names( menu_window, 0, width, height, names - (height -1));
  182. X      }
  183. X      break;
  184. X    case MV_DOWN:
  185. X      if( (names+1)->name != NULL){
  186. X    names++;
  187. X    counter++;
  188. X        if( counter >= height ){
  189. X      counter = height -1;
  190. X      refresh_names( menu_window, 0, width, height, names - (height -1));
  191. X    }
  192. X      }
  193. X      else if(( flags & WRAP) == WRAP ){
  194. X    names = namesstart;
  195. X    counter = 0;
  196. X    refresh_names( menu_window, 0, width, height, names);
  197. X      }
  198. X      break;
  199. X    case PG_UP:
  200. X      break;
  201. X    case PG_DOWN:
  202. X      break;
  203. X    case SELECT:
  204. X      names_select = TRUE;
  205. X      break;
  206. X    case QUIT:
  207. X      if( (flags & ENABLE_QUIT) == ENABLE_QUIT){
  208. X    names_select = -1;
  209. X      }
  210. X      break;
  211. X    case HELP:
  212. X      if( (flags & ENABLE_HELP) == ENABLE_HELP){
  213. X    /* help command */
  214. X      }
  215. X      break;
  216. X    } /* switch */
  217. X    
  218. X    wstandout( menu_window);
  219. X    mvwaddstr( menu_window, counter, 0, (names -> name ));
  220. X  } while( names_select == FALSE);
  221. X  
  222. X  if( (flags & CLEAR_ON_EXIT) == CLEAR_ON_EXIT ){
  223. X    wclear( menu_window );
  224. X    wrefresh( menu_window );
  225. X  }
  226. X  delwin( menu_window );
  227. X  
  228. X  if( names_select == -1){
  229. X    return(-1);
  230. X  }
  231. X  else{
  232. X    return(names - namesstart);
  233. X  }
  234. X}   
  235. X       
  236. X
  237. Xrefresh_names( menu_window, y, width, height,  names)
  238. XWINDOW *menu_window;
  239. XMenuEntry *names;
  240. Xint width, height, y;
  241. X{
  242. X  int counter;
  243. X  
  244. X  for( counter = y; ( counter < height  ) && ( names -> name != NULL ); counter++ ){
  245. X    mvwaddstr( menu_window, counter , 0 , (names) -> name );
  246. X    if( strlen( names -> name) < width){
  247. X      write_space( menu_window, width - strlen(names->name));
  248. X      write_space( menu_window, 1);
  249. X    }
  250. X    names++;
  251. X  }
  252. X}
  253. X
  254. Xwrite_space( menu_window, spaces)
  255. XWINDOW *menu_window;
  256. Xint spaces;
  257. X{
  258. X  int counter;
  259. X  
  260. X  for( counter = 0; counter < spaces; counter++ ){
  261. X    waddch( menu_window, ' ' );
  262. X  }
  263. X}
  264. END_OF_FILE
  265. if test 4269 -ne `wc -c <'menu.c'`; then
  266.     echo shar: \"'menu.c'\" unpacked with wrong size!
  267. fi
  268. # end of 'menu.c'
  269. fi
  270. if test -f 'reversi.h' -a "${1}" != "-c" ; then 
  271.   echo shar: Will not clobber existing file \"'reversi.h'\"
  272. else
  273. echo shar: Extracting \"'reversi.h'\" \(1311 characters\)
  274. sed "s/^X//" >'reversi.h' <<'END_OF_FILE'
  275. X/*
  276. X    reversi - play a game of reversi against the computer or a human
  277. X    Copyright (C) 1992  Elias Martenson
  278. X
  279. X    This program is free software; you can redistribute it and/or modify
  280. X    it under the terms of the GNU General Public License as published by
  281. X    the Free Software Foundation; either version 2 of the License, or
  282. X    (at your option) any later version.
  283. X
  284. X    This program is distributed in the hope that it will be useful,
  285. X    but WITHOUT ANY WARRANTY; without even the implied warranty of
  286. X    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  287. X    GNU General Public License for more details.
  288. X
  289. X    You should have received a copy of the GNU General Public License
  290. X    along with this program; if not, write to the Free Software
  291. X    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  292. X
  293. X    Contact me by email at elias@proxxi.se
  294. X*/
  295. X
  296. X#define TRUE (1)
  297. X#define FALSE (0)
  298. X
  299. X/* Some score definitions */
  300. X
  301. X#define SQUARE_SCORE 10
  302. X#define BORDER_SCORE 800
  303. X#define CORNER_SCORE 4000
  304. X#define BORDER_POS_BONUS 10
  305. X#define BORDER2_POS_BONUS 10
  306. X#define BORDER2_SCORE 50
  307. X#define BORDER2_CORNER_SCORE -200
  308. X#define BORDER3_CORNER_SCORE 150
  309. X#define BORDER3_SCORE 400
  310. X
  311. X#define NO_MOVE_BONUS 10000
  312. X#define DIV_POINTS 1.2  /* This is a float! */
  313. X
  314. X#define get_board(board,X,Y) (board)[((X)*8) + (Y)]
  315. X
  316. END_OF_FILE
  317. if test 1311 -ne `wc -c <'reversi.h'`; then
  318.     echo shar: \"'reversi.h'\" unpacked with wrong size!
  319. fi
  320. # end of 'reversi.h'
  321. fi
  322. echo shar: End of archive 2 \(of 2\).
  323. cp /dev/null ark2isdone
  324. MISSING=""
  325. for I in 1 2 ; do
  326.     if test ! -f ark${I}isdone ; then
  327.     MISSING="${MISSING} ${I}"
  328.     fi
  329. done
  330. if test "${MISSING}" = "" ; then
  331.     echo You have unpacked both archives.
  332.     rm -f ark[1-9]isdone
  333. else
  334.     echo You still need to unpack the following archives:
  335.     echo "        " ${MISSING}
  336. fi
  337. ##  End of shell archive.
  338. exit 0
  339.