home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / games / volume15 / reversi / part01 < prev    next >
Encoding:
Internet Message Format  |  1993-01-26  |  55.1 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: v15i007:  reversi - play a game of reversi against the computer or a human, Part01/02
  5. Message-ID: <3803@master.CNA.TEK.COM>
  6. Date: 23 Oct 92 15:38:10 GMT
  7. Sender: news@master.CNA.TEK.COM
  8. Lines: 1804
  9. Approved: billr@saab.CNA.TEK.COM
  10. Xref: uunet comp.sources.games:1506
  11.  
  12. Submitted-by: elias@proxxi.se (Elias M}rtensson )
  13. Posting-number: Volume 15, Issue 7
  14. Archive-name: reversi/Part01
  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 1 (of 2)."
  26. # Contents:  README MANIFEST COPYING comp.c graphics.c menu.h move.c
  27. #   reversi.c
  28. # Wrapped by billr@saab on Fri Oct 23 08:35:19 1992
  29. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  30. if test -f 'README' -a "${1}" != "-c" ; then 
  31.   echo shar: Will not clobber existing file \"'README'\"
  32. else
  33. echo shar: Extracting \"'README'\" \(2083 characters\)
  34. sed "s/^X//" >'README' <<'END_OF_FILE'
  35. X    reversi - play a game of reversi against the computer or a human
  36. X    Copyright (C) 1992  Elias Martenson
  37. X
  38. X    This program is free software; you can redistribute it and/or modify
  39. X    it under the terms of the GNU General Public License as published by
  40. X    the Free Software Foundation; either version 2 of the License, or
  41. X    (at your option) any later version.
  42. X
  43. X    This program is distributed in the hope that it will be useful,
  44. X    but WITHOUT ANY WARRANTY; without even the implied warranty of
  45. X    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  46. X    GNU General Public License for more details.
  47. X
  48. X    You should have received a copy of the GNU General Public License
  49. X    along with this program; if not, write to the Free Software
  50. X    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  51. X
  52. X    Contact me by email at elias@proxxi.se
  53. X
  54. X
  55. X
  56. X
  57. X            COMPILING AND INSTALLING
  58. X
  59. XEdit the Makefile to suit Your needs and enter "make" or "make
  60. Xinstall". The program should compile without problems on any
  61. XANSI-C compiler. If You don't have an ANSI-C compiler at hand You
  62. Xmight have to change the struct initializations for the menu
  63. Xroutines by hand.
  64. X
  65. XThe game has been tested on several machines (VAX 11/750 running
  66. XBDS4.3, DECstation 3100 running Ultrix 4.2, i486 running Linux,
  67. Xi486 running Interactive Unix. The game was compiled with GCC on
  68. Xall systems).
  69. X
  70. XIf You have problems compiling the game, please send me a mail
  71. Xdescribing You problems and eventually what You did to fix it. I
  72. Xwould like to see that this game compiles and runs sucessfully on
  73. Xas many machines as possible.
  74. X
  75. X
  76. X            PLAYING THE GAME
  77. X
  78. XWhen the game starts up You will be presented with a menu. Move
  79. Xthe pointer using "j" and "k", select with RETURN. In the game
  80. XYou move the cursor using "h", "j", "k" and "l", and You place a
  81. Xtile on the board using SPACE. A menu with variuos selections is
  82. Xavailable by pressing ESC.
  83. X
  84. XIn-game documentation is available by pressing "?" at any time in
  85. Xthe game.
  86. X
  87. X
  88. XPlease send bug reports and suggestions to: elias@proxxi.se. Send
  89. Xflames anywhere except to me. :-)
  90. END_OF_FILE
  91. if test 2083 -ne `wc -c <'README'`; then
  92.     echo shar: \"'README'\" unpacked with wrong size!
  93. fi
  94. # end of 'README'
  95. fi
  96. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  97.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  98. else
  99. echo shar: Extracting \"'MANIFEST'\" \(455 characters\)
  100. sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  101. X   File Name        Archive #    Description
  102. X-----------------------------------------------------------
  103. X COPYING                    1    
  104. X MANIFEST                   1    This shipping list
  105. X Makefile                   2    
  106. X README                     1    
  107. X comp.c                     1    
  108. X graphics.c                 1    
  109. X menu.c                     2    
  110. X menu.h                     1    
  111. X move.c                     1    
  112. X reversi.c                  1    
  113. X reversi.h                  2    
  114. END_OF_FILE
  115. if test 455 -ne `wc -c <'MANIFEST'`; then
  116.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  117. fi
  118. # end of 'MANIFEST'
  119. fi
  120. if test -f 'COPYING' -a "${1}" != "-c" ; then 
  121.   echo shar: Will not clobber existing file \"'COPYING'\"
  122. else
  123. echo shar: Extracting \"'COPYING'\" \(17976 characters\)
  124. sed "s/^X//" >'COPYING' <<'END_OF_FILE'
  125. X            GNU GENERAL PUBLIC LICENSE
  126. X               Version 2, June 1991
  127. X
  128. X Copyright (C) 1989, 1991 Free Software Foundation, Inc.
  129. X                          675 Mass Ave, Cambridge, MA 02139, USA
  130. X Everyone is permitted to copy and distribute verbatim copies
  131. X of this license document, but changing it is not allowed.
  132. X
  133. X                Preamble
  134. X
  135. X  The licenses for most software are designed to take away your
  136. Xfreedom to share and change it.  By contrast, the GNU General Public
  137. XLicense is intended to guarantee your freedom to share and change free
  138. Xsoftware--to make sure the software is free for all its users.  This
  139. XGeneral Public License applies to most of the Free Software
  140. XFoundation's software and to any other program whose authors commit to
  141. Xusing it.  (Some other Free Software Foundation software is covered by
  142. Xthe GNU Library General Public License instead.)  You can apply it to
  143. Xyour programs, too.
  144. X
  145. X  When we speak of free software, we are referring to freedom, not
  146. Xprice.  Our General Public Licenses are designed to make sure that you
  147. Xhave the freedom to distribute copies of free software (and charge for
  148. Xthis service if you wish), that you receive source code or can get it
  149. Xif you want it, that you can change the software or use pieces of it
  150. Xin new free programs; and that you know you can do these things.
  151. X
  152. X  To protect your rights, we need to make restrictions that forbid
  153. Xanyone to deny you these rights or to ask you to surrender the rights.
  154. XThese restrictions translate to certain responsibilities for you if you
  155. Xdistribute copies of the software, or if you modify it.
  156. X
  157. X  For example, if you distribute copies of such a program, whether
  158. Xgratis or for a fee, you must give the recipients all the rights that
  159. Xyou have.  You must make sure that they, too, receive or can get the
  160. Xsource code.  And you must show them these terms so they know their
  161. Xrights.
  162. X
  163. X  We protect your rights with two steps: (1) copyright the software, and
  164. X(2) offer you this license which gives you legal permission to copy,
  165. Xdistribute and/or modify the software.
  166. X
  167. X  Also, for each author's protection and ours, we want to make certain
  168. Xthat everyone understands that there is no warranty for this free
  169. Xsoftware.  If the software is modified by someone else and passed on, we
  170. Xwant its recipients to know that what they have is not the original, so
  171. Xthat any problems introduced by others will not reflect on the original
  172. Xauthors' reputations.
  173. X
  174. X  Finally, any free program is threatened constantly by software
  175. Xpatents.  We wish to avoid the danger that redistributors of a free
  176. Xprogram will individually obtain patent licenses, in effect making the
  177. Xprogram proprietary.  To prevent this, we have made it clear that any
  178. Xpatent must be licensed for everyone's free use or not licensed at all.
  179. X
  180. X  The precise terms and conditions for copying, distribution and
  181. Xmodification follow.
  182. X
  183. X            GNU GENERAL PUBLIC LICENSE
  184. X   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  185. X
  186. X  0. This License applies to any program or other work which contains
  187. Xa notice placed by the copyright holder saying it may be distributed
  188. Xunder the terms of this General Public License.  The "Program", below,
  189. Xrefers to any such program or work, and a "work based on the Program"
  190. Xmeans either the Program or any derivative work under copyright law:
  191. Xthat is to say, a work containing the Program or a portion of it,
  192. Xeither verbatim or with modifications and/or translated into another
  193. Xlanguage.  (Hereinafter, translation is included without limitation in
  194. Xthe term "modification".)  Each licensee is addressed as "you".
  195. X
  196. XActivities other than copying, distribution and modification are not
  197. Xcovered by this License; they are outside its scope.  The act of
  198. Xrunning the Program is not restricted, and the output from the Program
  199. Xis covered only if its contents constitute a work based on the
  200. XProgram (independent of having been made by running the Program).
  201. XWhether that is true depends on what the Program does.
  202. X
  203. X  1. You may copy and distribute verbatim copies of the Program's
  204. Xsource code as you receive it, in any medium, provided that you
  205. Xconspicuously and appropriately publish on each copy an appropriate
  206. Xcopyright notice and disclaimer of warranty; keep intact all the
  207. Xnotices that refer to this License and to the absence of any warranty;
  208. Xand give any other recipients of the Program a copy of this License
  209. Xalong with the Program.
  210. X
  211. XYou may charge a fee for the physical act of transferring a copy, and
  212. Xyou may at your option offer warranty protection in exchange for a fee.
  213. X
  214. X  2. You may modify your copy or copies of the Program or any portion
  215. Xof it, thus forming a work based on the Program, and copy and
  216. Xdistribute such modifications or work under the terms of Section 1
  217. Xabove, provided that you also meet all of these conditions:
  218. X
  219. X    a) You must cause the modified files to carry prominent notices
  220. X    stating that you changed the files and the date of any change.
  221. X
  222. X    b) You must cause any work that you distribute or publish, that in
  223. X    whole or in part contains or is derived from the Program or any
  224. X    part thereof, to be licensed as a whole at no charge to all third
  225. X    parties under the terms of this License.
  226. X
  227. X    c) If the modified program normally reads commands interactively
  228. X    when run, you must cause it, when started running for such
  229. X    interactive use in the most ordinary way, to print or display an
  230. X    announcement including an appropriate copyright notice and a
  231. X    notice that there is no warranty (or else, saying that you provide
  232. X    a warranty) and that users may redistribute the program under
  233. X    these conditions, and telling the user how to view a copy of this
  234. X    License.  (Exception: if the Program itself is interactive but
  235. X    does not normally print such an announcement, your work based on
  236. X    the Program is not required to print an announcement.)
  237. X
  238. XThese requirements apply to the modified work as a whole.  If
  239. Xidentifiable sections of that work are not derived from the Program,
  240. Xand can be reasonably considered independent and separate works in
  241. Xthemselves, then this License, and its terms, do not apply to those
  242. Xsections when you distribute them as separate works.  But when you
  243. Xdistribute the same sections as part of a whole which is a work based
  244. Xon the Program, the distribution of the whole must be on the terms of
  245. Xthis License, whose permissions for other licensees extend to the
  246. Xentire whole, and thus to each and every part regardless of who wrote it.
  247. X
  248. XThus, it is not the intent of this section to claim rights or contest
  249. Xyour rights to work written entirely by you; rather, the intent is to
  250. Xexercise the right to control the distribution of derivative or
  251. Xcollective works based on the Program.
  252. X
  253. XIn addition, mere aggregation of another work not based on the Program
  254. Xwith the Program (or with a work based on the Program) on a volume of
  255. Xa storage or distribution medium does not bring the other work under
  256. Xthe scope of this License.
  257. X
  258. X  3. You may copy and distribute the Program (or a work based on it,
  259. Xunder Section 2) in object code or executable form under the terms of
  260. XSections 1 and 2 above provided that you also do one of the following:
  261. X
  262. X    a) Accompany it with the complete corresponding machine-readable
  263. X    source code, which must be distributed under the terms of Sections
  264. X    1 and 2 above on a medium customarily used for software interchange; or,
  265. X
  266. X    b) Accompany it with a written offer, valid for at least three
  267. X    years, to give any third party, for a charge no more than your
  268. X    cost of physically performing source distribution, a complete
  269. X    machine-readable copy of the corresponding source code, to be
  270. X    distributed under the terms of Sections 1 and 2 above on a medium
  271. X    customarily used for software interchange; or,
  272. X
  273. X    c) Accompany it with the information you received as to the offer
  274. X    to distribute corresponding source code.  (This alternative is
  275. X    allowed only for noncommercial distribution and only if you
  276. X    received the program in object code or executable form with such
  277. X    an offer, in accord with Subsection b above.)
  278. X
  279. XThe source code for a work means the preferred form of the work for
  280. Xmaking modifications to it.  For an executable work, complete source
  281. Xcode means all the source code for all modules it contains, plus any
  282. Xassociated interface definition files, plus the scripts used to
  283. Xcontrol compilation and installation of the executable.  However, as a
  284. Xspecial exception, the source code distributed need not include
  285. Xanything that is normally distributed (in either source or binary
  286. Xform) with the major components (compiler, kernel, and so on) of the
  287. Xoperating system on which the executable runs, unless that component
  288. Xitself accompanies the executable.
  289. X
  290. XIf distribution of executable or object code is made by offering
  291. Xaccess to copy from a designated place, then offering equivalent
  292. Xaccess to copy the source code from the same place counts as
  293. Xdistribution of the source code, even though third parties are not
  294. Xcompelled to copy the source along with the object code.
  295. X
  296. X  4. You may not copy, modify, sublicense, or distribute the Program
  297. Xexcept as expressly provided under this License.  Any attempt
  298. Xotherwise to copy, modify, sublicense or distribute the Program is
  299. Xvoid, and will automatically terminate your rights under this License.
  300. XHowever, parties who have received copies, or rights, from you under
  301. Xthis License will not have their licenses terminated so long as such
  302. Xparties remain in full compliance.
  303. X
  304. X  5. You are not required to accept this License, since you have not
  305. Xsigned it.  However, nothing else grants you permission to modify or
  306. Xdistribute the Program or its derivative works.  These actions are
  307. Xprohibited by law if you do not accept this License.  Therefore, by
  308. Xmodifying or distributing the Program (or any work based on the
  309. XProgram), you indicate your acceptance of this License to do so, and
  310. Xall its terms and conditions for copying, distributing or modifying
  311. Xthe Program or works based on it.
  312. X
  313. X  6. Each time you redistribute the Program (or any work based on the
  314. XProgram), the recipient automatically receives a license from the
  315. Xoriginal licensor to copy, distribute or modify the Program subject to
  316. Xthese terms and conditions.  You may not impose any further
  317. Xrestrictions on the recipients' exercise of the rights granted herein.
  318. XYou are not responsible for enforcing compliance by third parties to
  319. Xthis License.
  320. X
  321. X  7. If, as a consequence of a court judgment or allegation of patent
  322. Xinfringement or for any other reason (not limited to patent issues),
  323. Xconditions are imposed on you (whether by court order, agreement or
  324. Xotherwise) that contradict the conditions of this License, they do not
  325. Xexcuse you from the conditions of this License.  If you cannot
  326. Xdistribute so as to satisfy simultaneously your obligations under this
  327. XLicense and any other pertinent obligations, then as a consequence you
  328. Xmay not distribute the Program at all.  For example, if a patent
  329. Xlicense would not permit royalty-free redistribution of the Program by
  330. Xall those who receive copies directly or indirectly through you, then
  331. Xthe only way you could satisfy both it and this License would be to
  332. Xrefrain entirely from distribution of the Program.
  333. X
  334. XIf any portion of this section is held invalid or unenforceable under
  335. Xany particular circumstance, the balance of the section is intended to
  336. Xapply and the section as a whole is intended to apply in other
  337. Xcircumstances.
  338. X
  339. XIt is not the purpose of this section to induce you to infringe any
  340. Xpatents or other property right claims or to contest validity of any
  341. Xsuch claims; this section has the sole purpose of protecting the
  342. Xintegrity of the free software distribution system, which is
  343. Ximplemented by public license practices.  Many people have made
  344. Xgenerous contributions to the wide range of software distributed
  345. Xthrough that system in reliance on consistent application of that
  346. Xsystem; it is up to the author/donor to decide if he or she is willing
  347. Xto distribute software through any other system and a licensee cannot
  348. Ximpose that choice.
  349. X
  350. XThis section is intended to make thoroughly clear what is believed to
  351. Xbe a consequence of the rest of this License.
  352. X
  353. X  8. If the distribution and/or use of the Program is restricted in
  354. Xcertain countries either by patents or by copyrighted interfaces, the
  355. Xoriginal copyright holder who places the Program under this License
  356. Xmay add an explicit geographical distribution limitation excluding
  357. Xthose countries, so that distribution is permitted only in or among
  358. Xcountries not thus excluded.  In such case, this License incorporates
  359. Xthe limitation as if written in the body of this License.
  360. X
  361. X  9. The Free Software Foundation may publish revised and/or new versions
  362. Xof the General Public License from time to time.  Such new versions will
  363. Xbe similar in spirit to the present version, but may differ in detail to
  364. Xaddress new problems or concerns.
  365. X
  366. XEach version is given a distinguishing version number.  If the Program
  367. Xspecifies a version number of this License which applies to it and "any
  368. Xlater version", you have the option of following the terms and conditions
  369. Xeither of that version or of any later version published by the Free
  370. XSoftware Foundation.  If the Program does not specify a version number of
  371. Xthis License, you may choose any version ever published by the Free Software
  372. XFoundation.
  373. X
  374. X  10. If you wish to incorporate parts of the Program into other free
  375. Xprograms whose distribution conditions are different, write to the author
  376. Xto ask for permission.  For software which is copyrighted by the Free
  377. XSoftware Foundation, write to the Free Software Foundation; we sometimes
  378. Xmake exceptions for this.  Our decision will be guided by the two goals
  379. Xof preserving the free status of all derivatives of our free software and
  380. Xof promoting the sharing and reuse of software generally.
  381. X
  382. X                NO WARRANTY
  383. X
  384. X  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
  385. XFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
  386. XOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
  387. XPROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
  388. XOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  389. XMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
  390. XTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
  391. XPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
  392. XREPAIR OR CORRECTION.
  393. X
  394. X  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
  395. XWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
  396. XREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
  397. XINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
  398. XOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
  399. XTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
  400. XYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
  401. XPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
  402. XPOSSIBILITY OF SUCH DAMAGES.
  403. X
  404. X             END OF TERMS AND CONDITIONS
  405. X
  406. X        How to Apply These Terms to Your New Programs
  407. X
  408. X  If you develop a new program, and you want it to be of the greatest
  409. Xpossible use to the public, the best way to achieve this is to make it
  410. Xfree software which everyone can redistribute and change under these terms.
  411. X
  412. X  To do so, attach the following notices to the program.  It is safest
  413. Xto attach them to the start of each source file to most effectively
  414. Xconvey the exclusion of warranty; and each file should have at least
  415. Xthe "copyright" line and a pointer to where the full notice is found.
  416. X
  417. X    <one line to give the program's name and a brief idea of what it does.>
  418. X    Copyright (C) 19yy  <name of author>
  419. X
  420. X    This program is free software; you can redistribute it and/or modify
  421. X    it under the terms of the GNU General Public License as published by
  422. X    the Free Software Foundation; either version 2 of the License, or
  423. X    (at your option) any later version.
  424. X
  425. X    This program is distributed in the hope that it will be useful,
  426. X    but WITHOUT ANY WARRANTY; without even the implied warranty of
  427. X    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  428. X    GNU General Public License for more details.
  429. X
  430. X    You should have received a copy of the GNU General Public License
  431. X    along with this program; if not, write to the Free Software
  432. X    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  433. X
  434. XAlso add information on how to contact you by electronic and paper mail.
  435. X
  436. XIf the program is interactive, make it output a short notice like this
  437. Xwhen it starts in an interactive mode:
  438. X
  439. X    Gnomovision version 69, Copyright (C) 19yy name of author
  440. X    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
  441. X    This is free software, and you are welcome to redistribute it
  442. X    under certain conditions; type `show c' for details.
  443. X
  444. XThe hypothetical commands `show w' and `show c' should show the appropriate
  445. Xparts of the General Public License.  Of course, the commands you use may
  446. Xbe called something other than `show w' and `show c'; they could even be
  447. Xmouse-clicks or menu items--whatever suits your program.
  448. X
  449. XYou should also get your employer (if you work as a programmer) or your
  450. Xschool, if any, to sign a "copyright disclaimer" for the program, if
  451. Xnecessary.  Here is a sample; alter the names:
  452. X
  453. X  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
  454. X  `Gnomovision' (which makes passes at compilers) written by James Hacker.
  455. X
  456. X  <signature of Ty Coon>, 1 April 1989
  457. X  Ty Coon, President of Vice
  458. X
  459. XThis General Public License does not permit incorporating your program into
  460. Xproprietary programs.  If your program is a subroutine library, you may
  461. Xconsider it more useful to permit linking proprietary applications with the
  462. Xlibrary.  If this is what you want to do, use the GNU Library General
  463. XPublic License instead of this License.
  464. END_OF_FILE
  465. if test 17976 -ne `wc -c <'COPYING'`; then
  466.     echo shar: \"'COPYING'\" unpacked with wrong size!
  467. fi
  468. # end of 'COPYING'
  469. fi
  470. if test -f 'comp.c' -a "${1}" != "-c" ; then 
  471.   echo shar: Will not clobber existing file \"'comp.c'\"
  472. else
  473. echo shar: Extracting \"'comp.c'\" \(7143 characters\)
  474. sed "s/^X//" >'comp.c' <<'END_OF_FILE'
  475. X/*
  476. X    reversi - play a game of reversi against the computer or a human
  477. X    Copyright (C) 1992  Elias Martenson
  478. X
  479. X    This program is free software; you can redistribute it and/or modify
  480. X    it under the terms of the GNU General Public License as published by
  481. X    the Free Software Foundation; either version 2 of the License, or
  482. X    (at your option) any later version.
  483. X
  484. X    This program is distributed in the hope that it will be useful,
  485. X    but WITHOUT ANY WARRANTY; without even the implied warranty of
  486. X    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  487. X    GNU General Public License for more details.
  488. X
  489. X    You should have received a copy of the GNU General Public License
  490. X    along with this program; if not, write to the Free Software
  491. X    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  492. X
  493. X    Contact me by email at elias@proxxi.se
  494. X*/
  495. X
  496. X#include <stdio.h>
  497. X#include <curses.h>
  498. X#include "reversi.h"
  499. X
  500. Xextern int *game_board;
  501. X
  502. X/*
  503. X * get_comp_move, calculates the best move for player
  504. X *
  505. X */
  506. X
  507. Xget_comp_move( player, board, x, y, level, f )
  508. Xint player;
  509. Xint *board;
  510. Xint *x, *y;
  511. Xint level, f;
  512. X{
  513. X  int score[8][8];
  514. X  int max_score = -10000;
  515. X  int x2, y2, c = 0;
  516. X  int t = FALSE;
  517. X  char str[20];
  518. X  
  519. X  for( x2 = 0 ; x2 < 8 ; x2++ ){
  520. X    for( y2 = 0 ; y2 < 8 ; y2++ ){
  521. X      score[x2][y2] = -10000;
  522. X    }
  523. X  }
  524. X  
  525. X  if( f ){
  526. X    for( x2 = 0 ; x2 < 8 ; x2++ ){
  527. X      for( y2 = 0 ; y2 < 8 ; y2++ ){
  528. X    if( get_board( board, x2, y2 ) == 0 ){
  529. X      c++;
  530. X    }
  531. X      }
  532. X    }
  533. X    if( c <= 15 ){
  534. X      level++;
  535. X    }
  536. X
  537. X    mvaddstr( 7, 52, "                   " );
  538. X    move( 7, 52 );
  539. X    refresh();
  540. X  }    
  541. X  
  542. X  /* Go though all possible squares */
  543. X  for( x2 = 0 ; x2 < 8 ; x2++ ){
  544. X    for( y2 = 0 ; y2 < 8 ; y2++ ){
  545. X      if( possible_move_square( board, x2, y2, player ) ){
  546. X    score[x2][y2] = calc_score_move( board, x2, y2, player, level );
  547. X    if( f ) addch( '.' );
  548. X    refresh();
  549. X      }
  550. X    }
  551. X  }
  552. X
  553. X#ifndef DEBUG
  554. X  /* Return best score for move */
  555. X  for( x2 = 0 ; x2 < 8 ; x2++ ){
  556. X    for( y2 = 0 ; y2 < 8 ; y2++ ){
  557. X      if( possible_move_square( board, x2, y2, player ) ){
  558. X    if( score[x2][y2] > max_score ){
  559. X      max_score = score[x2][y2];
  560. X      *x = x2;
  561. X      *y = y2;
  562. X    }
  563. X    t = TRUE;
  564. X      }
  565. X    }
  566. X  }
  567. X#else /* DEBUG */
  568. X  /* Return best score for move */
  569. X  if( !f ){
  570. X    for( x2 = 0 ; x2 < 8 ; x2++ ){
  571. X      for( y2 = 0 ; y2 < 8 ; y2++ ){
  572. X    if( possible_move_square( board, x2, y2, player ) ){
  573. X      if( score[x2][y2] > max_score ){
  574. X        max_score = score[x2][y2];
  575. X        *x = x2;
  576. X        *y = y2;
  577. X      }
  578. X      t = TRUE;
  579. X    }
  580. X      }
  581. X    }
  582. X  }
  583. X  else{
  584. X    for( x2 = 0 ; x2 < 8 ; x2++ ){
  585. X      for( y2 = 0 ; y2 < 8 ; y2++ ){
  586. X    if( possible_move_square( board, x2, y2, player ) ){
  587. X      sprintf( str, "%d", score[x2][y2] );
  588. X      mvaddstr( y2 * 3, x2 * 6, str );
  589. X      if( score[x2][y2] > max_score ){
  590. X        max_score = score[x2][y2];
  591. X        *x = x2;
  592. X        *y = y2;
  593. X      }
  594. X      t = TRUE;
  595. X    }
  596. X      }
  597. X    }
  598. X    refresh();
  599. X    getch();
  600. X    draw_board( game_board );
  601. X  }
  602. X#endif /* DEBUG */
  603. X
  604. X  if( !t ){
  605. X    printf( "Internal panic! No possible move found!\n" );
  606. X    printf( "x = %d, y = %d, score = %d\n", *x, *y, max_score );
  607. X    exit( 1 );
  608. X  }
  609. X  return( max_score );
  610. X}
  611. X
  612. X/*
  613. X * calc_score_move, returns the score for move
  614. X *
  615. X */
  616. X
  617. Xcalc_score_move( board, x, y, player, level )
  618. Xint *board;
  619. Xint x, y, player, level;
  620. X{
  621. X  int temp_board[64];
  622. X  int dir, score;
  623. X  int x2, y2, x3, y3, tmp;
  624. X  
  625. X  score = 0;
  626. X
  627. X  for( x2 = 0 ; x2 < 8 ; x2++ ){
  628. X    for( y2 = 0 ; y2 < 8 ; y2++ ){
  629. X      get_board( temp_board, x2, y2 ) = get_board( board, x2, y2 );
  630. X    }
  631. X  }
  632. X
  633. X  for( dir = 0 ; dir < 8 ; dir++ ){
  634. X    if( (tmp = possible_move_dir( board, x, y, dir, player, &x2, &y2 )) != 0 ){
  635. X      tmp *= SQUARE_SCORE;
  636. X      score += tmp;
  637. X    }
  638. X  }
  639. X  tmp = add_score_move( board, x, y, player );
  640. X  score += tmp;
  641. X  
  642. X  if( level != 0 ){
  643. X    put_square( player, temp_board, x, y );
  644. X    if( possible_move( temp_board, !player ) ){
  645. X      tmp = get_comp_move( !player, temp_board, &x3, &y3, level - 1, 0 );
  646. X      score += 4000 - (int)((float)tmp / DIV_POINTS);
  647. X    }
  648. X    else{
  649. X      score += NO_MOVE_BONUS;
  650. X    }
  651. X  }
  652. X  
  653. X  return( score );
  654. X}
  655. X
  656. X/*
  657. X * add_score_move, calulate the bonus for this position
  658. X *
  659. X */
  660. X
  661. Xadd_score_move( board, x, y, player )
  662. Xint *board;
  663. Xint x, y, player;
  664. X{
  665. X  int tmp;
  666. X  int c;
  667. X
  668. X  if( (x == 0 && y == 0 ) ||
  669. X     (x == 0 && y == 7 ) ||
  670. X     (x == 7 && y == 0 ) ||
  671. X     (x == 7 && y == 7 )){
  672. X    return( CORNER_SCORE );
  673. X  }
  674. X  
  675. X  if( (x == 0) || (x == 7) ){
  676. X    if( y <= 3 ){
  677. X      tmp = BORDER_SCORE + BORDER_POS_BONUS * (y + 1);
  678. X    }
  679. X    else{
  680. X      tmp = BORDER_SCORE + (BORDER_POS_BONUS * ((3 - (y - 4)) + 1));
  681. X    }
  682. X    
  683. X    if( get_board( board, x, y - 1 ) == (!player + 1) && get_board( board, x, y + 1 ) != (!player + 1) ){
  684. X      c = y - 1;
  685. X      while( (get_board( board, x, c ) == (!player + 1)) && (c > 0) ) c--;
  686. X      if( get_board( board, x, c ) != (player + 1) ){
  687. X    return( 0 );
  688. X      }
  689. X    }
  690. X    else if( get_board( board, x, y + 1 ) == (!player + 1) && get_board( board, x, y - 1 ) != (!player + 1) ){
  691. X      c = y + 1;
  692. X      while( (get_board( board, x, c ) == (!player + 1)) && (c < 7) ) c++;
  693. X      if( get_board( board, x, c ) != (player + 1) ){
  694. X    return( 0 );
  695. X      }
  696. X    }
  697. X
  698. X/* Check if this is a double score position */
  699. X    if( get_board( board, x, y - 1 ) == (!player + 1) && get_board( board, x, y + 1 ) == (!player + 1) ){
  700. X      return( tmp * 2 );
  701. X    }
  702. X    else{
  703. X      return( tmp );
  704. X    }
  705. X  }
  706. X  
  707. X  if( (y == 0) || (y == 7) ){
  708. X    if( x <= 3 ){
  709. X      tmp = BORDER_SCORE + BORDER_POS_BONUS * (x + 1);
  710. X    }
  711. X    else{
  712. X      tmp = BORDER_SCORE + (BORDER_POS_BONUS * ((3 - (x - 4)) + 1));
  713. X    }
  714. X    
  715. X    if( get_board( board, x - 1, y ) == (!player + 1) && get_board( board, x + 1, y ) != (!player + 1) ){
  716. X      c = x - 1;
  717. X      while( (get_board( board, c, y ) == (!player + 1)) && (c > 0) ) c--;
  718. X      if( get_board( board, c, x ) != (player + 1) ){
  719. X    return( 0 );
  720. X      }
  721. X    }
  722. X    else if( get_board( board, x + 1, y ) == (!player + 1) && get_board( board, x - 1, y ) != (!player + 1) ){
  723. X      c = y - 1;
  724. X      while( (get_board( board, c, y ) == (!player + 1)) && (c < 7) ) c++;
  725. X      if( get_board( board, c, x ) != (player + 1) ){
  726. X    return( 0 );
  727. X      }
  728. X    }
  729. X
  730. X/* Check if this is a double score position */
  731. X    if( get_board( board, x - 1, y ) == (!player + 1) && get_board( board, x + 1, y ) == (!player + 1) ){
  732. X      return( tmp * 2 );
  733. X    }
  734. X    else{
  735. X      return( tmp );
  736. X    }
  737. X  }
  738. X  
  739. X  if( (x == 1 && y == 1) ||
  740. X     (x == 1 && y == 6) ||
  741. X     (x == 6 && y == 1) ||
  742. X     (x == 6 && y == 6)){
  743. X    return( BORDER2_CORNER_SCORE );
  744. X  }
  745. X  
  746. X  if( (x == 1) || (x == 6) ){
  747. X    if( y <= 3 ) return( BORDER2_SCORE + BORDER2_POS_BONUS * y );
  748. X    else return( BORDER2_SCORE + (BORDER2_POS_BONUS * (4 - (y - 3))) );
  749. X  }
  750. X  
  751. X  if( (y == 1) || (y == 6) ){
  752. X    if( x <= 3 ) return( BORDER2_SCORE + BORDER2_POS_BONUS * x );
  753. X    else return( BORDER2_SCORE + (BORDER2_POS_BONUS * (4 - (x - 3))) );
  754. X  }
  755. X  
  756. X  if( (x == 2 && y == 2) ||
  757. X     (x == 2 && y == 5) ||
  758. X     (x == 5 && y == 2) ||
  759. X     (x == 5 && y == 5)){
  760. X    return( BORDER3_CORNER_SCORE );
  761. X  }
  762. X  
  763. X  if( (x == 2) || (y == 5) ){
  764. X    return( BORDER3_SCORE );
  765. X  }
  766. X  
  767. X  if( (y == 2) || (y == 5) ){
  768. X    return( BORDER3_SCORE );
  769. X  }
  770. X  
  771. X  return( 0 );
  772. X}
  773. END_OF_FILE
  774. if test 7143 -ne `wc -c <'comp.c'`; then
  775.     echo shar: \"'comp.c'\" unpacked with wrong size!
  776. fi
  777. # end of 'comp.c'
  778. fi
  779. if test -f 'graphics.c' -a "${1}" != "-c" ; then 
  780.   echo shar: Will not clobber existing file \"'graphics.c'\"
  781. else
  782. echo shar: Extracting \"'graphics.c'\" \(6179 characters\)
  783. sed "s/^X//" >'graphics.c' <<'END_OF_FILE'
  784. X/*
  785. X    reversi - play a game of reversi against the computer or human
  786. X    Copyright (C) 1992  Elias Martenson
  787. X
  788. X    This program is free software; you can redistribute it and/or modify
  789. X    it under the terms of the GNU General Public License as published by
  790. X    the Free Software Foundation; either version 2 of the License, or
  791. X    (at your option) any later version.
  792. X
  793. X    This program is distributed in the hope that it will be useful,
  794. X    but WITHOUT ANY WARRANTY; without even the implied warranty of
  795. X    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  796. X    GNU General Public License for more details.
  797. X
  798. X    You should have received a copy of the GNU General Public License
  799. X    along with this program; if not, write to the Free Software
  800. X    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  801. X
  802. X    Contact me by email at elias@proxxi.se
  803. X*/
  804. X
  805. X
  806. X#include <curses.h>
  807. X#include "reversi.h"
  808. X#include "menu.h"
  809. X
  810. Xextern int *game_board;
  811. X
  812. X/*
  813. X * Do all curses screen init
  814. X *
  815. X */
  816. X
  817. Xinit_screen()
  818. X{
  819. X  initscr();
  820. X  cbreak();
  821. X  nonl();
  822. X  noecho();
  823. X
  824. X  clear();
  825. X  refresh();
  826. X}
  827. X
  828. Xexit_screen()
  829. X{
  830. X  endwin();
  831. X}
  832. X
  833. Xdraw_board( board )
  834. Xint *board;
  835. X{
  836. X  int x, y;
  837. X  int num_w = 0, num_b = 0;
  838. X  char str[80];
  839. X
  840. X  for( x = 0 ; x < 8 ; x++ ){
  841. X    for( y = 0 ; y < 8 ; y++ ){
  842. X      if( get_board( board, x, y ) == 1 ) num_w++;
  843. X      else if( get_board( board, x, y ) == 2 ) num_b++;
  844. X    }
  845. X  }
  846. X
  847. X  mvaddstr( 17, 52, "           " );
  848. X  mvaddstr( 18, 52, "           " );
  849. X  sprintf( str, "White: %d", num_w );
  850. X  mvaddstr( 17, 52, str );
  851. X  sprintf( str, "Black: %d", num_b );
  852. X  mvaddstr( 18, 52, str );
  853. X
  854. X  mvaddstr( 20, 52, "ESC for menu" );
  855. X  mvaddstr( 21, 52, "By Elias Martenson" );
  856. X
  857. X  for( y = 0 ; y < 8 ; y++ ){
  858. X    for( x = 0 ; x < 8 ; x++ ){
  859. X      switch( get_board( board, x, y ) ){
  860. X      case 0:
  861. X    mvaddstr( y * 3, x * 6, " .. " );
  862. X    mvaddstr( y * 3 + 1, x * 6, " .. " );
  863. X    break;
  864. X      case 1:
  865. X    mvaddstr( y * 3, x * 6, "<  >" );
  866. X    mvaddstr( y * 3 + 1, x * 6, "<  >" );
  867. X    break;
  868. X      case 2:
  869. X    mvaddstr( y * 3, x * 6, "####" );
  870. X    mvaddstr( y * 3 + 1, x * 6, "####" );
  871. X    break;
  872. X      default:
  873. X    printf( "Error: I see there is an illegal square on the board!\n" );
  874. X    break;
  875. X      }
  876. X    }
  877. X  }
  878. X
  879. X  refresh();
  880. X}
  881. X
  882. Xget_move( player, x, y )
  883. Xint player;
  884. Xint *x, *y;
  885. X{
  886. X  int x2, y2, end_getmove = FALSE;
  887. X
  888. X  x2 = 3;
  889. X  y2 = 3;
  890. X
  891. X  do{
  892. X    move( y2 * 3, x2 * 6 + 1 );
  893. X    refresh();
  894. X
  895. X    switch( getch() ){
  896. X    case 'h':
  897. X      if( x2 >= 1 ) x2--;
  898. X      break;
  899. X    case 'j':
  900. X      if( y2 <= 6 ) y2++;
  901. X      break;
  902. X    case 'k':
  903. X      if( y2 >= 1 ) y2--;
  904. X      break;
  905. X    case 'l':
  906. X      if( x2 <= 6 ) x2++;
  907. X      break;
  908. X    case ' ':
  909. X      if( possible_move_square( game_board, x2, y2, player ) ){
  910. X    end_getmove = TRUE;
  911. X      }
  912. X      break;
  913. X    case '?':
  914. X      do_help();
  915. X      draw_board( game_board );
  916. X      break;
  917. X    case 12:
  918. X      clearok( stdscr, TRUE );
  919. X      refresh();
  920. X      break;
  921. X    case 27:
  922. X      do_game_menu( player );
  923. X      break;
  924. X    }
  925. X  }while( !end_getmove );
  926. X
  927. X  *x = x2;
  928. X  *y = y2;
  929. X}
  930. X
  931. Xdo_help( player )
  932. Xint player;
  933. X{
  934. X  WINDOW *win;
  935. X
  936. X  win = newwin( 24, 80, 0, 0 );
  937. X
  938. X  wclear( win );
  939. X  touchwin( win );
  940. X
  941. X  mvwaddstr( win, 0, 0, "reversi, V1.24" );
  942. X  mvwaddstr( win, 1, 0, "Copyright 1992 Elias Martenson" );
  943. X  mvwaddstr( win, 3, 0, "Move the cursor by using the keys h, j, k, l" );
  944. X  mvwaddstr( win, 4, 0, "And place your tile on a square with space." );
  945. X  mvwaddstr( win, 6, 0, "The object of the game is to have the most number" );
  946. X  mvwaddstr( win, 7, 0, "of tiles with your colour when none of the players" );
  947. X  mvwaddstr( win, 8, 0, "has a legal move." );
  948. X  mvwaddstr( win, 10, 0, "Each tile is white on one side and black on the" );
  949. X  mvwaddstr( win, 11, 0, "other. When a tile is placed, you flip the enemys" );
  950. X  mvwaddstr( win, 12, 0, "tiles that has become \"trapped\" between the one" );
  951. X  mvwaddstr( win, 13, 0, "you just put and another tile of your colour." );
  952. X  mvwaddstr( win, 23, 0, "Press a key to resume play." );
  953. X
  954. X  wrefresh( win );
  955. X
  956. X  getch();
  957. X
  958. X  delwin( win );
  959. X  clearok( stdscr, TRUE );
  960. X  refresh();
  961. X}
  962. X
  963. Xdo_game_menu( player )
  964. Xint player;
  965. X{
  966. X  int selected_menu;
  967. X  MenuEntry game_menu[] = {
  968. X    "About", NULL, SELECTABLE,
  969. X    "Setup", NULL, SELECTABLE,
  970. X    "Undo last move", NULL, SELECTABLE,
  971. X    "Show possible moves", NULL, SELECTABLE,
  972. X    "Save game", NULL, SELECTABLE,
  973. X    "Quit game", NULL, SELECTABLE,
  974. X    "Resume game", NULL, SELECTABLE,
  975. X    NULL, NULL, 0
  976. X  };
  977. X
  978. X  do{
  979. X    selected_menu = menu( 52, 9, 0, 0, 0, WRAP | ENABLE_QUIT | CLEAR_ON_EXIT, game_menu );
  980. X    
  981. X    switch( selected_menu ){
  982. X    case 0:
  983. X      show_about();
  984. X      break;
  985. X    case 1:
  986. X      /*    do_setup();*/
  987. X      break;
  988. X    case 2:
  989. X      do_undo_move();
  990. X      break;
  991. X    case 3:
  992. X      do_show_possible( player );
  993. X      break;
  994. X    case 4:
  995. X      save_game( player );
  996. X      break;
  997. X    case 5:
  998. X      exit_rout( 0 );
  999. X      break;
  1000. X    }
  1001. X
  1002. X  }while( selected_menu != -1 && selected_menu != 5 );
  1003. X}
  1004. X
  1005. Xshow_about()
  1006. X{
  1007. X  WINDOW *win;
  1008. X
  1009. X  win = newwin( 24, 80, 0, 0 );
  1010. X
  1011. X  wclear( win );
  1012. X  touchwin( win );
  1013. X
  1014. X  mvwaddstr( win, 0, 0, "reversi, V1.24" );
  1015. X  mvwaddstr( win, 1, 0, "Copyright 1992 Elias Martenson (elias@proxxi.se)" );
  1016. X  mvwaddstr( win, 3, 0, "Menu routines by Stefan Rapp (rappen@proxxi.se)" );
  1017. X  mvwaddstr( win, 5, 0, "Beta testers:" );
  1018. X  mvwaddstr( win, 6, 0, "Gustav Berggren (gustav@proxxi.se)" );
  1019. X  mvwaddstr( win, 7, 0, "Anders Bollmark (bollen@proxxi.se)" );
  1020. X  mvwaddstr( win, 8, 0, "Martin Green (bullen@proxxi.se)" );
  1021. X  mvwaddstr( win, 9, 0, "Magnus Krafft (krafft@proxxi.se)" );
  1022. X  mvwaddstr( win, 10, 0, "Stefan Rapp (rappen@proxxi.se)" );
  1023. X  mvwaddstr( win, 11, 0, "Carl Serrander (calle@proxxi.se)" );
  1024. X  mvwaddstr( win, 23, 0, "Press any key to resume play." );
  1025. X
  1026. X  wrefresh( win );
  1027. X
  1028. X  getch();
  1029. X
  1030. X  delwin( win );
  1031. X  clearok( stdscr, TRUE );
  1032. X  refresh();
  1033. X}
  1034. X
  1035. Xdo_show_possible( player )
  1036. Xint player;
  1037. X{
  1038. X  int count_x, count_y;
  1039. X
  1040. X  for( count_x = 0 ; count_x < 8 ; count_x++ ){
  1041. X    for( count_y = 0 ; count_y < 8 ; count_y++ ){
  1042. X      if( possible_move_square( game_board, count_x, count_y, player ) ){
  1043. X    standout();
  1044. X    mvaddstr( count_y * 3, count_x * 6, "    " );
  1045. X    mvaddstr( count_y * 3 + 1, count_x * 6, "    " );
  1046. X    standend();
  1047. X      }
  1048. X    }
  1049. X  }
  1050. X
  1051. X  refresh();
  1052. X  getch();
  1053. X
  1054. X  draw_board( game_board );
  1055. X}
  1056. END_OF_FILE
  1057. if test 6179 -ne `wc -c <'graphics.c'`; then
  1058.     echo shar: \"'graphics.c'\" unpacked with wrong size!
  1059. fi
  1060. # end of 'graphics.c'
  1061. fi
  1062. if test -f 'menu.h' -a "${1}" != "-c" ; then 
  1063.   echo shar: Will not clobber existing file \"'menu.h'\"
  1064. else
  1065. echo shar: Extracting \"'menu.h'\" \(1011 characters\)
  1066. sed "s/^X//" >'menu.h' <<'END_OF_FILE'
  1067. X/*
  1068. X *  If TRUE and FALSE isn't defined, we define our own
  1069. X *
  1070. X */
  1071. X
  1072. X#ifndef TRUE
  1073. X#define TRUE (1)
  1074. X#define FALSE (0)
  1075. X#endif
  1076. X
  1077. X/*
  1078. X * Definitions for the keys to control the menus.
  1079. X *
  1080. X */
  1081. X
  1082. X#define MV_UP 'k'
  1083. X#define MV_DOWN 'j'
  1084. X#define PG_UP 'K'
  1085. X#define PG_DOWN 'J'
  1086. X#define QUIT 27
  1087. X#define SELECT 13
  1088. X#define HELP '?'
  1089. X
  1090. X/*
  1091. X * Definitions for menu flags
  1092. X *
  1093. X */
  1094. X
  1095. X#define WRAP 0x01        /* If the menu should wrap */
  1096. X#define DRAW_BOX  0x02          /* If the menu should have a box */
  1097. X#define ENABLE_QUIT 0x04        /* If the menu should accept QUIT key */
  1098. X                 /* and return -1                      */
  1099. X#define ENABLE_HELP 0x08        /* If the menu should accept help key */
  1100. X#define CLEAR_ON_EXIT 0x10    /* Clear the menuwindow on exit */
  1101. X
  1102. X#define DRAW_BOX_SYMBOL_HORIZ '-'
  1103. X#define DRAW_BOX_SYMBOL_VERT '?'
  1104. X
  1105. X#define SELECTABLE 0x01
  1106. X
  1107. X/*
  1108. X * Types for the menu
  1109. X *
  1110. X */
  1111. X
  1112. Xtypedef struct {
  1113. X  char *name;
  1114. X  char *help;
  1115. X  int flags;
  1116. X} MenuEntry;
  1117. X
  1118. Xint menu( int x, int y, int width, int height, int start, int flags, MenuEntry *names );
  1119. END_OF_FILE
  1120. if test 1011 -ne `wc -c <'menu.h'`; then
  1121.     echo shar: \"'menu.h'\" unpacked with wrong size!
  1122. fi
  1123. # end of 'menu.h'
  1124. fi
  1125. if test -f 'move.c' -a "${1}" != "-c" ; then 
  1126.   echo shar: Will not clobber existing file \"'move.c'\"
  1127. else
  1128. echo shar: Extracting \"'move.c'\" \(6182 characters\)
  1129. sed "s/^X//" >'move.c' <<'END_OF_FILE'
  1130. X/*
  1131. X    reversi - play a game of reversi against the computer or a human
  1132. X    Copyright (C) 1992  Elias Martenson
  1133. X
  1134. X    This program is free software; you can redistribute it and/or modify
  1135. X    it under the terms of the GNU General Public License as published by
  1136. X    the Free Software Foundation; either version 2 of the License, or
  1137. X    (at your option) any later version.
  1138. X
  1139. X    This program is distributed in the hope that it will be useful,
  1140. X    but WITHOUT ANY WARRANTY; without even the implied warranty of
  1141. X    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1142. X    GNU General Public License for more details.
  1143. X
  1144. X    You should have received a copy of the GNU General Public License
  1145. X    along with this program; if not, write to the Free Software
  1146. X    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1147. X
  1148. X    Contact me by email at elias@proxxi.se
  1149. X*/
  1150. X
  1151. X#include "reversi.h"
  1152. X
  1153. Xextern int *game_board;
  1154. X
  1155. X/*
  1156. X * possible_move, returns FALSE if there are no possible moves for
  1157. X * the player, and TRUE if there is.
  1158. X *
  1159. X */
  1160. X
  1161. Xpossible_move( board, player )
  1162. Xint *board;
  1163. Xint player;
  1164. X{
  1165. X  int x, y;
  1166. X  
  1167. X  for( x = 0 ; x < 8 ; x++ ){
  1168. X    for( y = 0 ; y < 8 ; y++ ){
  1169. X      if( get_board( board, x, y ) == 0 ){
  1170. X    if( possible_move_square( board, x, y, player ) ){
  1171. X      return( TRUE );
  1172. X    }
  1173. X      }
  1174. X    }
  1175. X  }
  1176. X  return( FALSE );
  1177. X}
  1178. X
  1179. X/*
  1180. X * possible_move_square, returns FALSE if x, y is an illegal move
  1181. X * for player.
  1182. X *
  1183. X */
  1184. X
  1185. Xpossible_move_square( board, x, y, player )
  1186. Xint *board;
  1187. Xint x, y, player;
  1188. X{
  1189. X  int dir, x2, y2;
  1190. X  
  1191. X  if( get_board( board, x, y ) != 0 ) return( FALSE );
  1192. X  for( dir = 0 ; dir < 8 ; dir++ ){
  1193. X    if( possible_move_dir( board, x, y, dir, player, &x2, &y2 ) != 0 ){
  1194. X      return( TRUE );
  1195. X    }
  1196. X  }
  1197. X  return( FALSE );
  1198. X}
  1199. X
  1200. X/*
  1201. X * possible_move_dir, returns 0 if x, y, dir is an illegal move
  1202. X * for player, otherwise the number of turned squares
  1203. X *
  1204. X */
  1205. X
  1206. Xpossible_move_dir( board, x, y, dir, player, x2, y2 )
  1207. Xint *board;
  1208. Xint x, y, dir, player;
  1209. Xint *x2, *y2;
  1210. X{
  1211. X  *x2 = x;
  1212. X  *y2 = y;
  1213. X
  1214. X
  1215. X  switch( dir ){
  1216. X  case 0: /* Up */
  1217. X    if( --*y2 < 1 ) return( 0 );
  1218. X    if( get_board( board, x, *y2 ) == 0 || get_board( board, x, *y2 ) == (player + 1)) return( 0 );
  1219. X    while( *y2 > 0 ){
  1220. X      (*y2)--;
  1221. X      if( get_board( board, x, *y2 ) == 0 ) return( 0 );
  1222. X      if( get_board( board, x, *y2 ) == (player + 1) ) return( y - *y2 );
  1223. X    }
  1224. X    break;
  1225. X  case 1: /* Up Right */
  1226. X    if( --*y2 < 1 || ++*x2 > 6 ) return( 0 );
  1227. X    if( get_board( board, *x2, *y2 ) == 0 || get_board( board, *x2, *y2 ) == (player + 1)) return( 0 );
  1228. X    while( *y2 > 0 && *x2 < 7 ){
  1229. X      (*y2)--;
  1230. X      (*x2)++;
  1231. X      if( get_board( board, *x2, *y2 ) == 0 ) return( 0 );
  1232. X      if( get_board( board, *x2, *y2 ) == (player + 1) ) return( *x2 - x );
  1233. X    }
  1234. X    break;
  1235. X  case 2: /* Right */
  1236. X    if( ++*x2 > 6 ) return( 0 );
  1237. X    if( get_board( board, *x2, y ) == 0 || get_board( board, *x2, y ) == (player + 1)) return( 0 );
  1238. X    while( *x2 < 7 ){
  1239. X      (*x2)++;
  1240. X      if( get_board( board, *x2, y ) == 0 ) return( 0 );
  1241. X      if( get_board( board, *x2, y ) == (player + 1) ) return( *x2 - x );
  1242. X    }
  1243. X    break;
  1244. X  case 3: /* Down Right */
  1245. X    if( ++*y2 > 6 || ++*x2 > 6 ) return( 0 );
  1246. X    if( get_board( board, *x2, *y2 ) == 0 || get_board( board, *x2, *y2 ) == ( player + 1)) return( 0 );
  1247. X    while( *y2 < 7 && *x2 < 7 ){
  1248. X      (*y2)++;
  1249. X      (*x2)++;
  1250. X      if( get_board( board, *x2, *y2 ) == 0 ) return( 0 );
  1251. X      if( get_board( board, *x2, *y2 ) == (player + 1) ) return( *x2 - x );
  1252. X    }
  1253. X    break;
  1254. X  case 4: /* Down */
  1255. X    if( ++*y2 > 6 ) return( 0 );
  1256. X    if( get_board( board, x, *y2 ) == 0 || get_board( board, x, *y2 ) == (player + 1)) return( 0 );
  1257. X    while( *y2 < 7 ){
  1258. X      (*y2)++;
  1259. X      if( get_board( board, x, *y2 ) == 0 ) return( 0 );
  1260. X      if( get_board( board, x, *y2 ) == (player + 1) ) return( *y2 - y );
  1261. X    }
  1262. X    break;
  1263. X  case 5: /* Down Left */
  1264. X    if( ++*y2 > 6 || --*x2 < 1 ) return( 0 );
  1265. X    if( get_board( board, *x2, *y2 ) == 0 || get_board( board, *x2, *y2 ) == (player + 1)) return( 0 );
  1266. X    while( *y2 < 7 && *x2 > 0 ){
  1267. X      (*y2)++;
  1268. X      (*x2)--;
  1269. X      if( get_board( board, *x2, *y2 ) == 0 ) return( 0 );
  1270. X      if( get_board( board, *x2, *y2 ) == (player + 1) ) return( x - *x2 );
  1271. X    }
  1272. X    break;
  1273. X  case 6: /* Left */
  1274. X    if( --*x2 < 1 ) return( 0 );
  1275. X    if( get_board( board, *x2, y ) == 0 || get_board( board, *x2, y ) == (player + 1)) return( 0 );
  1276. X    while( *x2 > 0 ){
  1277. X      (*x2)--;
  1278. X      if( get_board( board, *x2, y ) == 0 ) return( 0 );
  1279. X      if( get_board( board, *x2, y ) == (player + 1) ) return( x - *x2 );
  1280. X    }
  1281. X    break;
  1282. X  case 7: /* Up Left */
  1283. X    if( --*y2 < 1 || --*x2 < 1 ) return( 0 );
  1284. X    if( get_board( board, *x2, *y2 ) == 0 || get_board( board, *x2, *y2 ) == (player + 1)) return( 0 );
  1285. X    while( *y2 > 0 && *x2 > 0 ){
  1286. X      (*y2)--;
  1287. X      (*x2)--;
  1288. X      if( get_board( board, *x2, *y2 ) == 0 ) return( 0 );
  1289. X      if( get_board( board, *x2, *y2 ) == (player + 1) ) return( x - *x2 );
  1290. X    }
  1291. X    break;
  1292. X  }
  1293. X  return( 0 );
  1294. X}
  1295. X
  1296. X/*
  1297. X * put_square, puts a square of mark player on the board, turning
  1298. X * other squares
  1299. X *
  1300. X */
  1301. X
  1302. Xput_square( player, board, x, y )
  1303. Xint player;
  1304. Xint *board;
  1305. Xint x, y;
  1306. X{
  1307. X  int dir, x2, y2;
  1308. X  
  1309. X  for( dir = 0 ; dir < 8 ; dir++ ){
  1310. X    if( possible_move_dir( board, x, y, dir, player, &x2, &y2 ) != 0 ){
  1311. X      get_board( board, x, y ) = player + 1;
  1312. X      flip( board, x, y, x2, y2, dir, player );
  1313. X    }
  1314. X  }
  1315. X}
  1316. X
  1317. X/*
  1318. X * flip, flips all squares in a line, direction dir
  1319. X *
  1320. X */
  1321. X
  1322. Xflip( board, x, y, x2, y2, dir, player )
  1323. Xint *board;
  1324. Xint x, y, x2, y2, dir, player;
  1325. X{
  1326. X  int a_x, a_y;
  1327. X  
  1328. X  switch( dir ){
  1329. X  case 0: /* Up */
  1330. X    a_x = 0;
  1331. X    a_y = -1;
  1332. X    break;
  1333. X  case 1: /* Up Right */
  1334. X    a_x = 1;
  1335. X    a_y = -1;
  1336. X    break;
  1337. X  case 2: /* Right */
  1338. X    a_x = 1;
  1339. X    a_y = 0;
  1340. X    break;
  1341. X  case 3: /* Down Right */
  1342. X    a_x = 1;
  1343. X    a_y = 1;
  1344. X    break;
  1345. X  case 4: /* Down */
  1346. X    a_x = 0;
  1347. X    a_y = 1;
  1348. X    break;
  1349. X  case 5: /* Down Left */
  1350. X    a_x = -1;
  1351. X    a_y = 1;
  1352. X    break;
  1353. X  case 6: /* Left */
  1354. X    a_x = -1;
  1355. X    a_y = 0;
  1356. X    break;
  1357. X  case 7: /* Up Left */
  1358. X    a_x = -1;
  1359. X    a_y = -1;
  1360. X    break;
  1361. X  }
  1362. X  
  1363. X  x += a_x;
  1364. X  y += a_y;
  1365. X  
  1366. X  do{
  1367. X    get_board( board, x, y ) = player + 1;
  1368. X    x += a_x;
  1369. X    y += a_y;
  1370. X  }while( get_board( board, x, y ) == ( !player + 1 ) );
  1371. X}
  1372. END_OF_FILE
  1373. if test 6182 -ne `wc -c <'move.c'`; then
  1374.     echo shar: \"'move.c'\" unpacked with wrong size!
  1375. fi
  1376. # end of 'move.c'
  1377. fi
  1378. if test -f 'reversi.c' -a "${1}" != "-c" ; then 
  1379.   echo shar: Will not clobber existing file \"'reversi.c'\"
  1380. else
  1381. echo shar: Extracting \"'reversi.c'\" \(9443 characters\)
  1382. sed "s/^X//" >'reversi.c' <<'END_OF_FILE'
  1383. X/*
  1384. X    reversi - play a game of reversi against the computer or a human
  1385. X    Copyright (C) 1992  Elias Martenson
  1386. X
  1387. X    This program is free software; you can redistribute it and/or modify
  1388. X    it under the terms of the GNU General Public License as published by
  1389. X    the Free Software Foundation; either version 2 of the License, or
  1390. X    (at your option) any later version.
  1391. X
  1392. X    This program is distributed in the hope that it will be useful,
  1393. X    but WITHOUT ANY WARRANTY; without even the implied warranty of
  1394. X    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1395. X    GNU General Public License for more details.
  1396. X
  1397. X    You should have received a copy of the GNU General Public License
  1398. X    along with this program; if not, write to the Free Software
  1399. X    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1400. X
  1401. X    Contact me by email at elias@proxxi.se
  1402. X*/
  1403. X
  1404. X#include <stdio.h>
  1405. X#include <signal.h>
  1406. X#include <curses.h>
  1407. X#include <string.h>
  1408. X#include "reversi.h"
  1409. X#include "menu.h"
  1410. X
  1411. Xchar *getenv( char * );
  1412. X
  1413. Xint game_board2[64];
  1414. Xint *game_board;
  1415. Xint *old_gameboard;
  1416. Xint game_lev1, game_lev2;
  1417. Xint old_pointer;
  1418. Xint to_load = 0;
  1419. Xint p1, p2;
  1420. X
  1421. X#ifdef HAVE_VOID_SIGNALS
  1422. Xvoid exit_rout();
  1423. X#else
  1424. Xint exit_rout();
  1425. X#endif
  1426. X
  1427. Xmain( argc, argv )
  1428. Xint argc;
  1429. Xchar **argv;
  1430. X{
  1431. X  int w_b;
  1432. X  char str[20];
  1433. X  char c;
  1434. X  int starting_player;
  1435. X  char tmp_str[80];
  1436. X  FILE *fp;
  1437. X  int curr_scr;
  1438. X  int x, y;
  1439. X  int t;
  1440. X  MenuEntry game_setup[] = {
  1441. X    "Standard", NULL, SELECTABLE,
  1442. X    "Inverse ", NULL, SELECTABLE,
  1443. X    NULL, NULL, 0
  1444. X  };
  1445. X  MenuEntry select_player[] = {
  1446. X    "Human   ", NULL, SELECTABLE,
  1447. X    "Computer", NULL, SELECTABLE,
  1448. X    NULL, NULL, 0
  1449. X  };
  1450. X  MenuEntry level_menu[] = {
  1451. X    "Apprentice", NULL, SELECTABLE,
  1452. X    "Amateur   ", NULL, SELECTABLE,
  1453. X    "Regular   ", NULL, SELECTABLE,
  1454. X    "Advanced  ", NULL, SELECTABLE,
  1455. X    "Hard      ", NULL, SELECTABLE,
  1456. X    "Very Hard ", NULL, SELECTABLE,
  1457. X    NULL, NULL, 0 
  1458. X  };
  1459. X
  1460. X  old_pointer = 0;
  1461. X  starting_player = 0;
  1462. X
  1463. X  if( argc == 2 ){
  1464. X    if( strcmp( argv[1], "-r" ) == 0 ){
  1465. X      to_load = TRUE;
  1466. X    }
  1467. X    else{
  1468. X      usage();
  1469. X    }
  1470. X  }
  1471. X  else if( argc > 2 ){
  1472. X    usage();
  1473. X  }
  1474. X
  1475. X  init_screen();
  1476. X  
  1477. X  signal( SIGINT, exit_rout );
  1478. X
  1479. X  game_board = (int *)game_board2;
  1480. X  if( (old_gameboard = (int *)malloc( sizeof(int) * 64 * 60 )) == NULL ){
  1481. X    fprintf( stderr, "Could not allocate memory.\n" );
  1482. X    endwin();
  1483. X    exit( 1 );
  1484. X  }
  1485. X
  1486. X  addstr( "reversi version 1.24, Copyright (C) 1992 Elias Martenson\n" );
  1487. X  addstr( "reversi comes with ABSOLUTELY NO WARRANTY.\n" );
  1488. X  addstr( "This is free software, and you are welcome to redistribute it\n" );
  1489. X  addstr( "under certain conditions; see the file COPYING for details.\n\n" );
  1490. X
  1491. X  refresh();
  1492. X
  1493. X  if( !to_load ){
  1494. X    
  1495. X    mvaddstr( 8, 0, "Select game setup" );
  1496. X    refresh();
  1497. X    w_b = menu( 0, 10, 18, 2, 0, WRAP, game_setup );
  1498. X    
  1499. X    mvaddstr( 8, 20, "White played by?" );
  1500. X    refresh();
  1501. X    p1 = menu( 20, 10, 18, 2, 0, WRAP, select_player );
  1502. X    if( p1 == 1 ){
  1503. X      mvaddstr( 14, 20, "Enter level:" );
  1504. X      refresh();
  1505. X      game_lev1 = menu( 20, 16, 18, 6, 0, WRAP, level_menu );
  1506. X    }
  1507. X    
  1508. X    mvaddstr( 8, 40, "Black played by?" );
  1509. X    refresh();
  1510. X    p2 = menu( 40, 10, 18, 2, 0, WRAP, select_player );
  1511. X    if( p2 == 1 ){
  1512. X      mvaddstr( 14, 40, "Enter level:" );
  1513. X      refresh();
  1514. X      game_lev2 = menu( 40, 16, 18, 6, 0, WRAP, level_menu );
  1515. X    }
  1516. X    
  1517. X    clear();
  1518. X    refresh();
  1519. X    init_board( w_b );
  1520. X
  1521. X  }
  1522. X  else{
  1523. X    strcpy( tmp_str, getenv( "HOME" ) );
  1524. X    strcat( tmp_str, "/.reversi_save" );
  1525. X    if( (fp = fopen( tmp_str, "r" )) == NULL ){
  1526. X      fprintf( stderr, "Could not open save file\n" );
  1527. X      exit_rout( 0 );
  1528. X    }
  1529. X    fread( &starting_player, sizeof( int ), 1, fp );
  1530. X    fread( &p1, sizeof( int ), 1, fp );
  1531. X    fread( &p2, sizeof( int ), 1, fp );
  1532. X    fread( &game_lev1, sizeof( int ), 1, fp );
  1533. X    fread( &game_lev2, sizeof( int ), 1, fp );
  1534. X
  1535. X    curr_scr = 0;
  1536. X    do{
  1537. X      for( x = 0 ; x < 8 ; x++ ){
  1538. X    for( y = 0 ; y < 8 ; y++ ){
  1539. X      fread( &t, sizeof( int ), 1, fp );
  1540. X      get_board( old_gameboard + curr_scr, x, y ) = t;
  1541. X    }
  1542. X      }
  1543. X      curr_scr += 64;
  1544. X    }while( !feof( fp ) );
  1545. X    fclose( fp );
  1546. X    curr_scr -= 64;
  1547. X    old_pointer = curr_scr;
  1548. X    for( x = 0 ; x < 8 ; x++ ){
  1549. X      for( y = 0 ; y < 8 ; y++ ){
  1550. X    get_board( game_board, x, y ) = get_board( old_gameboard + curr_scr - 64, x, y );
  1551. X      }
  1552. X    }
  1553. X  }
  1554. X  clear();
  1555. X
  1556. X  draw_board( game_board );
  1557. X  play( p1, p2, starting_player );
  1558. X  exit_rout( 0 );
  1559. X}
  1560. X
  1561. Xusage()
  1562. X{
  1563. X  fprintf( stderr, "Usage: reversi [-r]\n" );
  1564. X  exit( 1 );
  1565. X}
  1566. X
  1567. X/*
  1568. X * Init game board
  1569. X *
  1570. X */
  1571. X
  1572. Xinit_board( w_b )
  1573. Xint w_b;
  1574. X{
  1575. X  int x, y;
  1576. X  
  1577. X  for( x = 0 ; x < 8 ; x++ ){
  1578. X    for( y = 0 ; y < 8 ; y++ ){
  1579. X      get_board( game_board, x, y ) = 0;
  1580. X    }
  1581. X  }
  1582. X
  1583. X  if( w_b == 0 ){
  1584. X    get_board( game_board, 3, 3 ) = 1;
  1585. X    get_board( game_board, 4, 3 ) = 2;
  1586. X    get_board( game_board, 3, 4 ) = 2;
  1587. X    get_board( game_board, 4, 4 ) = 1;
  1588. X  }
  1589. X  else{
  1590. X    get_board( game_board, 3, 3 ) = 2;
  1591. X    get_board( game_board, 4, 3 ) = 1;
  1592. X    get_board( game_board, 3, 4 ) = 1;
  1593. X    get_board( game_board, 4, 4 ) = 2;
  1594. X  }
  1595. X}
  1596. X
  1597. X#ifdef HAVE_VOID_SIGNALS
  1598. Xvoid exit_rout( sig )
  1599. X#else
  1600. Xint exit_rout( sig )
  1601. X#endif
  1602. Xint sig;
  1603. X{
  1604. X  move( 23, 0 );
  1605. X  refresh();
  1606. X  exit_screen();
  1607. X  exit(0);
  1608. X}
  1609. X
  1610. Xplay( p1, p2, starting_player )
  1611. Xint p1, p2, starting_player;
  1612. X{
  1613. X  int x, y, x2, y2;
  1614. X  int c_w, c_w2, cur_player, end_w = FALSE;
  1615. X  int p[2], game_l[2];
  1616. X  int a;
  1617. X  char str[200];
  1618. X  char player_str[2][40];
  1619. X  int count_x, count_y;
  1620. X  
  1621. X  c_w = 0;
  1622. X  c_w2 = 0;
  1623. X  
  1624. X  p[0] = p1;
  1625. X  p[1] = p2;
  1626. X  game_l[0] = game_lev1;
  1627. X  game_l[1] = game_lev2;
  1628. X
  1629. X  if( p[0] == 0 ){
  1630. X    strcpy( player_str[0], "Human plays white" );
  1631. X  }
  1632. X  else{
  1633. X    sprintf( player_str[0], "Computer level %d plays white", game_l[0] );
  1634. X  }
  1635. X
  1636. X  if( p[1] == 0 ){
  1637. X    strcpy( player_str[1], "Human plays black" );
  1638. X  }
  1639. X  else{
  1640. X    sprintf( player_str[1], "Computer level %d plays black", game_l[1] );
  1641. X  }
  1642. X
  1643. X  mvaddstr( 2, 52, player_str[0] );
  1644. X  mvaddstr( 3, 52, player_str[1] );
  1645. X  refresh();
  1646. X
  1647. X  if( !to_load ){
  1648. X    for( count_x = 0 ; count_x < 8 ; count_x++ ){
  1649. X      for( count_y = 0 ; count_y < 8 ; count_y++ ){
  1650. X    get_board( old_gameboard, count_x, count_y ) = get_board( game_board, count_x, count_y );
  1651. X      }
  1652. X    }
  1653. X    
  1654. X    old_pointer += 64;
  1655. X    
  1656. X    for( count_x = 0 ; count_x < 8 ; count_x++ ){
  1657. X      for( count_y = 0 ; count_y < 8 ; count_y++ ){
  1658. X    get_board( old_gameboard + old_pointer, count_x, count_y ) = get_board( game_board, count_x, count_y );
  1659. X      }
  1660. X    }
  1661. X    
  1662. X    old_pointer += 64;
  1663. X  }
  1664. X
  1665. X  do{
  1666. X    for( cur_player = starting_player ; cur_player < 2 ; cur_player++ ){
  1667. X      starting_player = 0;
  1668. X      if( possible_move( game_board, cur_player ) ){
  1669. X    if( p[cur_player] == 0 ){
  1670. X      get_move( cur_player, &x, &y );
  1671. X    }
  1672. X    else{
  1673. X#ifndef DEBUG
  1674. X      get_comp_move( cur_player, game_board, &x, &y, game_l[cur_player], 1 );
  1675. X#else /* DEBUG */
  1676. X      a = get_comp_move( cur_player, game_board, &x, &y, game_l[cur_player], 1 );
  1677. X      mvaddstr( 6, 52, "                       " );
  1678. X      sprintf( str, "Score for move: %d", a );
  1679. X      mvaddstr( 6, 52, str );
  1680. X#endif /* DEBUG */
  1681. X      if( !possible_move_square( game_board, x, y, cur_player ) ){
  1682. X        printf( "Internal panic! Tried to put square at: %d, %d\n", x, y );
  1683. X        exit( 1 );
  1684. X      }
  1685. X    }
  1686. X    put_square( cur_player, game_board, x, y );
  1687. X    draw_board( game_board );
  1688. X
  1689. X      }
  1690. X      else{
  1691. X    if( possible_move( game_board, !cur_player ) ){
  1692. X      mvaddstr( 7, 52, "Cannot move, press space." );
  1693. X      refresh();
  1694. X      getch();
  1695. X      mvaddstr( 7, 52, "                         " );
  1696. X      refresh();
  1697. X    }
  1698. X    else{
  1699. X      end_w = TRUE;
  1700. X    }
  1701. X      }
  1702. X
  1703. X      for( count_x = 0 ; count_x < 8 ; count_x++ ){
  1704. X    for( count_y = 0 ; count_y < 8 ; count_y++ ){
  1705. X      get_board( old_gameboard + old_pointer, count_x, count_y ) = get_board( game_board, count_x, count_y );
  1706. X    }
  1707. X      }
  1708. X      old_pointer += 64;
  1709. X    
  1710. X    }
  1711. X  }while( !end_w );
  1712. X
  1713. X  for( x2 = 0 ; x2 < 8 ; x2++ ){
  1714. X    for( y2 = 0 ; y2 < 8 ; y2++ ){
  1715. X      if( get_board( game_board, x2, y2 ) == 1 ){
  1716. X    c_w++;
  1717. X      }
  1718. X      else if( get_board( game_board, x2, y2 ) == 2 ){
  1719. X    c_w2++;
  1720. X      }
  1721. X    }
  1722. X  }
  1723. X  
  1724. X  if( c_w == c_w2 ){
  1725. X    mvaddstr( 9, 52, "This game was a draw." );
  1726. X    refresh();
  1727. X  }
  1728. X  else if( c_w > c_w2 ){
  1729. X    mvaddstr( 9, 52, "White is the winner." );
  1730. X    refresh();
  1731. X  }
  1732. X  else{
  1733. X    mvaddstr( 9, 52, "Black is the winner." );
  1734. X    refresh();
  1735. X  }
  1736. X  sprintf( str, "White: %d, Black: %d", c_w, c_w2 );
  1737. X  mvaddstr( 10, 52, str );
  1738. X  move( 23, 0 );
  1739. X  refresh();
  1740. X}
  1741. X
  1742. Xdo_undo_move()
  1743. X{
  1744. X  int count_x, count_y;
  1745. X
  1746. X  if( old_pointer > 192 ){
  1747. X    old_pointer -= 192;
  1748. X    for( count_x = 0 ; count_x < 8 ; count_x++ ){
  1749. X      for( count_y = 0 ; count_y < 8 ; count_y++ ){
  1750. X    get_board( game_board, count_x, count_y ) = get_board( old_gameboard + old_pointer, count_x, count_y );
  1751. X      }
  1752. X    }
  1753. X
  1754. X    draw_board( game_board );
  1755. X    old_pointer += 64;
  1756. X  }
  1757. X}
  1758. X
  1759. Xsave_game( player )
  1760. Xint player;
  1761. X{
  1762. X  FILE *fp;
  1763. X  char home_path[80];
  1764. X  int c;
  1765. X  int x, y;
  1766. X  int t;
  1767. X
  1768. X  strcpy( home_path, getenv( "HOME" ) );
  1769. X  strcat( home_path, "/.reversi_save" );
  1770. X  
  1771. X  if( (fp = fopen( home_path, "w" )) == NULL ){
  1772. X    mvaddstr( 8, 52, "Could not open save file" );
  1773. X    refresh();
  1774. X    return;
  1775. X  }
  1776. X
  1777. X  fwrite( &player, sizeof( int ), 1, fp );
  1778. X  fwrite( &p1, sizeof( int ), 1, fp );
  1779. X  fwrite( &p2, sizeof( int ), 1, fp );
  1780. X  fwrite( &game_lev1, sizeof( int ), 1, fp );
  1781. X  fwrite( &game_lev2, sizeof( int ), 1, fp );
  1782. X
  1783. X  for( c = 0 ; c < old_pointer ; c += 64 ){
  1784. X    for( x = 0 ; x < 8 ; x++ ){
  1785. X      for( y = 0 ; y < 8 ; y++ ){
  1786. X    t = get_board( old_gameboard + c, x, y );
  1787. X    fwrite( &t, sizeof( int ), 1, fp );
  1788. X      }
  1789. X    }
  1790. X  }
  1791. X  fclose( fp );
  1792. X}
  1793. END_OF_FILE
  1794. if test 9443 -ne `wc -c <'reversi.c'`; then
  1795.     echo shar: \"'reversi.c'\" unpacked with wrong size!
  1796. fi
  1797. # end of 'reversi.c'
  1798. fi
  1799. echo shar: End of archive 1 \(of 2\).
  1800. cp /dev/null ark1isdone
  1801. MISSING=""
  1802. for I in 1 2 ; do
  1803.     if test ! -f ark${I}isdone ; then
  1804.     MISSING="${MISSING} ${I}"
  1805.     fi
  1806. done
  1807. if test "${MISSING}" = "" ; then
  1808.     echo You have unpacked both archives.
  1809.     rm -f ark[1-9]isdone
  1810. else
  1811.     echo You still need to unpack the following archives:
  1812.     echo "        " ${MISSING}
  1813. fi
  1814. ##  End of shell archive.
  1815. exit 0
  1816.