Ported mille game.

This commit is contained in:
Serge Vakulenko
2014-09-08 19:19:18 -07:00
parent aecac2f5d7
commit e4e9ff1ef4
17 changed files with 537 additions and 489 deletions

View File

@@ -419,6 +419,7 @@ file /games/factor
file /games/fish
file /games/fortune
file /games/hangman
file /games/mille
file /games/morse
file /games/number
file /games/ppt
@@ -731,6 +732,7 @@ file /share/man/cat6/canfield.0
file /share/man/cat6/fish.0
file /share/man/cat6/fortune.0
file /share/man/cat6/hangman.0
file /share/man/cat6/mille.0
file /share/man/cat6/number.0
file /share/man/cat6/rain.0
file /share/man/cat6/rogue.0

View File

@@ -12,8 +12,8 @@ CFLAGS += -Werror -Wall -Os
# Programs that live in subdirectories, and have makefiles of their own.
#
SUBDIR = adventure atc backgammon battlestar boggle btlgammon \
cribbage fortune hangman rogue sail trek
# TODO: mille monop quiz robots snake
cribbage fortune hangman mille rogue sail trek
# TODO: monop quiz robots snake
# C programs that live in the current directory and do not need
# explicit make lines.

1
src/games/mille/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
mille

View File

@@ -1,75 +1,32 @@
#
# mille bourne game makefile
#
HEADERS=mille.h
CFILES= comp.c end.c extern.c init.c mille.c misc.c move.c print.c \
roll.c save.c types.c varpush.c
OBJS= comp.o end.o extern.o init.o mille.o misc.o move.o print.o \
roll.o save.o types.o varpush.o
POBJS= comp.po end.po extern.po init.po mille.po misc.po move.po \
roll.po print.po save.po types.po varpush.po
# CRL= /jb/ingres/arnold/=lib/=curses/crlib
# CRL= =curses/screen/libcurses.a
CRL=
# L= -ltermlib
L= -lcurses -ltermlib
LIBS= ${CRL} ${L}
DEFS=
CFLAGS= -O ${DEFS}
SEPFLAG= -i
LDFLAGS=
DESTDIR=
BINDIR= /usr/games
.SUFFIXES: .po .i
TOPSRC = $(shell cd ../../..; pwd)
include $(TOPSRC)/target.mk
#include $(TOPSRC)/cross.mk
#CFLAGS = -O -DCROSS -Werror -Wall
.c.po:
rm -f x.c ; ln $*.c x.c
${CC} ${CFLAGS} -p -c x.c
mv x.o $*.po
#CFLAGS += -Werror -Wall
.c.i:
${CC} ${LDFLAGS} -P $*.c
OBJS = comp.o end.o extern.o init.o mille.o misc.o move.o print.o \
roll.o save.o types.o varpush.o
MAN = mille.0
LIBS = -lcurses -ltermcap -lc
a.out: ${OBJS} ${CRL}
${CC} ${SEPFLAG} ${LDFLAGS} ${OBJS} ${LIBS}
all: mille $(MAN)
mille: ${OBJS} ${CRL}
${CC} ${SEPFLAG} ${CFLAGS} -o mille ${OBJS} ${LIBS}
mille: $(OBJS)
$(CC) $(LDFLAGS) -o $@.elf $(OBJS) $(LIBS)
$(OBJDUMP) -S $@.elf > $@.dis
$(SIZE) $@.elf
$(ELF2AOUT) $@.elf $@ && rm $@.elf
install: mille
install -s mille ${DESTDIR}${BINDIR}
pmb: ${POBJS} ../pcrlib
${CC} ${SEPFLAG} ${CFLAGS} -p -o pmb ${POBJS} ../pcrlib -ltermlib
mille.po: mille.c
rm -f x.c ; ln mille.c x.c
${CC} ${CFLAGS} -DPROF -p -c x.c
mv x.o mille.po
table: table.o extern.o
${CC} ${SEPFLAG} ${CFLAGS} -i -o table table.o extern.o
readdump: readdump.o extern.o varpush.o
${CC} ${SEPFLAG} ${CFLAGS} -i -o readdump readdump.o extern.o varpush.o
ctags:
ctags ${HEADERS} ${CFILES}
ed - tags < :ctfix
sort tags -o tags
lint:
lint -hxb ${DEFS} ${CFILES} ${L} > lint.out
mille.ar:
ar ruv mille.ar Makefile tags ${HEADERS} ${CFILES}
tar:
tar rvf /dev/rmt0 Makefile tags :ctfix ${HEADERS} ${CFILES}
lpr:
pr Makefile ${HEADERS} ${CFILES} tags | lpr ; lpq
$(MAN): mille.6
nroff -man $< > $@
clean:
rm -f ${OBJS} ${POBJS} core ? a.out errs mille lint.out mille.ar \
tags pmb
rm -f *.o core mille *.0 *.dis
install: all
install mille $(DESTDIR)/games/
install -m 644 $(MAN) $(DESTDIR)/share/man/cat6/

View File

@@ -1,11 +1,12 @@
# include "mille.h"
#include "mille.h"
/*
* @(#)comp.c 1.1 (Berkeley) 4/1/82
*/
# define V_VALUABLE 40
#define V_VALUABLE 40
void
calcmove()
{
register CARD card;
@@ -33,7 +34,8 @@ calcmove()
switch (card) {
case C_STOP: case C_CRASH:
case C_FLAT: case C_EMPTY:
if (playit[i] = canplay(pp, op, card))
playit[i] = canplay(pp, op, card);
if (playit[i])
canstop = TRUE;
goto norm;
case C_LIMIT:
@@ -350,6 +352,7 @@ play_it:
mvprintw(MOVE_Y + 2, MOVE_X, "%16s", C_name[pp->hand[Card_no]]);
}
int
onecard(pp)
register PLAY *pp;
{
@@ -382,6 +385,7 @@ register PLAY *pp;
return FALSE;
}
int
canplay(pp, op, card)
register PLAY *pp, *op;
register CARD card;

View File

@@ -8,10 +8,11 @@
* print out the score as if it was final, and add the totals for
* the end-of-games points to the user who deserves it (if any).
*/
void
finalscore(pp)
reg PLAY *pp; {
PLAY *pp; {
reg int temp, tot, num;
int temp, tot, num;
if (pp->was_finished == Finished)
return;
@@ -45,13 +46,14 @@ reg PLAY *pp; {
}
}
# ifdef EXTRAP
#ifdef EXTRAP
static int Last_tot[2]; /* last tot used for extrapolate */
/*
* print out the score as if it was final, and add the totals for
* the end-of-games points to the user who deserves it (if any).
*/
void
extrapolate(pp)
reg PLAY *pp; {
@@ -96,6 +98,7 @@ reg PLAY *pp; {
Last_tot[num] = tot;
}
void
undoex() {
reg PLAY *pp;
@@ -107,5 +110,4 @@ undoex() {
pp->hand_tot -= Last_tot[i++];
}
}
# endif
#endif

View File

@@ -25,7 +25,7 @@ char *C_fmt = "%-18.18s", /* format for printing cards */
"Flat Tire",
"Accident",
"Stop",
"Speed Limit",
"Speed Limit",
"Gasoline",
"Spare Tire",
"Repairs",
@@ -71,7 +71,7 @@ int Card_no, /* Card number for current move */
1, /* C_RIGHT_WAY */
0 /* C_INIT */
};
Numneed[NUM_CARDS] = { /* number of cards needed per hand */
int Numneed[NUM_CARDS] = { /* number of cards needed per hand */
0, /* C_25 */
0, /* C_50 */
0, /* C_75 */
@@ -132,4 +132,3 @@ PLAY Player[2]; /* Player descriptions */
WINDOW *Board, /* Playing field screen */
*Miles, /* Mileage screen */
*Score; /* Score screen */

View File

@@ -1,14 +1,15 @@
# include "mille.h"
#include "mille.h"
#include <strings.h>
/*
* @(#)init.c 1.1 (Berkeley) 4/1/82
*/
void
init() {
reg PLAY *pp;
reg int i, j;
reg CARD card;
PLAY *pp;
int i, j;
CARD card;
bzero(Numseen, sizeof Numseen);
Numgos = 0;
@@ -47,10 +48,11 @@ init() {
End = 700;
}
void
shuffle() {
reg int i, r;
reg CARD temp;
int i, r;
CARD temp;
for (i = 0; i < DECK_SZ; i++) {
r = roll(1, DECK_SZ) - 1;
@@ -65,6 +67,7 @@ shuffle() {
Topcard = &Deck[DECK_SZ];
}
void
newboard() {
register int i;
@@ -123,10 +126,11 @@ newboard() {
newscore();
}
void
newscore() {
reg int i, new;
register PLAY *pp;
int i, new;
register PLAY *pp = 0;
static int was_full = -1;
static int last_win = -1;

View File

@@ -1,23 +1,38 @@
# include "mille.h"
# include <signal.h>
# ifdef attron
# include <term.h>
# endif attron
#include "mille.h"
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#ifdef attron
# include <term.h>
#endif
/*
* @(#)mille.c 1.3.1 (2.11BSD GTE) 1/16/95
*/
int rub();
char _sobuf[BUFSIZ];
main(ac, av)
reg int ac;
reg char *av[]; {
/*
* Routine to trap rubouts, and make sure they really want to
* quit.
*/
void
rub(int sig) {
reg bool restore;
double avs[3];
signal(SIGINT, SIG_IGN);
if (getyn(REALLYPROMPT))
die();
signal(SIGINT, rub);
}
int
main(ac, av)
int ac;
char *av[]; {
bool restore;
double avs[3];
if (strcmp(av[0], "a.out") == 0) {
outf = fopen("q", "w");
@@ -108,21 +123,10 @@ reg char *av[]; {
}
}
/*
* Routine to trap rubouts, and make sure they really want to
* quit.
*/
rub() {
signal(SIGINT, SIG_IGN);
if (getyn(REALLYPROMPT))
die();
signal(SIGINT, rub);
}
/*
* Time to go beddy-by
*/
void
die() {
signal(SIGINT, SIG_IGN);
@@ -132,4 +136,3 @@ die() {
endwin();
exit(1);
}

View File

@@ -1,5 +1,5 @@
# include <ctype.h>
# include "curses.h"
#include <ctype.h>
#include "curses.h"
/*
* @(#)mille.h 1.1 (Berkeley) 4/1/82
@@ -9,125 +9,117 @@
* Miscellaneous constants
*/
# define unsgn unsigned
# define CARD short
#define unsgn unsigned
#define CARD short
# define ARNOLD 214 /* my uid */
#define ARNOLD 214 /* my uid */
# define GURP 28672 /* bad uid */
# define MAXUSERS 35 /* max # of users for startup */
# define HAND_SZ 7 /* number of cards in a hand */
# define DECK_SZ 101 /* number of cards in decks */
# define NUM_SAFE 4 /* number of saftey cards */
# define NUM_MILES 5 /* number of milestones types */
# define NUM_CARDS 20 /* number of types of cards */
# define BOARD_Y 17 /* size of board screen */
# define BOARD_X 40
# define MILES_Y 7 /* size of mileage screen */
# define MILES_X 80
# define SCORE_Y 17 /* size of score screen */
# define SCORE_X 40
# define MOVE_Y 10 /* Where to print move prompt */
# define MOVE_X 20
# define ERR_Y 15 /* Where to print errors */
# define ERR_X 5
# define EXT_Y 4 /* Where to put Extension */
# define EXT_X 9
#define GURP 28672 /* bad uid */
#define MAXUSERS 35 /* max # of users for startup */
#define HAND_SZ 7 /* number of cards in a hand */
#define DECK_SZ 101 /* number of cards in decks */
#define NUM_SAFE 4 /* number of saftey cards */
#define NUM_MILES 5 /* number of milestones types */
#define NUM_CARDS 20 /* number of types of cards */
#define BOARD_Y 17 /* size of board screen */
#define BOARD_X 40
#define MILES_Y 7 /* size of mileage screen */
#define MILES_X 80
#define SCORE_Y 17 /* size of score screen */
#define SCORE_X 40
#define MOVE_Y 10 /* Where to print move prompt */
#define MOVE_X 20
#define ERR_Y 15 /* Where to print errors */
#define ERR_X 5
#define EXT_Y 4 /* Where to put Extension */
#define EXT_X 9
# define PLAYER 0
# define COMP 1
#define PLAYER 0
#define COMP 1
# define W_SMALL 0 /* Small (initial) window */
# define W_FULL 1 /* Full (final) window */
#define W_SMALL 0 /* Small (initial) window */
#define W_FULL 1 /* Full (final) window */
/*
* Move types
*/
# define M_DISCARD 0
# define M_DRAW 1
# define M_PLAY 2
# define M_ORDER 3
#define M_DISCARD 0
#define M_DRAW 1
#define M_PLAY 2
#define M_ORDER 3
/*
* Scores
*/
# define SC_SAFETY 100
# define SC_ALL_SAFE 300
# define SC_COUP 300
# define SC_TRIP 400
# define SC_SAFE 300
# define SC_DELAY 300
# define SC_EXTENSION 200
# define SC_SHUT_OUT 500
#define SC_SAFETY 100
#define SC_ALL_SAFE 300
#define SC_COUP 300
#define SC_TRIP 400
#define SC_SAFE 300
#define SC_DELAY 300
#define SC_EXTENSION 200
#define SC_SHUT_OUT 500
/*
* safety descriptions
*/
# define S_UNKNOWN 0 /* location of safety unknown */
# define S_IN_HAND 1 /* safety in player's hand */
# define S_PLAYED 2 /* safety has been played */
# define S_GAS_SAFE 0 /* Gas safety card index */
# define S_SPARE_SAFE 1 /* Tire safety card index */
# define S_DRIVE_SAFE 2 /* Driveing safety card index */
# define S_RIGHT_WAY 3 /* Right-of-Way card index */
# define S_CONV 15 /* conversion from C_ to S_ */
#define S_UNKNOWN 0 /* location of safety unknown */
#define S_IN_HAND 1 /* safety in player's hand */
#define S_PLAYED 2 /* safety has been played */
#define S_GAS_SAFE 0 /* Gas safety card index */
#define S_SPARE_SAFE 1 /* Tire safety card index */
#define S_DRIVE_SAFE 2 /* Driveing safety card index */
#define S_RIGHT_WAY 3 /* Right-of-Way card index */
#define S_CONV 15 /* conversion from C_ to S_ */
/*
* card numbers
*/
# define C_INIT -1
# define C_25 0
# define C_50 1
# define C_75 2
# define C_100 3
# define C_200 4
# define C_EMPTY 5
# define C_FLAT 6
# define C_CRASH 7
# define C_STOP 8
# define C_LIMIT 9
# define C_GAS 10
# define C_SPARE 11
# define C_REPAIRS 12
# define C_GO 13
# define C_END_LIMIT 14
# define C_GAS_SAFE 15
# define C_SPARE_SAFE 16
# define C_DRIVE_SAFE 17
# define C_RIGHT_WAY 18
#define C_INIT -1
#define C_25 0
#define C_50 1
#define C_75 2
#define C_100 3
#define C_200 4
#define C_EMPTY 5
#define C_FLAT 6
#define C_CRASH 7
#define C_STOP 8
#define C_LIMIT 9
#define C_GAS 10
#define C_SPARE 11
#define C_REPAIRS 12
#define C_GO 13
#define C_END_LIMIT 14
#define C_GAS_SAFE 15
#define C_SPARE_SAFE 16
#define C_DRIVE_SAFE 17
#define C_RIGHT_WAY 18
/*
* prompt types
*/
# define MOVEPROMPT 0
# define REALLYPROMPT 1
# define ANOTHERHANDPROMPT 2
# define ANOTHERGAMEPROMPT 3
# define SAVEGAMEPROMPT 4
# define SAMEFILEPROMPT 5
# define FILEPROMPT 6
# define EXTENSIONPROMPT 7
# define OVERWRITEFILEPROMPT 8
#define MOVEPROMPT 0
#define REALLYPROMPT 1
#define ANOTHERHANDPROMPT 2
#define ANOTHERGAMEPROMPT 3
#define SAVEGAMEPROMPT 4
#define SAMEFILEPROMPT 5
#define FILEPROMPT 6
#define EXTENSIONPROMPT 7
#define OVERWRITEFILEPROMPT 8
# ifdef SYSV
# define srandom(x) srand(x)
# define random() rand()
# ifndef attron
# define erasechar() _tty.c_cc[VERASE]
# define killchar() _tty.c_cc[VKILL]
# endif
# else
# ifndef erasechar
# define erasechar() _tty.sg_erase
# define killchar() _tty.sg_kill
# endif
# endif SYSV
#ifndef erasechar
# define erasechar() _tty.c_cc[VERASE]
#endif
#ifndef killchar
# define killchar() _tty.c_cc[VKILL]
#endif
typedef struct {
bool coups[NUM_SAFE];
@@ -162,11 +154,11 @@ typedef struct {
* macros
*/
# define other(x) (1 - x)
# define nextplay() (Play = other(Play))
# define nextwin(x) (1 - x)
# define opposite(x) (Opposite[x])
# define issafety(x) (x >= C_GAS_SAFE)
#define other(x) (1 - x)
#define nextplay() (Play = other(Play))
#define nextwin(x) (1 - x)
#define opposite(x) (Opposite[x])
#define issafety(x) (x >= C_GAS_SAFE)
/*
* externals
@@ -193,3 +185,32 @@ extern WINDOW *Board, *Miles, *Score;
*/
CARD getcard();
int canplay(PLAY *pp, PLAY *op, CARD card);
int check_ext(bool forcomp);
int onecard(PLAY *pp);
int roll(int ndie, int nsides);
int isrepair(CARD card);
int safety(CARD card);
int getyn(int promptno);
int rest_f(char *file);
int readch(void);
int save(void);
int error(char *str, int arg);
void getmove(void);
void account(CARD card);
void sort(CARD *hand);
void die(void);
void newscore(void);
void shuffle(void);
void init(void);
void newboard(void);
void prboard(void);
void domove(void);
void check_more(void);
void prompt(int promptno);
void calcmove(void);
void rub(int sig);
void prscore(bool for_real);
void finalscore(PLAY *pp);
void varpush(int file, int (*func)());

View File

@@ -1,14 +1,16 @@
#include "mille.h"
#include "mille.h"
#ifndef unctrl
#include "unctrl.h"
# include "unctrl.h"
#endif
# include <sys/file.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/file.h>
# ifdef attron
# include <term.h>
# define _tty cur_term->Nttyb
# endif attron
#ifdef attron
# include <term.h>
# define _tty cur_term->Nttyb
#endif
/*
* @(#)misc.c 1.2 (Berkeley) 3/28/83
@@ -17,6 +19,7 @@
#define NUMSAFE 4
/* VARARGS1 */
int
error(str, arg)
char *str;
{
@@ -32,7 +35,7 @@ char *str;
CARD
getcard()
{
reg int c, c1;
int c, c1;
for (;;) {
while ((c = readch()) == '\n' || c == '\r' || c == ' ')
@@ -69,17 +72,19 @@ getcard()
clrtoeol();
refresh();
goto cont;
}
else
write(0, "", 1);
} else {
if (write(0, "", 1) != 1)
/*ignore*/;
}
return c;
}
cont: ;
}
}
int
check_ext(forcomp)
reg bool forcomp; {
bool forcomp; {
if (End == 700)
@@ -98,8 +103,8 @@ done:
}
}
else {
reg PLAY *pp, *op;
reg int i, safe, miles;
PLAY *pp, *op;
int i, safe, miles;
pp = &Player[COMP];
op = &Player[PLAYER];
@@ -119,7 +124,7 @@ done:
goto extend;
for (miles = 0, i = 0; i < HAND_SZ; i++)
if ((safe = pp->hand[i]) <= C_200)
miles += Value[safe];
miles += Value[safe];
if (miles + (Topcard - Deck) * 3 > 1000)
goto extend;
goto done;
@@ -132,10 +137,11 @@ done:
* Get a yes or no answer to the given question. Saves are
* also allowed. Return TRUE if the answer was yes, FALSE if no.
*/
int
getyn(promptno)
register int promptno; {
reg char c;
char c;
Saved = FALSE;
for (;;) {
@@ -168,11 +174,24 @@ register int promptno; {
}
}
static void
flush_input()
{
# ifdef TIOCFLUSH
static int ioctl_args = FREAD;
(void) ioctl(fileno(stdin), TIOCFLUSH, &ioctl_args);
# else
fflush(stdin);
# endif
}
/*
* Check to see if more games are desired. If not, and game
* came from a saved file, make sure that they don't want to restore
* it. Exit appropriately.
*/
void
check_more() {
flush_input();
@@ -201,9 +220,10 @@ check_more() {
die();
}
int
readch()
{
reg int cnt;
int cnt;
static char c;
for (cnt = 0; read(0, &c, 1) <= 0; cnt++)
@@ -212,13 +232,21 @@ readch()
return c;
}
flush_input()
{
# ifdef TIOCFLUSH
static int ioctl_args = FREAD;
(void) ioctl(fileno(stdin), TIOCFLUSH, &ioctl_args);
# else
fflush(stdin);
# endif
}
#ifdef CROSS
/*
* define unctrl codes for each character
*
*/
char *_unctrl[] = { /* unctrl codes for ttys */
"^@", "^A", "^B", "^C", "^D", "^E", "^F", "^G", "^H", "^I", "^J", "^K",
"^L", "^M", "^N", "^O", "^P", "^Q", "^R", "^S", "^T", "^U", "^V", "^W",
"^X", "^Y", "^Z", "^[", "^\\", "^]", "^~", "^_",
" ", "!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-",
".", "/", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ":", ";",
"<", "=", ">", "?", "@", "A", "B", "C", "D", "E", "F", "G", "H", "I",
"J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W",
"X", "Y", "Z", "[", "\\", "]", "^", "_", "`", "a", "b", "c", "d", "e",
"f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
"t", "u", "v", "w", "x", "y", "z", "{", "|", "}", "~", "^?"
};
#endif

View File

@@ -1,12 +1,14 @@
#include "mille.h"
#include "mille.h"
#include <string.h>
#include <unistd.h>
#ifndef unctrl
#include "unctrl.h"
# include "unctrl.h"
#endif
# ifdef attron
# include <term.h>
# define _tty cur_term->Nttyb
# endif attron
#ifdef attron
# include <term.h>
# define _tty cur_term->Nttyb
#endif
/*
* @(#)move.c 1.2 (Berkeley) 3/28/83
@@ -19,136 +21,35 @@ char *Movenames[] = {
"M_DISCARD", "M_DRAW", "M_PLAY", "M_ORDER"
};
domove()
{
reg PLAY *pp;
reg int i, j;
reg bool goodplay;
pp = &Player[Play];
if (Play == PLAYER)
getmove();
else
calcmove();
Next = FALSE;
goodplay = TRUE;
switch (Movetype) {
case M_DISCARD:
if (haspicked(pp)) {
if (pp->hand[Card_no] == C_INIT)
if (Card_no == 6)
Finished = TRUE;
else
error("no card there");
else {
if (issafety(pp->hand[Card_no])) {
error("discard a safety?");
goodplay = FALSE;
break;
}
Discard = pp->hand[Card_no];
pp->hand[Card_no] = C_INIT;
Next = TRUE;
if (Play == PLAYER)
account(Discard);
}
}
else
error("must pick first");
break;
case M_PLAY:
goodplay = playcard(pp);
break;
case M_DRAW:
Card_no = 0;
if (Topcard <= Deck)
error("no more cards");
else if (haspicked(pp))
error("already picked");
else {
pp->hand[0] = *--Topcard;
if (Debug)
fprintf(outf, "DOMOVE: Draw %s\n", C_name[*Topcard]);
acc:
if (Play == COMP) {
account(*Topcard);
if (issafety(*Topcard))
pp->safety[*Topcard-S_CONV] = S_IN_HAND;
}
if (pp->hand[1] == C_INIT && Topcard > Deck) {
Card_no = 1;
pp->hand[1] = *--Topcard;
if (Debug)
fprintf(outf, "DOMOVE: Draw %s\n", C_name[*Topcard]);
goto acc;
}
pp->new_battle = FALSE;
pp->new_speed = FALSE;
}
break;
case M_ORDER:
break;
}
/*
* move blank card to top by one of two methods. If the
* computer's hand was sorted, the randomness for picking
* between equally valued cards would be lost
*/
if (Order && Movetype != M_DRAW && goodplay && pp == &Player[PLAYER])
sort(pp->hand);
else
for (i = 1; i < HAND_SZ; i++)
if (pp->hand[i] == C_INIT) {
for (j = 0; pp->hand[j] == C_INIT; j++)
if (j >= HAND_SZ) {
j = 0;
break;
}
pp->hand[i] = pp->hand[j];
pp->hand[j] = C_INIT;
}
if (Topcard <= Deck)
check_go();
if (Next)
nextplay();
}
/*
* Check and see if either side can go. If they cannot,
* the game is over
* return whether or not the player has picked
*/
check_go() {
static int
haspicked(pp)
PLAY *pp; {
reg CARD card;
reg PLAY *pp, *op;
reg int i;
int card;
for (pp = Player; pp < &Player[2]; pp++) {
op = (pp == &Player[COMP] ? &Player[PLAYER] : &Player[COMP]);
for (i = 0; i < HAND_SZ; i++) {
card = pp->hand[i];
if (issafety(card) || canplay(pp, op, card)) {
if (Debug) {
fprintf(outf, "CHECK_GO: can play %s (%d), ", C_name[card], card);
fprintf(outf, "issafety(card) = %d, ", issafety(card));
fprintf(outf, "canplay(pp, op, card) = %d\n", canplay(pp, op, card));
}
return;
}
else if (Debug)
fprintf(outf, "CHECK_GO: cannot play %s\n",
C_name[card]);
}
if (Topcard <= Deck)
return TRUE;
switch (pp->hand[Card_no]) {
case C_GAS_SAFE: case C_SPARE_SAFE:
case C_DRIVE_SAFE: case C_RIGHT_WAY:
card = 1;
break;
default:
card = 0;
break;
}
Finished = TRUE;
return (pp->hand[card] != C_INIT);
}
static int
playcard(pp)
reg PLAY *pp;
PLAY *pp;
{
reg int v;
reg CARD card;
int v;
CARD card;
/*
* check and see if player has picked
@@ -157,7 +58,7 @@ reg PLAY *pp;
default:
if (!haspicked(pp))
mustpick:
return error("must pick first");
return error("must pick first", 0);
case C_GAS_SAFE: case C_SPARE_SAFE:
case C_DRIVE_SAFE: case C_RIGHT_WAY:
break;
@@ -170,16 +71,16 @@ mustpick:
switch (card) {
case C_200:
if (pp->nummiles[C_200] == 2)
return error("only two 200's per hand");
return error("only two 200's per hand", 0);
case C_100: case C_75:
if (pp->speed == C_LIMIT)
return error("limit of 50");
return error("limit of 50", 0);
case C_50:
if (pp->mileage + Value[card] > End)
return error("puts you over %d", End);
case C_25:
if (!pp->can_go)
return error("cannot move now");
return error("cannot move now", 0);
pp->nummiles[card]++;
v = Value[card];
pp->total += v;
@@ -190,7 +91,7 @@ mustpick:
case C_GAS: case C_SPARE: case C_REPAIRS:
if (pp->battle != opposite(card))
return error("can't play \"%s\"", C_name[card]);
return error("can't play \"%s\"", (int)C_name[card]);
pp->battle = card;
if (pp->safety[S_RIGHT_WAY] == S_PLAYED)
pp->can_go = TRUE;
@@ -200,14 +101,14 @@ mustpick:
if (pp->battle != C_INIT && pp->battle != C_STOP
&& !isrepair(pp->battle))
return error("cannot play \"Go\" on a \"%s\"",
C_name[pp->battle]);
(int)C_name[pp->battle]);
pp->battle = C_GO;
pp->can_go = TRUE;
break;
case C_END_LIMIT:
if (pp->speed != C_LIMIT)
return error("not limited");
return error("not limited", 0);
pp->speed = C_END_LIMIT;
break;
@@ -215,10 +116,10 @@ mustpick:
case C_STOP:
pp = &Player[other(Play)];
if (!pp->can_go)
return error("opponent cannot go");
return error("opponent cannot go", 0);
else if (pp->safety[safety(card) - S_CONV] == S_PLAYED)
protected:
return error("opponent is protected");
return error("opponent is protected", 0);
pp->battle = card;
pp->new_battle = TRUE;
pp->can_go = FALSE;
@@ -228,7 +129,7 @@ protected:
case C_LIMIT:
pp = &Player[other(Play)];
if (pp->speed == C_LIMIT)
return error("opponent has limit");
return error("opponent has limit", 0);
if (pp->safety[S_RIGHT_WAY] == S_PLAYED)
goto protected;
pp->speed = C_LIMIT;
@@ -280,7 +181,7 @@ protected:
break;
case C_INIT:
error("no card there");
error("no card there", 0);
Next = -1;
break;
}
@@ -291,10 +192,137 @@ protected:
return TRUE;
}
/*
* Check and see if either side can go. If they cannot,
* the game is over
*/
static void
check_go() {
CARD card;
PLAY *pp, *op;
int i;
for (pp = Player; pp < &Player[2]; pp++) {
op = (pp == &Player[COMP] ? &Player[PLAYER] : &Player[COMP]);
for (i = 0; i < HAND_SZ; i++) {
card = pp->hand[i];
if (issafety(card) || canplay(pp, op, card)) {
if (Debug) {
fprintf(outf, "CHECK_GO: can play %s (%d), ", C_name[card], card);
fprintf(outf, "issafety(card) = %d, ", issafety(card));
fprintf(outf, "canplay(pp, op, card) = %d\n", canplay(pp, op, card));
}
return;
}
else if (Debug)
fprintf(outf, "CHECK_GO: cannot play %s\n",
C_name[card]);
}
}
Finished = TRUE;
}
void
domove()
{
PLAY *pp;
int i, j;
bool goodplay;
pp = &Player[Play];
if (Play == PLAYER)
getmove();
else
calcmove();
Next = FALSE;
goodplay = TRUE;
switch (Movetype) {
case M_DISCARD:
if (haspicked(pp)) {
if (pp->hand[Card_no] == C_INIT)
if (Card_no == 6)
Finished = TRUE;
else
error("no card there", 0);
else {
if (issafety(pp->hand[Card_no])) {
error("discard a safety?", 0);
goodplay = FALSE;
break;
}
Discard = pp->hand[Card_no];
pp->hand[Card_no] = C_INIT;
Next = TRUE;
if (Play == PLAYER)
account(Discard);
}
}
else
error("must pick first", 0);
break;
case M_PLAY:
goodplay = playcard(pp);
break;
case M_DRAW:
Card_no = 0;
if (Topcard <= Deck)
error("no more cards", 0);
else if (haspicked(pp))
error("already picked", 0);
else {
pp->hand[0] = *--Topcard;
if (Debug)
fprintf(outf, "DOMOVE: Draw %s\n", C_name[*Topcard]);
acc:
if (Play == COMP) {
account(*Topcard);
if (issafety(*Topcard))
pp->safety[*Topcard-S_CONV] = S_IN_HAND;
}
if (pp->hand[1] == C_INIT && Topcard > Deck) {
Card_no = 1;
pp->hand[1] = *--Topcard;
if (Debug)
fprintf(outf, "DOMOVE: Draw %s\n", C_name[*Topcard]);
goto acc;
}
pp->new_battle = FALSE;
pp->new_speed = FALSE;
}
break;
case M_ORDER:
break;
}
/*
* move blank card to top by one of two methods. If the
* computer's hand was sorted, the randomness for picking
* between equally valued cards would be lost
*/
if (Order && Movetype != M_DRAW && goodplay && pp == &Player[PLAYER])
sort(pp->hand);
else
for (i = 1; i < HAND_SZ; i++)
if (pp->hand[i] == C_INIT) {
for (j = 0; pp->hand[j] == C_INIT; j++)
if (j >= HAND_SZ) {
j = 0;
break;
}
pp->hand[i] = pp->hand[j];
pp->hand[j] = C_INIT;
}
if (Topcard <= Deck)
check_go();
if (Next)
nextplay();
}
void
getmove()
{
reg char c, *sp;
static char moveprompt[] = ">>:Move:";
char c, *sp;
#ifdef EXTRAP
static bool last_ex = FALSE; /* set if last command was E */
@@ -340,7 +368,7 @@ getmove()
Movetype = M_ORDER;
goto ret;
case 'Q': /* Quit */
rub(); /* Same as a rubout */
rub(0); /* Same as a rubout */
break;
case 'W': /* Window toggle */
Window = nextwin(Window);
@@ -413,39 +441,19 @@ over:
}
/* FALLTHROUGH */
default:
error("unknown command: %s", unctrl(c));
error("unknown command: %s", (int)unctrl(c));
break;
}
}
ret:
leaveok(Board, TRUE);
}
/*
* return whether or not the player has picked
*/
haspicked(pp)
reg PLAY *pp; {
reg int card;
if (Topcard <= Deck)
return TRUE;
switch (pp->hand[Card_no]) {
case C_GAS_SAFE: case C_SPARE_SAFE:
case C_DRIVE_SAFE: case C_RIGHT_WAY:
card = 1;
break;
default:
card = 0;
break;
}
return (pp->hand[card] != C_INIT);
}
void
account(card)
reg CARD card; {
CARD card; {
reg CARD oppos;
CARD oppos;
if (card == C_INIT)
return;
@@ -467,6 +475,7 @@ reg CARD card; {
}
}
void
prompt(promptno)
int promptno;
{
@@ -498,11 +507,12 @@ int promptno;
clrtoeol();
}
void
sort(hand)
reg CARD *hand;
CARD *hand;
{
reg CARD *cp, *tp;
reg CARD temp;
CARD *cp, *tp;
CARD temp;
cp = hand;
hand += HAND_SZ;
@@ -514,4 +524,3 @@ reg CARD *hand;
*tp = temp;
}
}

View File

@@ -7,10 +7,27 @@
# define COMP_STRT 20
# define CARD_STRT 2
/*
* show_card:
* Show the given card if it is different from the last one shown
*/
static void
show_card(y, x, c, lc)
int y, x;
register CARD c, *lc;
{
if (c == *lc)
return;
mvprintw(y, x, C_fmt, C_name[c]);
*lc = c;
}
void
prboard() {
reg PLAY *pp;
reg int i, j, k, temp;
PLAY *pp;
int i, j, k, temp;
for (k = 0; k < 2; k++) {
pp = &Player[k];
@@ -25,8 +42,8 @@ prboard() {
show_card(14, temp, pp->battle, &pp->sh_battle);
show_card(16, temp, pp->speed, &pp->sh_speed);
for (i = C_25; i <= C_200; i++) {
reg char *name;
reg int end;
char *name;
int end;
if (pp->nummiles[i] == pp->sh_nummiles[i])
continue;
@@ -57,28 +74,31 @@ prboard() {
wrefresh(Score);
}
/*
* show_card:
* Show the given card if it is different from the last one shown
*/
show_card(y, x, c, lc)
int y, x;
register CARD c, *lc;
{
if (c == *lc)
return;
mvprintw(y, x, C_fmt, C_name[c]);
*lc = c;
}
static char Score_fmt[] = "%4d";
prscore(for_real)
reg bool for_real; {
/*
* show_score:
* Show a score value if it is different from the last time we
* showed it.
*/
static void
show_score(y, x, s, ls)
int y, x;
register int s, *ls;
{
if (s == *ls)
return;
reg PLAY *pp;
reg int x;
mvprintw(y, x, Score_fmt, s);
*ls = s;
}
void
prscore(for_real)
bool for_real; {
PLAY *pp;
int x;
stdscr = Score;
for (pp = Player; pp < &Player[2]; pp++) {
@@ -114,19 +134,3 @@ reg bool for_real; {
}
stdscr = Board;
}
/*
* show_score:
* Show a score value if it is different from the last time we
* showed it.
*/
show_score(y, x, s, ls)
int y, x;
register int s, *ls;
{
if (s == *ls)
return;
mvprintw(y, x, Score_fmt, s);
*ls = s;
}

View File

@@ -1,4 +1,5 @@
# include "mille.h"
#include "mille.h"
#include <stdlib.h>
/*
* This routine rolls ndie nside-sided dice.
@@ -7,11 +8,11 @@
*
*/
int
roll(ndie, nsides)
reg int ndie, nsides; {
int ndie, nsides; {
reg int tot;
extern unsigned int random();
int tot;
tot = 0;
while (ndie--)

View File

@@ -1,15 +1,20 @@
#include "mille.h"
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "mille.h"
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <time.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifndef unctrl
#include "unctrl.h"
# include "unctrl.h"
#endif
# ifdef attron
# include <term.h>
# define _tty cur_term->Nttyb
# endif attron
#ifdef attron
# include <term.h>
# define _tty cur_term->Nttyb
#endif
/*
* @(#)save.c 1.3 (2.11BSD) 1996/3/21
@@ -17,27 +22,24 @@
typedef struct stat STAT;
extern char *ctime();
extern int read(), write();
/*
* This routine saves the current game for use at a later date
*/
extern int errno;
int
save() {
reg char *sp;
reg int outf;
reg time_t *tp;
char buf[80];
time_t tme;
STAT junk;
char *sp;
int outf;
time_t *tp;
char buf[80];
time_t tme;
STAT junk;
tp = &tme;
if (Fromfile && getyn(SAMEFILEPROMPT))
if (Fromfile && getyn(SAMEFILEPROMPT)) {
strcpy(buf, Fromfile);
else {
sp = buf;
} else {
over:
prompt(FILEPROMPT);
leaveok(Board, FALSE);
@@ -77,7 +79,7 @@ over:
return FALSE;
if ((outf = creat(buf, 0644)) < 0) {
error(strerror(errno));
error(strerror(errno), 0);
return FALSE;
}
mvwaddstr(Score, ERR_Y, ERR_X, buf);
@@ -100,13 +102,14 @@ over:
* backup was made on exiting, in which case certain things must
* be cleaned up before the game starts.
*/
int
rest_f(file)
reg char *file; {
char *file; {
reg char *sp;
reg int inf;
char buf[80];
STAT sbuf;
char *sp;
int inf;
char buf[80];
STAT sbuf;
if ((inf = open(file, 0)) < 0) {
perror(file);
@@ -129,4 +132,3 @@ reg char *file; {
Fromfile = file;
return !On_exit;
}

View File

@@ -1,17 +1,19 @@
# include "mille.h"
#include "mille.h"
/*
* @(#)types.c 1.1 (Berkeley) 4/1/82
*/
int
isrepair(card)
reg CARD card; {
CARD card; {
return card == C_GAS || card == C_SPARE || card == C_REPAIRS || card == C_INIT;
}
int
safety(card)
reg CARD card; {
CARD card; {
switch (card) {
case C_EMPTY:
@@ -34,5 +36,5 @@ reg CARD card; {
return C_RIGHT_WAY;
}
/* NOTREACHED */
return 0;
}

View File

@@ -1,18 +1,20 @@
# include "mille.h"
#include "mille.h"
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
/*
* @(#)varpush.c 1.1 (Berkeley) 4/1/82
*/
int read(), write();
/*
* push variables around via the routine func() on the file
* channel file. func() is either read or write.
*/
void
varpush(file, func)
reg int file;
reg int (*func)(); {
int file;
int (*func)(); {
int temp;
@@ -30,13 +32,18 @@ reg int (*func)(); {
(*func)(file, (char *) &Discard, sizeof Discard);
(*func)(file, (char *) Player, sizeof Player);
if (func == read) {
read(file, (char *) &temp, sizeof temp);
if (read(file, (char *) &temp, sizeof temp) != sizeof temp) {
perror("read");
exit(-1);
}
Topcard = &Deck[temp];
if (Debug) {
char buf[80];
over:
printf("Debug file:");
gets(buf);
if (! fgets(buf, sizeof(buf), stdin)) {
exit(0);
}
if ((outf = fopen(buf, "w")) == NULL) {
perror(buf);
goto over;
@@ -47,7 +54,9 @@ over:
}
else {
temp = Topcard - Deck;
write(file, (char *) &temp, sizeof temp);
if (write(file, (char *) &temp, sizeof temp) != sizeof temp) {
perror("write");
exit(-1);
}
}
}