home *** CD-ROM | disk | FTP | other *** search
- Path: uunet!ogicse!news.u.washington.edu!uw-beaver!zephyr.ens.tek.com!master!saab!billr
- From: billr@saab.CNA.TEK.COM (Bill Randle)
- Newsgroups: comp.sources.games
- Subject: v15i019: reversi2 - another reversi game, Part02/02
- Message-ID: <3834@master.CNA.TEK.COM>
- Date: 29 Oct 92 16:28:19 GMT
- Article-I.D.: master.3834
- Sender: news@master.CNA.TEK.COM
- Lines: 1056
- Approved: billr@saab.CNA.TEK.COM
- Xref: uunet comp.sources.games:1518
-
- Submitted-by: esafern@shearson.COM (Eric Safern)
- Posting-number: Volume 15, Issue 19
- Archive-name: reversi2/Part02
- Environment: curses
-
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of archive 2 (of 2)."
- # Contents: corners.c count.c display.c edges.c fini.c genedge.c
- # hasmove.c makefile minmax.c move.c reversi.h score.c
- # Wrapped by billr@saab on Thu Oct 29 08:20:57 1992
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'corners.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'corners.c'\"
- else
- echo shar: Extracting \"'corners.c'\" \(1758 characters\)
- sed "s/^X//" >'corners.c' <<'END_OF_FILE'
- X/*
- X * cornerscores.c
- X */
- X
- Xshort cornerscores[81] = {
- X -20, /* O O O O */
- X 0, /* O O O - */
- X 10, /* O O O * */
- X -20, /* O O - O */
- X 0, /* O O - - */
- X -10, /* O O - * */
- X -20, /* O O * O */
- X 0, /* O O * - */
- X 20, /* O O * * */
- X -20, /* O - O O */
- X 0, /* O - O - */
- X -10, /* O - O * */
- X -20, /* O - - O */
- X 0, /* O - - - */
- X -10, /* O - - * */
- X -20, /* O - * O */
- X 0, /* O - * - */
- X 20, /* O - * * */
- X -20, /* O * O O */
- X 0, /* O * O - */
- X 20, /* O * O * */
- X -20, /* O * - O */
- X 0, /* O * - - */
- X 10, /* O * - * */
- X -20, /* O * * O */
- X 0, /* O * * - */
- X 10, /* O * * * */
- X 40, /* - O O O */
- X 0, /* - O O - */
- X -40, /* - O O * */
- X 40, /* - O - O */
- X 0, /* - O - - */
- X -40, /* - O - * */
- X 40, /* - O * O */
- X 0, /* - O * - */
- X -40, /* - O * * */
- X 40, /* - - O O */
- X 0, /* - - O - */
- X -40, /* - - O * */
- X 40, /* - - - O */
- X 0, /* - - - - */
- X -40, /* - - - * */
- X 40, /* - - * O */
- X 0, /* - - * - */
- X -40, /* - - * * */
- X 40, /* - * O O */
- X 0, /* - * O - */
- X -40, /* - * O * */
- X 40, /* - * - O */
- X 0, /* - * - - */
- X -40, /* - * - * */
- X 40, /* - * * O */
- X 0, /* - * * - */
- X -40, /* - * * * */
- X -20, /* * O O O */
- X 0, /* * O O - */
- X 20, /* * O O * */
- X -10, /* * O - O */
- X 0, /* * O - - */
- X 20, /* * O - * */
- X -10, /* * O * O */
- X 0, /* * O * - */
- X 20, /* * O * * */
- X -10, /* * - O O */
- X 0, /* * - O - */
- X 20, /* * - O * */
- X -10, /* * - - O */
- X 0, /* * - - - */
- X 20, /* * - - * */
- X -10, /* * - * O */
- X 0, /* * - * - */
- X 20, /* * - * * */
- X -10, /* * * O O */
- X 0, /* * * O - */
- X 20, /* * * O * */
- X -10, /* * * - O */
- X 0, /* * * - - */
- X 20, /* * * - * */
- X -10, /* * * * O */
- X 0, /* * * * - */
- X 20, /* * * * * */
- X };
- END_OF_FILE
- if test 1758 -ne `wc -c <'corners.c'`; then
- echo shar: \"'corners.c'\" unpacked with wrong size!
- fi
- # end of 'corners.c'
- fi
- if test -f 'count.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'count.c'\"
- else
- echo shar: Extracting \"'count.c'\" \(255 characters\)
- sed "s/^X//" >'count.c' <<'END_OF_FILE'
- X/*
- X * count.c
- X *
- X * count up the board
- X */
- X
- X# include "reversi.h"
- X
- Xcount (player, board)
- XboardT board;
- X{
- X register int x, y, count;
- X
- X count = 0;
- X for (x = 1; x <= SIZE; x++)
- X for (y = 1; y <= SIZE; y++)
- X count += board[x][y];
- X return count * player;
- X}
- END_OF_FILE
- if test 255 -ne `wc -c <'count.c'`; then
- echo shar: \"'count.c'\" unpacked with wrong size!
- fi
- # end of 'count.c'
- fi
- if test -f 'display.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'display.c'\"
- else
- echo shar: Extracting \"'display.c'\" \(4938 characters\)
- sed "s/^X//" >'display.c' <<'END_OF_FILE'
- X/*
- X * display.c
- X */
- X
- X# include "reversi.h"
- X# include <curses.h>
- X# include <ctype.h>
- X
- X# define toscrx(x) ((x) * 5 - 1)
- X# define toscry(y) ((y) * 3 - 2)
- X
- X# define LINEX (toscrx(10)-2)
- X# define LINEY (toscry(5)+1)
- X
- Xstatic helpShown;
- X
- XdispInit ()
- X{
- X register int i, j;
- X int dispEnd();
- X
- X initscr ();
- X savetty();
- X noecho ();
- X crmode ();
- X helpShown = 0;
- X for (i = 1; i <= SIZE; i++) {
- X move (toscry(i), 0);
- X printw ("%1d", i);
- X move (0, toscrx(i));
- X printw ("%1d", i);
- X }
- X refresh ();
- X}
- X
- XdispGrid ()
- X{
- X register int i, j;
- X
- X for (i = 1; i <= SIZE; i++) {
- X for (j = 1; j <= SIZE + 1; j++) {
- X if (i <= SIZE) {
- X move (toscry(i)+1, toscrx(j)-2);
- X addch ('|');
- X move (toscry(i), toscrx(j)-2);
- X addch ('|');
- X move (toscry(i)-1, toscrx(j)-2);
- X }
- X if (j <= SIZE) {
- X if (i == 1)
- X printw ("+-%1d--", j);
- X else
- X addstr ("+----");
- X } else
- X addstr ("+");
- X }
- X }
- X refresh ();
- X}
- X
- XdispNoGrid ()
- X{
- X register int i, j;
- X
- X for (i = 1; i <= SIZE; i++) {
- X for (j = 1; j <= SIZE + 1; j++) {
- X move (toscry(i)+1, toscrx(j)-2);
- X addch (' ');
- X move (toscry(i), toscrx(j)-2);
- X addch (' ');
- X move (toscry(i)-1, toscrx(j)-2);
- X if (j <= SIZE) {
- X if (i == 1)
- X printw (" %1d ", j);
- X else
- X addstr (" ");
- X } else
- X addstr (" ");
- X }
- X }
- X refresh ();
- X}
- X
- XdispEnd ()
- X{
- X clearok(stdscr, 1);
- X erase ();
- X refresh ();
- X resetty();
- X endwin ();
- X exit (0);
- X}
- X
- XboardT old;
- X
- Xdisplay (board)
- XboardT board;
- X{
- X register int i,j;
- X extern int showScore;
- X
- X for (i = 1; i <= SIZE; i++)
- X for (j = 1; j <= SIZE; j++)
- X if (board[i][j] != old[i][j]) {
- X dispOne (i, j, board[i][j]);
- X old[i][j] = board[i][j];
- X }
- X refresh ();
- X if (showScore)
- X dispScore (board);
- X}
- X
- XdispOne (y, x, who)
- X{
- X move (toscry (y), toscrx (x));
- X switch (who) {
- X case BLACK:
- X addstr ("/\\");
- X break;
- X case WHITE:
- X addstr ("**");
- X break;
- X case EMPTY:
- X addstr (" ");
- X break;
- X }
- X move (toscry(y) + 1, toscrx (x));
- X switch (who) {
- X case BLACK:
- X addstr ("\\/");
- X break;
- X case WHITE:
- X addstr ("**");
- X break;
- X case EMPTY:
- X addstr (" ");
- X break;
- X }
- X}
- X
- XdispScore (board)
- Xregister boardT board;
- X{
- X register int i,j;
- X register int ws, bs;
- X
- X ws = bs = 0;
- X for (i = 1; i <= SIZE; i++)
- X for (j = 1; j <= SIZE; j++)
- X switch (board[i][j]) {
- X case WHITE:
- X ws++; break;
- X case BLACK:
- X bs++; break;
- X }
- X move (LINEY - 3, LINEX);
- X printw ("white: %-2d black: %-2d", ws, bs);
- X refresh ();
- X}
- X
- XdispNoScore ()
- X{
- X move (LINEY - 3, LINEX);
- X clrtoeol ();
- X refresh ();
- X}
- X
- Xstatic char *helpText[] = {
- X "y, x [no] grid",
- X "[no] help hint",
- X "play quit",
- X "restart record",
- X "replay save",
- X "[no] score undo",
- X "level",
- X "white|black first",
- X "white|black second",
- X 0,
- X};
- X
- XdispTurn (player)
- X{
- X static displayed = EMPTY;
- X
- X if (displayed == player)
- X return;
- X move (LINEY-1, LINEX);
- X switch (player) {
- X case WHITE:
- X addstr ("white's turn");
- X break;
- X case BLACK:
- X addstr ("black's turn");
- X break;
- X case EMPTY:
- X clrtoeol ();
- X }
- X displayed = player;
- X refresh ();
- X}
- X
- XdispHelp ()
- X{
- X register int i;
- X register char **h;
- X
- X if (helpShown)
- X return;
- X i = 0;
- X for (h = helpText; *h; ++h) {
- X move (i, LINEX);
- X addstr (*h);
- X ++i;
- X }
- X move (LINEY+4, LINEX);
- X printw ("white pieces are **");
- X move (LINEY+5, LINEX+18);
- X printw ("**");
- X move (LINEY+7, LINEX);
- X printw ("black pieces are /\\");
- X move (LINEY+8, LINEX+18);
- X printw ("\\/");
- X refresh ();
- X ++helpShown;
- X}
- X
- XdispNoHelp ()
- X{
- X register int i;
- X register char **h;
- X
- X if (!helpShown)
- X return;
- X i = 0;
- X for (h = helpText; *h; ++h) {
- X move (i, LINEX);
- X clrtoeol ();
- X ++i;
- X }
- X move (LINEY+4, LINEX);
- X clrtoeol ();
- X move (LINEY+5, LINEX+18);
- X clrtoeol ();
- X move (LINEY+7, LINEX);
- X clrtoeol ();
- X move (LINEY+8, LINEX+18);
- X clrtoeol ();
- X refresh ();
- X helpShown = 0;
- X}
- X
- Xstatic char lexbuf[256];
- Xstatic char *lexpnt;
- X
- XreadLine ()
- X{
- X int ch, x, y;
- X
- X move (LINEY, LINEX);
- X addstr ("-> ");
- Xloop:
- X x = LINEX+3;
- X y = LINEY;
- X move (y, x);
- X clrtoeol ();
- X refresh ();
- X lexpnt = lexbuf;
- X for (;;) {
- X ch = getch ();
- X if (ch == -1)
- X ch = '\004';
- X *lexpnt++ = ch;
- X if (isprint (ch)) {
- X addch (ch);
- X ++x;
- X refresh ();
- X } else
- X switch (ch) {
- X case '\f':
- X clearok (stdscr, 1);
- X case '\030':
- X case '\025':
- X goto loop;
- X case '\004':
- X *lexpnt++ = -1;
- X case '\r':
- X case '\n':
- X move (LINEY+1, LINEX);
- X refresh ();
- X *lexpnt++ = '\0';
- X goto done;
- X case '\b':
- X if (lexpnt >= lexbuf + 2) {
- X lexpnt -= 2;
- X --x;
- X move (y,x);
- X delch ();
- X refresh ();
- X } else
- X --lexpnt;
- X break;
- X default:
- X --lexpnt;
- X write (1, "\007", 1);
- X break;
- X }
- X }
- Xdone: lexpnt = lexbuf;
- X dispError ("");
- X}
- X
- Xlexgetc ()
- X{
- X int c;
- X extern int yylineno;
- X
- X c = *lexpnt++;
- X if (c == -1)
- X c = 4;
- X c &= 0177;
- X if (c == '\r')
- X c = '\n';
- X if (c == '\n')
- X ++yylineno;
- X return c;
- X}
- X
- Xlexungetc (c)
- X{
- X --lexpnt;
- X}
- X
- XdispError (s)
- Xchar *s;
- X{
- X move (LINEY+1, LINEX);
- X clrtoeol ();
- X addstr (s);
- X refresh ();
- X}
- END_OF_FILE
- if test 4938 -ne `wc -c <'display.c'`; then
- echo shar: \"'display.c'\" unpacked with wrong size!
- fi
- # end of 'display.c'
- fi
- if test -f 'edges.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'edges.c'\"
- else
- echo shar: Extracting \"'edges.c'\" \(77 characters\)
- sed "s/^X//" >'edges.c' <<'END_OF_FILE'
- X/*
- X * edgescores.c
- X */
- X
- Xshort edgescores [6561] = {
- X# include "edges.out"
- X};
- END_OF_FILE
- if test 77 -ne `wc -c <'edges.c'`; then
- echo shar: \"'edges.c'\" unpacked with wrong size!
- fi
- # end of 'edges.c'
- fi
- if test -f 'fini.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'fini.c'\"
- else
- echo shar: Extracting \"'fini.c'\" \(599 characters\)
- sed "s/^X//" >'fini.c' <<'END_OF_FILE'
- X/*
- X * fini.c
- X *
- X * count up score and display winner
- X */
- X
- X# include "reversi.h"
- X
- Xfini (board)
- XboardT board;
- X{
- X register int x,y;
- X register int wscore, bscore;
- X char sbuf[80];
- X
- X wscore = bscore = 0;
- X
- X for (x = 1; x <= SIZE; x++)
- X for (y = 1; y <= SIZE; y++)
- X if (board[x][y] == WHITE)
- X ++wscore;
- X else if (board[x][y] == BLACK)
- X ++bscore;
- X if (wscore > bscore)
- X sprintf (sbuf, "white wins %d to %d.", wscore, bscore);
- X else if (bscore > wscore)
- X sprintf (sbuf, "black wins %d to %d.", bscore, wscore);
- X else
- X sprintf (sbuf, "tie game %d to %d.", wscore, bscore);
- X dispError (sbuf);
- X}
- END_OF_FILE
- if test 599 -ne `wc -c <'fini.c'`; then
- echo shar: \"'fini.c'\" unpacked with wrong size!
- fi
- # end of 'fini.c'
- fi
- if test -f 'genedge.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'genedge.c'\"
- else
- echo shar: Extracting \"'genedge.c'\" \(679 characters\)
- sed "s/^X//" >'genedge.c' <<'END_OF_FILE'
- X/*
- X * generate preliminary edge score array
- X */
- X
- Xchar board[9];
- X
- Xmain ()
- X{
- X register int i;
- X for (board[1] = -1; board[1] <= 1; board[1]++)
- X for (board[2] = -1; board[2] <= 1; board[2]++)
- X for (board[3] = -1; board[3] <= 1; board[3]++)
- X for (board[4] = -1; board[4] <= 1; board[4]++)
- X for (board[5] = -1; board[5] <= 1; board[5]++)
- X for (board[6] = -1; board[6] <= 1; board[6]++)
- X for (board[7] = -1; board[7] <= 1; board[7]++)
- X for (board[8] = -1; board[8] <= 1; board[8]++) {
- X for (i = 1; i <= 8; i++)
- X switch (board[i]) {
- X case 0:
- X printf (" -");
- X break;
- X case -1:
- X printf (" O");
- X break;
- X case 1:
- X printf (" *");
- X break;
- X }
- X printf ("\n");
- X }
- X}
- END_OF_FILE
- if test 679 -ne `wc -c <'genedge.c'`; then
- echo shar: \"'genedge.c'\" unpacked with wrong size!
- fi
- # end of 'genedge.c'
- fi
- if test -f 'hasmove.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'hasmove.c'\"
- else
- echo shar: Extracting \"'hasmove.c'\" \(271 characters\)
- sed "s/^X//" >'hasmove.c' <<'END_OF_FILE'
- X/*
- X * hasmove.c
- X *
- X * figure out if player has move in board
- X */
- X
- X# include "reversi.h"
- X
- Xhasmove (player, board)
- XboardT board;
- X{
- X register int x,y;
- X
- X for (x = 1; x <= SIZE; x++)
- X for (y = 1; y <= SIZE; y++)
- X if (legal (player, x, y, board))
- X return 1;
- X return 0;
- X}
- END_OF_FILE
- if test 271 -ne `wc -c <'hasmove.c'`; then
- echo shar: \"'hasmove.c'\" unpacked with wrong size!
- fi
- # end of 'hasmove.c'
- fi
- if test -f 'makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'makefile'\"
- else
- echo shar: Extracting \"'makefile'\" \(934 characters\)
- sed "s/^X//" >'makefile' <<'END_OF_FILE'
- XCFLAGS=-g
- XOFILES=user.o ulex.o move.o display.o hasmove.o fini.o \
- X minmax.o score.o edges.o corners.o count.o
- XSOURCE= makefile corners.c count.c display.c edges.c fini.c genedge.c \
- X hasmove.c makeedge.y minmax.c move.c reversi.h score.c ulex.l user.y
- X
- Xreversi: $(OFILES)
- X cc $(CFLAGS) -o reversi $(OFILES) -lcurses -ltermlib
- X
- Xreversi.shar: $(SOURCE)
- X shar -c $(SOURCE) > reversi.shar
- X
- X$(OFILES): reversi.h
- Xuser.o: user.c
- Xuser.c: user.y
- X yacc -dv user.y
- X mv y.tab.c user.c
- Xulex.o: ulex.c
- Xulex.c: ulex.l
- X lex ulex.l
- X mv lex.yy.c ulex.c
- Xcorners.o: corners.c
- X $(CC) $(CFLAGS) -R -c corners.c
- X
- Xedges.o: edges.c edges.out
- X $(CC) $(CFLAGS) -R -c edges.c
- Xedges.out: makeedge genedge
- X genedge | makeedge > edges.out
- Xmakeedge: makeedge.o
- X $(CC) $(CFLAGS) -o makeedge makeedge.o
- Xmakeedge.o: makeedge.c
- Xmakeedge.c: makeedge.y
- X yacc makeedge.y
- X mv y.tab.c makeedge.c
- Xgenedge: genedge.o
- X $(CC) $(CFLAGS) -o genedge genedge.o
- Xgenedge.o: genedge.c
- END_OF_FILE
- if test 934 -ne `wc -c <'makefile'`; then
- echo shar: \"'makefile'\" unpacked with wrong size!
- fi
- # end of 'makefile'
- fi
- if test -f 'minmax.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'minmax.c'\"
- else
- echo shar: Extracting \"'minmax.c'\" \(2658 characters\)
- sed "s/^X//" >'minmax.c' <<'END_OF_FILE'
- X/*
- X * minmax.c
- X */
- X
- X# include "reversi.h"
- X
- Xint maxlev, movex, movey;
- X
- X/*
- X * this defines the order in which the board
- X * is searched for the best move. It is
- X * here to shorten the time to best move,
- X * this increasing the chance of hitting
- X * a good trimming point as well as
- X * increasing the possibility of making
- X * a reasonable move when an interrupt is
- X * caught.
- X */
- Xshort morder[64][2] = {
- X 1,1, 1,8, 8,1, 8,8,
- X 1,3, 1,6, 3,1, 3,8, 6,1, 6,8, 8,3, 8,6,
- X 3,3, 3,6, 6,3, 6,6,
- X 1,4, 1,5, 4,1, 4,8, 5,1, 5,8, 8,4, 8,5,
- X 3,4, 3,5, 4,3, 4,6, 5,3, 5,6, 6,4, 6,5,
- X 2,3, 2,6, 3,2, 3,7, 6,2, 6,7, 7,3, 7,6,
- X 2,4, 2,5, 4,2, 4,7, 5,2, 5,7, 7,4, 7,5,
- X 1,2, 1,7, 2,1, 2,8, 7,1, 7,8, 8,2, 8,7,
- X 2,2, 2,7, 7,2, 7,7, 4,4, 4,5, 5,4, 5,5,
- X};
- X
- X# define NOMOVE (-32760)
- X
- X
- X# define USECOPY
- X# ifdef USECOPY
- Xstruct copyB {
- X boardT data;
- X};
- X# define copyb(next,board) (*((struct copyB *)next) = *((struct copyB *) board))
- X# else
- X# define copyb(next,board) copy(next,board)
- X# endif
- X
- Xcopy(next, board)
- Xregister int *next, *board;
- X{
- X register int count;
- X
- X count = sizeof (boardT) / sizeof (int);
- X do {
- X *next++ = *board++;
- X } while (--count);
- X}
- X
- Xcomputer (player, board, level)
- XboardT board;
- X{
- X int i;
- X extern int com, defcom;
- X
- X maxlev = level;
- X movex = movey = -1;
- X i = seek (player, board, 0, 1, -NOMOVE);
- X if (movex == -1 || movey == -1)
- X return 0;
- X move (player, movex, movey, board);
- X return 1;
- X}
- X
- Xhint (player, board, level)
- XboardT board;
- X{
- X int i;
- X
- X maxlev = level;
- X i = seek (player, board, 0, 1, -NOMOVE);
- X if (movex == -1 || movey == -1)
- X return 0;
- X return 1;
- X}
- X
- Xseek (player, board, level, moved, best)
- Xregister player;
- Xregister boardT board;
- X{
- X boardT next;
- X register int x, y;
- X register int s;
- X int max, i;
- X int bestx, besty;
- X int m, j;
- X extern int gotsignal;
- X
- X max = NOMOVE;
- X m = 0;
- X for (j = 0; j < 60; j++) {
- X x = morder[j][0];
- X y = morder[j][1];
- X if (gotsignal)
- X return 0;
- X if (legal (player, x, y, board)) {
- X copyb (next, board);
- X if (level == 0 && movex == -1) {
- X movex = x;
- X movey = y;
- X }
- X move (player, x, y, next);
- X ++m;
- X if (level >= maxlev)
- X s = score (next, player);
- X else
- X s = seek (-player, next, level+1, 1, -max);
- X if (s >= max) {
- X /*
- X * try to make the game appear random
- X * by choosing among equal moves
- X * randomly
- X */
- X if (s == max && rand()&01)
- X goto skip;
- X if (s > best)
- X return -s;
- X bestx = x;
- X besty = y;
- X if (level == 0) {
- X movex = bestx;
- X movey = besty;
- X }
- X max = s;
- X }
- Xskip: ;
- X }
- X }
- X if (m == 0)
- X if (moved && level)
- X return seek (-player, board, level + 1, 0, -best);
- X else
- X return - count (player, board) * 500;
- X return -max;
- X}
- END_OF_FILE
- if test 2658 -ne `wc -c <'minmax.c'`; then
- echo shar: \"'minmax.c'\" unpacked with wrong size!
- fi
- # end of 'minmax.c'
- fi
- if test -f 'move.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'move.c'\"
- else
- echo shar: Extracting \"'move.c'\" \(867 characters\)
- sed "s/^X//" >'move.c' <<'END_OF_FILE'
- X/*
- X * move.c
- X *
- X * move player to x,y in board
- X */
- X
- X# include "reversi.h"
- X
- Xint offsets[] = { -11, -10, -9, -1, 1, 9, 10, 11, 0 };
- X
- Xmove (player, x, y, board)
- Xregister int player;
- Xint x, y;
- XboardT board;
- X{
- X register char *b, *m;
- X register int *o, i;
- X
- X b = & board[x][y];
- X *b = player;
- X player = -player;
- X for (o = offsets; i = *o++;) {
- X if (b[i] == player) {
- X m = b+i;
- X while (*m == player)
- X m += i;
- X if (*m == -player) {
- X while (m != b) {
- X *m = -player;
- X m -= i;
- X }
- X }
- X }
- X }
- X}
- X
- Xlegal (player, x, y, board)
- Xregister int player;
- Xint x, y;
- XboardT board;
- X{
- X register char *b, *m;
- X register int *o, i;
- X
- X b = & board[x][y];
- X player = -player;
- X if (*b == EMPTY) {
- X for (o = offsets; i = *o++;) {
- X if (b[i] == player) {
- X m = b+i;
- X while (*m == player)
- X m += i;
- X if (*m == -player)
- X return 1;
- X }
- X }
- X }
- X return 0;
- X}
- END_OF_FILE
- if test 867 -ne `wc -c <'move.c'`; then
- echo shar: \"'move.c'\" unpacked with wrong size!
- fi
- # end of 'move.c'
- fi
- if test -f 'reversi.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'reversi.h'\"
- else
- echo shar: Extracting \"'reversi.h'\" \(189 characters\)
- sed "s/^X//" >'reversi.h' <<'END_OF_FILE'
- X/*
- X * reversi.h
- X *
- X * include file for game program
- X */
- X
- X# define SIZE 8
- X
- Xtypedef char boardT[SIZE+2][SIZE+2];
- X
- Xtypedef boardT *boardP;
- X
- X# define EMPTY 0
- X# define WHITE 1
- X# define BLACK -1
- END_OF_FILE
- if test 189 -ne `wc -c <'reversi.h'`; then
- echo shar: \"'reversi.h'\" unpacked with wrong size!
- fi
- # end of 'reversi.h'
- fi
- if test -f 'score.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'score.c'\"
- else
- echo shar: Extracting \"'score.c'\" \(2547 characters\)
- sed "s/^X//" >'score.c' <<'END_OF_FILE'
- X/*
- X * score.c
- X *
- X * score a board position
- X */
- X
- X# include "reversi.h"
- X#ifdef SDEBUG
- Xextern int sdebug;
- X#endif
- X
- XboardT base = {
- X 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- X 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- X 0, 0, -40, -10, -5, -5, -10, -40, 0, 0,
- X 0, 0, -10, 3, 1, 1, 3, -10, 0, 0,
- X 0, 0, -5, 1, 0, 0, 1, -5, 0, 0,
- X 0, 0, -5, 1, 0, 0, 1, -5, 0, 0,
- X 0, 0, -10, 3, 1, 1, 3, -10, 0, 0,
- X 0, 0, -40, -10, -5, -5, -10, -40, 0, 0,
- X 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- X 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- X};
- X
- Xshort edgemod[10][3] = {
- X 0, 0, 0,
- X 0, 0, 0,
- X 0, 0, 0,
- X 5, -10, 5,
- X 5, -5, 5,
- X 5, -5, 5,
- X 5, -10, 5,
- X 0, 0, 0,
- X 0, 0, 0,
- X 0, 0, 0,
- X};
- X
- Xextern short cornerscores[3][3][3][3];
- X
- Xextern short edgescores[6561];
- X
- X# define edgesc(a,b,c,d,e,f,g,h) edgescores[a*2187 + b*729 + c*243 + \
- X d*81 + e*27 + f*9 + g*3 + h + 3280]
- X
- Xscore (board, player)
- Xregister boardT board;
- Xint player;
- X{
- X register char *j, *b;
- X char *l;
- X register int score;
- X int i;
- X int n, m;
- X
- X#ifdef SDEBUG
- X if (sdebug) {
- X display (board);
- X }
- X#endif
- X score = 0;
- X for (i = 3; i < SIZE - 1; i++) {
- X j = & board[i][3];
- X b = & base [i][3];
- X l = & board[i][SIZE-1];
- X while (j != l) {
- X n = *j++;
- X score += n * *b++;
- X }
- X score += board[2][i] * edgemod[i][board[1][i]+1];
- X score += board[SIZE-1][i] * edgemod[i][board[SIZE][i]+1];
- X score += board[i][2] * edgemod[i][board[i][1]+1];
- X score += board[i][SIZE-1] * edgemod[i][board[i][SIZE]+1];
- X }
- X score +=
- X cornerscores[board[1][1] + 1]
- X [board[1][2] + 1]
- X [board[2][1] + 1]
- X [board[2][2] + 1] +
- X cornerscores[board[1][8] + 1]
- X [board[1][7] + 1]
- X [board[2][8] + 1]
- X [board[2][7] + 1] +
- X cornerscores[board[8][1] + 1]
- X [board[8][2] + 1]
- X [board[7][1] + 1]
- X [board[7][2] + 1] +
- X cornerscores[board[8][8] + 1]
- X [board[8][7] + 1]
- X [board[7][8] + 1]
- X [board[7][7] + 1];
- X score += edgesc (board[1][1], board[1][2], board[1][3], board[1][4],
- X board[1][5], board[1][6], board[1][7], board[1][8]) +
- X edgesc (board[8][1], board[8][2], board[8][3], board[8][4],
- X board[8][5], board[8][6], board[8][7], board[8][8]);
- X score += edgesc (board[1][1], board[2][1], board[3][1], board[4][1],
- X board[5][1], board[6][1], board[7][1], board[8][1]) +
- X edgesc (board[1][8], board[2][8], board[3][8], board[4][8],
- X board[5][8], board[6][8], board[7][8], board[8][8]);
- X#ifdef SDEBUG
- X if (sdebug)
- X printf ("score: %d\n", score);
- X#endif
- X return score * player;
- X}
- END_OF_FILE
- if test 2547 -ne `wc -c <'score.c'`; then
- echo shar: \"'score.c'\" unpacked with wrong size!
- fi
- # end of 'score.c'
- fi
- echo shar: End of archive 2 \(of 2\).
- cp /dev/null ark2isdone
- MISSING=""
- for I in 1 2 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked both archives.
- rm -f ark[1-9]isdone
- else
- echo You still need to unpack the following archives:
- echo " " ${MISSING}
- fi
- ## End of shell archive.
- exit 0
-