Path: uunet!zephyr.ens.tek.com!master!saab!billr From: billr@saab.CNA.TEK.COM (Bill Randle) Newsgroups: comp.sources.games Subject: v15i008: reversi - play a game of reversi against the computer or a human, Part02/02 Message-ID: <3804@master.CNA.TEK.COM> Date: 23 Oct 92 15:38:31 GMT Sender: news@master.CNA.TEK.COM Lines: 328 Approved: billr@saab.CNA.TEK.COM Xref: uunet comp.sources.games:1507 Submitted-by: elias@proxxi.se (Elias M}rtensson ) Posting-number: Volume 15, Issue 8 Archive-name: reversi/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 'Makefile' <<'END_OF_FILE' X# reversi - play a game of reversi against the computer or a human X# Copyright (C) 1992 Elias Martenson X# X# This program is free software; you can redistribute it and/or modify X# it under the terms of the GNU General Public License as published by X# the Free Software Foundation; either version 2 of the License, or X# (at your option) any later version. X# X# This program is distributed in the hope that it will be useful, X# but WITHOUT ANY WARRANTY; without even the implied warranty of X# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X# GNU General Public License for more details. X# X# You should have received a copy of the GNU General Public License X# along with this program; if not, write to the Free Software X# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X# X# Contact me by email at elias@proxxi.se X XEXEC = reversi XGAMEDIR = /usr/games X XOBJS = reversi.o graphics.o move.o comp.o menu.o X XCC = gcc X X# Put -DHAVE_VOID_SIGNALS in OPTFLAGS if Your compiler requres it X X#OPTFLAGS = -g -DDEBUG -DHAVE_VOID_SIGNALS XOPTFLAGS = -O -DHAVE_VOID_SIGNALS X XCFLAGS = $(OPTFLAGS) X Xall: $(EXEC) X X$(EXEC): $(OBJS) X $(CC) $(OPTFLAGS) -o $(EXEC) $(OBJS) -lcurses -ltermcap X Xinstall: $(EXEC) X cp $(EXEC) $(GAMEDIR) X Xclean: X rm -f *.o *~ $(EXEC) core END_OF_FILE if test 1310 -ne `wc -c <'Makefile'`; then echo shar: \"'Makefile'\" unpacked with wrong size! fi # end of 'Makefile' fi if test -f 'menu.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'menu.c'\" else echo shar: Extracting \"'menu.c'\" \(4269 characters\) sed "s/^X//" >'menu.c' <<'END_OF_FILE' X/* X reversi - play a game of reversi against the computer or a human X Copyright (C) 1992 Elias Martenson X X This program is free software; you can redistribute it and/or modify X it under the terms of the GNU General Public License as published by X the Free Software Foundation; either version 2 of the License, or X (at your option) any later version. X X This program is distributed in the hope that it will be useful, X but WITHOUT ANY WARRANTY; without even the implied warranty of X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X GNU General Public License for more details. X X You should have received a copy of the GNU General Public License X along with this program; if not, write to the Free Software X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X X Contact me by email at elias@proxxi.se X*/ X X/* X * These menu routines is written by Stefan Rapp (rappen@proxxi.se) X * X */ X X#include X#include "menu.h" X X/* */ X/* Start: 0 = First */ X/* */ X Xmenu (x, y, width, height, start, flags, names) Xint x, y, width, height, start, flags; XMenuEntry *names; X{ X MenuEntry *namesstart = names; X WINDOW *menu_window; X int max_width=0, number_names= 0, counter, names_select = FALSE; X char ch; X char *str; X X do{ X if( strlen( names->name ) > max_width ){ X max_width = strlen(names->name); X } X number_names++; X } while((++names) -> name != NULL ); X X if( height == 0){ X height = number_names; X } X X if( width == 0){ X width = max_width; X } X X names=namesstart; X names+=start; X X counter = 0; X X menu_window = newwin( height, width + 1, y, x ); X if( ( flags & DRAW_BOX ) == DRAW_BOX ){ X box( menu_window, DRAW_BOX_SYMBOL_VERT, DRAW_BOX_SYMBOL_HORIZ ); X } X wclear( menu_window ); X refresh_names( menu_window, 1, width, height, names+1); X wstandout( menu_window ); X mvwaddstr(menu_window, 0, 0, (names)->name); X wstandend( menu_window ); X X do{ X wrefresh(menu_window); X ch = wgetch( menu_window ); X X wstandend( menu_window ); X mvwaddstr( menu_window, counter, 0, names-> name); X X switch( ch ){ X case MV_UP: X if(names-namesstart > 0){ X names--; X counter--; X if( counter < 0 ){ X counter = 0; X refresh_names( menu_window, 0, width, height, names); X } X } X else if( (flags & WRAP) == WRAP ){ X names = namesstart; X names += number_names -1; X counter = height -1; X refresh_names( menu_window, 0, width, height, names - (height -1)); X } X break; X case MV_DOWN: X if( (names+1)->name != NULL){ X names++; X counter++; X if( counter >= height ){ X counter = height -1; X refresh_names( menu_window, 0, width, height, names - (height -1)); X } X } X else if(( flags & WRAP) == WRAP ){ X names = namesstart; X counter = 0; X refresh_names( menu_window, 0, width, height, names); X } X break; X case PG_UP: X break; X case PG_DOWN: X break; X case SELECT: X names_select = TRUE; X break; X case QUIT: X if( (flags & ENABLE_QUIT) == ENABLE_QUIT){ X names_select = -1; X } X break; X case HELP: X if( (flags & ENABLE_HELP) == ENABLE_HELP){ X /* help command */ X } X break; X } /* switch */ X X wstandout( menu_window); X mvwaddstr( menu_window, counter, 0, (names -> name )); X } while( names_select == FALSE); X X if( (flags & CLEAR_ON_EXIT) == CLEAR_ON_EXIT ){ X wclear( menu_window ); X wrefresh( menu_window ); X } X delwin( menu_window ); X X if( names_select == -1){ X return(-1); X } X else{ X return(names - namesstart); X } X} X X Xrefresh_names( menu_window, y, width, height, names) XWINDOW *menu_window; XMenuEntry *names; Xint width, height, y; X{ X int counter; X X for( counter = y; ( counter < height ) && ( names -> name != NULL ); counter++ ){ X mvwaddstr( menu_window, counter , 0 , (names) -> name ); X if( strlen( names -> name) < width){ X write_space( menu_window, width - strlen(names->name)); X write_space( menu_window, 1); X } X names++; X } X} X Xwrite_space( menu_window, spaces) XWINDOW *menu_window; Xint spaces; X{ X int counter; X X for( counter = 0; counter < spaces; counter++ ){ X waddch( menu_window, ' ' ); X } X} END_OF_FILE if test 4269 -ne `wc -c <'menu.c'`; then echo shar: \"'menu.c'\" unpacked with wrong size! fi # end of 'menu.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'\" \(1311 characters\) sed "s/^X//" >'reversi.h' <<'END_OF_FILE' X/* X reversi - play a game of reversi against the computer or a human X Copyright (C) 1992 Elias Martenson X X This program is free software; you can redistribute it and/or modify X it under the terms of the GNU General Public License as published by X the Free Software Foundation; either version 2 of the License, or X (at your option) any later version. X X This program is distributed in the hope that it will be useful, X but WITHOUT ANY WARRANTY; without even the implied warranty of X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X GNU General Public License for more details. X X You should have received a copy of the GNU General Public License X along with this program; if not, write to the Free Software X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X X Contact me by email at elias@proxxi.se X*/ X X#define TRUE (1) X#define FALSE (0) X X/* Some score definitions */ X X#define SQUARE_SCORE 10 X#define BORDER_SCORE 800 X#define CORNER_SCORE 4000 X#define BORDER_POS_BONUS 10 X#define BORDER2_POS_BONUS 10 X#define BORDER2_SCORE 50 X#define BORDER2_CORNER_SCORE -200 X#define BORDER3_CORNER_SCORE 150 X#define BORDER3_SCORE 400 X X#define NO_MOVE_BONUS 10000 X#define DIV_POINTS 1.2 /* This is a float! */ X X#define get_board(board,X,Y) (board)[((X)*8) + (Y)] X END_OF_FILE if test 1311 -ne `wc -c <'reversi.h'`; then echo shar: \"'reversi.h'\" unpacked with wrong size! fi # end of 'reversi.h' 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