Merge branch 'games'.
This commit is contained in:
2
cross.mk
2
cross.mk
@@ -1,7 +1,7 @@
|
||||
DESTDIR = /usr/local/retrobsd
|
||||
MACHINE = mips
|
||||
|
||||
CC = gcc
|
||||
CC = gcc -m32
|
||||
|
||||
AS = $(CC) -x assembler-with-cpp
|
||||
LD = ld
|
||||
|
||||
1
etc/.gitignore
vendored
1
etc/.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
phones
|
||||
remote
|
||||
termcap
|
||||
termcap.full
|
||||
|
||||
16
etc/ttys
16
etc/ttys
@@ -1,16 +1,16 @@
|
||||
#
|
||||
# name getty type status comments
|
||||
#
|
||||
console "/libexec/getty std.default" vt100 on secure #special
|
||||
console "/libexec/getty std.default" xterm on secure #special
|
||||
|
||||
# Enable some of these for additional logins. Do NOT enable the same one as the
|
||||
# console port, or strange things will happen. You can turn off the console port
|
||||
# if you would rather use the getty on the real tty - it's up to you.
|
||||
|
||||
tty0 "/libexec/getty std.default" vt100 off secure
|
||||
tty1 "/libexec/getty std.default" vt100 off secure
|
||||
tty2 "/libexec/getty std.default" vt100 off secure
|
||||
tty3 "/libexec/getty std.default" vt100 off secure
|
||||
tty4 "/libexec/getty std.default" vt100 off secure
|
||||
tty5 "/libexec/getty std.default" vt100 off secure
|
||||
ttyUSB0 "/libexec/getty std.default" vt100 off secure
|
||||
tty0 "/libexec/getty std.default" xterm off secure
|
||||
tty1 "/libexec/getty std.default" xterm off secure
|
||||
tty2 "/libexec/getty std.default" xterm off secure
|
||||
tty3 "/libexec/getty std.default" xterm off secure
|
||||
tty4 "/libexec/getty std.default" xterm off secure
|
||||
tty5 "/libexec/getty std.default" xterm off secure
|
||||
ttyUSB0 "/libexec/getty std.default" xterm off secure
|
||||
|
||||
@@ -181,6 +181,10 @@ int waddstr (WINDOW *, char *);
|
||||
int wgetstr (WINDOW *, char *);
|
||||
int wdeleteln (WINDOW *);
|
||||
void mvcur(int ly, int lx, int y, int x);
|
||||
void overwrite(WINDOW *win1, WINDOW *win2);
|
||||
void wclrtobot(WINDOW *win);
|
||||
int mvprintw(int y, int x, char *fmt, ...);
|
||||
int mvwprintw(WINDOW *win, int y, int x, char *fmt, ...);
|
||||
|
||||
/*
|
||||
* Used to be in unctrl.h.
|
||||
|
||||
@@ -417,13 +417,21 @@ file /games/canfield
|
||||
file /games/cfscores
|
||||
file /games/factor
|
||||
file /games/fish
|
||||
file /games/fortune
|
||||
file /games/hangman
|
||||
file /games/mille
|
||||
file /games/monop
|
||||
file /games/morse
|
||||
file /games/number
|
||||
file /games/ppt
|
||||
file /games/primes
|
||||
file /games/quiz
|
||||
file /games/rain
|
||||
file /games/robots
|
||||
file /games/rogue
|
||||
file /games/sail
|
||||
file /games/snake
|
||||
file /games/snscore
|
||||
file /games/teachgammon
|
||||
file /games/trek
|
||||
file /games/worm
|
||||
@@ -433,13 +441,52 @@ file /games/wump
|
||||
#
|
||||
# Files: /games/lib
|
||||
#
|
||||
default
|
||||
filemode 0444
|
||||
dir /games/lib
|
||||
file /games/lib/adventure.dat
|
||||
mode 0444
|
||||
file /games/lib/battle_strings
|
||||
mode 0444
|
||||
file /games/lib/cfscores
|
||||
mode 0666
|
||||
file /games/lib/fortunes.dat
|
||||
file /games/lib/cards.pck
|
||||
file /games/lib/robots_roll
|
||||
mode 0666
|
||||
file /games/lib/snakerawscores
|
||||
mode 0666
|
||||
dir /games/lib/quiz.k
|
||||
file /games/lib/quiz.k/africa
|
||||
file /games/lib/quiz.k/america
|
||||
file /games/lib/quiz.k/areas
|
||||
file /games/lib/quiz.k/arith
|
||||
file /games/lib/quiz.k/asia
|
||||
file /games/lib/quiz.k/babies
|
||||
file /games/lib/quiz.k/bard
|
||||
file /games/lib/quiz.k/chinese
|
||||
file /games/lib/quiz.k/collectives
|
||||
file /games/lib/quiz.k/ed
|
||||
file /games/lib/quiz.k/elements
|
||||
file /games/lib/quiz.k/europe
|
||||
file /games/lib/quiz.k/greek
|
||||
file /games/lib/quiz.k/inca
|
||||
file /games/lib/quiz.k/index
|
||||
file /games/lib/quiz.k/latin
|
||||
file /games/lib/quiz.k/locomotive
|
||||
file /games/lib/quiz.k/midearth
|
||||
file /games/lib/quiz.k/morse
|
||||
file /games/lib/quiz.k/murders
|
||||
file /games/lib/quiz.k/poetry
|
||||
file /games/lib/quiz.k/posneg
|
||||
file /games/lib/quiz.k/pres
|
||||
file /games/lib/quiz.k/province
|
||||
file /games/lib/quiz.k/seq-easy
|
||||
file /games/lib/quiz.k/seq-hard
|
||||
file /games/lib/quiz.k/sexes
|
||||
file /games/lib/quiz.k/sov
|
||||
file /games/lib/quiz.k/spell
|
||||
file /games/lib/quiz.k/state
|
||||
file /games/lib/quiz.k/trek
|
||||
file /games/lib/quiz.k/ucc
|
||||
|
||||
#
|
||||
# Files: /include
|
||||
@@ -627,9 +674,12 @@ file /libexec/smlrc
|
||||
default
|
||||
filemode 0444
|
||||
dir /share
|
||||
dir /share/dict
|
||||
dir /share/misc
|
||||
file /share/emg.keys
|
||||
file /share/re.help
|
||||
file /share/dict/words
|
||||
file /share/misc/more.help
|
||||
|
||||
#
|
||||
# Files: /share/example
|
||||
@@ -716,16 +766,26 @@ file /share/man/cat5/crontab.0
|
||||
file /share/man/cat5/ranlib.0
|
||||
file /share/man/cat6/adventure.0
|
||||
file /share/man/cat6/arithmetic.0
|
||||
file /share/man/cat6/atc.0
|
||||
file /share/man/cat6/backgammon.0
|
||||
file /share/man/cat6/banner.0
|
||||
file /share/man/cat6/battlestar.0
|
||||
file /share/man/cat6/bcd.0
|
||||
file /share/man/cat6/canfield.0
|
||||
file /share/man/cat6/crib.0
|
||||
file /share/man/cat6/cribbage.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/monop.0
|
||||
file /share/man/cat6/number.0
|
||||
file /share/man/cat6/quiz.0
|
||||
file /share/man/cat6/rain.0
|
||||
file /share/man/cat6/robots.0
|
||||
file /share/man/cat6/rogue.0
|
||||
file /share/man/cat6/sail.0
|
||||
file /share/man/cat6/snake.0
|
||||
file /share/man/cat6/trek.0
|
||||
file /share/man/cat6/worm.0
|
||||
file /share/man/cat6/worms.0
|
||||
|
||||
25486
share/dict/words
Normal file
25486
share/dict/words
Normal file
File diff suppressed because it is too large
Load Diff
@@ -11,10 +11,9 @@ CFLAGS += -Werror -Wall -Os
|
||||
|
||||
# Programs that live in subdirectories, and have makefiles of their own.
|
||||
#
|
||||
SUBDIR = adventure backgammon battlestar rogue sail trek
|
||||
# TODO: atc boggle btlgammon cribbage
|
||||
# fortune hangman hunt mille monop phantasia quiz robots
|
||||
# sail snake warp
|
||||
SUBDIR = adventure atc backgammon battlestar boggle btlgammon \
|
||||
cribbage fortune hangman mille monop quiz robots rogue \
|
||||
sail snake trek
|
||||
|
||||
# C programs that live in the current directory and do not need
|
||||
# explicit make lines.
|
||||
|
||||
2
src/games/atc/.gitignore
vendored
Normal file
2
src/games/atc/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
atc
|
||||
y.tab.h
|
||||
@@ -5,26 +5,37 @@
|
||||
#
|
||||
# @(#)Makefile 5.1.2 (2.11BSD) 1999/10/25
|
||||
#
|
||||
TOPSRC = $(shell cd ../../..; pwd)
|
||||
include $(TOPSRC)/target.mk
|
||||
#include $(TOPSRC)/cross.mk
|
||||
|
||||
DESTDIR =
|
||||
CFLAGS = -O -DSYSV -DDEST=\"${DESTDIR}/usr/games/lib/atc/\"
|
||||
YFLAGS = -d
|
||||
LIBS = -ll -lm -lcurses -ltermcap
|
||||
OBJS = extern.o grammar.o input.o lex.o list.o log.o main.o tunable.o \
|
||||
graphics.o update.o
|
||||
CFLAGS = -Os -g -Werror -Wall
|
||||
CFLAGS += -DBSD -DDEST=\"/games/lib/atc/\"
|
||||
#CFLAGS += -DSYSV -DDEST=\"games/\"
|
||||
YFLAGS = -d
|
||||
LEX = lex
|
||||
LIBS = -lm -lcurses -ltermcap -lc
|
||||
OBJS = extern.o grammar.o input.o lex.o list.o log.o main.o tunable.o \
|
||||
graphics.o update.o
|
||||
MAN = atc.0
|
||||
MANSRC = atc.6
|
||||
|
||||
all: atc
|
||||
all: atc $(MAN)
|
||||
|
||||
atc: ${OBJS}
|
||||
${CC} ${OBJS} ${LIBS} -o $@
|
||||
atc: $(OBJS)
|
||||
$(CC) $(LDFLAGS) -o atc.elf $(OBJS) $(LIBS)
|
||||
$(OBJDUMP) -S atc.elf > atc.dis
|
||||
$(SIZE) atc.elf
|
||||
$(ELF2AOUT) atc.elf $@ && rm atc.elf
|
||||
|
||||
${MAN}: ${MANSRC}
|
||||
${MANROFF} $< > $@
|
||||
|
||||
clean:
|
||||
rm -f *.o core atc grammar.c y.tab.h y.tab.c lex.yy.c lex.c
|
||||
rm -f *.o *.0 *.elf atc ${MAN} *.elf *.dis tags *~ grammar.c lex.c y.tab.h
|
||||
|
||||
install:
|
||||
-[ -d ${DESTDIR}/usr/games/lib/atc ] || mkdir ${DESTDIR}/usr/games/lib/atc
|
||||
chmod 700 ${DESTDIR}/usr/games/lib/atc
|
||||
chown games.bin ${DESTDIR}/usr/games/lib/atc
|
||||
(cd games; install -c -o games -g bin -m 600 * ${DESTDIR}/usr/games/lib/atc)
|
||||
install -s -o games -g bin -m 4700 atc ${DESTDIR}/usr/games/hide/atc
|
||||
(cd ${DESTDIR}/usr/games; rm -f atc; ln -s dm atc; chown games.bin atc)
|
||||
install: all
|
||||
install atc $(DESTDIR)/games/
|
||||
mkdir -p ${DESTDIR}/games/lib/atc
|
||||
cp -p games/* ${DESTDIR}/games/lib/atc
|
||||
cp ${MAN} $(DESTDIR)/share/man/cat6/
|
||||
|
||||
597
src/games/atc/atc.6
Normal file
597
src/games/atc/atc.6
Normal file
@@ -0,0 +1,597 @@
|
||||
.\" Copyright (c) 1990, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" Ed James.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. All advertising materials mentioning features or use of this software
|
||||
.\" must display the following acknowledgement:
|
||||
.\" This product includes software developed by the University of
|
||||
.\" California, Berkeley and its contributors.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)atc.6 8.1 (Berkeley) 5/31/93
|
||||
.\"
|
||||
. \" XP - exdented paragraph
|
||||
.de XP
|
||||
.RT
|
||||
.if \\n(1T .sp \\n(PDu
|
||||
.ne 1.1
|
||||
.if !\\n(IP .nr IP +1
|
||||
.in +\\n(I\\n(IRu
|
||||
.ti -\\n(I\\n(IRu
|
||||
..
|
||||
.\" Copyright (c) 1986 Ed James. All rights reserved.
|
||||
.\"
|
||||
.TH ATC 6 "May 31, 1993"
|
||||
.UC
|
||||
.SH NAME
|
||||
atc \- air traffic controller game
|
||||
.SH SYNOPSIS
|
||||
.B atc
|
||||
-[u?lstp] [-[gf] game_name] [-r random seed]
|
||||
.SH DESCRIPTION
|
||||
.LP
|
||||
.I Atc
|
||||
lets you try your hand at the nerve wracking duties of the air traffic
|
||||
controller without endangering the lives of millions of
|
||||
travelers each year.
|
||||
Your responsibilities require you to direct the flight of jets
|
||||
and prop planes into and out of the flight arena and airports.
|
||||
The speed (update time) and frequency of the planes depend on the
|
||||
difficulty of the chosen arena.
|
||||
.SH OPTIONS
|
||||
.LP
|
||||
.TP 8
|
||||
.B \-u
|
||||
Print the usage line and exit.
|
||||
.TP
|
||||
.B \-?
|
||||
Same as
|
||||
.B \-u.
|
||||
.TP
|
||||
.B \-l
|
||||
Print a list of available games and exit.
|
||||
The first game name printed is the default game.
|
||||
.TP
|
||||
.B \-s
|
||||
Print the score list (formerly the Top Ten list).
|
||||
.TP
|
||||
.B \-t
|
||||
Same as
|
||||
.B \-s.
|
||||
.TP
|
||||
.B \-p
|
||||
Print the path to the special directory where
|
||||
.I atc
|
||||
expects to find its private files. This is used during the
|
||||
installation of the program.
|
||||
.TP
|
||||
.B "\-g game"
|
||||
Play the named game. If the game listed is not one of the
|
||||
ones printed from the
|
||||
.B \-l
|
||||
option, the default game is played.
|
||||
.TP
|
||||
.B "\-f game"
|
||||
Same as
|
||||
.B \-g.
|
||||
.TP
|
||||
.B "\-r seed"
|
||||
Set the random seed. The purpose of this flag is questionable.
|
||||
.SH GOALS
|
||||
.LP
|
||||
Your goal in
|
||||
.I atc
|
||||
is to keep the game going as long as possible.
|
||||
There is no winning state, except to beat the times of other players.
|
||||
You will need to: launch planes at airports (by instructing them to
|
||||
increase their altitude); land planes at airports (by instructing them to
|
||||
go to altitude zero when exactly over the airport); and maneuver planes
|
||||
out of exit points.
|
||||
.LP
|
||||
Several things will cause the end of the game.
|
||||
Each plane has a destination (see information area), and
|
||||
sending a plane to the wrong destination is an error.
|
||||
Planes can run out of fuel, or can collide. Collision is defined as
|
||||
adjacency in any of the three dimensions. A plane leaving the arena
|
||||
in any other way than through its destination exit is an error as well.
|
||||
.LP
|
||||
Scores are sorted in order of the number of planes safe. The other
|
||||
statistics are provided merely for fun. There is no penalty for
|
||||
taking longer than another player (except in the case of ties).
|
||||
.LP
|
||||
Suspending a game is not permitted. If you get a talk message, tough.
|
||||
When was the last time an Air Traffic Controller got called away to
|
||||
the phone?
|
||||
.SH "THE DISPLAY"
|
||||
.LP
|
||||
Depending on the terminal you run
|
||||
.I atc
|
||||
on, the screen will be divided into 4 areas.
|
||||
It should be stressed that the terminal driver portion of the
|
||||
game was designed to be reconfigurable, so the display format can vary
|
||||
depending the version you are playing. The descriptions here are based
|
||||
on the ascii version
|
||||
of the game. The game rules and input format, however,
|
||||
should remain consistent.
|
||||
Control-L redraws the screen, should it become muddled.
|
||||
.SS RADAR
|
||||
.IP
|
||||
The first screen area is the radar display, showing the relative locations
|
||||
of the planes, airports, standard entry/exit points, radar
|
||||
beacons, and "lines" which simply serve to aid you in guiding
|
||||
the planes.
|
||||
.IP
|
||||
Planes are shown as a single letter with an altitude. If
|
||||
the numerical altitude is a single digit, then it represents
|
||||
thousands of feet.
|
||||
Some distinction is made between the prop
|
||||
planes and the jets. On ascii terminals, prop planes are
|
||||
represented by a upper case letter, jets by a lower case letter.
|
||||
.IP
|
||||
Airports are shown as a number and some indication of the direction
|
||||
planes must be going to land at the airport.
|
||||
On ascii terminals, this is one of '^', '>', '<', and 'v', to indicate
|
||||
north (0 degrees), east (90), west (270) and south (180), respectively.
|
||||
The planes will also
|
||||
take off in this direction.
|
||||
.IP
|
||||
Beacons are represented as circles or asterisks and a number.
|
||||
Their purpose is to offer a place of easy reference to the plane pilots.
|
||||
See 'the delay command' under the input section of this manual.
|
||||
.IP
|
||||
Entry/exit points are displayed as numbers along the border of the
|
||||
radar screen. Planes will enter the arena from these points without
|
||||
warning. These points have a direction associated with them, and
|
||||
planes will always enter the arena from this direction. On the
|
||||
ascii version of
|
||||
.I atc,
|
||||
this direction is not displayed. It will become apparent
|
||||
what this direction is as the game progresses.
|
||||
.IP
|
||||
Incoming planes will always enter at the same altitude: 7000 feet.
|
||||
For a plane to successfully depart through an entry/exit point,
|
||||
it must be flying at 9000 feet.
|
||||
It is not necessary for the planes to be flying in any particular
|
||||
direction when they leave the arena (yet).
|
||||
.SS "INFORMATION AREA"
|
||||
.IP
|
||||
The second area of the display is the information area, which lists
|
||||
the time (number of updates since start), and the number of planes you
|
||||
have directed safely out of the arena.
|
||||
Below this is a list of planes currently in the air, followed by a
|
||||
blank line, and then a list of planes on the ground (at airports).
|
||||
Each line lists the plane name and its current altitude,
|
||||
an optional asterisk indicating low fuel, the plane's destination,
|
||||
and the plane's current command. Changing altitude is not considered
|
||||
to be a command and is therefore not displayed. The following are
|
||||
some possible information lines:
|
||||
.IP
|
||||
B4*A0: Circle @ b1
|
||||
.br
|
||||
g7 E4: 225
|
||||
.IP
|
||||
The first example shows a prop plane named 'B' that is flying at 4000
|
||||
feet. It is low on fuel (note the '*'). It's destination is
|
||||
Airport #0.
|
||||
The next command it expects
|
||||
to do is circle when it reaches Beacon #1.
|
||||
The second example shows a jet named 'g' at 7000 feet, destined for
|
||||
Exit #4. It is just now executing a turn to 225 degrees (South-West).
|
||||
.SS "INPUT AREA"
|
||||
.IP
|
||||
The third area of the display is the input area. It is here that
|
||||
your input is reflected. See the INPUT heading of this manual
|
||||
for more details.
|
||||
.SS "AUTHOR AREA"
|
||||
.IP
|
||||
This area is used simply to give credit where credit is due. :-)
|
||||
.SH INPUT
|
||||
.LP
|
||||
A command completion interface is built into
|
||||
the game. At any time, typing '?' will list possible input characters.
|
||||
Typing a backspace (your erase character) backs up, erasing the last part
|
||||
of the command. When a command is complete, a return enters it, and
|
||||
any semantic checking is done at that time. If no errors are detected,
|
||||
the command is sent to the appropriate plane. If an error is discovered
|
||||
during the check, the offending statement will be underscored and a
|
||||
(hopefully) descriptive message will be printed under it.
|
||||
.LP
|
||||
The command syntax is broken into two parts:
|
||||
.I "Immediate Only"
|
||||
and
|
||||
.I Delayable
|
||||
commands.
|
||||
.I "Immediate Only"
|
||||
commands happen on the next
|
||||
update.
|
||||
.I Delayable
|
||||
commands also happen on the next update unless they
|
||||
are followed by an optional predicate called the
|
||||
.I Delay
|
||||
command.
|
||||
.LP
|
||||
In the following tables, the syntax
|
||||
.B [0\-9]
|
||||
means any single digit, and
|
||||
.B <dir>
|
||||
refers to the keys around the 's' key, namely ``wedcxzaq''.
|
||||
In absolute references, 'q' refers to North-West or 315 degrees, and 'w'
|
||||
refers to North, or 0 degrees.
|
||||
In relative references, 'q' refers to -45 degrees or 45 degrees left, and 'w'
|
||||
refers to 0 degrees, or no change in direction.
|
||||
.LP
|
||||
All commands start with a plane letter. This indicates the recipient
|
||||
of the command. Case is ignored.
|
||||
.SS "IMMEDIATE ONLY COMMANDS"
|
||||
.RS
|
||||
.B "\- a Altitude:"
|
||||
.RS
|
||||
Affect a plane's altitude (and take off).
|
||||
.RE
|
||||
.RS
|
||||
.B "\- [0\-9] Number:"
|
||||
.RS
|
||||
Go to the given altitude (thousands of feet).
|
||||
.RE
|
||||
.B "\- c/+ Climb:"
|
||||
.RS
|
||||
Relative altitude change.
|
||||
.RE
|
||||
.RS
|
||||
.B "\- [0\-9] Number:"
|
||||
.RS
|
||||
Difference in thousands of feet.
|
||||
.RE
|
||||
.RE
|
||||
.B "\- d/\- Descend:"
|
||||
.RS
|
||||
Relative altitude change.
|
||||
.RE
|
||||
.RS
|
||||
.B "\- [0\-9] Number:"
|
||||
.RS
|
||||
Difference in thousands of feet.
|
||||
.RE
|
||||
.RE
|
||||
.RE
|
||||
.B "\- m Mark:"
|
||||
.RS
|
||||
Display in highlighted mode. Command is displayed normally.
|
||||
.RE
|
||||
.B "\- i Ignore:"
|
||||
.RS
|
||||
Do not display highlighted. Command is displayed as a
|
||||
line of dashes if there is no command.
|
||||
.RE
|
||||
.B "\- u Unmark:"
|
||||
.RS
|
||||
Same as ignore, but if a delayed command is processed,
|
||||
the plane will become marked. This is useful if you want
|
||||
to forget about a plane during part, but not all, of its
|
||||
journey.
|
||||
.RE
|
||||
.RE
|
||||
.SS "DELAYABLE COMMANDS"
|
||||
.RS
|
||||
.B "\- c Circle:"
|
||||
.RS
|
||||
Have the plane circle (clockwise by default).
|
||||
.RE
|
||||
.RS
|
||||
.B "\- l Left:"
|
||||
.RS
|
||||
Circle counterclockwise.
|
||||
.RE
|
||||
.B "\- r Right:"
|
||||
.RS
|
||||
Circle clockwise.
|
||||
.RE
|
||||
.RE
|
||||
.B "\- t Turn:"
|
||||
.RS
|
||||
Change direction.
|
||||
.RE
|
||||
.RS
|
||||
.B "\- l Left:"
|
||||
.RS
|
||||
Turn counterclockwise (45 degrees by default).
|
||||
.RE
|
||||
.RS
|
||||
.B "\- <dir> Direction:"
|
||||
.RS
|
||||
Turn ccw the given number of degrees.
|
||||
Zero degrees is no turn. A ccw turn
|
||||
of -45 degrees is 45 cw.
|
||||
.RE
|
||||
.RE
|
||||
.B "\- r Right:"
|
||||
.RS
|
||||
Turn clockwise (45 degrees by default).
|
||||
.RE
|
||||
.RS
|
||||
.B "\- <dir> Direction:"
|
||||
.RS
|
||||
Same as turn left <dir>.
|
||||
.RE
|
||||
.RE
|
||||
.B "\- L Left 90:"
|
||||
.RS
|
||||
Turn counterclockwise 90 degrees.
|
||||
.RE
|
||||
.B "\- R Right 90:"
|
||||
.RS
|
||||
Turn clockwise 90 degrees.
|
||||
.RE
|
||||
.B "\- <dir> Direction:"
|
||||
.RS
|
||||
Turn to the absolute compass heading given.
|
||||
The shortest turn will be taken.
|
||||
.RE
|
||||
.B "\- t Towards:"
|
||||
.RS
|
||||
Turn towards a beacon, airport or exit. The turn is
|
||||
just an estimate.
|
||||
.RE
|
||||
.RS
|
||||
.B "\- b/* Beacon:"
|
||||
.RS
|
||||
Turn towards the beacon.
|
||||
.RE
|
||||
.RS
|
||||
.B "\- [0-9] Number:"
|
||||
.RS
|
||||
The beacon number.
|
||||
.RE
|
||||
.RE
|
||||
.B "\- e Exit:"
|
||||
.RS
|
||||
Turn towards the exit.
|
||||
.RE
|
||||
.RS
|
||||
.B "\- [0-9] Number:"
|
||||
.RS
|
||||
The exit number.
|
||||
.RE
|
||||
.RE
|
||||
.B "\- a Airport:"
|
||||
.RS
|
||||
Turn towards the airport.
|
||||
.RE
|
||||
.RS
|
||||
.B "\- [0-9] Number:"
|
||||
.RS
|
||||
The airport number.
|
||||
.RE
|
||||
.RE
|
||||
.RE
|
||||
.RE
|
||||
.RE
|
||||
.SS THE DELAY COMMAND
|
||||
.LP
|
||||
The
|
||||
.B Delay
|
||||
(a/@)
|
||||
command may be appended to any
|
||||
.B Delayable
|
||||
command. It allows the controller to instruct a plane to do an action
|
||||
when the plane reaches a particular beacon (or other objects in future
|
||||
versions).
|
||||
.sp
|
||||
.RS
|
||||
.B "\- a/@ At:"
|
||||
.RS
|
||||
Do the given delayable command when the plane reaches the given beacon.
|
||||
.RE
|
||||
.RS
|
||||
.B "\- b/* Beacon:"
|
||||
.RS
|
||||
This is redundant to allow for expansion.
|
||||
.RE
|
||||
.RS
|
||||
.B "\- [0-9] Number:"
|
||||
.RS
|
||||
The beacon number.
|
||||
.RE
|
||||
.RE
|
||||
.RE
|
||||
.RE
|
||||
.SS "MARKING, UNMARKING AND IGNORING"
|
||||
.LP
|
||||
Planes are
|
||||
.B marked
|
||||
when they enter the arena. This means they are displayed in highlighted
|
||||
mode on the radar display. A plane may also be either
|
||||
.B unmarked
|
||||
or
|
||||
.B ignored.
|
||||
An
|
||||
.B unmarked
|
||||
plane is drawn in unhighlighted mode, and a line of dashes is displayed in
|
||||
the command field of the information area. The plane will remain this
|
||||
way until a mark command has been issued. Any other command will be issued,
|
||||
but the command line will return to a line of dashes when the command
|
||||
is completed.
|
||||
.LP
|
||||
An
|
||||
.B ignored
|
||||
plane is treated the same as an unmarked plane, except that it will
|
||||
automatically switch to
|
||||
.B marked
|
||||
status when a delayed command has been processed. This is useful if
|
||||
you want to forget about a plane for a while, but its flight path has
|
||||
not yet been completely set.
|
||||
.LP
|
||||
As with all of the commands, marking, unmarking and ignoring will take effect
|
||||
at the beginning of the next update. Do not be surprised if the plane does
|
||||
not immediately switch to unhighlighted mode.
|
||||
.SS EXAMPLES
|
||||
.RS
|
||||
.TP 16
|
||||
atlab1
|
||||
a: turn left at beacon #1
|
||||
.TP 16
|
||||
cc
|
||||
C: circle
|
||||
.TP 16
|
||||
gtte4ab2
|
||||
g: turn towards exit #4 at beacon #2
|
||||
.TP 16
|
||||
ma+2
|
||||
m: altitude: climb 2000 feet
|
||||
.TP 16
|
||||
stq
|
||||
S: turn to 315
|
||||
.TP 16
|
||||
xi
|
||||
x: ignore
|
||||
.RE
|
||||
.SH "OTHER INFORMATION"
|
||||
.LP
|
||||
Jets move every update; prop planes move every other update.
|
||||
.LP
|
||||
All planes turn a most 90 degrees per movement.
|
||||
.LP
|
||||
Planes enter at 7000 feet and leave at 9000 feet.
|
||||
.LP
|
||||
Planes flying at an altitude of 0 crash if they are not over an airport.
|
||||
.LP
|
||||
Planes waiting at airports can only be told to take off (climb in altitude).
|
||||
.SH "NEW GAMES"
|
||||
.LP
|
||||
The
|
||||
.B Game_List
|
||||
file lists the currently available play fields. New field description
|
||||
file names must be placed in this file to be 'playable'. If a player
|
||||
specifies a game not in this file, his score will not be logged.
|
||||
.LP
|
||||
The game field description files are broken into two parts. The first
|
||||
part is the definition section. Here, the four tunable game parameters
|
||||
must be set. These variables are set with the syntax:
|
||||
.IP
|
||||
variable = number;
|
||||
.LP
|
||||
Variable may be one of:
|
||||
.B update,
|
||||
indicating the number of seconds between forced updates;
|
||||
.B newplane,
|
||||
indicating (about) the number of updates between new plane entries;
|
||||
.B width,
|
||||
indicating the width of the play field; and
|
||||
.B height,
|
||||
indicating the height of the play field.
|
||||
.LP
|
||||
The second part of the field description files describes the locations
|
||||
of the exits, the beacons, the airports and the lines.
|
||||
The syntax is as follows:
|
||||
.IP
|
||||
beacon: (x y) ... ;
|
||||
.br
|
||||
airport: (x y direction) ... ;
|
||||
.br
|
||||
exit: (x y direction) ... ;
|
||||
.br
|
||||
line: [ (x1 y1) (x2 y2) ] ... ;
|
||||
.LP
|
||||
For beacons, a simple x, y coordinate pair is used (enclosed in parenthesis).
|
||||
Airports and exits require a third value, a direction, which is one
|
||||
of
|
||||
.B wedcxzaq.
|
||||
For airports, this is the direction that planes must be going to take
|
||||
off and land, and for exits, this is the direction that planes will going
|
||||
when they
|
||||
.B enter
|
||||
the arena. This may not seem intuitive, but as there is no restriction on
|
||||
direction of exit, this is appropriate.
|
||||
Lines are slightly different, since they need two coordinate pairs to
|
||||
specify the line endpoints. These endpoints must be enclosed in
|
||||
square brackets.
|
||||
.LP
|
||||
All statements are semi-colon (;) terminated. Multiple item statements
|
||||
accumulate. Each definition must occur exactly once, before any
|
||||
item statements. Comments begin with a hash (#) symbol
|
||||
and terminate with a newline.
|
||||
The coordinates are between zero and width-1 and height-1
|
||||
inclusive. All of the exit coordinates must lie on the borders, and
|
||||
all of the beacons and airports must lie inside of the borders.
|
||||
Line endpoints may be anywhere within the field, so long as
|
||||
the lines are horizontal, vertical or
|
||||
.B "exactly diagonal."
|
||||
.SS "FIELD FILE EXAMPLE"
|
||||
.RS
|
||||
.sp
|
||||
.nf
|
||||
.TA 1i 1i
|
||||
.ta 1i 1i
|
||||
# This is the default game.
|
||||
|
||||
update = 5;
|
||||
newplane = 5;
|
||||
width = 30;
|
||||
height = 21;
|
||||
|
||||
exit: ( 12 0 x ) ( 29 0 z ) ( 29 7 a ) ( 29 17 a )
|
||||
( 9 20 e ) ( 0 13 d ) ( 0 7 d ) ( 0 0 c ) ;
|
||||
|
||||
beacon: ( 12 7 ) ( 12 17 ) ;
|
||||
|
||||
airport: ( 20 15 w ) ( 20 18 d ) ;
|
||||
|
||||
line: [ ( 1 1 ) ( 6 6 ) ]
|
||||
[ ( 12 1 ) ( 12 6 ) ]
|
||||
[ ( 13 7 ) ( 28 7 ) ]
|
||||
[ ( 28 1 ) ( 13 16 ) ]
|
||||
[ ( 1 13 ) ( 11 13 ) ]
|
||||
[ ( 12 8 ) ( 12 16 ) ]
|
||||
[ ( 11 18 ) ( 10 19 ) ]
|
||||
[ ( 13 17 ) ( 28 17 ) ]
|
||||
[ ( 1 7 ) ( 11 7 ) ] ;
|
||||
.fi
|
||||
.RE
|
||||
.SH FILES
|
||||
.LP
|
||||
Files are kept in a special directory. See the OPTIONS for a way to
|
||||
print this path out.
|
||||
.TP 16
|
||||
.B ATC_score
|
||||
Where the scores are kept.
|
||||
.TP 16
|
||||
.B Game_List
|
||||
The list of playable games.
|
||||
.SH AUTHOR
|
||||
.LP
|
||||
Ed James, UC Berkeley: edjames@ucbvax.berkeley.edu, ucbvax!edjames
|
||||
.LP
|
||||
This game is based on someone's description of the overall flavor
|
||||
of a game written for some unknown PC many years ago, maybe.
|
||||
.SH BUGS
|
||||
.LP
|
||||
The screen sometimes refreshes after you have quit.
|
||||
.LP
|
||||
Yet Another Curses Bug was discovered during the development of this game.
|
||||
If your curses library clrtobot.o is version 5.1 or earlier,
|
||||
you will have erase problems with the backspace operator in the input
|
||||
window.
|
||||
@@ -12,7 +12,7 @@
|
||||
char GAMES[] = "Game_List",
|
||||
LOG[] = "ATC_scores";
|
||||
|
||||
int clock, safe_planes, start_time, test_mode;
|
||||
int clocktick, safe_planes, start_time, test_mode;
|
||||
|
||||
char *file;
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
extern char GAMES[], LOG[], *file;
|
||||
|
||||
extern int clock, safe_planes, start_time, test_mode;
|
||||
extern int clocktick, safe_planes, start_time, test_mode;
|
||||
|
||||
extern FILE *filein, *fileout;
|
||||
|
||||
@@ -22,3 +22,29 @@ extern struct sgttyb tty_start, tty_new;
|
||||
extern DISPLACEMENT displacement[MAXDIR];
|
||||
|
||||
extern PLANE *findplane(), *newplane();
|
||||
|
||||
int dir_no(int ch);
|
||||
void ioclrtoeol(int pos);
|
||||
void iomove(int pos);
|
||||
void ioaddstr(int pos, char *str);
|
||||
void ioclrtobot(void);
|
||||
int getAChar(void);
|
||||
void done_screen(void);
|
||||
void redraw(void);
|
||||
void ioerror(int pos, int len, char *str);
|
||||
int number(int l);
|
||||
void loser(PLANE *p, char *s);
|
||||
void init_gr(void);
|
||||
int yyparse(void);
|
||||
void setup_screen(C_SCREEN *scp);
|
||||
int addplane(void);
|
||||
void log_score(int list_em);
|
||||
void quit(int sig);
|
||||
void update(int sig);
|
||||
int getcommand(void);
|
||||
void planewin(void);
|
||||
int name(PLANE *p);
|
||||
void erase_all(void);
|
||||
void append(LIST *l, PLANE *p);
|
||||
void delete(LIST *l, PLANE *p);
|
||||
void draw_all(void);
|
||||
|
||||
@@ -27,12 +27,15 @@
|
||||
|
||||
int errors = 0;
|
||||
int line = 1;
|
||||
|
||||
int yylex(void);
|
||||
int yyerror(char *s);
|
||||
%}
|
||||
|
||||
%%
|
||||
file:
|
||||
bunch_of_defs { if (checkdefs() < 0) return (errors); } bunch_of_lines
|
||||
{
|
||||
{
|
||||
if (sp->num_exits + sp->num_airports < 2)
|
||||
yyerror("Need at least 2 airports and/or exits.");
|
||||
return (errors);
|
||||
@@ -83,7 +86,7 @@ hdef:
|
||||
else if ($3 < 3)
|
||||
return (yyerror("'height' is too small."));
|
||||
else
|
||||
sp->height = $3;
|
||||
sp->height = $3;
|
||||
}
|
||||
;
|
||||
|
||||
@@ -95,7 +98,7 @@ wdef:
|
||||
else if ($3 < 3)
|
||||
return (yyerror("'width' is too small."));
|
||||
else
|
||||
sp->width = $3;
|
||||
sp->width = $3;
|
||||
}
|
||||
;
|
||||
|
||||
@@ -133,7 +136,7 @@ Bpoint:
|
||||
+ REALLOC) * sizeof (BEACON));
|
||||
else
|
||||
sp->beacon = (BEACON *) realloc(sp->beacon,
|
||||
(sp->num_beacons + REALLOC) *
|
||||
(sp->num_beacons + REALLOC) *
|
||||
sizeof (BEACON));
|
||||
if (sp->beacon == NULL)
|
||||
return (yyerror("No memory available."));
|
||||
@@ -159,11 +162,11 @@ Epoint:
|
||||
|
||||
if (sp->num_exits % REALLOC == 0) {
|
||||
if (sp->exit == NULL)
|
||||
sp->exit = (EXIT *) malloc((sp->num_exits +
|
||||
sp->exit = (EXIT *) malloc((sp->num_exits +
|
||||
REALLOC) * sizeof (EXIT));
|
||||
else
|
||||
sp->exit = (EXIT *) realloc(sp->exit,
|
||||
(sp->num_exits + REALLOC) *
|
||||
(sp->num_exits + REALLOC) *
|
||||
sizeof (EXIT));
|
||||
if (sp->exit == NULL)
|
||||
return (yyerror("No memory available."));
|
||||
@@ -196,7 +199,7 @@ Apoint:
|
||||
+ REALLOC) * sizeof(AIRPORT));
|
||||
else
|
||||
sp->airport = (AIRPORT *) realloc(sp->airport,
|
||||
(sp->num_airports + REALLOC) *
|
||||
(sp->num_airports + REALLOC) *
|
||||
sizeof(AIRPORT));
|
||||
if (sp->airport == NULL)
|
||||
return (yyerror("No memory available."));
|
||||
@@ -223,7 +226,7 @@ Lline:
|
||||
{
|
||||
if (sp->num_lines % REALLOC == 0) {
|
||||
if (sp->line == NULL)
|
||||
sp->line = (LINE *) malloc((sp->num_lines +
|
||||
sp->line = (LINE *) malloc((sp->num_lines +
|
||||
REALLOC) * sizeof (LINE));
|
||||
else
|
||||
sp->line = (LINE *) realloc(sp->line,
|
||||
@@ -242,14 +245,14 @@ Lline:
|
||||
;
|
||||
%%
|
||||
|
||||
check_edge(x, y)
|
||||
void check_edge(x, y)
|
||||
{
|
||||
if (!(x == 0) && !(x == sp->width - 1) &&
|
||||
if (!(x == 0) && !(x == sp->width - 1) &&
|
||||
!(y == 0) && !(y == sp->height - 1))
|
||||
yyerror("edge value not on edge.");
|
||||
}
|
||||
|
||||
check_point(x, y)
|
||||
void check_point(x, y)
|
||||
{
|
||||
if (x < 1 || x >= sp->width - 1)
|
||||
yyerror("X value out of range.");
|
||||
@@ -257,7 +260,7 @@ check_point(x, y)
|
||||
yyerror("Y value out of range.");
|
||||
}
|
||||
|
||||
check_linepoint(x, y)
|
||||
void check_linepoint(x, y)
|
||||
{
|
||||
if (x < 0 || x >= sp->width)
|
||||
yyerror("X value out of range.");
|
||||
@@ -265,7 +268,7 @@ check_linepoint(x, y)
|
||||
yyerror("Y value out of range.");
|
||||
}
|
||||
|
||||
check_line(x1, y1, x2, y2)
|
||||
void check_line(x1, y1, x2, y2)
|
||||
{
|
||||
int d1, d2;
|
||||
|
||||
@@ -279,7 +282,7 @@ check_line(x1, y1, x2, y2)
|
||||
yyerror("Bad line endpoints.");
|
||||
}
|
||||
|
||||
yyerror(s)
|
||||
int yyerror(char *s)
|
||||
{
|
||||
fprintf(stderr, "\"%s\": line %d: %s\n", file, line, s);
|
||||
errors++;
|
||||
@@ -287,7 +290,7 @@ yyerror(s)
|
||||
return (errors);
|
||||
}
|
||||
|
||||
check_edir(x, y, dir)
|
||||
void check_edir(x, y, dir)
|
||||
{
|
||||
int bad = 0;
|
||||
|
||||
@@ -299,7 +302,7 @@ check_edir(x, y, dir)
|
||||
y = 2;
|
||||
else if (y != 0)
|
||||
y = 1;
|
||||
|
||||
|
||||
switch (x * 10 + y) {
|
||||
case 00: if (dir != 3) bad++; break;
|
||||
case 01: if (dir < 1 || dir > 3) bad++; break;
|
||||
@@ -318,11 +321,11 @@ check_edir(x, y, dir)
|
||||
yyerror("Bad direction for entrance at exit.");
|
||||
}
|
||||
|
||||
check_adir(x, y, dir)
|
||||
void check_adir(x, y, dir)
|
||||
{
|
||||
}
|
||||
|
||||
checkdefs()
|
||||
int checkdefs()
|
||||
{
|
||||
int err = 0;
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
WINDOW *radar, *cleanradar, *credit, *input, *planes;
|
||||
|
||||
getAChar()
|
||||
int getAChar()
|
||||
{
|
||||
#ifdef BSD
|
||||
return (getchar());
|
||||
@@ -35,7 +35,7 @@ getAChar()
|
||||
#endif
|
||||
}
|
||||
|
||||
erase_all()
|
||||
void erase_all()
|
||||
{
|
||||
PLANE *pp;
|
||||
|
||||
@@ -49,7 +49,7 @@ erase_all()
|
||||
}
|
||||
}
|
||||
|
||||
draw_all()
|
||||
void draw_all()
|
||||
{
|
||||
PLANE *pp;
|
||||
|
||||
@@ -68,19 +68,37 @@ draw_all()
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
init_gr()
|
||||
void init_gr()
|
||||
{
|
||||
static char buffer[BUFSIZ];
|
||||
|
||||
initscr();
|
||||
setbuf(stdout, buffer);
|
||||
input = newwin(INPUT_LINES, COLS - PLANE_COLS, LINES - INPUT_LINES, 0);
|
||||
credit = newwin(INPUT_LINES, PLANE_COLS, LINES - INPUT_LINES,
|
||||
credit = newwin(INPUT_LINES, PLANE_COLS, LINES - INPUT_LINES,
|
||||
COLS - PLANE_COLS);
|
||||
planes = newwin(LINES - INPUT_LINES, PLANE_COLS, 0, COLS - PLANE_COLS);
|
||||
}
|
||||
|
||||
setup_screen(scp)
|
||||
void draw_line(w, x, y, lx, ly, s)
|
||||
WINDOW *w;
|
||||
char *s;
|
||||
{
|
||||
int dx, dy;
|
||||
|
||||
dx = SGN(lx - x);
|
||||
dy = SGN(ly - y);
|
||||
for (;;) {
|
||||
wmove(w, y, x * 2);
|
||||
waddstr(w, s);
|
||||
if (x == lx && y == ly)
|
||||
break;
|
||||
x += dx;
|
||||
y += dy;
|
||||
}
|
||||
}
|
||||
|
||||
void setup_screen(scp)
|
||||
C_SCREEN *scp;
|
||||
{
|
||||
register int i, j;
|
||||
@@ -164,32 +182,14 @@ setup_screen(scp)
|
||||
wmove(radar, scp->airport[i].y, scp->airport[i].x * 2);
|
||||
waddstr(radar, str);
|
||||
}
|
||||
|
||||
|
||||
overwrite(radar, cleanradar);
|
||||
wrefresh(radar);
|
||||
wrefresh(credit);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
draw_line(w, x, y, lx, ly, s)
|
||||
WINDOW *w;
|
||||
char *s;
|
||||
{
|
||||
int dx, dy;
|
||||
|
||||
dx = SGN(lx - x);
|
||||
dy = SGN(ly - y);
|
||||
for (;;) {
|
||||
wmove(w, y, x * 2);
|
||||
waddstr(w, s);
|
||||
if (x == lx && y == ly)
|
||||
break;
|
||||
x += dx;
|
||||
y += dy;
|
||||
}
|
||||
}
|
||||
|
||||
ioclrtoeol(pos)
|
||||
void ioclrtoeol(pos)
|
||||
{
|
||||
wmove(input, 0, pos);
|
||||
wclrtoeol(input);
|
||||
@@ -197,14 +197,14 @@ ioclrtoeol(pos)
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
iomove(pos)
|
||||
void iomove(pos)
|
||||
{
|
||||
wmove(input, 0, pos);
|
||||
wrefresh(input);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
ioaddstr(pos, str)
|
||||
void ioaddstr(pos, str)
|
||||
char *str;
|
||||
{
|
||||
wmove(input, 0, pos);
|
||||
@@ -213,14 +213,14 @@ ioaddstr(pos, str)
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
ioclrtobot()
|
||||
void ioclrtobot()
|
||||
{
|
||||
wclrtobot(input);
|
||||
wrefresh(input);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
ioerror(pos, len, str)
|
||||
void ioerror(pos, len, str)
|
||||
char *str;
|
||||
{
|
||||
int i;
|
||||
@@ -234,7 +234,7 @@ ioerror(pos, len, str)
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
quit()
|
||||
void quit(int sig)
|
||||
{
|
||||
int c, y, x;
|
||||
#ifdef BSD
|
||||
@@ -271,10 +271,9 @@ quit()
|
||||
wmove(input, y, x);
|
||||
wrefresh(input);
|
||||
fflush(stdout);
|
||||
return;
|
||||
}
|
||||
|
||||
planewin()
|
||||
void planewin()
|
||||
{
|
||||
PLANE *pp;
|
||||
char *command();
|
||||
@@ -289,7 +288,7 @@ planewin()
|
||||
#ifdef SYSV
|
||||
wclrtobot(planes);
|
||||
#endif
|
||||
wprintw(planes, "Time: %-4d Safe: %d", clock, safe_planes);
|
||||
wprintw(planes, "Time: %-4d Safe: %d", clocktick, safe_planes);
|
||||
wmove(planes, 2, 0);
|
||||
|
||||
waddstr(planes, "pl dt comm");
|
||||
@@ -317,7 +316,7 @@ planewin()
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
loser(p, s)
|
||||
void loser(p, s)
|
||||
PLANE *p;
|
||||
char *s;
|
||||
{
|
||||
@@ -351,7 +350,7 @@ loser(p, s)
|
||||
exit(0);
|
||||
}
|
||||
|
||||
redraw()
|
||||
void redraw()
|
||||
{
|
||||
clear();
|
||||
refresh();
|
||||
@@ -370,7 +369,7 @@ redraw()
|
||||
}
|
||||
|
||||
|
||||
done_screen()
|
||||
void done_screen()
|
||||
{
|
||||
clear();
|
||||
refresh();
|
||||
|
||||
@@ -8,11 +8,20 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#ifdef SYSV
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/utsname.h>
|
||||
#ifdef SYSV
|
||||
#include <sys/ioctl.h>
|
||||
#endif
|
||||
#include <pwd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifdef BSD
|
||||
#include <sgtty.h>
|
||||
@@ -21,25 +30,17 @@
|
||||
#endif
|
||||
|
||||
#ifdef SYSV
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <termios.h>
|
||||
#endif
|
||||
|
||||
#include <signal.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <curses.h>
|
||||
|
||||
#ifdef SYSV
|
||||
#define index strchr
|
||||
#define rindex strrchr
|
||||
#define bcopy(a,b,c) memcpy((b), (a), (c))
|
||||
#define bzero(a,b) memset((a), '\0', (b))
|
||||
#define srandom srand
|
||||
#define random rand
|
||||
#define sgttyb termio
|
||||
#ifdef SYSV
|
||||
#define sgttyb termios
|
||||
#define sg_erase c_cc[2]
|
||||
#define sg_kill c_cc[3]
|
||||
#endif
|
||||
|
||||
@@ -6,11 +6,6 @@
|
||||
*
|
||||
* For more info on this and all of my stuff, mail edjames@berkeley.edu.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)input.c 1.2 (Berkeley) 10/22/87";
|
||||
#endif not lint
|
||||
|
||||
#include "include.h"
|
||||
|
||||
#define MAXRULES 6
|
||||
@@ -56,8 +51,8 @@ typedef struct {
|
||||
|
||||
#define NUMSTATES NUMELS(st)
|
||||
|
||||
char *setplane(), *circle(), *left(), *right(), *Left(), *Right(),
|
||||
*beacon(), *ex_it(), *climb(), *descend(), *setalt(), *setrelalt(),
|
||||
char *setplane(), *circle(), *left(), *right(), *Left(), *Right(),
|
||||
*beacon(), *ex_it(), *climb(), *descend(), *setalt(), *setrelalt(),
|
||||
*benum(), *to_dir(), *rel_dir(), *delayb(), *mark(), *unmark(),
|
||||
*airport(), *turn(), *ignore();
|
||||
|
||||
@@ -67,17 +62,17 @@ RULE state0[] = { { ALPHATOKEN, 1, "%c:", setplane},
|
||||
{ CRTOKEN, -1, "", NULL },
|
||||
#endif
|
||||
{ HELPTOKEN, 12, " [a-z]<ret>", NULL }},
|
||||
state1[] = { { 't', 2, " turn", turn },
|
||||
{ 'a', 3, " altitude:", NULL },
|
||||
state1[] = { { 't', 2, " turn", turn },
|
||||
{ 'a', 3, " altitude:", NULL },
|
||||
{ 'c', 4, " circle", circle },
|
||||
{ 'm', 7, " mark", mark },
|
||||
{ 'u', 7, " unmark", unmark },
|
||||
{ 'i', 7, " ignore", ignore },
|
||||
{ HELPTOKEN, 12, " tacmui", NULL }},
|
||||
state2[] = { { 'l', 6, " left", left },
|
||||
{ 'r', 6, " right", right },
|
||||
state2[] = { { 'l', 6, " left", left },
|
||||
{ 'r', 6, " right", right },
|
||||
{ 'L', 4, " left 90", Left },
|
||||
{ 'R', 4, " right 90", Right },
|
||||
{ 'R', 4, " right 90", Right },
|
||||
{ 't', 11, " towards", NULL },
|
||||
{ 'w', 4, " to 0", to_dir },
|
||||
{ 'e', 4, " to 45", to_dir },
|
||||
@@ -88,14 +83,14 @@ RULE state0[] = { { ALPHATOKEN, 1, "%c:", setplane},
|
||||
{ 'a', 4, " to 270", to_dir },
|
||||
{ 'q', 4, " to 315", to_dir },
|
||||
{ HELPTOKEN, 12, " lrLRt<dir>", NULL }},
|
||||
state3[] = { { '+', 10, " climb", climb },
|
||||
{ 'c', 10, " climb", climb },
|
||||
{ '-', 10, " descend", descend },
|
||||
{ 'd', 10, " descend", descend },
|
||||
state3[] = { { '+', 10, " climb", climb },
|
||||
{ 'c', 10, " climb", climb },
|
||||
{ '-', 10, " descend", descend },
|
||||
{ 'd', 10, " descend", descend },
|
||||
{ NUMTOKEN, 7, " %c000 feet", setalt },
|
||||
{ HELPTOKEN, 12, " +-cd[0-9]", NULL }},
|
||||
state4[] = { { '@', 9, " at", NULL },
|
||||
{ 'a', 9, " at", NULL },
|
||||
state4[] = { { '@', 9, " at", NULL },
|
||||
{ 'a', 9, " at", NULL },
|
||||
{ RETTOKEN, -1, "", NULL },
|
||||
#ifdef SYSV
|
||||
{ CRTOKEN, -1, "", NULL },
|
||||
@@ -113,9 +108,9 @@ RULE state0[] = { { ALPHATOKEN, 1, "%c:", setplane},
|
||||
{ 'z', 4, " 225", rel_dir },
|
||||
{ 'a', 4, " 270", rel_dir },
|
||||
{ 'q', 4, " 315", rel_dir },
|
||||
{ RETTOKEN, -1, "", NULL },
|
||||
{ RETTOKEN, -1, "", NULL },
|
||||
#ifdef SYSV
|
||||
{ CRTOKEN, -1, "", NULL },
|
||||
{ CRTOKEN, -1, "", NULL },
|
||||
#endif
|
||||
{ HELPTOKEN, 12, " @a<dir><ret>",NULL }},
|
||||
state7[] = { { RETTOKEN, -1, "", NULL },
|
||||
@@ -130,7 +125,7 @@ RULE state0[] = { { ALPHATOKEN, 1, "%c:", setplane},
|
||||
{ HELPTOKEN, 12, " b*", NULL }},
|
||||
state10[] = { { NUMTOKEN, 7, " %c000 ft", setrelalt},
|
||||
{ HELPTOKEN, 12, " [0-9]", NULL }},
|
||||
state11[] = { { 'b', 8, " beacon #", beacon },
|
||||
state11[] = { { 'b', 8, " beacon #", beacon },
|
||||
{ '*', 8, " beacon #", beacon },
|
||||
{ 'e', 8, " exit #", ex_it },
|
||||
{ 'a', 8, " airport #", airport },
|
||||
@@ -153,7 +148,7 @@ int level;
|
||||
int tval;
|
||||
int dest_type, dest_no, dir;
|
||||
|
||||
pop()
|
||||
int pop()
|
||||
{
|
||||
if (level == 0)
|
||||
return (-1);
|
||||
@@ -167,7 +162,7 @@ pop()
|
||||
return (0);
|
||||
}
|
||||
|
||||
rezero()
|
||||
void rezero()
|
||||
{
|
||||
iomove(0);
|
||||
|
||||
@@ -179,7 +174,7 @@ rezero()
|
||||
strcpy(T_STR, "");
|
||||
}
|
||||
|
||||
push(ruleno, ch)
|
||||
void push(ruleno, ch)
|
||||
{
|
||||
int newstate, newpos;
|
||||
|
||||
@@ -200,7 +195,77 @@ push(ruleno, ch)
|
||||
strcpy(T_STR, "");
|
||||
}
|
||||
|
||||
getcommand()
|
||||
int gettoken()
|
||||
{
|
||||
while ((tval = getAChar()) == REDRAWTOKEN || tval == SHELLTOKEN)
|
||||
{
|
||||
if (tval == SHELLTOKEN)
|
||||
{
|
||||
#ifdef BSD
|
||||
struct itimerval itv;
|
||||
itv.it_value.tv_sec = 0;
|
||||
itv.it_value.tv_usec = 0;
|
||||
setitimer(ITIMER_REAL, &itv, NULL);
|
||||
#endif
|
||||
#ifdef SYSV
|
||||
int aval;
|
||||
aval = alarm(0);
|
||||
#endif
|
||||
if (fork() == 0) /* child */
|
||||
{
|
||||
char *shell, *base, *getenv(), *strrchr();
|
||||
|
||||
setuid(getuid()); /* turn off setuid bit */
|
||||
done_screen();
|
||||
|
||||
/* run user's favorite shell */
|
||||
if ((shell = getenv("SHELL")) != NULL)
|
||||
{
|
||||
base = strrchr(shell, '/');
|
||||
if (base == NULL)
|
||||
base = shell;
|
||||
else
|
||||
base++;
|
||||
execl(shell, base, (char*)0);
|
||||
}
|
||||
else
|
||||
execl("/bin/sh", "sh", (char*)0);
|
||||
|
||||
exit(0); /* oops */
|
||||
}
|
||||
|
||||
wait(0);
|
||||
#ifdef BSD
|
||||
ioctl(fileno(stdin), TIOCSETP, &tty_new);
|
||||
itv.it_value.tv_sec = 0;
|
||||
itv.it_value.tv_usec = 1;
|
||||
itv.it_interval.tv_sec = sp->update_secs;
|
||||
itv.it_interval.tv_usec = 0;
|
||||
setitimer(ITIMER_REAL, &itv, NULL);
|
||||
#endif
|
||||
#ifdef SYSV
|
||||
ioctl(fileno(stdin), TCSETAW, &tty_new);
|
||||
alarm(aval);
|
||||
#endif
|
||||
}
|
||||
redraw();
|
||||
}
|
||||
|
||||
if (isdigit(tval))
|
||||
return (NUMTOKEN);
|
||||
else if (isalpha(tval))
|
||||
return (ALPHATOKEN);
|
||||
else
|
||||
return (tval);
|
||||
}
|
||||
|
||||
void noise()
|
||||
{
|
||||
putchar('\07');
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
int getcommand()
|
||||
{
|
||||
int c, i, done;
|
||||
char *s, *(*func)();
|
||||
@@ -235,7 +300,7 @@ getcommand()
|
||||
return (1); /* forced update */
|
||||
|
||||
dest_type = T_NODEST;
|
||||
|
||||
|
||||
for (i = 0; i < level; i++) {
|
||||
func = st[stack[i].state].rule[stack[i].rule].func;
|
||||
if (func != NULL)
|
||||
@@ -258,76 +323,6 @@ getcommand()
|
||||
return (0);
|
||||
}
|
||||
|
||||
noise()
|
||||
{
|
||||
putchar('\07');
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
gettoken()
|
||||
{
|
||||
while ((tval = getAChar()) == REDRAWTOKEN || tval == SHELLTOKEN)
|
||||
{
|
||||
if (tval == SHELLTOKEN)
|
||||
{
|
||||
#ifdef BSD
|
||||
struct itimerval itv;
|
||||
itv.it_value.tv_sec = 0;
|
||||
itv.it_value.tv_usec = 0;
|
||||
setitimer(ITIMER_REAL, &itv, NULL);
|
||||
#endif
|
||||
#ifdef SYSV
|
||||
int aval;
|
||||
aval = alarm(0);
|
||||
#endif
|
||||
if (fork() == 0) /* child */
|
||||
{
|
||||
char *shell, *base, *getenv(), *strrchr();
|
||||
|
||||
setuid(getuid()); /* turn off setuid bit */
|
||||
done_screen();
|
||||
|
||||
/* run user's favorite shell */
|
||||
if ((shell = getenv("SHELL")) != NULL)
|
||||
{
|
||||
base = strrchr(shell, '/');
|
||||
if (base == NULL)
|
||||
base = shell;
|
||||
else
|
||||
base++;
|
||||
execl(shell, base, 0);
|
||||
}
|
||||
else
|
||||
execl("/bin/sh", "sh", 0);
|
||||
|
||||
exit(0); /* oops */
|
||||
}
|
||||
|
||||
wait(0);
|
||||
#ifdef BSD
|
||||
ioctl(fileno(stdin), TIOCSETP, &tty_new);
|
||||
itv.it_value.tv_sec = 0;
|
||||
itv.it_value.tv_usec = 1;
|
||||
itv.it_interval.tv_sec = sp->update_secs;
|
||||
itv.it_interval.tv_usec = 0;
|
||||
setitimer(ITIMER_REAL, &itv, NULL);
|
||||
#endif
|
||||
#ifdef SYSV
|
||||
ioctl(fileno(stdin), TCSETAW, &tty_new);
|
||||
alarm(aval);
|
||||
#endif
|
||||
}
|
||||
redraw();
|
||||
}
|
||||
|
||||
if (isdigit(tval))
|
||||
return (NUMTOKEN);
|
||||
else if (isalpha(tval))
|
||||
return (ALPHATOKEN);
|
||||
else
|
||||
return (tval);
|
||||
}
|
||||
|
||||
char *
|
||||
setplane(c)
|
||||
{
|
||||
@@ -604,10 +599,9 @@ ignore(c)
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
dir_no(ch)
|
||||
char ch;
|
||||
int dir_no(ch)
|
||||
{
|
||||
int dir;
|
||||
int dir = 0;
|
||||
|
||||
switch (ch) {
|
||||
case 'w': dir = 0; break;
|
||||
|
||||
@@ -8,9 +8,13 @@
|
||||
* For more info on this and all of my stuff, mail edjames@berkeley.edu.
|
||||
*/
|
||||
|
||||
#define YY_NO_INPUT
|
||||
#define YY_SKIP_YYWRAP
|
||||
#include "y.tab.h"
|
||||
#define yywrap() 0
|
||||
extern int line;
|
||||
%}
|
||||
%option nounput
|
||||
%%
|
||||
[0-9]+ { yylval.ival = atoi(yytext); return(ConstOp); }
|
||||
height { return(HeightOp); }
|
||||
|
||||
@@ -15,7 +15,7 @@ newplane()
|
||||
return ((PLANE *) calloc(1, sizeof (PLANE)));
|
||||
}
|
||||
|
||||
append(l, p)
|
||||
void append(l, p)
|
||||
LIST *l;
|
||||
PLANE *p;
|
||||
{
|
||||
@@ -53,13 +53,13 @@ append(l, p)
|
||||
}
|
||||
}
|
||||
|
||||
delete(l, p)
|
||||
void delete(l, p)
|
||||
LIST *l;
|
||||
PLANE *p;
|
||||
{
|
||||
if (l->head == NULL)
|
||||
loser(p, "deleted a non-existant plane! Get help!");
|
||||
|
||||
|
||||
if (l->head == p && l->tail == p)
|
||||
l->head = l->tail = NULL;
|
||||
else if (l->head == p) {
|
||||
|
||||
@@ -6,14 +6,9 @@
|
||||
*
|
||||
* For more info on this and all of my stuff, mail edjames@berkeley.edu.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)log.c 1.4 (Berkeley) 12/26/87";
|
||||
#endif not lint
|
||||
|
||||
#include "include.h"
|
||||
|
||||
compar(a, b)
|
||||
int compar(a, b)
|
||||
SCORE *a, *b;
|
||||
{
|
||||
if (b->planes == a->planes)
|
||||
@@ -51,16 +46,14 @@ timestr(t)
|
||||
return (s);
|
||||
}
|
||||
|
||||
log_score(list_em)
|
||||
void log_score(list_em)
|
||||
{
|
||||
register int i, fd, num_scores = 0, good, changed = 0, found = 0;
|
||||
struct passwd *pw;
|
||||
FILE *fp;
|
||||
char *cp, logstr[BUFSIZ], *index(), *rindex();
|
||||
char *cp, logstr[BUFSIZ];
|
||||
SCORE score[100], thisscore;
|
||||
#ifdef SYSV
|
||||
struct utsname name;
|
||||
#endif
|
||||
|
||||
strcpy(logstr, SPECIAL_DIR);
|
||||
strcat(logstr, LOG);
|
||||
@@ -69,16 +62,16 @@ log_score(list_em)
|
||||
fd = open(logstr, O_CREAT|O_RDWR, 0644);
|
||||
if (fd < 0) {
|
||||
perror(logstr);
|
||||
return (-1);
|
||||
return;
|
||||
}
|
||||
/*
|
||||
* This is done to take advantage of stdio, while still
|
||||
* This is done to take advantage of stdio, while still
|
||||
* allowing a O_CREAT during the open(2) of the log file.
|
||||
*/
|
||||
fp = fdopen(fd, "r+");
|
||||
if (fp == NULL) {
|
||||
perror(logstr);
|
||||
return (-1);
|
||||
return;
|
||||
}
|
||||
#ifdef BSD
|
||||
if (flock(fileno(fp), LOCK_EX) < 0)
|
||||
@@ -88,14 +81,14 @@ log_score(list_em)
|
||||
#endif
|
||||
{
|
||||
perror("flock");
|
||||
return (-1);
|
||||
return;
|
||||
}
|
||||
for (;;) {
|
||||
good = fscanf(fp, "%s %s %s %d %d %d",
|
||||
score[num_scores].name,
|
||||
score[num_scores].host,
|
||||
score[num_scores].name,
|
||||
score[num_scores].host,
|
||||
score[num_scores].game,
|
||||
&score[num_scores].planes,
|
||||
&score[num_scores].planes,
|
||||
&score[num_scores].time,
|
||||
&score[num_scores].real_time);
|
||||
if (good != 6 || ++num_scores >= NUM_SCORES)
|
||||
@@ -103,32 +96,24 @@ log_score(list_em)
|
||||
}
|
||||
if (!test_mode && !list_em) {
|
||||
if ((pw = (struct passwd *) getpwuid(getuid())) == NULL) {
|
||||
fprintf(stderr,
|
||||
fprintf(stderr,
|
||||
"getpwuid failed for uid %d. Who are you?\n",
|
||||
getuid());
|
||||
return (-1);
|
||||
return;
|
||||
}
|
||||
strcpy(thisscore.name, pw->pw_name);
|
||||
#ifdef BSD
|
||||
if (gethostname(thisscore.host, sizeof (thisscore.host)) < 0) {
|
||||
perror("gethostname");
|
||||
return (-1);
|
||||
}
|
||||
#endif
|
||||
#ifdef SYSV
|
||||
uname(&name);
|
||||
strcpy(thisscore.host, name.sysname);
|
||||
#endif
|
||||
|
||||
cp = rindex(file, '/');
|
||||
cp = strrchr(file, '/');
|
||||
if (cp == NULL) {
|
||||
fprintf(stderr, "log: where's the '/' in %s?\n", file);
|
||||
return (-1);
|
||||
return;
|
||||
}
|
||||
cp++;
|
||||
strcpy(thisscore.game, cp);
|
||||
|
||||
thisscore.time = clock;
|
||||
thisscore.time = clocktick;
|
||||
thisscore.planes = safe_planes;
|
||||
thisscore.real_time = time(0) - start_time;
|
||||
|
||||
@@ -153,7 +138,7 @@ log_score(list_em)
|
||||
if (num_scores < NUM_SCORES)
|
||||
num_scores++;
|
||||
bcopy(&score[i],
|
||||
&score[num_scores - 1],
|
||||
&score[num_scores - 1],
|
||||
sizeof (score[i]));
|
||||
bcopy(&thisscore, &score[i],
|
||||
sizeof (score[i]));
|
||||
@@ -163,7 +148,7 @@ log_score(list_em)
|
||||
}
|
||||
}
|
||||
if (!found && !changed && num_scores < NUM_SCORES) {
|
||||
bcopy(&thisscore, &score[num_scores],
|
||||
bcopy(&thisscore, &score[num_scores],
|
||||
sizeof (score[num_scores]));
|
||||
num_scores++;
|
||||
changed++;
|
||||
@@ -178,7 +163,7 @@ log_score(list_em)
|
||||
rewind(fp);
|
||||
for (i = 0; i < num_scores; i++)
|
||||
fprintf(fp, "%s %s %s %d %d %d\n",
|
||||
score[i].name, score[i].host,
|
||||
score[i].name, score[i].host,
|
||||
score[i].game, score[i].planes,
|
||||
score[i].time, score[i].real_time);
|
||||
} else {
|
||||
@@ -196,11 +181,11 @@ log_score(list_em)
|
||||
/* lock will evaporate upon close */
|
||||
#endif
|
||||
fclose(fp);
|
||||
printf("%2s: %-8s %-8s %-18s %4s %9s %4s\n", "#", "name", "host",
|
||||
printf("%2s: %-8s %-8s %-18s %4s %9s %4s\n", "#", "name", "host",
|
||||
"game", "time", "real time", "planes safe");
|
||||
puts("-------------------------------------------------------------------------------");
|
||||
for (i = 0; i < num_scores; i++) {
|
||||
cp = index(score[i].host, '.');
|
||||
cp = strchr(score[i].host, '.');
|
||||
if (cp != NULL)
|
||||
*cp = '\0';
|
||||
printf("%2d: %-8s %-8s %-18s %4d %9s %4d\n", i + 1,
|
||||
@@ -209,5 +194,4 @@ log_score(list_em)
|
||||
score[i].planes);
|
||||
}
|
||||
putchar('\n');
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -9,169 +9,7 @@
|
||||
|
||||
#include "include.h"
|
||||
|
||||
main(ac, av)
|
||||
char *av[];
|
||||
{
|
||||
int seed;
|
||||
int f_usage = 0, f_list = 0, f_showscore = 0;
|
||||
int f_printpath = 0;
|
||||
char *file = NULL;
|
||||
char *name, *ptr;
|
||||
#ifdef BSD
|
||||
struct itimerval itv;
|
||||
#endif
|
||||
extern int update(), quit(), log_score();
|
||||
extern char *default_game(), *okay_game();
|
||||
|
||||
start_time = seed = time(0);
|
||||
|
||||
name = *av++;
|
||||
while (*av) {
|
||||
#ifndef SAVEDASH
|
||||
if (**av == '-')
|
||||
*++*av;
|
||||
else
|
||||
break;
|
||||
#endif
|
||||
ptr = *av++;
|
||||
while (*ptr) {
|
||||
switch (*ptr) {
|
||||
case '?':
|
||||
case 'u':
|
||||
f_usage++;
|
||||
break;
|
||||
case 'l':
|
||||
f_list++;
|
||||
break;
|
||||
case 's':
|
||||
case 't':
|
||||
f_showscore++;
|
||||
break;
|
||||
case 'p':
|
||||
f_printpath++;
|
||||
break;
|
||||
case 'r':
|
||||
seed = atoi(*av);
|
||||
av++;
|
||||
break;
|
||||
case 'f':
|
||||
case 'g':
|
||||
file = *av;
|
||||
av++;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Unknown option '%c'\n", *ptr,
|
||||
name);
|
||||
f_usage++;
|
||||
break;
|
||||
}
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
srandom(seed);
|
||||
|
||||
if (f_usage)
|
||||
fprintf(stderr,
|
||||
"Usage: %s -[u?lstp] [-[gf] game_name] [-r random seed]\n",
|
||||
name);
|
||||
if (f_showscore)
|
||||
log_score(1);
|
||||
if (f_list)
|
||||
list_games();
|
||||
if (f_printpath) {
|
||||
char buf[100];
|
||||
|
||||
strcpy(buf, SPECIAL_DIR);
|
||||
buf[strlen(buf) - 1] = '\0';
|
||||
puts(buf);
|
||||
}
|
||||
|
||||
if (f_usage || f_showscore || f_list || f_printpath)
|
||||
exit(0);
|
||||
|
||||
if (file == NULL)
|
||||
file = default_game();
|
||||
else
|
||||
file = okay_game(file);
|
||||
|
||||
if (file == NULL || read_file(file) < 0)
|
||||
exit(1);
|
||||
|
||||
init_gr();
|
||||
setup_screen(sp);
|
||||
|
||||
addplane();
|
||||
|
||||
signal(SIGINT, quit);
|
||||
signal(SIGQUIT, quit);
|
||||
#ifdef BSD
|
||||
signal(SIGTSTP, SIG_IGN);
|
||||
signal(SIGSTOP, SIG_IGN);
|
||||
#endif
|
||||
signal(SIGHUP, log_score);
|
||||
signal(SIGTERM, log_score);
|
||||
|
||||
#ifdef BSD
|
||||
ioctl(fileno(stdin), TIOCGETP, &tty_start);
|
||||
bcopy(&tty_start, &tty_new, sizeof(tty_new));
|
||||
tty_new.sg_flags |= CBREAK;
|
||||
tty_new.sg_flags &= ~ECHO;
|
||||
ioctl(fileno(stdin), TIOCSETP, &tty_new);
|
||||
#endif
|
||||
|
||||
#ifdef SYSV
|
||||
ioctl(fileno(stdin), TCGETA, &tty_start);
|
||||
bcopy(&tty_start, &tty_new, sizeof(tty_new));
|
||||
tty_new.c_lflag &= ~ICANON;
|
||||
tty_new.c_lflag &= ~ECHO;
|
||||
tty_new.c_cc[VMIN] = 1;
|
||||
tty_new.c_cc[VTIME] = 0;
|
||||
ioctl(fileno(stdin), TCSETAW, &tty_new);
|
||||
#endif
|
||||
|
||||
signal(SIGALRM, update);
|
||||
|
||||
#ifdef BSD
|
||||
itv.it_value.tv_sec = 0;
|
||||
itv.it_value.tv_usec = 1;
|
||||
itv.it_interval.tv_sec = sp->update_secs;
|
||||
itv.it_interval.tv_usec = 0;
|
||||
setitimer(ITIMER_REAL, &itv, NULL);
|
||||
#endif
|
||||
#ifdef SYSV
|
||||
alarm(sp->update_secs);
|
||||
#endif
|
||||
|
||||
for (;;) {
|
||||
if (getcommand() != 1)
|
||||
planewin();
|
||||
else {
|
||||
#ifdef BSD
|
||||
itv.it_value.tv_sec = 0;
|
||||
itv.it_value.tv_usec = 0;
|
||||
setitimer(ITIMER_REAL, &itv, NULL);
|
||||
#endif
|
||||
#ifdef SYSV
|
||||
alarm(0);
|
||||
#endif
|
||||
|
||||
update();
|
||||
|
||||
#ifdef BSD
|
||||
itv.it_value.tv_sec = sp->update_secs;
|
||||
itv.it_value.tv_usec = 0;
|
||||
itv.it_interval.tv_sec = sp->update_secs;
|
||||
itv.it_interval.tv_usec = 0;
|
||||
setitimer(ITIMER_REAL, &itv, NULL);
|
||||
#endif
|
||||
#ifdef SYSV
|
||||
alarm(sp->update_secs);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
read_file(s)
|
||||
int read_file(s)
|
||||
char *s;
|
||||
{
|
||||
extern FILE *yyin;
|
||||
@@ -252,7 +90,7 @@ okay_game(s)
|
||||
return (ret);
|
||||
}
|
||||
|
||||
list_games()
|
||||
int list_games()
|
||||
{
|
||||
FILE *fp;
|
||||
char line[256], games[256];
|
||||
@@ -277,3 +115,162 @@ list_games()
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int main(ac, av)
|
||||
char *av[];
|
||||
{
|
||||
int seed;
|
||||
int f_usage = 0, f_list = 0, f_showscore = 0;
|
||||
int f_printpath = 0;
|
||||
char *file = NULL;
|
||||
char *name, *ptr;
|
||||
#ifdef BSD
|
||||
struct itimerval itv;
|
||||
#endif
|
||||
|
||||
start_time = seed = time(0);
|
||||
|
||||
name = *av++;
|
||||
while (*av) {
|
||||
#ifndef SAVEDASH
|
||||
if (**av == '-')
|
||||
(*av)++;
|
||||
else
|
||||
break;
|
||||
#endif
|
||||
ptr = *av++;
|
||||
while (*ptr) {
|
||||
switch (*ptr) {
|
||||
case '?':
|
||||
case 'u':
|
||||
f_usage++;
|
||||
break;
|
||||
case 'l':
|
||||
f_list++;
|
||||
break;
|
||||
case 's':
|
||||
case 't':
|
||||
f_showscore++;
|
||||
break;
|
||||
case 'p':
|
||||
f_printpath++;
|
||||
break;
|
||||
case 'r':
|
||||
seed = atoi(*av);
|
||||
av++;
|
||||
break;
|
||||
case 'f':
|
||||
case 'g':
|
||||
file = *av;
|
||||
av++;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Unknown option '%c'\n", *ptr);
|
||||
f_usage++;
|
||||
break;
|
||||
}
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
srandom(seed);
|
||||
|
||||
if (f_usage)
|
||||
fprintf(stderr,
|
||||
"Usage: %s -[u?lstp] [-[gf] game_name] [-r random seed]\n",
|
||||
name);
|
||||
if (f_showscore)
|
||||
log_score(1);
|
||||
if (f_list)
|
||||
list_games();
|
||||
if (f_printpath) {
|
||||
char buf[100];
|
||||
|
||||
strcpy(buf, SPECIAL_DIR);
|
||||
buf[strlen(buf) - 1] = '\0';
|
||||
puts(buf);
|
||||
}
|
||||
|
||||
if (f_usage || f_showscore || f_list || f_printpath)
|
||||
exit(0);
|
||||
|
||||
if (file == NULL)
|
||||
file = default_game();
|
||||
else
|
||||
file = okay_game(file);
|
||||
|
||||
if (file == NULL || read_file(file) < 0)
|
||||
exit(1);
|
||||
|
||||
init_gr();
|
||||
setup_screen(sp);
|
||||
|
||||
addplane();
|
||||
|
||||
signal(SIGINT, quit);
|
||||
signal(SIGQUIT, quit);
|
||||
#ifdef BSD
|
||||
signal(SIGTSTP, SIG_IGN);
|
||||
signal(SIGSTOP, SIG_IGN);
|
||||
#endif
|
||||
signal(SIGHUP, log_score);
|
||||
signal(SIGTERM, log_score);
|
||||
|
||||
#ifdef BSD
|
||||
ioctl(fileno(stdin), TIOCGETP, &tty_start);
|
||||
bcopy(&tty_start, &tty_new, sizeof(tty_new));
|
||||
tty_new.sg_flags |= CBREAK;
|
||||
tty_new.sg_flags &= ~ECHO;
|
||||
ioctl(fileno(stdin), TIOCSETP, &tty_new);
|
||||
#endif
|
||||
|
||||
#ifdef SYSV
|
||||
ioctl(fileno(stdin), TCGETA, &tty_start);
|
||||
bcopy(&tty_start, &tty_new, sizeof(tty_new));
|
||||
tty_new.c_lflag &= ~ICANON;
|
||||
tty_new.c_lflag &= ~ECHO;
|
||||
tty_new.c_cc[VMIN] = 1;
|
||||
tty_new.c_cc[VTIME] = 0;
|
||||
ioctl(fileno(stdin), TCSETAW, &tty_new);
|
||||
#endif
|
||||
|
||||
signal(SIGALRM, update);
|
||||
|
||||
#ifdef BSD
|
||||
itv.it_value.tv_sec = 0;
|
||||
itv.it_value.tv_usec = 1;
|
||||
itv.it_interval.tv_sec = sp->update_secs;
|
||||
itv.it_interval.tv_usec = 0;
|
||||
setitimer(ITIMER_REAL, &itv, NULL);
|
||||
#endif
|
||||
#ifdef SYSV
|
||||
alarm(sp->update_secs);
|
||||
#endif
|
||||
|
||||
for (;;) {
|
||||
if (getcommand() != 1)
|
||||
planewin();
|
||||
else {
|
||||
#ifdef BSD
|
||||
itv.it_value.tv_sec = 0;
|
||||
itv.it_value.tv_usec = 0;
|
||||
setitimer(ITIMER_REAL, &itv, NULL);
|
||||
#endif
|
||||
#ifdef SYSV
|
||||
alarm(0);
|
||||
#endif
|
||||
|
||||
update(0);
|
||||
|
||||
#ifdef BSD
|
||||
itv.it_value.tv_sec = sp->update_secs;
|
||||
itv.it_value.tv_usec = 0;
|
||||
itv.it_interval.tv_sec = sp->update_secs;
|
||||
itv.it_interval.tv_usec = 0;
|
||||
setitimer(ITIMER_REAL, &itv, NULL);
|
||||
#endif
|
||||
#ifdef SYSV
|
||||
alarm(sp->update_secs);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,24 +6,29 @@
|
||||
*
|
||||
* For more info on this and all of my stuff, mail edjames@berkeley.edu.
|
||||
*/
|
||||
|
||||
#if !defined(lint) && defined(DOSCCS)
|
||||
static char sccsid[] = "@(#)update.c 1.3.1 (2.11BSD) 1999/10/25";
|
||||
#endif
|
||||
|
||||
#include "include.h"
|
||||
|
||||
update()
|
||||
int too_close(p1, p2, dist)
|
||||
PLANE *p1, *p2;
|
||||
{
|
||||
if (ABS(p1->altitude - p2->altitude) <= dist &&
|
||||
ABS(p1->xpos - p2->xpos) <= dist && ABS(p1->ypos - p2->ypos) <= dist)
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
|
||||
void update(int sig)
|
||||
{
|
||||
int i, dir_diff, unclean;
|
||||
PLANE *pp, *p1, *p2, *p;
|
||||
PLANE *pp, *p1, *p2;
|
||||
sigset_t set, oset;
|
||||
|
||||
sigemptyset(&set);
|
||||
sigaddset(&set, SIGINT);
|
||||
(void)sigprocmask(SIG_BLOCK, &set, &oset);
|
||||
|
||||
clock++;
|
||||
clocktick++;
|
||||
erase_all();
|
||||
|
||||
/* put some planes in the air */
|
||||
@@ -42,7 +47,7 @@ update()
|
||||
/* do altitude change and basic movement */
|
||||
for (pp = air.head; pp != NULL; pp = pp->next) {
|
||||
/* type 0 only move every other turn */
|
||||
if (pp->plane_type == 0 && clock & 1)
|
||||
if (pp->plane_type == 0 && clocktick & 1)
|
||||
continue;
|
||||
|
||||
pp->fuel--;
|
||||
@@ -117,10 +122,10 @@ update()
|
||||
if (pp->xpos == sp->airport[i].x &&
|
||||
pp->ypos == sp->airport[i].y) {
|
||||
if (pp->dest_type == T_AIRPORT)
|
||||
loser(pp,
|
||||
loser(pp,
|
||||
"landed at the wrong airport.");
|
||||
else
|
||||
loser(pp,
|
||||
loser(pp,
|
||||
"landed instead of exited.");
|
||||
}
|
||||
loser(pp, "crashed on the ground.");
|
||||
@@ -131,10 +136,10 @@ update()
|
||||
if (pp->xpos == sp->exit[i].x &&
|
||||
pp->ypos == sp->exit[i].y) {
|
||||
if (pp->dest_type == T_EXIT)
|
||||
loser(pp,
|
||||
loser(pp,
|
||||
"exited via the wrong exit.");
|
||||
else
|
||||
loser(pp,
|
||||
loser(pp,
|
||||
"exited instead of landed.");
|
||||
}
|
||||
loser(pp, "illegally left the flight arena.");
|
||||
@@ -174,20 +179,35 @@ update()
|
||||
(void)sigprocmask(SIG_SETMASK, &oset, NULL);
|
||||
}
|
||||
|
||||
int dir_deg(d)
|
||||
{
|
||||
switch (d) {
|
||||
case 0: return (0);
|
||||
case 1: return (45);
|
||||
case 2: return (90);
|
||||
case 3: return (135);
|
||||
case 4: return (180);
|
||||
case 5: return (225);
|
||||
case 6: return (270);
|
||||
case 7: return (315);
|
||||
default:
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
char *
|
||||
command(pp)
|
||||
PLANE *pp;
|
||||
{
|
||||
static char buf[50], *bp, *comm_start;
|
||||
char *index();
|
||||
|
||||
buf[0] = '\0';
|
||||
bp = buf;
|
||||
(void)sprintf(bp, "%c%d%c%c%d: ", name(pp), pp->altitude,
|
||||
(void)sprintf(bp, "%c%d%c%c%d: ", name(pp), pp->altitude,
|
||||
(pp->fuel < LOWFUEL) ? '*' : ' ',
|
||||
(pp->dest_type == T_AIRPORT) ? 'A' : 'E', pp->dest_no);
|
||||
|
||||
comm_start = bp = index(buf, '\0');
|
||||
comm_start = bp = strchr(buf, '\0');
|
||||
if (pp->altitude == 0)
|
||||
(void)sprintf(bp, "Holding @ A%d", pp->orig_no);
|
||||
else if (pp->new_dir >= MAXDIR || pp->new_dir < 0)
|
||||
@@ -195,19 +215,19 @@ command(pp)
|
||||
else if (pp->new_dir != pp->dir)
|
||||
(void)sprintf(bp, "%d", dir_deg(pp->new_dir));
|
||||
|
||||
bp = index(buf, '\0');
|
||||
bp = strchr(buf, '\0');
|
||||
if (pp->delayd)
|
||||
(void)sprintf(bp, " @ B%d", pp->delayd_no);
|
||||
|
||||
bp = index(buf, '\0');
|
||||
if (*comm_start == '\0' &&
|
||||
bp = strchr(buf, '\0');
|
||||
if (*comm_start == '\0' &&
|
||||
(pp->status == S_UNMARKED || pp->status == S_IGNORED))
|
||||
strcpy(bp, "---------");
|
||||
return (buf);
|
||||
}
|
||||
|
||||
/* char */
|
||||
name(p)
|
||||
int name(p)
|
||||
PLANE *p;
|
||||
{
|
||||
if (p->plane_type == 0)
|
||||
@@ -216,17 +236,17 @@ name(p)
|
||||
return ('a' + p->plane_no);
|
||||
}
|
||||
|
||||
number(l)
|
||||
int number(l)
|
||||
{
|
||||
if (l < 'a' && l > 'z' && l < 'A' && l > 'Z')
|
||||
return (-1);
|
||||
else if (l >= 'a' && l <= 'z')
|
||||
return (l - 'a');
|
||||
else
|
||||
else
|
||||
return (l - 'A');
|
||||
}
|
||||
|
||||
next_plane()
|
||||
int next_plane()
|
||||
{
|
||||
static int last_plane = -1;
|
||||
PLANE *pp;
|
||||
@@ -254,7 +274,7 @@ next_plane()
|
||||
return (last_plane);
|
||||
}
|
||||
|
||||
addplane()
|
||||
int addplane()
|
||||
{
|
||||
PLANE p, *pp, *p1;
|
||||
int i, num_starts, close, rnd, rnd2, pnum;
|
||||
@@ -337,29 +357,3 @@ findplane(n)
|
||||
return (pp);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
too_close(p1, p2, dist)
|
||||
PLANE *p1, *p2;
|
||||
{
|
||||
if (ABS(p1->altitude - p2->altitude) <= dist &&
|
||||
ABS(p1->xpos - p2->xpos) <= dist && ABS(p1->ypos - p2->ypos) <= dist)
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
|
||||
dir_deg(d)
|
||||
{
|
||||
switch (d) {
|
||||
case 0: return (0);
|
||||
case 1: return (45);
|
||||
case 2: return (90);
|
||||
case 3: return (135);
|
||||
case 4: return (180);
|
||||
case 5: return (225);
|
||||
case 6: return (270);
|
||||
case 7: return (315);
|
||||
default:
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
3
src/games/boggle/.gitignore
vendored
Normal file
3
src/games/boggle/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
bogdict
|
||||
boggle
|
||||
comp
|
||||
@@ -5,28 +5,36 @@
|
||||
#
|
||||
# @(#)Makefile 5.3 (Berkeley) 9/7/85
|
||||
#
|
||||
DESTDIR=
|
||||
CC = /bin/cc
|
||||
SEPFLAG= -i
|
||||
CFLAGS = -O
|
||||
TOPSRC = $(shell cd ../../..; pwd)
|
||||
include $(TOPSRC)/target.mk
|
||||
#include $(TOPSRC)/cross.mk
|
||||
|
||||
all: boggle bogdict
|
||||
CFLAGS += -O
|
||||
OBJS = boggle.o
|
||||
MAN = boggle.0
|
||||
MANSRC = boggle.6
|
||||
|
||||
bogdict: comp sfile
|
||||
-if [ -f /usr/local/lib/w2a ]; \
|
||||
then dict=/usr/local/lib/w2a; \
|
||||
else dict=/usr/dict/words; fi; \
|
||||
sed -f sfile $$dict | uniq | ./comp >bogdict
|
||||
all: boggle bogdict ${MAN}
|
||||
|
||||
install: all
|
||||
install -s boggle ${DESTDIR}/usr/games/boggle
|
||||
install -m 644 bogdict ${DESTDIR}/usr/games/lib/bogdict
|
||||
boggle: ${OBJS}
|
||||
$(CC) $(LDFLAGS) -o $@.elf $(OBJS) $(LIBS)
|
||||
$(OBJDUMP) -S $@.elf > $@.dis
|
||||
$(SIZE) $@.elf
|
||||
$(ELF2AOUT) $@.elf $@ && rm $@.elf
|
||||
|
||||
boggle: boggle.c
|
||||
cc ${SEPFLAG} -o boggle ${CFLAGS} boggle.c
|
||||
bogdict: comp sfile
|
||||
sed -f sfile ../../../share/dict/words | uniq | ./comp > bogdict
|
||||
|
||||
comp: comp.c
|
||||
cc ${SEPFLAG} -o comp ${CFLAGS} comp.c
|
||||
comp: comp.c
|
||||
cc -O comp.c -o comp
|
||||
|
||||
${MAN}: ${MANSRC}
|
||||
${MANROFF} $< > $@
|
||||
|
||||
clean:
|
||||
rm -f bogdict boggle comp *.o
|
||||
rm -f *.o core boggle comp bogdict
|
||||
|
||||
install:
|
||||
install boggle $(DESTDIR)/games/
|
||||
install -m 644 bogdict $(DESTDIR)/games/lib/bogdict
|
||||
cp ${MAN} $(DESTDIR)/share/man/cat6/
|
||||
|
||||
@@ -3,15 +3,6 @@
|
||||
* All rights reserved. The Berkeley software License Agreement
|
||||
* specifies the terms and conditions for redistribution.
|
||||
*/
|
||||
|
||||
#if !defined(lint) && defined(DOSCCS)
|
||||
char copyright[] =
|
||||
"@(#) Copyright (c) 1980 Regents of the University of California.\n\
|
||||
All rights reserved.\n";
|
||||
|
||||
static char sccsid[] = "@(#)boggle.c 5.1.1 (2.11BSD) 1997/10/2";
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <setjmp.h>
|
||||
@@ -19,7 +10,11 @@ static char sccsid[] = "@(#)boggle.c 5.1.1 (2.11BSD) 1997/10/2";
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
/* basic parameters */
|
||||
#define N 4
|
||||
@@ -62,7 +57,7 @@ long logloc;
|
||||
char logbuff[100] = {"inst\t"};
|
||||
|
||||
/* dictionary interface */
|
||||
char defname[] = "/usr/games/lib/bogdict";
|
||||
char defname[] = "/games/lib/bogdict";
|
||||
char *dictname = &defname[0];
|
||||
FILE *dict;
|
||||
|
||||
@@ -89,14 +84,13 @@ char *cube [BSIZE] = {
|
||||
"anedvz", "pinesh", "abilyt", "gkyleu"
|
||||
};
|
||||
|
||||
|
||||
/* storage for words found */
|
||||
int ubotch, ustart, wcount;
|
||||
char *word [MAXWORDS];
|
||||
char *freesp;
|
||||
char space[10000];
|
||||
|
||||
endline ()
|
||||
void endline ()
|
||||
{
|
||||
if (column != 0) {
|
||||
putchar('\n');
|
||||
@@ -104,7 +98,7 @@ endline ()
|
||||
}
|
||||
}
|
||||
|
||||
timeout ()
|
||||
void timeout ()
|
||||
{
|
||||
if (*timept > 0) {
|
||||
signal (SIGALRM, timeout);
|
||||
@@ -113,7 +107,7 @@ timeout ()
|
||||
putchar('\007');
|
||||
}
|
||||
|
||||
interrupt ()
|
||||
void interrupt ()
|
||||
{
|
||||
signal(SIGINT, interrupt);
|
||||
if (delct++ >= 1)
|
||||
@@ -121,7 +115,7 @@ interrupt ()
|
||||
timept = &zero;
|
||||
}
|
||||
|
||||
goodbye (stat)
|
||||
void goodbye (stat)
|
||||
int stat;
|
||||
{
|
||||
if (master != 0) {
|
||||
@@ -134,19 +128,13 @@ int stat;
|
||||
exit(stat);
|
||||
}
|
||||
|
||||
clearscreen ()
|
||||
void clearscreen ()
|
||||
{
|
||||
stty (fileno(stdin), &tempttyb);
|
||||
printf("\n\f\r");
|
||||
}
|
||||
|
||||
compare (a, b)
|
||||
char **a, **b;
|
||||
{
|
||||
return(wordcomp(*a, *b));
|
||||
}
|
||||
|
||||
wordcomp (p, q)
|
||||
int wordcomp (p, q)
|
||||
register char *p, *q;
|
||||
{
|
||||
if (*p=='0' && *q!='0')
|
||||
@@ -161,7 +149,13 @@ register char *p, *q;
|
||||
return(*p-*q);
|
||||
}
|
||||
|
||||
printinst ()
|
||||
int compare (a, b)
|
||||
char **a, **b;
|
||||
{
|
||||
return(wordcomp(*a, *b));
|
||||
}
|
||||
|
||||
void printinst ()
|
||||
{
|
||||
stty (fileno(stdin), &tempttyb);
|
||||
printf("instructions?");
|
||||
@@ -177,10 +171,10 @@ printinst ()
|
||||
printf(" This program is intended for people wishing to sharpen their\n");
|
||||
printf("skills at Boggle. If you invoke the program with 4 arguments of 4\n");
|
||||
printf("letters each, (e.g. \"boggle appl epie moth erhd\") the program forms the\n");
|
||||
printf("obvious Boggle grid and lists all the words from /usr/dict/words found\n");
|
||||
printf("obvious Boggle grid and lists all the words from /share/dict/words found\n");
|
||||
printf("therein. If you invoke the program without arguments, it will generate\n");
|
||||
printf("a board for you, let you enter words for 3 minutes, and then tell you\n");
|
||||
printf("how well you did relative to /usr/dict/words.\n");
|
||||
printf("how well you did relative to /share/dict/words.\n");
|
||||
printf(" In interactive play, enter your words separated by spaces, tabs,\n");
|
||||
printf("or newlines. A bell will ring when there is 2:00, 1:00, 0:10, 0:02,\n");
|
||||
printf("0:01, and 0:00 time left. You may complete any word started before the\n");
|
||||
@@ -198,7 +192,7 @@ printinst ()
|
||||
stty (fileno(stdin), &tempttyb);
|
||||
}
|
||||
|
||||
setup ()
|
||||
void setup ()
|
||||
{
|
||||
register int i, j;
|
||||
int rd, cd, k;
|
||||
@@ -229,7 +223,7 @@ setup ()
|
||||
level[1] = &stack[1];
|
||||
}
|
||||
|
||||
makelists ()
|
||||
void makelists ()
|
||||
{
|
||||
register int i, c;
|
||||
for (i=0; i<26; i++)
|
||||
@@ -241,7 +235,7 @@ makelists ()
|
||||
}
|
||||
}
|
||||
|
||||
genboard ()
|
||||
void genboard ()
|
||||
{
|
||||
register int i, j;
|
||||
for (i=0; i<BSIZE; i++)
|
||||
@@ -254,7 +248,7 @@ genboard ()
|
||||
}
|
||||
}
|
||||
|
||||
printboard ()
|
||||
void printboard ()
|
||||
{
|
||||
register int i, j;
|
||||
for (i=0; i<N; i++) {
|
||||
@@ -268,7 +262,7 @@ printboard ()
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
getdword ()
|
||||
int getdword ()
|
||||
{
|
||||
/* input: numsame = # chars same as last word */
|
||||
/* output: numsame = # same chars for next word */
|
||||
@@ -284,7 +278,7 @@ getdword ()
|
||||
return (1);
|
||||
}
|
||||
|
||||
getuword ()
|
||||
int getuword ()
|
||||
{
|
||||
int c;
|
||||
register char *p, *q, *r;
|
||||
@@ -316,13 +310,13 @@ getuword ()
|
||||
return(1);
|
||||
}
|
||||
|
||||
aputuword (ways)
|
||||
void aputuword (ways)
|
||||
int ways;
|
||||
{
|
||||
*word[wcount-1] = ways>=10 ? '*' : '0'+ways;
|
||||
}
|
||||
|
||||
aputword (ways)
|
||||
void aputword (ways)
|
||||
int ways;
|
||||
{
|
||||
/* store (wbuff, ways) in next slot in space */
|
||||
@@ -333,16 +327,7 @@ int ways;
|
||||
word[++wcount] = freesp;
|
||||
}
|
||||
|
||||
tputword (ways)
|
||||
int ways;
|
||||
{
|
||||
/* print (wbuff, ways) on terminal */
|
||||
wbuff[wlength+1] = '0';
|
||||
wbuff[0] = ways>=10 ? '*' : '0'+ways;
|
||||
outword(&wbuff[0]);
|
||||
}
|
||||
|
||||
outword (p)
|
||||
void outword (p)
|
||||
register char *p;
|
||||
{
|
||||
register int newcol;
|
||||
@@ -371,7 +356,16 @@ register char *p;
|
||||
}
|
||||
}
|
||||
|
||||
printdiff ()
|
||||
void tputword (ways)
|
||||
int ways;
|
||||
{
|
||||
/* print (wbuff, ways) on terminal */
|
||||
wbuff[wlength+1] = '0';
|
||||
wbuff[0] = ways>=10 ? '*' : '0'+ways;
|
||||
outword(&wbuff[0]);
|
||||
}
|
||||
|
||||
void printdiff ()
|
||||
{
|
||||
register int c, d, u;
|
||||
char both, donly, uonly;
|
||||
@@ -423,7 +417,7 @@ printdiff ()
|
||||
}
|
||||
}
|
||||
|
||||
numways (leaf, last)
|
||||
int numways (leaf, last)
|
||||
register struct frame *leaf;
|
||||
struct frame *last;
|
||||
{
|
||||
@@ -444,8 +438,9 @@ struct frame *last;
|
||||
return(count);
|
||||
}
|
||||
|
||||
evalboard (getword, putword)
|
||||
int (*getword)(), (*putword)();
|
||||
int evalboard (getword, putword)
|
||||
int (*getword)();
|
||||
void (*putword)();
|
||||
{
|
||||
register struct frame *top;
|
||||
register int l, q;
|
||||
@@ -461,7 +456,7 @@ int (*getword)(), (*putword)();
|
||||
if (!(*getword) ())
|
||||
break;
|
||||
top = level[l+1];
|
||||
|
||||
|
||||
while (1) {
|
||||
level[l+1] = lastparent = top;
|
||||
/* wbuff[1]...wbuff[l] have been matched */
|
||||
@@ -501,7 +496,7 @@ int (*getword)(), (*putword)();
|
||||
return(found);
|
||||
}
|
||||
|
||||
main (argc, argv)
|
||||
int main (argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
@@ -516,13 +511,13 @@ char **argv;
|
||||
goodbye(0);
|
||||
signal (SIGINT, interrupt);
|
||||
timein = time(0L);
|
||||
if (argv[0][0] != 'a' && (logfile = open("/usr/games/lib/boglog", 1)) >= 0) {
|
||||
if (argv[0][0] != 'a' && (logfile = open("/games/lib/boglog", 1)) >= 0) {
|
||||
p = &logbuff[5];
|
||||
q = getlogin();
|
||||
while (*p++ = *q++);
|
||||
while ((*p++ = *q++));
|
||||
p[-1] = '\t';
|
||||
q = ctime(&timein);
|
||||
while (*p++ = *q++);
|
||||
while ((*p++ = *q++));
|
||||
logloc = lseek(logfile, 0L, 2);
|
||||
write(logfile, &logbuff[0], p-&logbuff[1]);
|
||||
}
|
||||
@@ -612,11 +607,12 @@ char **argv;
|
||||
evalboard(getdword, aputword);
|
||||
p = freesp;
|
||||
while ((i = read(pipefd[0], freesp, 512)) != 0) {
|
||||
if (i < 0)
|
||||
if (i < 0) {
|
||||
if (errno != EINTR)
|
||||
break;
|
||||
else
|
||||
i = 0;
|
||||
}
|
||||
freesp += i;
|
||||
}
|
||||
close(pipefd[0]);
|
||||
|
||||
@@ -3,35 +3,27 @@
|
||||
* All rights reserved. The Berkeley software License Agreement
|
||||
* specifies the terms and conditions for redistribution.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
char copyright[] =
|
||||
"@(#) Copyright (c) 1980 Regents of the University of California.\n\
|
||||
All rights reserved.\n";
|
||||
#endif not lint
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)comp.c 5.1 (Berkeley) 5/30/85";
|
||||
#endif not lint
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define MAX ' '
|
||||
|
||||
char new[MAX], old[MAX];
|
||||
|
||||
main ()
|
||||
int main ()
|
||||
{
|
||||
register int i, j;
|
||||
|
||||
old[0] = '\0';
|
||||
while (fgets(&new[0], MAX, stdin) != NULL) {
|
||||
for (i=0; i<MAX && old[i]==new[i]; i++);
|
||||
if (i >= MAX) {
|
||||
fprintf(stderr, "long word\n");
|
||||
exit(1);
|
||||
return 1;
|
||||
}
|
||||
putc(i, stdout);
|
||||
for (j=0; (old[j]=new[j]) != '\n'; j++);
|
||||
old[j] = '\0';
|
||||
fputs(&old[i], stdout);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
1
src/games/btlgammon/.gitignore
vendored
Normal file
1
src/games/btlgammon/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
btlgammon
|
||||
@@ -1,36 +1,23 @@
|
||||
# @(#)Makefile 4.2 (Berkeley) 9/7/85
|
||||
# @(#)Makefile 4.2 (Berkeley) 9/7/85
|
||||
#
|
||||
DESTDIR=
|
||||
CFLAGS= -O
|
||||
SEPFLAG= -i
|
||||
TOPSRC = $(shell cd ../../..; pwd)
|
||||
include $(TOPSRC)/target.mk
|
||||
#include $(TOPSRC)/cross.mk
|
||||
|
||||
btlgammon: btlgammon.c
|
||||
cc ${SEPFLAG} ${CFLAGS} -o btlgammon btlgammon.c
|
||||
CFLAGS = -O
|
||||
OBJS = btlgammon.o
|
||||
|
||||
install: btlgammon backrules
|
||||
install -s btlgammon ${DESTDIR}/usr/games/btlgammon
|
||||
install -c backrules ${DESTDIR}/usr/games/lib/backrules
|
||||
all: btlgammon
|
||||
|
||||
btlgammon: ${OBJS}
|
||||
$(CC) $(LDFLAGS) -o $@.elf $(OBJS) $(LIBS)
|
||||
$(OBJDUMP) -S $@.elf > $@.dis
|
||||
$(SIZE) $@.elf
|
||||
$(ELF2AOUT) $@.elf $@ && rm $@.elf
|
||||
|
||||
clean:
|
||||
rm -f a.out core *.s *.o btlgammon
|
||||
|
||||
depend:
|
||||
cat </dev/null >x.c
|
||||
for i in btlgammon; do \
|
||||
(echo $$i: $$i.c >>makedep; \
|
||||
/bin/grep '^#[ ]*include' x.c $$i.c | sed \
|
||||
-e 's,<\(.*\)>,"/usr/include/\1",' \
|
||||
-e 's/:[^"]*"\([^"]*\)".*/: \1/' \
|
||||
-e 's/\.c//' >>makedep); done
|
||||
echo '/^# DO NOT DELETE THIS LINE/+2,$$d' >eddep
|
||||
echo '$$r makedep' >>eddep
|
||||
echo 'w' >>eddep
|
||||
cp Makefile Makefile.bak
|
||||
ed - Makefile < eddep
|
||||
rm eddep makedep x.c
|
||||
echo '# DEPENDENCIES MUST END AT END OF FILE' >> Makefile
|
||||
echo '# IF YOU PUT STUFF HERE IT WILL GO AWAY' >> Makefile
|
||||
echo '# see make depend above' >> Makefile
|
||||
|
||||
# DO NOT DELETE THIS LINE -- make depend uses it
|
||||
rm -f *.o core btlgammon
|
||||
|
||||
install:
|
||||
install btlgammon $(DESTDIR)/games/
|
||||
install -m 644 backrules $(DESTDIR)/games/lib/backrules
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
1
src/games/cribbage/.gitignore
vendored
Normal file
1
src/games/cribbage/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
cribbage
|
||||
@@ -7,45 +7,36 @@
|
||||
#
|
||||
# make file for cribbage
|
||||
#
|
||||
HDRS= cribbage.h deck.h cribcur.h
|
||||
OBJS= extern.o crib.o support.o cards.o score.o io.o
|
||||
CFILES= extern.c crib.c support.c cards.c score.c io.c
|
||||
TOBJS= test.o cards.o score.o io.o extern.o
|
||||
MAN= crib.0
|
||||
SEPFLAG= -i
|
||||
CFLAGS= -O
|
||||
DESTDIR=
|
||||
TOPSRC = $(shell cd ../../..; pwd)
|
||||
include $(TOPSRC)/target.mk
|
||||
#include $(TOPSRC)/cross.mk
|
||||
#CFLAGS = -O -Werror -DCROSS
|
||||
|
||||
all: cribbage ${MAN}
|
||||
OBJS = extern.o crib.o support.o cards.o score.o io.o
|
||||
TOBJS = test.o cards.o score.o io.o extern.o
|
||||
MAN = cribbage.0
|
||||
MANSRC = cribbage.6
|
||||
LIBS = -lcurses -ltermcap -lc
|
||||
|
||||
cribbage: ${OBJS}
|
||||
${CC} ${SEPFLAG} ${CFLAGS} -o cribbage ${OBJS} -lcurses -ltermlib
|
||||
all: cribbage ${MAN} crib.0
|
||||
|
||||
all: cribbage ${MAN}
|
||||
cribbage: ${OBJS}
|
||||
$(CC) $(LDFLAGS) -o $@.elf $(OBJS) $(LIBS)
|
||||
$(OBJDUMP) -S $@.elf > $@.dis
|
||||
$(SIZE) $@.elf
|
||||
$(ELF2AOUT) $@.elf $@ && rm $@.elf
|
||||
|
||||
crib.o io.o support.o: cribcur.h
|
||||
crib.0: cribbage.n macro
|
||||
nroff cribbage.n > $@
|
||||
|
||||
test: ${TOBJS}
|
||||
${CC} ${SEPFLAG} ${CFLAGS} -o test ${TOBJS} -lcurses -ltermlib
|
||||
|
||||
crib.0: cribbage.n macro
|
||||
nroff cribbage.n > crib.0
|
||||
|
||||
tags: ${HDRS} ${CFILES}
|
||||
ctags -u $?
|
||||
ed - tags < :ctfix
|
||||
sort tags -o tags
|
||||
${MAN}: ${MANSRC}
|
||||
${MANROFF} $< > $@
|
||||
|
||||
clean:
|
||||
rm -f ${OBJS} ? a.out core crib.0 cribbage errs
|
||||
rm -f *.o core cribbage ${MAN} *.dis
|
||||
|
||||
crib.o: deck.h cribbage.h cribcur.h
|
||||
support.o: deck.h cribbage.h cribcur.h
|
||||
test.o: deck.h
|
||||
cards.o: deck.h
|
||||
score.o: deck.h
|
||||
io.o: deck.h cribcur.h
|
||||
|
||||
install: cribbage crib.0
|
||||
install -s cribbage $(DESTDIR)/usr/games
|
||||
install -m 644 crib.0 $(DESTDIR)/usr/games/lib/crib.instr
|
||||
install: all
|
||||
install cribbage $(DESTDIR)/games/
|
||||
install -m 644 crib.0 $(DESTDIR)/games/lib/crib.instr
|
||||
cp ${MAN} $(DESTDIR)/share/man/cat6/
|
||||
cp crib.0 $(DESTDIR)/share/man/cat6/
|
||||
|
||||
@@ -3,21 +3,14 @@
|
||||
* All rights reserved. The Berkeley software License Agreement
|
||||
* specifies the terms and conditions for redistribution.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)cards.c 5.1 (Berkeley) 5/30/85";
|
||||
#endif not lint
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "deck.h"
|
||||
|
||||
|
||||
/*
|
||||
* initialize a deck of cards to contain one of each type
|
||||
*/
|
||||
|
||||
makedeck( d )
|
||||
|
||||
void makedeck( d )
|
||||
CARD d[];
|
||||
{
|
||||
register int i, j, k;
|
||||
@@ -35,15 +28,11 @@ makedeck( d )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* given a deck of cards, shuffle it -- i.e. randomize it
|
||||
* see Knuth, vol. 2, page 125
|
||||
*/
|
||||
|
||||
shuffle( d )
|
||||
|
||||
void shuffle( d )
|
||||
CARD d[];
|
||||
{
|
||||
register int j, k;
|
||||
@@ -57,27 +46,19 @@ shuffle( d )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* return true if the two cards are equal...
|
||||
*/
|
||||
|
||||
eq( a, b )
|
||||
|
||||
int eq( a, b )
|
||||
CARD a, b;
|
||||
{
|
||||
return( ( a.rank == b.rank ) && ( a.suit == b.suit ) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* isone returns TRUE if a is in the set of cards b
|
||||
*/
|
||||
|
||||
isone( a, b, n )
|
||||
|
||||
BOOLEAN isone( a, b, n )
|
||||
CARD a, b[];
|
||||
int n;
|
||||
{
|
||||
@@ -89,16 +70,12 @@ isone( a, b, n )
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* remove the card a from the deck d of n cards
|
||||
*/
|
||||
|
||||
remove( a, d, n )
|
||||
|
||||
CARD a, d[];
|
||||
int n;
|
||||
void cremove( a, d, n )
|
||||
CARD a, d[];
|
||||
int n;
|
||||
{
|
||||
register int i, j;
|
||||
|
||||
@@ -109,15 +86,13 @@ remove( a, d, n )
|
||||
if( j < n ) d[j].suit = d[j].rank = EMPTY;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* sorthand:
|
||||
* Sort a hand of n cards
|
||||
*/
|
||||
sorthand(h, n)
|
||||
register CARD h[];
|
||||
int n;
|
||||
void sorthand(h, n)
|
||||
register CARD h[];
|
||||
int n;
|
||||
{
|
||||
register CARD *cp, *endp;
|
||||
CARD c;
|
||||
@@ -131,4 +106,3 @@ int n;
|
||||
*cp = c;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,120 +3,36 @@
|
||||
* All rights reserved. The Berkeley software License Agreement
|
||||
* specifies the terms and conditions for redistribution.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
char copyright[] =
|
||||
"@(#) Copyright (c) 1980 Regents of the University of California.\n\
|
||||
All rights reserved.\n";
|
||||
#endif not lint
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)crib.c 5.1 (Berkeley) 5/30/85";
|
||||
#endif not lint
|
||||
|
||||
# include <curses.h>
|
||||
# include <stdlib.h>
|
||||
# include <signal.h>
|
||||
# include "deck.h"
|
||||
# include "cribbage.h"
|
||||
# include "cribcur.h"
|
||||
|
||||
# define LOGFILE "/games/lib/criblog"
|
||||
# define INSTRCMD "more /games/lib/crib.instr"
|
||||
|
||||
# define LOGFILE "/usr/games/lib/criblog"
|
||||
# define INSTRCMD "more /usr/games/lib/crib.instr"
|
||||
|
||||
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
/*
|
||||
* gamescore:
|
||||
* Print out the current game score
|
||||
*/
|
||||
void gamescore()
|
||||
{
|
||||
register char *p;
|
||||
BOOLEAN playing;
|
||||
char *s; /* for reading arguments */
|
||||
char bust; /* flag for arg reader */
|
||||
FILE *f;
|
||||
FILE *fopen();
|
||||
char *getline();
|
||||
int bye();
|
||||
extern int Lastscore[];
|
||||
|
||||
while (--argc > 0) {
|
||||
if ((*++argv)[0] != '-') {
|
||||
fprintf(stderr, "\n\ncribbage: usage is 'cribbage [-eqr]'\n");
|
||||
exit(1);
|
||||
}
|
||||
bust = FALSE;
|
||||
for (s = argv[0] + 1; *s != NULL; s++) {
|
||||
switch (*s) {
|
||||
case 'e':
|
||||
explain = TRUE;
|
||||
break;
|
||||
case 'q':
|
||||
quiet = TRUE;
|
||||
break;
|
||||
case 'r':
|
||||
rflag = TRUE;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "\n\ncribbage: usage is 'cribbage [-eqr]'\n");
|
||||
exit(2);
|
||||
break;
|
||||
}
|
||||
if (bust)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
initscr();
|
||||
signal(SIGINT, bye);
|
||||
crmode();
|
||||
noecho();
|
||||
Playwin = subwin(stdscr, PLAY_Y, PLAY_X, 0, 0);
|
||||
Tablewin = subwin(stdscr, TABLE_Y, TABLE_X, 0, PLAY_X);
|
||||
Compwin = subwin(stdscr, COMP_Y, COMP_X, 0, TABLE_X + PLAY_X);
|
||||
Msgwin = subwin(stdscr, MSG_Y, MSG_X, Y_MSG_START, SCORE_X + 1);
|
||||
leaveok(Playwin, TRUE);
|
||||
leaveok(Tablewin, TRUE);
|
||||
leaveok(Compwin, TRUE);
|
||||
clearok(stdscr, FALSE);
|
||||
|
||||
if (!quiet) {
|
||||
msg("Do you need instructions for cribbage? ");
|
||||
if (getuchar() == 'Y') {
|
||||
endwin();
|
||||
fflush(stdout);
|
||||
system(INSTRCMD);
|
||||
crmode();
|
||||
noecho();
|
||||
clear();
|
||||
refresh();
|
||||
msg("For the rules of this program, do \"man cribbage\"");
|
||||
}
|
||||
}
|
||||
playing = TRUE;
|
||||
do {
|
||||
wclrtobot(Msgwin);
|
||||
msg(quiet ? "L or S? " : "Long (to 121) or Short (to 61)? ");
|
||||
if (glimit == SGAME)
|
||||
glimit = (getuchar() == 'L' ? LGAME : SGAME);
|
||||
else
|
||||
glimit = (getuchar() == 'S' ? SGAME : LGAME);
|
||||
game();
|
||||
msg("Another game? ");
|
||||
playing = (getuchar() == 'Y');
|
||||
} while (playing);
|
||||
|
||||
if ((f = fopen(LOGFILE, "a")) != NULL) {
|
||||
fprintf(f, "Won %5.5d, Lost %5.5d\n", cgames, pgames);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
bye();
|
||||
if (pgames || cgames) {
|
||||
mvprintw(SCORE_Y + 1, SCORE_X + 28, "Games: %3d", pgames);
|
||||
mvprintw(SCORE_Y + 7, SCORE_X + 28, "Games: %3d", cgames);
|
||||
}
|
||||
Lastscore[0] = -1;
|
||||
Lastscore[1] = -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* makeboard:
|
||||
* Print out the initial board on the screen
|
||||
*/
|
||||
makeboard()
|
||||
void makeboard()
|
||||
{
|
||||
mvaddstr(SCORE_Y + 0, SCORE_X, "+---------------------------------------+");
|
||||
mvaddstr(SCORE_Y + 1, SCORE_X, "| Score: 0 YOU |");
|
||||
@@ -131,19 +47,345 @@ makeboard()
|
||||
}
|
||||
|
||||
/*
|
||||
* gamescore:
|
||||
* Print out the current game score
|
||||
* deal cards to both players from deck
|
||||
*/
|
||||
gamescore()
|
||||
int deal( mycrib )
|
||||
{
|
||||
extern int Lastscore[];
|
||||
register int i, j;
|
||||
|
||||
if (pgames || cgames) {
|
||||
mvprintw(SCORE_Y + 1, SCORE_X + 28, "Games: %3d", pgames);
|
||||
mvprintw(SCORE_Y + 7, SCORE_X + 28, "Games: %3d", cgames);
|
||||
}
|
||||
Lastscore[0] = -1;
|
||||
Lastscore[1] = -1;
|
||||
j = 0;
|
||||
for( i = 0; i < FULLHAND; i++ ) {
|
||||
if( mycrib ) {
|
||||
phand[i] = deck[j++];
|
||||
chand[i] = deck[j++];
|
||||
}
|
||||
else {
|
||||
chand[i] = deck[j++];
|
||||
phand[i] = deck[j++];
|
||||
}
|
||||
}
|
||||
return( j );
|
||||
}
|
||||
|
||||
/*
|
||||
* prcrib:
|
||||
* Print out the turnover card with crib indicator
|
||||
*/
|
||||
void prcrib(mycrib, blank)
|
||||
BOOLEAN mycrib, blank;
|
||||
{
|
||||
register int y, cardx;
|
||||
|
||||
if (mycrib)
|
||||
cardx = CRIB_X;
|
||||
else
|
||||
cardx = 0;
|
||||
|
||||
mvaddstr(CRIB_Y, cardx + 1, "CRIB");
|
||||
prcard(stdscr, CRIB_Y + 1, cardx, turnover, blank);
|
||||
|
||||
if (mycrib)
|
||||
cardx = 0;
|
||||
else
|
||||
cardx = CRIB_X;
|
||||
|
||||
for (y = CRIB_Y; y <= CRIB_Y + 5; y++)
|
||||
mvaddstr(y, cardx, " ");
|
||||
}
|
||||
|
||||
/*
|
||||
* discard:
|
||||
* Handle players discarding into the crib...
|
||||
* Note: we call cdiscard() after prining first message so player doesn't wait
|
||||
*/
|
||||
void discard(mycrib)
|
||||
BOOLEAN mycrib;
|
||||
{
|
||||
register char *prompt;
|
||||
CARD crd;
|
||||
|
||||
prcrib(mycrib, TRUE);
|
||||
prompt = (quiet ? "Discard --> " : "Discard a card --> ");
|
||||
cdiscard(mycrib); /* puts best discard at end */
|
||||
crd = phand[infrom(phand, FULLHAND, prompt)];
|
||||
cremove(crd, phand, FULLHAND);
|
||||
prhand(phand, FULLHAND, Playwin, FALSE);
|
||||
crib[0] = crd;
|
||||
/* next four lines same as last four except for cdiscard() */
|
||||
crd = phand[infrom(phand, FULLHAND - 1, prompt)];
|
||||
cremove(crd, phand, FULLHAND - 1);
|
||||
prhand(phand, FULLHAND, Playwin, FALSE);
|
||||
crib[1] = crd;
|
||||
crib[2] = chand[4];
|
||||
crib[3] = chand[5];
|
||||
chand[4].rank = chand[4].suit = chand[5].rank = chand[5].suit = EMPTY;
|
||||
}
|
||||
|
||||
/*
|
||||
* cut:
|
||||
* Cut the deck and set turnover. Actually, we only ASK the
|
||||
* player what card to turn. We do a random one, anyway.
|
||||
*/
|
||||
BOOLEAN cut(mycrib, pos)
|
||||
BOOLEAN mycrib;
|
||||
int pos;
|
||||
{
|
||||
register int i, cardx;
|
||||
BOOLEAN win = FALSE;
|
||||
|
||||
if (mycrib) {
|
||||
if (!rflag) { /* random cut */
|
||||
msg(quiet ? "Cut the deck? " :
|
||||
"How many cards down do you wish to cut the deck? ");
|
||||
getlin();
|
||||
}
|
||||
i = (rand() >> 4) % (CARDS - pos);
|
||||
turnover = deck[i + pos];
|
||||
addmsg(quiet ? "You cut " : "You cut the ");
|
||||
msgcard(turnover, FALSE);
|
||||
endmsg();
|
||||
if (turnover.rank == JACK) {
|
||||
msg("I get two for his heels");
|
||||
win = chkscr(&cscore,2 );
|
||||
}
|
||||
}
|
||||
else {
|
||||
i = (rand() >> 4) % (CARDS - pos) + pos;
|
||||
turnover = deck[i];
|
||||
addmsg(quiet ? "I cut " : "I cut the ");
|
||||
msgcard(turnover, FALSE);
|
||||
endmsg();
|
||||
if (turnover.rank == JACK) {
|
||||
msg("You get two for his heels");
|
||||
win = chkscr(&pscore, 2);
|
||||
}
|
||||
}
|
||||
makeknown(&turnover, 1);
|
||||
prcrib(mycrib, FALSE);
|
||||
return win;
|
||||
}
|
||||
|
||||
static CARD Table[14];
|
||||
|
||||
static int Tcnt;
|
||||
|
||||
/*
|
||||
* prtable:
|
||||
* Print out the table with the current score
|
||||
*/
|
||||
void prtable(score)
|
||||
int score;
|
||||
{
|
||||
prhand(Table, Tcnt, Tablewin, FALSE);
|
||||
mvwprintw(Tablewin, (Tcnt + 2) * 2, Tcnt + 1, "%2d", score);
|
||||
wrefresh(Tablewin);
|
||||
}
|
||||
|
||||
/*
|
||||
* peg:
|
||||
* Handle all the pegging...
|
||||
*/
|
||||
BOOLEAN peg(mycrib)
|
||||
BOOLEAN mycrib;
|
||||
{
|
||||
static CARD ch[CINHAND], ph[CINHAND];
|
||||
CARD crd;
|
||||
register int i, j, k;
|
||||
register int l;
|
||||
register int cnum, pnum, sum;
|
||||
register BOOLEAN myturn, mego, ugo, last, played;
|
||||
|
||||
cnum = pnum = CINHAND;
|
||||
for (i = 0; i < CINHAND; i++) { /* make copies of hands */
|
||||
ch[i] = chand[i];
|
||||
ph[i] = phand[i];
|
||||
}
|
||||
Tcnt = 0; /* index to table of cards played */
|
||||
sum = 0; /* sum of cards played */
|
||||
mego = ugo = FALSE;
|
||||
myturn = !mycrib;
|
||||
for (;;) {
|
||||
last = TRUE; /* enable last flag */
|
||||
prhand(ph, pnum, Playwin, FALSE);
|
||||
prhand(ch, cnum, Compwin, TRUE);
|
||||
prtable(sum);
|
||||
if (myturn) { /* my tyrn to play */
|
||||
if (!anymove(ch, cnum, sum)) { /* if no card to play */
|
||||
if (!mego && cnum) { /* go for comp? */
|
||||
msg("GO");
|
||||
mego = TRUE;
|
||||
}
|
||||
if (anymove(ph, pnum, sum)) /* can player move? */
|
||||
myturn = !myturn;
|
||||
else { /* give him his point */
|
||||
msg(quiet ? "You get one" : "You get one point");
|
||||
if (chkscr(&pscore, 1))
|
||||
return TRUE;
|
||||
sum = 0;
|
||||
mego = ugo = FALSE;
|
||||
Tcnt = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
played = TRUE;
|
||||
j = -1;
|
||||
k = 0;
|
||||
for (i = 0; i < cnum; i++) { /* maximize score */
|
||||
l = pegscore(ch[i], Table, Tcnt, sum);
|
||||
if (l > k) {
|
||||
k = l;
|
||||
j = i;
|
||||
}
|
||||
}
|
||||
if (j < 0) /* if nothing scores */
|
||||
j = cchose(ch, cnum, sum);
|
||||
crd = ch[j];
|
||||
cremove(crd, ch, cnum--);
|
||||
sum += VAL(crd.rank);
|
||||
Table[Tcnt++] = crd;
|
||||
if (k > 0) {
|
||||
addmsg(quiet ? "I get %d playing " :
|
||||
"I get %d points playing ", k);
|
||||
msgcard(crd, FALSE);
|
||||
endmsg();
|
||||
if (chkscr(&cscore, k))
|
||||
return TRUE;
|
||||
}
|
||||
myturn = !myturn;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!anymove(ph, pnum, sum)) { /* can player move? */
|
||||
if (!ugo && pnum) { /* go for player */
|
||||
msg("You have a GO");
|
||||
ugo = TRUE;
|
||||
}
|
||||
if (anymove(ch, cnum, sum)) /* can computer play? */
|
||||
myturn = !myturn;
|
||||
else {
|
||||
msg(quiet ? "I get one" : "I get one point");
|
||||
do_wait();
|
||||
if (chkscr(&cscore, 1))
|
||||
return TRUE;
|
||||
sum = 0;
|
||||
mego = ugo = FALSE;
|
||||
Tcnt = 0;
|
||||
}
|
||||
}
|
||||
else { /* player plays */
|
||||
played = FALSE;
|
||||
if (pnum == 1) {
|
||||
crd = ph[0];
|
||||
msg("You play your last card");
|
||||
}
|
||||
else
|
||||
for (;;) {
|
||||
prhand(ph, pnum, Playwin, FALSE);
|
||||
crd = ph[infrom(ph, pnum, "Your play: ")];
|
||||
if (sum + VAL(crd.rank) <= 31)
|
||||
break;
|
||||
else
|
||||
msg("Total > 31 -- try again");
|
||||
}
|
||||
makeknown(&crd, 1);
|
||||
cremove(crd, ph, pnum--);
|
||||
i = pegscore(crd, Table, Tcnt, sum);
|
||||
sum += VAL(crd.rank);
|
||||
Table[Tcnt++] = crd;
|
||||
if (i > 0) {
|
||||
msg(quiet ? "You got %d" : "You got %d points", i);
|
||||
if (chkscr(&pscore, i))
|
||||
return TRUE;
|
||||
}
|
||||
myturn = !myturn;
|
||||
}
|
||||
}
|
||||
if (sum >= 31) {
|
||||
if (!myturn)
|
||||
do_wait();
|
||||
sum = 0;
|
||||
mego = ugo = FALSE;
|
||||
Tcnt = 0;
|
||||
last = FALSE; /* disable last flag */
|
||||
}
|
||||
if (!pnum && !cnum)
|
||||
break; /* both done */
|
||||
}
|
||||
prhand(ph, pnum, Playwin, FALSE);
|
||||
prhand(ch, cnum, Compwin, TRUE);
|
||||
prtable(sum);
|
||||
if (last) {
|
||||
if (played) {
|
||||
msg(quiet ? "I get one for last" : "I get one point for last");
|
||||
do_wait();
|
||||
if (chkscr(&cscore, 1))
|
||||
return TRUE;
|
||||
} else {
|
||||
msg(quiet ? "You get one for last" :
|
||||
"You get one point for last");
|
||||
if (chkscr(&pscore, 1))
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* score:
|
||||
* Handle the scoring of the hands
|
||||
*/
|
||||
BOOLEAN score(mycrib)
|
||||
BOOLEAN mycrib;
|
||||
{
|
||||
sorthand(crib, CINHAND);
|
||||
if (mycrib) {
|
||||
if (plyrhand(phand, "hand"))
|
||||
return TRUE;
|
||||
if (comphand(chand, "hand"))
|
||||
return TRUE;
|
||||
do_wait();
|
||||
if (comphand(crib, "crib"))
|
||||
return TRUE;
|
||||
}
|
||||
else {
|
||||
if (comphand(chand, "hand"))
|
||||
return TRUE;
|
||||
if (plyrhand(phand, "hand"))
|
||||
return TRUE;
|
||||
if (plyrhand(crib, "crib"))
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* playhand:
|
||||
* Do up one hand of the game
|
||||
*/
|
||||
BOOLEAN playhand(mycrib)
|
||||
BOOLEAN mycrib;
|
||||
{
|
||||
register int deckpos;
|
||||
extern char Msgbuf[];
|
||||
|
||||
werase(Compwin);
|
||||
|
||||
knownum = 0;
|
||||
deckpos = deal(mycrib);
|
||||
sorthand(chand, FULLHAND);
|
||||
sorthand(phand, FULLHAND);
|
||||
makeknown(chand, FULLHAND);
|
||||
prhand(phand, FULLHAND, Playwin, FALSE);
|
||||
discard(mycrib);
|
||||
if (cut(mycrib, deckpos))
|
||||
return TRUE;
|
||||
if (peg(mycrib))
|
||||
return TRUE;
|
||||
werase(Tablewin);
|
||||
wrefresh(Tablewin);
|
||||
if (score(mycrib))
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -151,7 +393,7 @@ gamescore()
|
||||
* Play one game up to glimit points. Actually, we only ASK the
|
||||
* player what card to turn. We do a random one, anyway.
|
||||
*/
|
||||
game()
|
||||
void game()
|
||||
{
|
||||
register int i, j;
|
||||
BOOLEAN flag;
|
||||
@@ -167,7 +409,7 @@ game()
|
||||
if (!rflag) { /* player cuts deck */
|
||||
msg(quiet ? "Cut for crib? " :
|
||||
"Cut to see whose crib it is -- low card wins? ");
|
||||
getline();
|
||||
getlin();
|
||||
}
|
||||
i = (rand() >> 4) % CARDS; /* random cut */
|
||||
do { /* comp cuts deck */
|
||||
@@ -240,348 +482,86 @@ game()
|
||||
gamescore();
|
||||
}
|
||||
|
||||
/*
|
||||
* playhand:
|
||||
* Do up one hand of the game
|
||||
*/
|
||||
playhand(mycrib)
|
||||
BOOLEAN mycrib;
|
||||
int main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
register int deckpos;
|
||||
extern char Msgbuf[];
|
||||
register char *p;
|
||||
BOOLEAN playing;
|
||||
char *s; /* for reading arguments */
|
||||
char bust; /* flag for arg reader */
|
||||
FILE *f;
|
||||
|
||||
werase(Compwin);
|
||||
|
||||
knownum = 0;
|
||||
deckpos = deal(mycrib);
|
||||
sorthand(chand, FULLHAND);
|
||||
sorthand(phand, FULLHAND);
|
||||
makeknown(chand, FULLHAND);
|
||||
prhand(phand, FULLHAND, Playwin, FALSE);
|
||||
discard(mycrib);
|
||||
if (cut(mycrib, deckpos))
|
||||
return TRUE;
|
||||
if (peg(mycrib))
|
||||
return TRUE;
|
||||
werase(Tablewin);
|
||||
wrefresh(Tablewin);
|
||||
if (score(mycrib))
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* deal cards to both players from deck
|
||||
*/
|
||||
|
||||
deal( mycrib )
|
||||
{
|
||||
register int i, j;
|
||||
|
||||
j = 0;
|
||||
for( i = 0; i < FULLHAND; i++ ) {
|
||||
if( mycrib ) {
|
||||
phand[i] = deck[j++];
|
||||
chand[i] = deck[j++];
|
||||
while (--argc > 0) {
|
||||
if ((*++argv)[0] != '-') {
|
||||
fprintf(stderr, "\n\ncribbage: usage is 'cribbage [-eqr]'\n");
|
||||
exit(1);
|
||||
}
|
||||
else {
|
||||
chand[i] = deck[j++];
|
||||
phand[i] = deck[j++];
|
||||
}
|
||||
}
|
||||
return( j );
|
||||
}
|
||||
|
||||
/*
|
||||
* discard:
|
||||
* Handle players discarding into the crib...
|
||||
* Note: we call cdiscard() after prining first message so player doesn't wait
|
||||
*/
|
||||
discard(mycrib)
|
||||
BOOLEAN mycrib;
|
||||
{
|
||||
register char *prompt;
|
||||
CARD crd;
|
||||
|
||||
prcrib(mycrib, TRUE);
|
||||
prompt = (quiet ? "Discard --> " : "Discard a card --> ");
|
||||
cdiscard(mycrib); /* puts best discard at end */
|
||||
crd = phand[infrom(phand, FULLHAND, prompt)];
|
||||
remove(crd, phand, FULLHAND);
|
||||
prhand(phand, FULLHAND, Playwin, FALSE);
|
||||
crib[0] = crd;
|
||||
/* next four lines same as last four except for cdiscard() */
|
||||
crd = phand[infrom(phand, FULLHAND - 1, prompt)];
|
||||
remove(crd, phand, FULLHAND - 1);
|
||||
prhand(phand, FULLHAND, Playwin, FALSE);
|
||||
crib[1] = crd;
|
||||
crib[2] = chand[4];
|
||||
crib[3] = chand[5];
|
||||
chand[4].rank = chand[4].suit = chand[5].rank = chand[5].suit = EMPTY;
|
||||
}
|
||||
|
||||
/*
|
||||
* cut:
|
||||
* Cut the deck and set turnover. Actually, we only ASK the
|
||||
* player what card to turn. We do a random one, anyway.
|
||||
*/
|
||||
cut(mycrib, pos)
|
||||
BOOLEAN mycrib;
|
||||
int pos;
|
||||
{
|
||||
register int i, cardx;
|
||||
BOOLEAN win = FALSE;
|
||||
|
||||
if (mycrib) {
|
||||
if (!rflag) { /* random cut */
|
||||
msg(quiet ? "Cut the deck? " :
|
||||
"How many cards down do you wish to cut the deck? ");
|
||||
getline();
|
||||
}
|
||||
i = (rand() >> 4) % (CARDS - pos);
|
||||
turnover = deck[i + pos];
|
||||
addmsg(quiet ? "You cut " : "You cut the ");
|
||||
msgcard(turnover, FALSE);
|
||||
endmsg();
|
||||
if (turnover.rank == JACK) {
|
||||
msg("I get two for his heels");
|
||||
win = chkscr(&cscore,2 );
|
||||
}
|
||||
}
|
||||
else {
|
||||
i = (rand() >> 4) % (CARDS - pos) + pos;
|
||||
turnover = deck[i];
|
||||
addmsg(quiet ? "I cut " : "I cut the ");
|
||||
msgcard(turnover, FALSE);
|
||||
endmsg();
|
||||
if (turnover.rank == JACK) {
|
||||
msg("You get two for his heels");
|
||||
win = chkscr(&pscore, 2);
|
||||
}
|
||||
}
|
||||
makeknown(&turnover, 1);
|
||||
prcrib(mycrib, FALSE);
|
||||
return win;
|
||||
}
|
||||
|
||||
/*
|
||||
* prcrib:
|
||||
* Print out the turnover card with crib indicator
|
||||
*/
|
||||
prcrib(mycrib, blank)
|
||||
BOOLEAN mycrib, blank;
|
||||
{
|
||||
register int y, cardx;
|
||||
|
||||
if (mycrib)
|
||||
cardx = CRIB_X;
|
||||
else
|
||||
cardx = 0;
|
||||
|
||||
mvaddstr(CRIB_Y, cardx + 1, "CRIB");
|
||||
prcard(stdscr, CRIB_Y + 1, cardx, turnover, blank);
|
||||
|
||||
if (mycrib)
|
||||
cardx = 0;
|
||||
else
|
||||
cardx = CRIB_X;
|
||||
|
||||
for (y = CRIB_Y; y <= CRIB_Y + 5; y++)
|
||||
mvaddstr(y, cardx, " ");
|
||||
}
|
||||
|
||||
/*
|
||||
* peg:
|
||||
* Handle all the pegging...
|
||||
*/
|
||||
|
||||
static CARD Table[14];
|
||||
|
||||
static int Tcnt;
|
||||
|
||||
peg(mycrib)
|
||||
BOOLEAN mycrib;
|
||||
{
|
||||
static CARD ch[CINHAND], ph[CINHAND];
|
||||
CARD crd;
|
||||
register int i, j, k;
|
||||
register int l;
|
||||
register int cnum, pnum, sum;
|
||||
register BOOLEAN myturn, mego, ugo, last, played;
|
||||
|
||||
cnum = pnum = CINHAND;
|
||||
for (i = 0; i < CINHAND; i++) { /* make copies of hands */
|
||||
ch[i] = chand[i];
|
||||
ph[i] = phand[i];
|
||||
}
|
||||
Tcnt = 0; /* index to table of cards played */
|
||||
sum = 0; /* sum of cards played */
|
||||
mego = ugo = FALSE;
|
||||
myturn = !mycrib;
|
||||
for (;;) {
|
||||
last = TRUE; /* enable last flag */
|
||||
prhand(ph, pnum, Playwin, FALSE);
|
||||
prhand(ch, cnum, Compwin, TRUE);
|
||||
prtable(sum);
|
||||
if (myturn) { /* my tyrn to play */
|
||||
if (!anymove(ch, cnum, sum)) { /* if no card to play */
|
||||
if (!mego && cnum) { /* go for comp? */
|
||||
msg("GO");
|
||||
mego = TRUE;
|
||||
}
|
||||
if (anymove(ph, pnum, sum)) /* can player move? */
|
||||
myturn = !myturn;
|
||||
else { /* give him his point */
|
||||
msg(quiet ? "You get one" : "You get one point");
|
||||
if (chkscr(&pscore, 1))
|
||||
return TRUE;
|
||||
sum = 0;
|
||||
mego = ugo = FALSE;
|
||||
Tcnt = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
played = TRUE;
|
||||
j = -1;
|
||||
k = 0;
|
||||
for (i = 0; i < cnum; i++) { /* maximize score */
|
||||
l = pegscore(ch[i], Table, Tcnt, sum);
|
||||
if (l > k) {
|
||||
k = l;
|
||||
j = i;
|
||||
}
|
||||
}
|
||||
if (j < 0) /* if nothing scores */
|
||||
j = cchose(ch, cnum, sum);
|
||||
crd = ch[j];
|
||||
remove(crd, ch, cnum--);
|
||||
sum += VAL(crd.rank);
|
||||
Table[Tcnt++] = crd;
|
||||
if (k > 0) {
|
||||
addmsg(quiet ? "I get %d playing " :
|
||||
"I get %d points playing ", k);
|
||||
msgcard(crd, FALSE);
|
||||
endmsg();
|
||||
if (chkscr(&cscore, k))
|
||||
return TRUE;
|
||||
}
|
||||
myturn = !myturn;
|
||||
bust = FALSE;
|
||||
for (s = argv[0] + 1; *s != 0; s++) {
|
||||
switch (*s) {
|
||||
case 'e':
|
||||
explain = TRUE;
|
||||
break;
|
||||
case 'q':
|
||||
quiet = TRUE;
|
||||
break;
|
||||
case 'r':
|
||||
rflag = TRUE;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "\n\ncribbage: usage is 'cribbage [-eqr]'\n");
|
||||
exit(2);
|
||||
break;
|
||||
}
|
||||
if (bust)
|
||||
break;
|
||||
}
|
||||
else {
|
||||
if (!anymove(ph, pnum, sum)) { /* can player move? */
|
||||
if (!ugo && pnum) { /* go for player */
|
||||
msg("You have a GO");
|
||||
ugo = TRUE;
|
||||
}
|
||||
if (anymove(ch, cnum, sum)) /* can computer play? */
|
||||
myturn = !myturn;
|
||||
else {
|
||||
msg(quiet ? "I get one" : "I get one point");
|
||||
do_wait();
|
||||
if (chkscr(&cscore, 1))
|
||||
return TRUE;
|
||||
sum = 0;
|
||||
mego = ugo = FALSE;
|
||||
Tcnt = 0;
|
||||
}
|
||||
}
|
||||
else { /* player plays */
|
||||
played = FALSE;
|
||||
if (pnum == 1) {
|
||||
crd = ph[0];
|
||||
msg("You play your last card");
|
||||
}
|
||||
else
|
||||
for (;;) {
|
||||
prhand(ph, pnum, Playwin, FALSE);
|
||||
crd = ph[infrom(ph, pnum, "Your play: ")];
|
||||
if (sum + VAL(crd.rank) <= 31)
|
||||
break;
|
||||
else
|
||||
msg("Total > 31 -- try again");
|
||||
}
|
||||
makeknown(&crd, 1);
|
||||
remove(crd, ph, pnum--);
|
||||
i = pegscore(crd, Table, Tcnt, sum);
|
||||
sum += VAL(crd.rank);
|
||||
Table[Tcnt++] = crd;
|
||||
if (i > 0) {
|
||||
msg(quiet ? "You got %d" : "You got %d points", i);
|
||||
if (chkscr(&pscore, i))
|
||||
return TRUE;
|
||||
}
|
||||
myturn = !myturn;
|
||||
}
|
||||
}
|
||||
if (sum >= 31) {
|
||||
if (!myturn)
|
||||
do_wait();
|
||||
sum = 0;
|
||||
mego = ugo = FALSE;
|
||||
Tcnt = 0;
|
||||
last = FALSE; /* disable last flag */
|
||||
}
|
||||
if (!pnum && !cnum)
|
||||
break; /* both done */
|
||||
}
|
||||
prhand(ph, pnum, Playwin, FALSE);
|
||||
prhand(ch, cnum, Compwin, TRUE);
|
||||
prtable(sum);
|
||||
if (last)
|
||||
if (played) {
|
||||
msg(quiet ? "I get one for last" : "I get one point for last");
|
||||
do_wait();
|
||||
if (chkscr(&cscore, 1))
|
||||
return TRUE;
|
||||
}
|
||||
else {
|
||||
msg(quiet ? "You get one for last" :
|
||||
"You get one point for last");
|
||||
if (chkscr(&pscore, 1))
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* prtable:
|
||||
* Print out the table with the current score
|
||||
*/
|
||||
prtable(score)
|
||||
int score;
|
||||
{
|
||||
prhand(Table, Tcnt, Tablewin, FALSE);
|
||||
mvwprintw(Tablewin, (Tcnt + 2) * 2, Tcnt + 1, "%2d", score);
|
||||
wrefresh(Tablewin);
|
||||
}
|
||||
initscr();
|
||||
signal(SIGINT, bye);
|
||||
crmode();
|
||||
noecho();
|
||||
Playwin = subwin(stdscr, PLAY_Y, PLAY_X, 0, 0);
|
||||
Tablewin = subwin(stdscr, TABLE_Y, TABLE_X, 0, PLAY_X);
|
||||
Compwin = subwin(stdscr, COMP_Y, COMP_X, 0, TABLE_X + PLAY_X);
|
||||
Msgwin = subwin(stdscr, MSG_Y, MSG_X, Y_MSG_START, SCORE_X + 1);
|
||||
leaveok(Playwin, TRUE);
|
||||
leaveok(Tablewin, TRUE);
|
||||
leaveok(Compwin, TRUE);
|
||||
clearok(stdscr, FALSE);
|
||||
|
||||
/*
|
||||
* score:
|
||||
* Handle the scoring of the hands
|
||||
*/
|
||||
score(mycrib)
|
||||
BOOLEAN mycrib;
|
||||
{
|
||||
sorthand(crib, CINHAND);
|
||||
if (mycrib) {
|
||||
if (plyrhand(phand, "hand"))
|
||||
return TRUE;
|
||||
if (comphand(chand, "hand"))
|
||||
return TRUE;
|
||||
do_wait();
|
||||
if (comphand(crib, "crib"))
|
||||
return TRUE;
|
||||
if (!quiet) {
|
||||
msg("Do you need instructions for cribbage? ");
|
||||
if (getuchar() == 'Y') {
|
||||
endwin();
|
||||
fflush(stdout);
|
||||
system(INSTRCMD);
|
||||
crmode();
|
||||
noecho();
|
||||
clear();
|
||||
refresh();
|
||||
msg("For the rules of this program, do \"man cribbage\"");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (comphand(chand, "hand"))
|
||||
return TRUE;
|
||||
if (plyrhand(phand, "hand"))
|
||||
return TRUE;
|
||||
if (plyrhand(crib, "crib"))
|
||||
return TRUE;
|
||||
playing = TRUE;
|
||||
do {
|
||||
wclrtobot(Msgwin);
|
||||
msg(quiet ? "L or S? " : "Long (to 121) or Short (to 61)? ");
|
||||
if (glimit == SGAME)
|
||||
glimit = (getuchar() == 'L' ? LGAME : SGAME);
|
||||
else
|
||||
glimit = (getuchar() == 'S' ? SGAME : LGAME);
|
||||
game();
|
||||
msg("Another game? ");
|
||||
playing = (getuchar() == 'Y');
|
||||
} while (playing);
|
||||
|
||||
if ((f = fopen(LOGFILE, "a")) != NULL) {
|
||||
fprintf(f, "Won %5.5d, Lost %5.5d\n", cgames, pgames);
|
||||
fclose(f);
|
||||
}
|
||||
return FALSE;
|
||||
|
||||
bye(0);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
*
|
||||
* @(#)cribbage.h 5.1 (Berkeley) 5/30/85
|
||||
*/
|
||||
# include <curses.h>
|
||||
|
||||
extern CARD deck[ CARDS ]; /* a deck */
|
||||
extern CARD phand[ FULLHAND ]; /* player's hand */
|
||||
@@ -30,5 +31,32 @@ extern BOOLEAN rflag; /* if all cuts random */
|
||||
extern BOOLEAN quiet; /* if suppress random mess */
|
||||
extern BOOLEAN playing; /* currently playing game */
|
||||
|
||||
extern char expl[]; /* string for explanation */
|
||||
extern char explstr[]; /* string for explanation */
|
||||
|
||||
char *getlin(void);
|
||||
void bye(int sig);
|
||||
void msg(char *fmt, ...);
|
||||
void addmsg(char *fmt, ...);
|
||||
BOOLEAN msgcard(CARD c, BOOLEAN brief);
|
||||
void endmsg(void);
|
||||
int getuchar(void);
|
||||
void makedeck(CARD d[]);
|
||||
void shuffle(CARD d[]);
|
||||
void sorthand(CARD h[], int n);
|
||||
void makeknown(CARD h[], int n);
|
||||
void prhand(CARD h[], int n, WINDOW *win, BOOLEAN blank);
|
||||
void prcard(WINDOW *win, int y, int x, CARD c, BOOLEAN blank);
|
||||
void cdiscard(BOOLEAN mycrib);
|
||||
int infrom(CARD hand[], int n, char *prompt);
|
||||
void cremove(CARD a, CARD d[], int n);
|
||||
BOOLEAN chkscr(int *scr, int inc);
|
||||
BOOLEAN anymove(CARD hand[], int n, int sum);
|
||||
int scorehand(CARD hand[], CARD starter, int n, BOOLEAN crb, BOOLEAN do_explain);
|
||||
int number(int lo, int hi, char *prompt);
|
||||
void do_wait(void);
|
||||
int adjust(CARD cb[], CARD tnv);
|
||||
int pegscore(CARD crd, CARD tbl[], int n, int sum);
|
||||
int cchose(CARD h[], int n, int s);
|
||||
BOOLEAN plyrhand(CARD hand[], char *s);
|
||||
BOOLEAN comphand(CARD h[], char *s);
|
||||
BOOLEAN isone(CARD a, CARD b[], int n);
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
* define structure of a deck of cards and other related things
|
||||
*/
|
||||
|
||||
|
||||
#define CARDS 52 /* number cards in deck */
|
||||
#define RANKS 13 /* number ranks in deck */
|
||||
#define SUITS 4 /* number suits in deck */
|
||||
@@ -43,16 +42,14 @@
|
||||
|
||||
#define VAL(c) ( (c) < 9 ? (c)+1 : 10 ) /* val of rank */
|
||||
|
||||
|
||||
#ifndef TRUE
|
||||
# define TRUE 1
|
||||
# define FALSE 0
|
||||
# define TRUE (1)
|
||||
# define FALSE (0)
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
int rank;
|
||||
int suit;
|
||||
} CARD;
|
||||
|
||||
typedef char BOOLEAN;
|
||||
typedef struct {
|
||||
int rank;
|
||||
int suit;
|
||||
} CARD;
|
||||
|
||||
typedef int BOOLEAN;
|
||||
|
||||
@@ -3,21 +3,15 @@
|
||||
* All rights reserved. The Berkeley software License Agreement
|
||||
* specifies the terms and conditions for redistribution.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)extern.c 5.1 (Berkeley) 5/30/85";
|
||||
#endif not lint
|
||||
|
||||
# include <curses.h>
|
||||
# include "deck.h"
|
||||
# include "cribbage.h"
|
||||
|
||||
bool explain = FALSE; /* player mistakes explained */
|
||||
bool iwon = FALSE; /* if comp won last game */
|
||||
bool quiet = FALSE; /* if suppress random mess */
|
||||
bool rflag = FALSE; /* if all cuts random */
|
||||
BOOLEAN explain = FALSE; /* player mistakes explained */
|
||||
BOOLEAN iwon = FALSE; /* if comp won last game */
|
||||
BOOLEAN quiet = FALSE; /* if suppress random mess */
|
||||
BOOLEAN rflag = FALSE; /* if all cuts random */
|
||||
|
||||
char expl[128]; /* explanation */
|
||||
char explstr[128]; /* explanation */
|
||||
|
||||
int cgames = 0; /* number games comp won */
|
||||
int cscore = 0; /* comp score in this game */
|
||||
|
||||
@@ -3,32 +3,38 @@
|
||||
* All rights reserved. The Berkeley software License Agreement
|
||||
* specifies the terms and conditions for redistribution.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)io.c 5.1 (Berkeley) 5/30/85";
|
||||
#endif not lint
|
||||
|
||||
# include <curses.h>
|
||||
# include <ctype.h>
|
||||
# include <signal.h>
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
# include <stdarg.h>
|
||||
# include <unistd.h>
|
||||
# include "deck.h"
|
||||
# include "cribbage.h"
|
||||
# include "cribcur.h"
|
||||
|
||||
# define LINESIZE 128
|
||||
# define LINESIZE 128
|
||||
|
||||
# ifdef CTRL
|
||||
# undef CTRL
|
||||
# endif
|
||||
# define CTRL(X) ('X' - 'A' + 1)
|
||||
# define CTRL(X) ('X' - 'A' + 1)
|
||||
|
||||
# ifndef erasechar()
|
||||
# define erasechar() _tty.sg_erase
|
||||
# endif erasechar()
|
||||
# ifdef CROSS
|
||||
# define erasechar() ('H' & 31)
|
||||
# endif
|
||||
|
||||
# ifndef killchar()
|
||||
# define killchar() _tty.sg_kill
|
||||
# endif killchar()
|
||||
# ifndef killchar
|
||||
# define killchar() ('U' & 31)
|
||||
# endif
|
||||
|
||||
# ifndef erasechar
|
||||
# define erasechar() _tty.sg_erase
|
||||
# endif
|
||||
|
||||
# ifndef killchar
|
||||
# define killchar() _tty.sg_kill
|
||||
# endif
|
||||
|
||||
char linebuf[ LINESIZE ];
|
||||
|
||||
@@ -45,32 +51,14 @@ char *suitname[ SUITS ] = { "SPADES", "HEARTS", "DIAMONDS",
|
||||
|
||||
char *suitchar[ SUITS ] = { "S", "H", "D", "C" };
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* msgcard:
|
||||
* Call msgcrd in one of two forms
|
||||
*/
|
||||
msgcard(c, brief)
|
||||
CARD c;
|
||||
BOOLEAN brief;
|
||||
{
|
||||
if (brief)
|
||||
return msgcrd(c, TRUE, (char *) NULL, TRUE);
|
||||
else
|
||||
return msgcrd(c, FALSE, " of ", FALSE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* msgcrd:
|
||||
* Print the value of a card in ascii
|
||||
*/
|
||||
msgcrd(c, brfrank, mid, brfsuit)
|
||||
CARD c;
|
||||
char *mid;
|
||||
BOOLEAN brfrank, brfsuit;
|
||||
BOOLEAN msgcrd(c, brfrank, mid, brfsuit)
|
||||
CARD c;
|
||||
char *mid;
|
||||
BOOLEAN brfrank, brfsuit;
|
||||
{
|
||||
if (c.rank == EMPTY || c.suit == EMPTY)
|
||||
return FALSE;
|
||||
@@ -87,15 +75,29 @@ BOOLEAN brfrank, brfsuit;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* msgcard:
|
||||
* Call msgcrd in one of two forms
|
||||
*/
|
||||
BOOLEAN msgcard(c, brief)
|
||||
CARD c;
|
||||
BOOLEAN brief;
|
||||
{
|
||||
if (brief)
|
||||
return msgcrd(c, TRUE, (char *) NULL, TRUE);
|
||||
else
|
||||
return msgcrd(c, FALSE, " of ", FALSE);
|
||||
}
|
||||
|
||||
/*
|
||||
* printcard:
|
||||
* Print out a card.
|
||||
*/
|
||||
printcard(win, cardno, c, blank)
|
||||
WINDOW *win;
|
||||
int cardno;
|
||||
CARD c;
|
||||
BOOLEAN blank;
|
||||
void printcard(win, cardno, c, blank)
|
||||
WINDOW *win;
|
||||
int cardno;
|
||||
CARD c;
|
||||
BOOLEAN blank;
|
||||
{
|
||||
prcard(win, cardno * 2, cardno, c, blank);
|
||||
}
|
||||
@@ -104,11 +106,11 @@ BOOLEAN blank;
|
||||
* prcard:
|
||||
* Print out a card on the window at the specified location
|
||||
*/
|
||||
prcard(win, y, x, c, blank)
|
||||
WINDOW *win;
|
||||
int y, x;
|
||||
CARD c;
|
||||
BOOLEAN blank;
|
||||
void prcard(win, y, x, c, blank)
|
||||
WINDOW *win;
|
||||
int y, x;
|
||||
CARD c;
|
||||
BOOLEAN blank;
|
||||
{
|
||||
if (c.rank == EMPTY)
|
||||
return;
|
||||
@@ -129,11 +131,11 @@ BOOLEAN blank;
|
||||
* prhand:
|
||||
* Print a hand of n cards
|
||||
*/
|
||||
prhand(h, n, win, blank)
|
||||
CARD h[];
|
||||
int n;
|
||||
WINDOW *win;
|
||||
BOOLEAN blank;
|
||||
void prhand(h, n, win, blank)
|
||||
CARD h[];
|
||||
int n;
|
||||
WINDOW *win;
|
||||
BOOLEAN blank;
|
||||
{
|
||||
register int i;
|
||||
|
||||
@@ -143,17 +145,96 @@ BOOLEAN blank;
|
||||
wrefresh(win);
|
||||
}
|
||||
|
||||
/*
|
||||
* incard:
|
||||
* Inputs a card in any format. It reads a line ending with a CR
|
||||
* and then parses it.
|
||||
*/
|
||||
BOOLEAN incard(crd)
|
||||
CARD *crd;
|
||||
{
|
||||
register int i;
|
||||
int rnk, sut;
|
||||
char *line, *p, *p1;
|
||||
BOOLEAN retval;
|
||||
|
||||
retval = FALSE;
|
||||
rnk = sut = EMPTY;
|
||||
if (!(line = getlin()))
|
||||
goto gotit;
|
||||
p = p1 = line;
|
||||
while(*p1 != ' ' && *p1 != 0)
|
||||
++p1;
|
||||
*p1++ = 0;
|
||||
if(*p == 0)
|
||||
goto gotit;
|
||||
/* IMPORTANT: no real card has 2 char first name */
|
||||
if( strlen(p) == 2 ) { /* check for short form */
|
||||
rnk = EMPTY;
|
||||
for( i = 0; i < RANKS; i++ ) {
|
||||
if( *p == *rankchar[i] ) {
|
||||
rnk = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( rnk == EMPTY ) goto gotit; /* it's nothing... */
|
||||
++p; /* advance to next char */
|
||||
sut = EMPTY;
|
||||
for( i = 0; i < SUITS; i++ ) {
|
||||
if( *p == *suitchar[i] ) {
|
||||
sut = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( sut != EMPTY ) retval = TRUE;
|
||||
goto gotit;
|
||||
}
|
||||
rnk = EMPTY;
|
||||
for( i = 0; i < RANKS; i++ ) {
|
||||
if( !strcmp( p, rankname[i] ) || !strcmp( p, rankchar[i] ) ) {
|
||||
rnk = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( rnk == EMPTY ) goto gotit;
|
||||
p = p1;
|
||||
while(*p1 != ' ' && *p1 != 0)
|
||||
++p1;
|
||||
*p1++ = 0;
|
||||
if(*p == 0)
|
||||
goto gotit;
|
||||
if(! strcmp("OF", p)) {
|
||||
p = p1;
|
||||
while(*p1 != ' ' && *p1 != 0)
|
||||
++p1;
|
||||
*p1++ = 0;
|
||||
if(*p == 0)
|
||||
goto gotit;
|
||||
}
|
||||
sut = EMPTY;
|
||||
for( i = 0; i < SUITS; i++ ) {
|
||||
if( !strcmp( p, suitname[i] ) || !strcmp( p, suitchar[i] ) ) {
|
||||
sut = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( sut != EMPTY )
|
||||
retval = TRUE;
|
||||
gotit:
|
||||
(*crd).rank = rnk;
|
||||
(*crd).suit = sut;
|
||||
return( retval );
|
||||
}
|
||||
|
||||
/*
|
||||
* infrom:
|
||||
* reads a card, supposedly in hand, accepting unambigous brief
|
||||
* input, returns the index of the card found...
|
||||
*/
|
||||
infrom(hand, n, prompt)
|
||||
CARD hand[];
|
||||
int n;
|
||||
char *prompt;
|
||||
int infrom(hand, n, prompt)
|
||||
CARD hand[];
|
||||
int n;
|
||||
char *prompt;
|
||||
{
|
||||
register int i, j;
|
||||
CARD crd;
|
||||
@@ -202,90 +283,35 @@ char *prompt;
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* incard:
|
||||
* Inputs a card in any format. It reads a line ending with a CR
|
||||
* and then parses it.
|
||||
* readchar:
|
||||
* Reads and returns a character, checking for gross input errors
|
||||
*/
|
||||
incard(crd)
|
||||
CARD *crd;
|
||||
int readchar()
|
||||
{
|
||||
char *getline();
|
||||
register int i;
|
||||
int rnk, sut;
|
||||
char *line, *p, *p1;
|
||||
BOOLEAN retval;
|
||||
register int cnt, y, x;
|
||||
auto char c;
|
||||
|
||||
retval = FALSE;
|
||||
rnk = sut = EMPTY;
|
||||
if (!(line = getline()))
|
||||
goto gotit;
|
||||
p = p1 = line;
|
||||
while( *p1 != ' ' && *p1 != NULL ) ++p1;
|
||||
*p1++ = NULL;
|
||||
if( *p == NULL ) goto gotit;
|
||||
/* IMPORTANT: no real card has 2 char first name */
|
||||
if( strlen(p) == 2 ) { /* check for short form */
|
||||
rnk = EMPTY;
|
||||
for( i = 0; i < RANKS; i++ ) {
|
||||
if( *p == *rankchar[i] ) {
|
||||
rnk = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( rnk == EMPTY ) goto gotit; /* it's nothing... */
|
||||
++p; /* advance to next char */
|
||||
sut = EMPTY;
|
||||
for( i = 0; i < SUITS; i++ ) {
|
||||
if( *p == *suitchar[i] ) {
|
||||
sut = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( sut != EMPTY ) retval = TRUE;
|
||||
goto gotit;
|
||||
}
|
||||
rnk = EMPTY;
|
||||
for( i = 0; i < RANKS; i++ ) {
|
||||
if( !strcmp( p, rankname[i] ) || !strcmp( p, rankchar[i] ) ) {
|
||||
rnk = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( rnk == EMPTY ) goto gotit;
|
||||
p = p1;
|
||||
while( *p1 != ' ' && *p1 != NULL ) ++p1;
|
||||
*p1++ = NULL;
|
||||
if( *p == NULL ) goto gotit;
|
||||
if( !strcmp( "OF", p ) ) {
|
||||
p = p1;
|
||||
while( *p1 != ' ' && *p1 != NULL ) ++p1;
|
||||
*p1++ = NULL;
|
||||
if( *p == NULL ) goto gotit;
|
||||
}
|
||||
sut = EMPTY;
|
||||
for( i = 0; i < SUITS; i++ ) {
|
||||
if( !strcmp( p, suitname[i] ) || !strcmp( p, suitchar[i] ) ) {
|
||||
sut = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( sut != EMPTY ) retval = TRUE;
|
||||
gotit:
|
||||
(*crd).rank = rnk;
|
||||
(*crd).suit = sut;
|
||||
return( retval );
|
||||
over:
|
||||
cnt = 0;
|
||||
while (read(0, &c, 1) <= 0)
|
||||
if (cnt++ > 100) /* if we are getting infinite EOFs */
|
||||
bye(0); /* quit the game */
|
||||
if (c == CTRL(L)) {
|
||||
wrefresh(curscr);
|
||||
goto over;
|
||||
}
|
||||
if (c == '\r')
|
||||
return '\n';
|
||||
else
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* getuchar:
|
||||
* Reads and converts to upper case
|
||||
*/
|
||||
getuchar()
|
||||
int getuchar()
|
||||
{
|
||||
register int c;
|
||||
|
||||
@@ -301,18 +327,17 @@ getuchar()
|
||||
* Reads in a decimal number and makes sure it is between "lo" and
|
||||
* "hi" inclusive.
|
||||
*/
|
||||
number(lo, hi, prompt)
|
||||
int lo, hi;
|
||||
char *prompt;
|
||||
int number(lo, hi, prompt)
|
||||
int lo, hi;
|
||||
char *prompt;
|
||||
{
|
||||
char *getline();
|
||||
register char *p;
|
||||
register int sum;
|
||||
|
||||
sum = 0;
|
||||
for (;;) {
|
||||
msg(prompt);
|
||||
if(!(p = getline()) || *p == NULL) {
|
||||
if(!(p = getlin()) || *p == 0) {
|
||||
msg(quiet ? "Not a number" : "That doesn't look like a number");
|
||||
continue;
|
||||
}
|
||||
@@ -326,7 +351,7 @@ char *prompt;
|
||||
++p;
|
||||
}
|
||||
|
||||
if (*p != ' ' && *p != '\t' && *p != NULL)
|
||||
if (*p != ' ' && *p != '\t' && *p != 0)
|
||||
sum = lo - 1;
|
||||
if (sum >= lo && sum <= hi)
|
||||
return sum;
|
||||
@@ -338,22 +363,46 @@ char *prompt;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* msg:
|
||||
* Display a message at the top of the screen.
|
||||
*/
|
||||
char Msgbuf[BUFSIZ] = { '\0' };
|
||||
|
||||
int Mpos = 0;
|
||||
|
||||
static int Newpos = 0;
|
||||
|
||||
/* VARARGS1 */
|
||||
msg(fmt, args)
|
||||
char *fmt;
|
||||
int args;
|
||||
/*
|
||||
* doadd:
|
||||
* Perform an add onto the message buffer
|
||||
*/
|
||||
void doadd(char *fmt, va_list ap)
|
||||
{
|
||||
doadd(fmt, &args);
|
||||
#ifdef CROSS
|
||||
vsnprintf(Msgbuf, BUFSIZ, fmt, ap);
|
||||
#else
|
||||
static FILE junk;
|
||||
|
||||
/*
|
||||
* Do the printf into Msgbuf
|
||||
*/
|
||||
junk._flag = _IOWRT + _IOSTRG;
|
||||
junk._ptr = &Msgbuf[Newpos];
|
||||
junk._cnt = BUFSIZ - 1;
|
||||
_doprnt(fmt, ap, &junk);
|
||||
putc('\0', &junk);
|
||||
#endif
|
||||
Newpos = strlen(Msgbuf);
|
||||
}
|
||||
|
||||
/*
|
||||
* msg:
|
||||
* Display a message at the top of the screen.
|
||||
*/
|
||||
void msg(char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
doadd(fmt, ap);
|
||||
va_end(ap);
|
||||
endmsg();
|
||||
}
|
||||
|
||||
@@ -362,21 +411,22 @@ int args;
|
||||
* Add things to the current message
|
||||
*/
|
||||
/* VARARGS1 */
|
||||
addmsg(fmt, args)
|
||||
char *fmt;
|
||||
int args;
|
||||
void addmsg(char *fmt, ...)
|
||||
{
|
||||
doadd(fmt, &args);
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
doadd(fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
int Lineno = 0;
|
||||
|
||||
/*
|
||||
* endmsg:
|
||||
* Display a new msg.
|
||||
*/
|
||||
|
||||
int Lineno = 0;
|
||||
|
||||
endmsg()
|
||||
void endmsg()
|
||||
{
|
||||
register int len;
|
||||
register char *mp, *omp;
|
||||
@@ -423,31 +473,27 @@ endmsg()
|
||||
}
|
||||
|
||||
/*
|
||||
* doadd:
|
||||
* Perform an add onto the message buffer
|
||||
* wait_for
|
||||
* Sit around until the guy types the right key
|
||||
*/
|
||||
doadd(fmt, args)
|
||||
char *fmt;
|
||||
int *args;
|
||||
void wait_for(ch)
|
||||
register int ch;
|
||||
{
|
||||
static FILE junk;
|
||||
register int c;
|
||||
|
||||
/*
|
||||
* Do the printf into Msgbuf
|
||||
*/
|
||||
junk._flag = _IOWRT + _IOSTRG;
|
||||
junk._ptr = &Msgbuf[Newpos];
|
||||
junk._cnt = 32767;
|
||||
_doprnt(fmt, args, &junk);
|
||||
putc('\0', &junk);
|
||||
Newpos = strlen(Msgbuf);
|
||||
if (ch == '\n')
|
||||
while ((c = readchar()) != '\n')
|
||||
continue;
|
||||
else
|
||||
while (readchar() != ch)
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* do_wait:
|
||||
* Wait for the user to type ' ' before doing anything else
|
||||
*/
|
||||
do_wait()
|
||||
void do_wait()
|
||||
{
|
||||
register int line;
|
||||
static char prompt[] = { '-', '-', 'M', 'o', 'r', 'e', '-', '-', '\0' };
|
||||
@@ -466,53 +512,11 @@ do_wait()
|
||||
}
|
||||
|
||||
/*
|
||||
* wait_for
|
||||
* Sit around until the guy types the right key
|
||||
*/
|
||||
wait_for(ch)
|
||||
register char ch;
|
||||
{
|
||||
register char c;
|
||||
|
||||
if (ch == '\n')
|
||||
while ((c = readchar()) != '\n')
|
||||
continue;
|
||||
else
|
||||
while (readchar() != ch)
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* readchar:
|
||||
* Reads and returns a character, checking for gross input errors
|
||||
*/
|
||||
readchar()
|
||||
{
|
||||
register int cnt, y, x;
|
||||
auto char c;
|
||||
|
||||
over:
|
||||
cnt = 0;
|
||||
while (read(0, &c, 1) <= 0)
|
||||
if (cnt++ > 100) /* if we are getting infinite EOFs */
|
||||
bye(); /* quit the game */
|
||||
if (c == CTRL(L)) {
|
||||
wrefresh(curscr);
|
||||
goto over;
|
||||
}
|
||||
if (c == '\r')
|
||||
return '\n';
|
||||
else
|
||||
return c;
|
||||
}
|
||||
|
||||
/*
|
||||
* getline:
|
||||
* getlin:
|
||||
* Reads the next line up to '\n' or EOF. Multiple spaces are
|
||||
* compressed to one space; a space is inserted before a ','
|
||||
*/
|
||||
char *
|
||||
getline()
|
||||
char *getlin()
|
||||
{
|
||||
register char *sp;
|
||||
register int c, oy, ox;
|
||||
@@ -564,7 +568,7 @@ getline()
|
||||
* bye:
|
||||
* Leave the program, cleaning things up as we go.
|
||||
*/
|
||||
bye()
|
||||
void bye(int sig)
|
||||
{
|
||||
signal(SIGINT, SIG_IGN);
|
||||
mvcur(0, COLS - 1, LINES - 1, 0);
|
||||
|
||||
@@ -3,23 +3,18 @@
|
||||
* All rights reserved. The Berkeley software License Agreement
|
||||
* specifies the terms and conditions for redistribution.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)score.c 5.1 (Berkeley) 5/30/85";
|
||||
#endif not lint
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "deck.h"
|
||||
#include "cribbage.h"
|
||||
|
||||
|
||||
/*
|
||||
* the following arrays give the sum of the scores of the (50 2)*48 = 58800
|
||||
* hands obtainable for the crib given the two cards whose ranks index the
|
||||
* array. the two arrays are for the case where the suits are equal and
|
||||
* not equal respectively
|
||||
*/
|
||||
|
||||
long crbescr[ 169 ] = {
|
||||
-10000, 271827, 278883, 332319, 347769, 261129, 250653, 253203, 248259,
|
||||
243435, 256275, 237435, 231051, -10000, -10000, 412815, 295707, 349497,
|
||||
@@ -66,90 +61,13 @@ long crbnescr[ 169 ] = {
|
||||
static int ichoose2[ 5 ] = { 0, 0, 2, 6, 12 };
|
||||
static int pairpoints, runpoints; /* globals from pairuns */
|
||||
|
||||
|
||||
/*
|
||||
* scorehand:
|
||||
* Score the given hand of n cards and the starter card.
|
||||
* n must be <= 4
|
||||
*/
|
||||
scorehand(hand, starter, n, crb, do_explain)
|
||||
register CARD hand[];
|
||||
CARD starter;
|
||||
int n;
|
||||
BOOLEAN crb; /* true if scoring crib */
|
||||
BOOLEAN do_explain; /* true if must explain this hand */
|
||||
{
|
||||
CARD h[(CINHAND + 1)];
|
||||
register int i, k;
|
||||
register int score;
|
||||
register BOOLEAN flag;
|
||||
char buf[32];
|
||||
|
||||
expl[0] = NULL; /* initialize explanation */
|
||||
score = 0;
|
||||
flag = TRUE;
|
||||
k = hand[0].suit;
|
||||
for (i = 0; i < n; i++) { /* check for flush */
|
||||
flag = (flag && (hand[i].suit == k));
|
||||
if (hand[i].rank == JACK) /* check for his nibs */
|
||||
if (hand[i].suit == starter.suit) {
|
||||
score++;
|
||||
if (do_explain)
|
||||
strcat(expl, "His Nobs");
|
||||
}
|
||||
h[i] = hand[i];
|
||||
}
|
||||
|
||||
if (flag && n >= CINHAND) {
|
||||
if (do_explain && expl[0] != NULL)
|
||||
strcat(expl, ", ");
|
||||
if (starter.suit == k) {
|
||||
score += 5;
|
||||
if (do_explain)
|
||||
strcat(expl, "Five-flush");
|
||||
}
|
||||
else if (!crb) {
|
||||
score += 4;
|
||||
if (do_explain && expl[0] != NULL)
|
||||
strcat(expl, ", Four-flush");
|
||||
else
|
||||
strcpy(expl, "Four-flush");
|
||||
}
|
||||
}
|
||||
|
||||
if (do_explain && expl[0] != NULL)
|
||||
strcat(expl, ", ");
|
||||
h[n] = starter;
|
||||
sorthand(h, n + 1); /* sort by rank */
|
||||
i = 2 * fifteens(h, n + 1);
|
||||
score += i;
|
||||
if (do_explain)
|
||||
if (i > 0) {
|
||||
sprintf(buf, "%d points in fifteens", i);
|
||||
strcat(expl, buf);
|
||||
}
|
||||
else
|
||||
strcat(expl, "No fifteens");
|
||||
i = pairuns(h, n + 1);
|
||||
score += i;
|
||||
if (do_explain)
|
||||
if (i > 0) {
|
||||
sprintf(buf, ", %d points in pairs, %d in runs", pairpoints,
|
||||
runpoints);
|
||||
strcat(expl, buf);
|
||||
}
|
||||
else
|
||||
strcat(expl, ", No pairs/runs");
|
||||
return score;
|
||||
}
|
||||
|
||||
/*
|
||||
* fifteens:
|
||||
* Return number of fifteens in hand of n cards
|
||||
*/
|
||||
fifteens(hand, n)
|
||||
register CARD hand[];
|
||||
int n;
|
||||
int fifteens(hand, n)
|
||||
register CARD hand[];
|
||||
int n;
|
||||
{
|
||||
register int *sp, *np;
|
||||
register int i;
|
||||
@@ -183,19 +101,15 @@ int n;
|
||||
return sums[14];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* pairuns returns the number of points in the n card sorted hand
|
||||
* due to pairs and runs
|
||||
* this routine only works if n is strictly less than 6
|
||||
* sets the globals pairpoints and runpoints appropriately
|
||||
*/
|
||||
|
||||
pairuns( h, n )
|
||||
|
||||
CARD h[];
|
||||
int n;
|
||||
int pairuns( h, n )
|
||||
CARD h[];
|
||||
int n;
|
||||
{
|
||||
register int i;
|
||||
int runlength, runmult, lastmult, curmult;
|
||||
@@ -260,18 +174,91 @@ pairuns( h, n )
|
||||
return( pairpoints + runpoints );
|
||||
}
|
||||
|
||||
/*
|
||||
* scorehand:
|
||||
* Score the given hand of n cards and the starter card.
|
||||
* n must be <= 4
|
||||
*/
|
||||
int scorehand(hand, starter, n, crb, do_explain)
|
||||
register CARD hand[];
|
||||
CARD starter;
|
||||
int n;
|
||||
BOOLEAN crb; /* true if scoring crib */
|
||||
BOOLEAN do_explain; /* true if must explain this hand */
|
||||
{
|
||||
CARD h[(CINHAND + 1)];
|
||||
register int i, k;
|
||||
register int score;
|
||||
register BOOLEAN flag;
|
||||
char buf[32];
|
||||
|
||||
explstr[0] = 0; /* initialize explanation */
|
||||
score = 0;
|
||||
flag = TRUE;
|
||||
k = hand[0].suit;
|
||||
for (i = 0; i < n; i++) { /* check for flush */
|
||||
flag = (flag && (hand[i].suit == k));
|
||||
if (hand[i].rank == JACK) /* check for his nibs */
|
||||
if (hand[i].suit == starter.suit) {
|
||||
score++;
|
||||
if (do_explain)
|
||||
strcat(explstr, "His Nobs");
|
||||
}
|
||||
h[i] = hand[i];
|
||||
}
|
||||
|
||||
if (flag && n >= CINHAND) {
|
||||
if (do_explain && explstr[0] != 0)
|
||||
strcat(explstr, ", ");
|
||||
if (starter.suit == k) {
|
||||
score += 5;
|
||||
if (do_explain)
|
||||
strcat(explstr, "Five-flush");
|
||||
}
|
||||
else if (!crb) {
|
||||
score += 4;
|
||||
if (do_explain && explstr[0] != 0)
|
||||
strcat(explstr, ", Four-flush");
|
||||
else
|
||||
strcpy(explstr, "Four-flush");
|
||||
}
|
||||
}
|
||||
|
||||
if (do_explain && explstr[0] != 0)
|
||||
strcat(explstr, ", ");
|
||||
h[n] = starter;
|
||||
sorthand(h, n + 1); /* sort by rank */
|
||||
i = 2 * fifteens(h, n + 1);
|
||||
score += i;
|
||||
if (do_explain) {
|
||||
if (i > 0) {
|
||||
sprintf(buf, "%d points in fifteens", i);
|
||||
strcat(explstr, buf);
|
||||
} else
|
||||
strcat(explstr, "No fifteens");
|
||||
}
|
||||
i = pairuns(h, n + 1);
|
||||
score += i;
|
||||
if (do_explain) {
|
||||
if (i > 0) {
|
||||
sprintf(buf, ", %d points in pairs, %d in runs", pairpoints,
|
||||
runpoints);
|
||||
strcat(explstr, buf);
|
||||
}
|
||||
else
|
||||
strcat(explstr, ", No pairs/runs");
|
||||
}
|
||||
return score;
|
||||
}
|
||||
|
||||
/*
|
||||
* pegscore tells how many points crd would get if played after
|
||||
* the n cards in tbl during pegging
|
||||
*/
|
||||
|
||||
pegscore( crd, tbl, n, sum )
|
||||
|
||||
CARD crd, tbl[];
|
||||
int n;
|
||||
int sum;
|
||||
int pegscore( crd, tbl, n, sum )
|
||||
CARD crd, tbl[];
|
||||
int n;
|
||||
int sum;
|
||||
{
|
||||
BOOLEAN got[ RANKS ];
|
||||
register int i, j, scr;
|
||||
@@ -302,17 +289,13 @@ pegscore( crd, tbl, n, sum )
|
||||
else return( scr );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* adjust takes a two card hand that will be put in the crib
|
||||
* and returns an adjusted normalized score for the number of
|
||||
* points such a crib will get.
|
||||
*/
|
||||
|
||||
adjust( cb, tnv )
|
||||
|
||||
CARD cb[], tnv;
|
||||
int adjust( cb, tnv )
|
||||
CARD cb[], tnv;
|
||||
{
|
||||
int i, c0, c1;
|
||||
long scr;
|
||||
@@ -332,6 +315,3 @@ adjust( cb, tnv )
|
||||
}
|
||||
return( (scr + 29400)/58800 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -3,33 +3,58 @@
|
||||
* All rights reserved. The Berkeley software License Agreement
|
||||
* specifies the terms and conditions for redistribution.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)support.c 5.1 (Berkeley) 5/30/85";
|
||||
#endif not lint
|
||||
|
||||
#include <curses.h>
|
||||
#include <string.h>
|
||||
#include "deck.h"
|
||||
#include "cribbage.h"
|
||||
#include "cribcur.h"
|
||||
|
||||
|
||||
#define NTV 10 /* number scores to test */
|
||||
|
||||
/* score to test reachability of, and order to test them in */
|
||||
int tv[ NTV ] = { 8, 7, 9, 6, 11, 12, 13, 14, 10, 5 };
|
||||
|
||||
/*
|
||||
* anysumto returns the index (0 <= i < n) of the card in hand that brings
|
||||
* the s up to t, or -1 if there is none
|
||||
*/
|
||||
int anysumto( hand, n, s, t )
|
||||
CARD hand[];
|
||||
int n;
|
||||
int s, t;
|
||||
{
|
||||
register int i;
|
||||
|
||||
for( i = 0; i < n; i++ ) {
|
||||
if( s + VAL( hand[i].rank ) == t ) return( i );
|
||||
}
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
/*
|
||||
* return the number of cards in h having the given rank value
|
||||
*/
|
||||
int numofval( h, n, v )
|
||||
CARD h[];
|
||||
int n;
|
||||
int v;
|
||||
{
|
||||
register int i, j;
|
||||
|
||||
j = 0;
|
||||
for( i = 0; i < n; i++ ) {
|
||||
if( VAL( h[i].rank ) == v ) ++j;
|
||||
}
|
||||
return( j );
|
||||
}
|
||||
|
||||
/*
|
||||
* computer chooses what to play in pegging...
|
||||
* only called if no playable card will score points
|
||||
*/
|
||||
|
||||
cchose( h, n, s )
|
||||
|
||||
CARD h[];
|
||||
int n;
|
||||
int s;
|
||||
int cchose( h, n, s )
|
||||
CARD h[];
|
||||
int n;
|
||||
int s;
|
||||
{
|
||||
register int i, j, l;
|
||||
|
||||
@@ -79,15 +104,13 @@ cchose( h, n, s )
|
||||
return( j );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* plyrhand:
|
||||
* Evaluate and score a player hand or crib
|
||||
*/
|
||||
plyrhand(hand, s)
|
||||
CARD hand[];
|
||||
char *s;
|
||||
BOOLEAN plyrhand(hand, s)
|
||||
CARD hand[];
|
||||
char *s;
|
||||
{
|
||||
register int i, j;
|
||||
register BOOLEAN win;
|
||||
@@ -110,7 +133,7 @@ char *s;
|
||||
msg("You should have taken %d, not %d!", i, j);
|
||||
}
|
||||
if (explain)
|
||||
msg("Explanation: %s", expl);
|
||||
msg("Explanation: %s", explstr);
|
||||
do_wait();
|
||||
}
|
||||
else
|
||||
@@ -122,9 +145,9 @@ char *s;
|
||||
* comphand:
|
||||
* Handle scoring and displaying the computers hand
|
||||
*/
|
||||
comphand(h, s)
|
||||
CARD h[];
|
||||
char *s;
|
||||
BOOLEAN comphand(h, s)
|
||||
CARD h[];
|
||||
char *s;
|
||||
{
|
||||
register int j;
|
||||
|
||||
@@ -134,39 +157,17 @@ char *s;
|
||||
return chkscr(&cscore, j);
|
||||
}
|
||||
|
||||
/*
|
||||
* chkscr:
|
||||
* Add inc to scr and test for > glimit, printing on the scoring
|
||||
* board while we're at it.
|
||||
*/
|
||||
|
||||
int Lastscore[2] = {-1, -1};
|
||||
|
||||
chkscr(scr, inc)
|
||||
int *scr, inc;
|
||||
{
|
||||
BOOLEAN myturn;
|
||||
|
||||
myturn = (scr == &cscore);
|
||||
if (inc != 0) {
|
||||
prpeg(Lastscore[myturn], '.', myturn);
|
||||
Lastscore[myturn] = *scr;
|
||||
*scr += inc;
|
||||
prpeg(*scr, PEG, myturn);
|
||||
refresh();
|
||||
}
|
||||
return (*scr >= glimit);
|
||||
}
|
||||
|
||||
/*
|
||||
* prpeg:
|
||||
* Put out the peg character on the score board and put the
|
||||
* score up on the board.
|
||||
*/
|
||||
prpeg(score, peg, myturn)
|
||||
register int score;
|
||||
char peg;
|
||||
BOOLEAN myturn;
|
||||
void prpeg(score, peg, myturn)
|
||||
register int score;
|
||||
char peg;
|
||||
BOOLEAN myturn;
|
||||
{
|
||||
register int y, x;
|
||||
|
||||
@@ -198,13 +199,32 @@ BOOLEAN myturn;
|
||||
mvprintw(SCORE_Y + (myturn ? 7 : 1), SCORE_X + 10, "%3d", score);
|
||||
}
|
||||
|
||||
/*
|
||||
* chkscr:
|
||||
* Add inc to scr and test for > glimit, printing on the scoring
|
||||
* board while we're at it.
|
||||
*/
|
||||
BOOLEAN chkscr(scr, inc)
|
||||
int *scr, inc;
|
||||
{
|
||||
BOOLEAN myturn;
|
||||
|
||||
myturn = (scr == &cscore);
|
||||
if (inc != 0) {
|
||||
prpeg(Lastscore[myturn], '.', myturn);
|
||||
Lastscore[myturn] = *scr;
|
||||
*scr += inc;
|
||||
prpeg(*scr, PEG, myturn);
|
||||
refresh();
|
||||
}
|
||||
return (*scr >= glimit);
|
||||
}
|
||||
|
||||
/*
|
||||
* cdiscard -- the computer figures out what is the best discard for
|
||||
* the crib and puts the best two cards at the end
|
||||
*/
|
||||
|
||||
cdiscard( mycrib )
|
||||
|
||||
void cdiscard( mycrib )
|
||||
BOOLEAN mycrib;
|
||||
{
|
||||
CARD d[ CARDS ], h[ FULLHAND ], cb[ 2 ];
|
||||
@@ -217,7 +237,7 @@ cdiscard( mycrib )
|
||||
makedeck( d );
|
||||
nc = CARDS;
|
||||
for( i = 0; i < knownum; i++ ) { /* get all other cards */
|
||||
remove( known[i], d, nc-- );
|
||||
cremove( known[i], d, nc-- );
|
||||
}
|
||||
for( i = 0; i < 15; i++ ) sums[i] = 0L;
|
||||
ns = 0;
|
||||
@@ -226,8 +246,8 @@ cdiscard( mycrib )
|
||||
for( j = i + 1; j < FULLHAND; j++ ) {
|
||||
cb[1] = chand[j];
|
||||
for( k = 0; k < FULLHAND; k++ ) h[k] = chand[k];
|
||||
remove( chand[i], h, FULLHAND );
|
||||
remove( chand[j], h, FULLHAND - 1 );
|
||||
cremove( chand[i], h, FULLHAND );
|
||||
cremove( chand[j], h, FULLHAND - 1 );
|
||||
for( k = 0; k < nc; k++ ) {
|
||||
sums[ns] += scorehand( h, d[k], CINHAND, TRUE, FALSE );
|
||||
if( mycrib ) sums[ns] += adjust( cb, d[k] );
|
||||
@@ -239,20 +259,16 @@ cdiscard( mycrib )
|
||||
j = 0;
|
||||
for( i = 1; i < 15; i++ ) if( sums[i] > sums[j] ) j = i;
|
||||
for( k = 0; k < FULLHAND; k++ ) h[k] = chand[k];
|
||||
remove( h[ undo1[j] ], chand, FULLHAND );
|
||||
remove( h[ undo2[j] ], chand, FULLHAND - 1 );
|
||||
cremove( h[ undo1[j] ], chand, FULLHAND );
|
||||
cremove( h[ undo2[j] ], chand, FULLHAND - 1 );
|
||||
chand[4] = h[ undo1[j] ];
|
||||
chand[5] = h[ undo2[j] ];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* returns true if some card in hand can be played without exceeding 31
|
||||
*/
|
||||
|
||||
anymove( hand, n, sum )
|
||||
|
||||
BOOLEAN anymove( hand, n, sum )
|
||||
CARD hand[];
|
||||
int n;
|
||||
int sum;
|
||||
@@ -267,57 +283,10 @@ anymove( hand, n, sum )
|
||||
return( sum + VAL( j ) <= 31 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* anysumto returns the index (0 <= i < n) of the card in hand that brings
|
||||
* the s up to t, or -1 if there is none
|
||||
*/
|
||||
|
||||
anysumto( hand, n, s, t )
|
||||
|
||||
CARD hand[];
|
||||
int n;
|
||||
int s, t;
|
||||
{
|
||||
register int i;
|
||||
|
||||
for( i = 0; i < n; i++ ) {
|
||||
if( s + VAL( hand[i].rank ) == t ) return( i );
|
||||
}
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* return the number of cards in h having the given rank value
|
||||
*/
|
||||
|
||||
numofval( h, n, v )
|
||||
|
||||
CARD h[];
|
||||
int n;
|
||||
int v;
|
||||
{
|
||||
register int i, j;
|
||||
|
||||
j = 0;
|
||||
for( i = 0; i < n; i++ ) {
|
||||
if( VAL( h[i].rank ) == v ) ++j;
|
||||
}
|
||||
return( j );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* makeknown remembers all n cards in h for future recall
|
||||
*/
|
||||
|
||||
makeknown( h, n )
|
||||
|
||||
void makeknown( h, n )
|
||||
CARD h[];
|
||||
int n;
|
||||
{
|
||||
@@ -327,4 +296,3 @@ makeknown( h, n )
|
||||
known[ knownum++ ] = h[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,17 +3,6 @@
|
||||
* All rights reserved. The Berkeley software License Agreement
|
||||
* specifies the terms and conditions for redistribution.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
char copyright[] =
|
||||
"@(#) Copyright (c) 1980 Regents of the University of California.\n\
|
||||
All rights reserved.\n";
|
||||
#endif not lint
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)test.c 5.1 (Berkeley) 5/30/85";
|
||||
#endif not lint
|
||||
|
||||
#include <stdio.h>
|
||||
#include "deck.h"
|
||||
|
||||
@@ -34,7 +23,7 @@ main( argc, argv )
|
||||
int i, j, is, n, sum, sum2;
|
||||
CARD ic, jc;
|
||||
CARD d[ CARDS];
|
||||
extern char expl[];
|
||||
extern char explstr[];
|
||||
|
||||
printf( "Assuming cards are same suit\n" );
|
||||
if( argc == 2 ) {
|
||||
@@ -57,8 +46,8 @@ main( argc, argv )
|
||||
hand[1] = jc;
|
||||
for( k = 0; k < CARDS; k++ ) d[k] = deck[k];
|
||||
n = CARDS;
|
||||
remove( ic, d, n-- );
|
||||
remove( jc, d, n-- );
|
||||
cremove( ic, d, n-- );
|
||||
cremove( jc, d, n-- );
|
||||
sum = 0;
|
||||
sum2 = 0;
|
||||
for( k = 0; k < n - 1; k++ ) { /* 3rd card */
|
||||
@@ -90,7 +79,7 @@ main( argc, argv )
|
||||
hand[3].suit = 0;
|
||||
hand[4].suit = 0;
|
||||
printf("scorehand of hand = %d\n", scorehand(hand, hand[4], CINHAND, FALSE, TRUE));
|
||||
printf("\t%s\n", expl);
|
||||
printf("\t%s\n", explstr);
|
||||
hand[0].rank = 0;
|
||||
hand[1].rank = 1;
|
||||
hand[2].rank = 2;
|
||||
@@ -102,7 +91,7 @@ main( argc, argv )
|
||||
hand[3].suit = 0;
|
||||
hand[4].suit = 0;
|
||||
printf("scorehand of crib = %d\n", scorehand(hand, hand[4], CINHAND, TRUE, TRUE));
|
||||
printf("\t%s\n", expl);
|
||||
printf("\t%s\n", explstr);
|
||||
hand[0].rank = 0;
|
||||
hand[1].rank = 1;
|
||||
hand[2].rank = 2;
|
||||
@@ -114,7 +103,7 @@ main( argc, argv )
|
||||
hand[3].suit = 0;
|
||||
hand[4].suit = 1;
|
||||
printf("scorehand of hand = %d\n", scorehand(hand, hand[4], CINHAND, FALSE, TRUE));
|
||||
printf("\t%s\n", expl);
|
||||
printf("\t%s\n", explstr);
|
||||
hand[0].rank = 0;
|
||||
hand[1].rank = 1;
|
||||
hand[2].rank = 2;
|
||||
@@ -126,6 +115,6 @@ main( argc, argv )
|
||||
hand[3].suit = 0;
|
||||
hand[4].suit = 1;
|
||||
printf("scorehand of crib = %d\n", scorehand(hand, hand[4], CINHAND, TRUE, TRUE));
|
||||
printf("\t%s\n", expl);
|
||||
printf("\t%s\n", explstr);
|
||||
# endif
|
||||
}
|
||||
|
||||
1
src/games/fortune/.gitignore
vendored
Normal file
1
src/games/fortune/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
fortune
|
||||
@@ -1,72 +1,45 @@
|
||||
FORTUNES= scene obscene
|
||||
SOURCE= fortune.c strfile.h strfile.c rnd.c unstr.c $(FORTUNES)
|
||||
TFILES= Troff.mac Troff.sed Do_troff
|
||||
LIBDIR= /usr/games/lib
|
||||
BINDIR= /usr/games
|
||||
OWN= arnold
|
||||
GRP= arpa
|
||||
DEFS=
|
||||
SEPFLAG= -i
|
||||
CFLAGS= -O $(DEFS)
|
||||
SFLAGS= -r
|
||||
TDEV= -Pver
|
||||
TROFF= ditroff $(TDEV)
|
||||
DESTDIR=
|
||||
TOPSRC = $(shell cd ../../..; pwd)
|
||||
include $(TOPSRC)/target.mk
|
||||
#include $(TOPSRC)/cross.mk
|
||||
|
||||
all: fortune strfile unstr fortunes.dat
|
||||
CFLAGS += -O -Werror -Wall
|
||||
LIBS = -lc
|
||||
|
||||
fortune: fortune.o rnd.o
|
||||
$(CC) ${SEPFLAG} $(CFLAGS) -o fortune fortune.o rnd.o
|
||||
OBJS = fortune.o
|
||||
MAN = fortune.0
|
||||
MANSRC = fortune.6
|
||||
|
||||
strfile: strfile.o rnd.o
|
||||
$(CC) ${SEPFLAG} $(CFLAGS) -o strfile strfile.o rnd.o
|
||||
all: fortune $(MAN) fortunes.dat
|
||||
|
||||
unstr: unstr.o
|
||||
$(CC) ${SEPFLAG} $(CFLAGS) -o unstr unstr.o
|
||||
fortune: $(OBJS)
|
||||
$(CC) $(LDFLAGS) -o fortune.elf $(OBJS) $(LIBS)
|
||||
$(OBJDUMP) -S fortune.elf > fortune.dis
|
||||
$(SIZE) fortune.elf
|
||||
$(ELF2AOUT) fortune.elf $@ && rm fortune.elf
|
||||
|
||||
fortune.o strfile.o unstr.o: strfile.h
|
||||
strfile: strfile.o
|
||||
$(CC) $(LDFLAGS) -o strfile strfile.o
|
||||
|
||||
fortunes.dat: fortunes strfile
|
||||
./strfile $(SFLAGS) fortunes
|
||||
unstr: unstr.o
|
||||
$(CC) $(LDFLAGS) -o unstr unstr.o
|
||||
|
||||
fortunes: $(FORTUNES)
|
||||
cp scene fortunes
|
||||
echo "%-" >> fortunes
|
||||
cat obscene >> fortunes
|
||||
fortunes.dat: #fortunes strfile
|
||||
./strfile -r fortunes
|
||||
|
||||
lint:
|
||||
lint -hxb $(DEFS) fortune.c rnd.c 2>&1 > fortune.lint
|
||||
lint -hxb $(DEFS) strfile.c rnd.c 2>&1 > strfile.lint
|
||||
lint -hxb $(DEFS) unstr.c 2>&1 > unstr.lint
|
||||
fortunes: scene obscene
|
||||
cp scene fortunes
|
||||
echo "%-" >> fortunes
|
||||
cat obscene >> fortunes
|
||||
|
||||
install: all install.data
|
||||
install -s -m 4711 -o daemon fortune $(DESTDIR)$(BINDIR)
|
||||
$(MAN): $(MANSRC)
|
||||
$(MANROFF) $< > $@
|
||||
|
||||
install.data: fortunes.dat
|
||||
install -m 600 -o daemon fortunes.dat $(DESTDIR)$(LIBDIR)
|
||||
clean:
|
||||
rm -f *.o *.0 *.elf $(MAN) fortune strfile unstr fortunes *.elf *.dis tags *~
|
||||
|
||||
troff: troff.scene troff.obscene
|
||||
install: all
|
||||
install fortune $(DESTDIR)/games/
|
||||
cp $(MAN) $(DESTDIR)/share/man/cat6/
|
||||
cp fortunes.dat $(DESTDIR)/games/lib/
|
||||
|
||||
troff.scene:
|
||||
./Do_troff scene $(TROFF)
|
||||
|
||||
troff.obscene:
|
||||
./Do_troff obscene $(TROFF)
|
||||
|
||||
clean: sort.clean
|
||||
rm -f fortune fortunes fortunes.dat strfile unstr ? core *.o
|
||||
|
||||
sort: sort.scene sort.obscene
|
||||
|
||||
sort.scene: strfile unstr
|
||||
strfile -oi scene
|
||||
mv scene Oscene
|
||||
unstr -o scene
|
||||
|
||||
sort.obscene: strfile unstr
|
||||
strfile -oi obscene
|
||||
mv obscene Oobscene
|
||||
unstr -o obscene
|
||||
|
||||
sort.clean:
|
||||
rm -f Oscene Oobscene
|
||||
#$(OBJS): fortune.h
|
||||
|
||||
72
src/games/fortune/Makefile.orig
Normal file
72
src/games/fortune/Makefile.orig
Normal file
@@ -0,0 +1,72 @@
|
||||
FORTUNES= scene obscene
|
||||
SOURCE= fortune.c strfile.h strfile.c rnd.c unstr.c $(FORTUNES)
|
||||
TFILES= Troff.mac Troff.sed Do_troff
|
||||
LIBDIR= /usr/games/lib
|
||||
BINDIR= /usr/games
|
||||
OWN= arnold
|
||||
GRP= arpa
|
||||
DEFS=
|
||||
SEPFLAG= -i
|
||||
CFLAGS= -O $(DEFS)
|
||||
SFLAGS= -r
|
||||
TDEV= -Pver
|
||||
TROFF= ditroff $(TDEV)
|
||||
DESTDIR=
|
||||
|
||||
all: fortune strfile unstr fortunes.dat
|
||||
|
||||
fortune: fortune.o rnd.o
|
||||
$(CC) ${SEPFLAG} $(CFLAGS) -o fortune fortune.o rnd.o
|
||||
|
||||
strfile: strfile.o rnd.o
|
||||
$(CC) ${SEPFLAG} $(CFLAGS) -o strfile strfile.o rnd.o
|
||||
|
||||
unstr: unstr.o
|
||||
$(CC) ${SEPFLAG} $(CFLAGS) -o unstr unstr.o
|
||||
|
||||
fortune.o strfile.o unstr.o: strfile.h
|
||||
|
||||
fortunes.dat: fortunes strfile
|
||||
./strfile $(SFLAGS) fortunes
|
||||
|
||||
fortunes: $(FORTUNES)
|
||||
cp scene fortunes
|
||||
echo "%-" >> fortunes
|
||||
cat obscene >> fortunes
|
||||
|
||||
lint:
|
||||
lint -hxb $(DEFS) fortune.c rnd.c 2>&1 > fortune.lint
|
||||
lint -hxb $(DEFS) strfile.c rnd.c 2>&1 > strfile.lint
|
||||
lint -hxb $(DEFS) unstr.c 2>&1 > unstr.lint
|
||||
|
||||
install: all install.data
|
||||
install -s -m 4711 -o daemon fortune $(DESTDIR)$(BINDIR)
|
||||
|
||||
install.data: fortunes.dat
|
||||
install -m 600 -o daemon fortunes.dat $(DESTDIR)$(LIBDIR)
|
||||
|
||||
troff: troff.scene troff.obscene
|
||||
|
||||
troff.scene:
|
||||
./Do_troff scene $(TROFF)
|
||||
|
||||
troff.obscene:
|
||||
./Do_troff obscene $(TROFF)
|
||||
|
||||
clean: sort.clean
|
||||
rm -f fortune fortunes fortunes.dat strfile unstr ? core *.o
|
||||
|
||||
sort: sort.scene sort.obscene
|
||||
|
||||
sort.scene: strfile unstr
|
||||
strfile -oi scene
|
||||
mv scene Oscene
|
||||
unstr -o scene
|
||||
|
||||
sort.obscene: strfile unstr
|
||||
strfile -oi obscene
|
||||
mv obscene Oobscene
|
||||
unstr -o obscene
|
||||
|
||||
sort.clean:
|
||||
rm -f Oscene Oobscene
|
||||
@@ -40,8 +40,8 @@ often used for potentially offensive ones.
|
||||
.B \-a
|
||||
Choose from either list of adages.
|
||||
.PP
|
||||
..The user may specify a file of adages.
|
||||
..This file must be created by strfile(6),
|
||||
.. The user may specify a file of adages.
|
||||
.. This file must be created by strfile(6),
|
||||
..and be given by the user as
|
||||
...it file.
|
||||
..Only one such file may be named,
|
||||
|
||||
@@ -1,21 +1,31 @@
|
||||
/* $Header: fortune.c,v 1.10 85/11/01 15:19:49 arnold Exp $ */
|
||||
|
||||
# include <sys/types.h>
|
||||
# include <stdio.h>
|
||||
# include <sys/file.h>
|
||||
# include "strfile.h"
|
||||
#include <sys/types.h>
|
||||
#ifdef CROSS
|
||||
# include </usr/include/stdio.h>
|
||||
#else
|
||||
# include <stdio.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <sys/file.h>
|
||||
#include "strfile.h"
|
||||
|
||||
# define TRUE 1
|
||||
# define FALSE 0
|
||||
# define bool short
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
# define MINW 6 /* minimum wait if desired */
|
||||
# define CPERS 20 /* # of chars for each sec */
|
||||
# define SLEN 160 /* # of chars in short fortune */
|
||||
#define MINW 6 /* minimum wait if desired */
|
||||
#define CPERS 20 /* # of chars for each sec */
|
||||
#define SLEN 160 /* # of chars in short fortune */
|
||||
|
||||
# define FORTFILE "/usr/games/lib/fortunes.dat"
|
||||
#ifdef CROSS
|
||||
# define FORTFILE "/usr/local/games/fortunes.dat"
|
||||
#else
|
||||
# define FORTFILE "/games/lib/fortunes.dat"
|
||||
#endif
|
||||
|
||||
bool Wflag = FALSE, /* wait desired after fortune */
|
||||
int Wflag = FALSE, /* wait desired after fortune */
|
||||
Sflag = FALSE, /* short fortune desired */
|
||||
Lflag = FALSE, /* long fortune desired */
|
||||
Oflag = FALSE, /* offensive fortunes only */
|
||||
@@ -41,70 +51,11 @@ FILE *Inf; /* input file */
|
||||
|
||||
STRFILE Tbl; /* input table */
|
||||
|
||||
time_t time();
|
||||
|
||||
main(ac, av)
|
||||
int ac;
|
||||
char *av[];
|
||||
{
|
||||
register char c;
|
||||
register int nchar = 0;
|
||||
register int i;
|
||||
|
||||
getargs(ac, av);
|
||||
if ((Inf = fopen(Fortfile, "r+")) == NULL) {
|
||||
perror(Fortfile);
|
||||
exit(-1);
|
||||
}
|
||||
fread((char *) &Tbl, sizeof Tbl, 1, Inf); /* NOSTRICT */
|
||||
if (Tbl.str_longlen <= SLEN && Lflag) {
|
||||
puts("Sorry, no long strings in this file");
|
||||
exit(0);
|
||||
}
|
||||
if (Tbl.str_shortlen > SLEN && Sflag) {
|
||||
puts("Sorry, no short strings in this file");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* initialize the pointer to the first -o fortune if need be.
|
||||
*/
|
||||
if (Tbl.str_delims[2] == 0)
|
||||
Tbl.str_delims[2] = Tbl.str_delims[0];
|
||||
|
||||
do {
|
||||
getfort();
|
||||
} while ((Sflag && !is_short()) || (Lflag && !is_long()));
|
||||
|
||||
fseek(Inf, Seekpts[0], 0);
|
||||
while (c = getc(Inf)) {
|
||||
nchar++;
|
||||
putchar(c);
|
||||
}
|
||||
fflush(stdout);
|
||||
fseek(Inf, 0L, 0);
|
||||
#ifdef LOCK_EX
|
||||
/*
|
||||
* if we can, we exclusive lock, but since it isn't very
|
||||
* important, we just punt if we don't have easy locking
|
||||
* available.
|
||||
*/
|
||||
flock(fileno(Inf), LOCK_EX);
|
||||
#endif LOCK_EX
|
||||
fwrite(&Tbl, 1, sizeof Tbl, Inf);
|
||||
#ifdef LOCK_EX
|
||||
flock(fileno(Inf), LOCK_UN);
|
||||
#endif LOCK_EX
|
||||
if (Wflag)
|
||||
sleep(max((int) nchar / CPERS, MINW));
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* is_short:
|
||||
* Return TRUE if fortune is "short".
|
||||
*/
|
||||
is_short()
|
||||
int is_short()
|
||||
{
|
||||
register int nchar;
|
||||
|
||||
@@ -121,7 +72,7 @@ is_short()
|
||||
* is_long:
|
||||
* Return TRUE if fortune is "long".
|
||||
*/
|
||||
is_long()
|
||||
int is_long()
|
||||
{
|
||||
register int nchar;
|
||||
|
||||
@@ -137,9 +88,7 @@ is_long()
|
||||
/*
|
||||
* This routine evaluates the arguments on the command line
|
||||
*/
|
||||
getargs(ac, av)
|
||||
register int ac;
|
||||
register char *av[];
|
||||
void getargs(int ac, char **av)
|
||||
{
|
||||
register int i;
|
||||
register char *sp;
|
||||
@@ -182,9 +131,9 @@ register char *av[];
|
||||
* few numbers to avoid any non-
|
||||
* randomness in startup
|
||||
*/
|
||||
srnd(time(NULL) + getpid());
|
||||
srandom(time(NULL) + getpid());
|
||||
for (j = 0; j < 20; j++)
|
||||
(void) rnd(100);
|
||||
(void) random();
|
||||
break;
|
||||
default:
|
||||
printf("unknown flag: '%c'\n", *sp);
|
||||
@@ -202,7 +151,7 @@ register char *av[];
|
||||
* getfort:
|
||||
* Get the fortune data file's seek pointer for the next fortune.
|
||||
*/
|
||||
getfort()
|
||||
void getfort()
|
||||
{
|
||||
register int fortune;
|
||||
|
||||
@@ -216,7 +165,7 @@ getfort()
|
||||
Tbl.str_delims[2] = Tbl.str_delims[0];
|
||||
|
||||
if (Aflag) {
|
||||
if (rnd(Tbl.str_numstr) < Tbl.str_delims[0])
|
||||
if (random() % Tbl.str_numstr < Tbl.str_delims[0])
|
||||
fortune = Tbl.str_delims[1]++;
|
||||
else
|
||||
fortune = Tbl.str_delims[2]++;
|
||||
@@ -227,11 +176,70 @@ getfort()
|
||||
fortune = Tbl.str_delims[1]++;
|
||||
|
||||
fseek(Inf, (long)(sizeof Seekpts[0]) * fortune + sizeof Tbl, 0);
|
||||
fread((char *) Seekpts, (sizeof Seekpts[0]), 2, Inf);
|
||||
if (fread((char *) Seekpts, (sizeof Seekpts[0]), 2, Inf) != 2) {
|
||||
puts("Error reading data from strings file");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
max(i, j)
|
||||
register int i, j;
|
||||
int max(int i, int j)
|
||||
{
|
||||
return (i >= j ? i : j);
|
||||
}
|
||||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
register char c;
|
||||
register int nchar = 0;
|
||||
|
||||
getargs(ac, av);
|
||||
if ((Inf = fopen(Fortfile, "r+")) == NULL) {
|
||||
perror(Fortfile);
|
||||
exit(-1);
|
||||
}
|
||||
if (fread((char *) &Tbl, sizeof Tbl, 1, Inf) != 1) {
|
||||
puts("Error reading strings file");
|
||||
exit(0);
|
||||
}
|
||||
if (Tbl.str_longlen <= SLEN && Lflag) {
|
||||
puts("Sorry, no long strings in this file");
|
||||
exit(0);
|
||||
}
|
||||
if (Tbl.str_shortlen > SLEN && Sflag) {
|
||||
puts("Sorry, no short strings in this file");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* initialize the pointer to the first -o fortune if need be.
|
||||
*/
|
||||
if (Tbl.str_delims[2] == 0)
|
||||
Tbl.str_delims[2] = Tbl.str_delims[0];
|
||||
|
||||
do {
|
||||
getfort();
|
||||
} while ((Sflag && !is_short()) || (Lflag && !is_long()));
|
||||
|
||||
fseek(Inf, Seekpts[0], 0);
|
||||
while ((c = getc(Inf))) {
|
||||
nchar++;
|
||||
putchar(c);
|
||||
}
|
||||
fflush(stdout);
|
||||
fseek(Inf, 0L, 0);
|
||||
#ifdef LOCK_EX
|
||||
/*
|
||||
* if we can, we exclusive lock, but since it isn't very
|
||||
* important, we just punt if we don't have easy locking
|
||||
* available.
|
||||
*/
|
||||
flock(fileno(Inf), LOCK_EX);
|
||||
#endif
|
||||
fwrite(&Tbl, 1, sizeof Tbl, Inf);
|
||||
#ifdef LOCK_EX
|
||||
flock(fileno(Inf), LOCK_UN);
|
||||
#endif
|
||||
if (Wflag)
|
||||
sleep(max((int) nchar / CPERS, MINW));
|
||||
exit(0);
|
||||
}
|
||||
|
||||
BIN
src/games/fortune/fortunes.dat
Normal file
BIN
src/games/fortune/fortunes.dat
Normal file
Binary file not shown.
@@ -1,13 +1,14 @@
|
||||
/*
|
||||
* code for when the good (berkeley) random number generator is around
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
|
||||
rnd(num)
|
||||
int rnd(int num)
|
||||
{
|
||||
return (random() % num);
|
||||
}
|
||||
|
||||
srnd(num)
|
||||
void srnd(int num)
|
||||
{
|
||||
srandom(num);
|
||||
}
|
||||
@@ -38,7 +39,7 @@ static char sccsid[] = "@(#)random.c 4.2 (Berkeley) 83/01/02";
|
||||
* zeroeth element of the array is the type of R.N.G. being used (small
|
||||
* integer); the remainder of the array is the state information for the
|
||||
* R.N.G. Thus, 32 bytes of state information will give 7 longs worth of
|
||||
* state information, which will allow a degree seven polynomial. (Note: the
|
||||
* state information, which will allow a degree seven polynomial. (Note: the
|
||||
* zeroeth word of state information also has some other information stored
|
||||
* in it -- see setstate() for details).
|
||||
* The random number generation technique is a linear feedback shift register
|
||||
@@ -120,13 +121,13 @@ static int seps[ MAX_TYPES ] = { SEP_0, SEP_1, SEP_2,
|
||||
*/
|
||||
|
||||
static long randtbl[ DEG_3 + 1 ] = { TYPE_3,
|
||||
0x9a319039, 0x32d9c024, 0x9b663182, 0x5da1f342,
|
||||
0xde3b81e0, 0xdf0a6fb5, 0xf103bc02, 0x48f340fb,
|
||||
0x7449e56b, 0xbeb1dbb0, 0xab5c5918, 0x946554fd,
|
||||
0x8c2e680f, 0xeb3d799f, 0xb11ee0b7, 0x2d436b86,
|
||||
0xda672e2a, 0x1588ca88, 0xe369735d, 0x904f35f7,
|
||||
0xd7158fd6, 0x6fa6f051, 0x616e6b96, 0xac94efdc,
|
||||
0x36413f93, 0xc622c298, 0xf5a42ab8, 0x8a88d77b,
|
||||
0x9a319039, 0x32d9c024, 0x9b663182, 0x5da1f342,
|
||||
0xde3b81e0, 0xdf0a6fb5, 0xf103bc02, 0x48f340fb,
|
||||
0x7449e56b, 0xbeb1dbb0, 0xab5c5918, 0x946554fd,
|
||||
0x8c2e680f, 0xeb3d799f, 0xb11ee0b7, 0x2d436b86,
|
||||
0xda672e2a, 0x1588ca88, 0xe369735d, 0x904f35f7,
|
||||
0xd7158fd6, 0x6fa6f051, 0x616e6b96, 0xac94efdc,
|
||||
0x36413f93, 0xc622c298, 0xf5a42ab8, 0x8a88d77b,
|
||||
0xf5ad9d0e, 0x8999220b, 0x27fb47b9 };
|
||||
|
||||
/*
|
||||
@@ -344,7 +345,7 @@ long
|
||||
random()
|
||||
{
|
||||
long i;
|
||||
|
||||
|
||||
if( rand_type == TYPE_0 ) {
|
||||
i = state[0] = ( state[0]*1103515245 + 12345 )&0x7fffffff;
|
||||
}
|
||||
@@ -362,4 +363,4 @@ random()
|
||||
return( i );
|
||||
}
|
||||
|
||||
#endif NO_RANDOM
|
||||
#endif /* NO_RANDOM */
|
||||
|
||||
@@ -1,6 +1,16 @@
|
||||
# include <stdio.h>
|
||||
# include <ctype.h>
|
||||
# include "strfile.h"
|
||||
#include <sys/types.h>
|
||||
#ifdef CROSS
|
||||
# include </usr/include/stdio.h>
|
||||
# include </usr/include/ctype.h>
|
||||
#else
|
||||
# include <stdio.h>
|
||||
# include <ctype.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include "strfile.h"
|
||||
|
||||
/*
|
||||
* This program takes a file composed of strings seperated by
|
||||
@@ -18,7 +28,7 @@
|
||||
* the run.
|
||||
* v - Verbose. Give summary of data processed. (Default)
|
||||
* o - order the strings in alphabetic order
|
||||
* i - if ordering, ignore case
|
||||
* i - if ordering, ignore case
|
||||
* r - randomize the order of the strings
|
||||
*
|
||||
* Ken Arnold Sept. 7, 1978 --
|
||||
@@ -31,10 +41,10 @@
|
||||
* Added ordering options.
|
||||
*/
|
||||
|
||||
# define TRUE 1
|
||||
# define FALSE 0
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
# define DELIM_CH '-'
|
||||
#define DELIM_CH '-'
|
||||
|
||||
typedef struct {
|
||||
char first;
|
||||
@@ -71,13 +81,187 @@ STRFILE Tbl; /* statistics table */
|
||||
|
||||
STR *Firstch; /* first chars of each string */
|
||||
|
||||
char *fgets(), *malloc(), *strcpy(), *strcat();
|
||||
/*
|
||||
* This routine evaluates arguments from the command line
|
||||
*/
|
||||
void getargs(int ac, char **av)
|
||||
{
|
||||
register char *sp;
|
||||
register int i;
|
||||
register int bad, j;
|
||||
|
||||
long ftell();
|
||||
bad = 0;
|
||||
for (i = 1; i < ac; i++)
|
||||
if (*av[i] == '-' && av[i][1]) {
|
||||
for (sp = &av[i][1]; *sp; sp++)
|
||||
switch (*sp) {
|
||||
case 'c': /* new delimiting char */
|
||||
if ((Delimch = *++sp) == '\0') {
|
||||
--sp;
|
||||
Delimch = *av[++i];
|
||||
}
|
||||
if (Delimch <= 0 || Delimch > '~' ||
|
||||
Delimch == DELIM_CH) {
|
||||
printf("bad delimiting character: '\\%o\n'",
|
||||
Delimch);
|
||||
bad++;
|
||||
}
|
||||
break;
|
||||
case 's': /* silent */
|
||||
Sflag++;
|
||||
break;
|
||||
case 'v': /* verbose */
|
||||
Sflag = 0;
|
||||
break;
|
||||
case 'o': /* order strings */
|
||||
Oflag++;
|
||||
break;
|
||||
case 'i': /* ignore case in ordering */
|
||||
Iflag++;
|
||||
break;
|
||||
case 'r': /* ignore case in ordering */
|
||||
Rflag++;
|
||||
break;
|
||||
default: /* unknown flag */
|
||||
bad++;
|
||||
printf("bad flag: '%c'\n", *sp);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (*av[i] == '-') {
|
||||
for (j = 0; Usage[j]; j++)
|
||||
puts(Usage[j]);
|
||||
exit(0);
|
||||
}
|
||||
else if (Infile)
|
||||
(void) strcpy(Outfile, av[i]);
|
||||
else
|
||||
Infile = av[i];
|
||||
if (!Infile) {
|
||||
bad++;
|
||||
puts("No input file name");
|
||||
}
|
||||
if (*Outfile == '\0' && !bad) {
|
||||
(void) strcpy(Outfile, Infile);
|
||||
(void) strcat(Outfile, ".dat");
|
||||
}
|
||||
if (bad) {
|
||||
puts("use \"strfile -\" to get usage");
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
main(ac, av)
|
||||
int ac;
|
||||
char **av;
|
||||
/*
|
||||
* do_order:
|
||||
* Order the strings alphabetically (possibly ignoring case).
|
||||
*/
|
||||
void do_order(long *seekpts, FILE *outf)
|
||||
{
|
||||
register int i;
|
||||
register long *lp;
|
||||
register STR *fp;
|
||||
extern int cmp_str();
|
||||
|
||||
(void) fflush(outf);
|
||||
Sort_1 = fopen(Outfile, "r");
|
||||
Sort_2 = fopen(Outfile, "r");
|
||||
Seekpts = seekpts;
|
||||
qsort((char *) Firstch, Tbl.str_numstr, sizeof *Firstch, cmp_str);
|
||||
i = Tbl.str_numstr;
|
||||
lp = seekpts;
|
||||
fp = Firstch;
|
||||
while (i--)
|
||||
*lp++ = fp++->pos;
|
||||
(void) fclose(Sort_1);
|
||||
(void) fclose(Sort_2);
|
||||
Tbl.str_flags |= STR_ORDERED;
|
||||
}
|
||||
|
||||
/*
|
||||
* cmp_str:
|
||||
* Compare two strings in the file
|
||||
*/
|
||||
int cmp_str(STR *p1, STR *p2)
|
||||
{
|
||||
register int c1, c2;
|
||||
|
||||
c1 = p1->first;
|
||||
c2 = p2->first;
|
||||
if (c1 != c2)
|
||||
return c1 - c2;
|
||||
|
||||
(void) fseek(Sort_1, p1->pos, 0);
|
||||
(void) fseek(Sort_2, p2->pos, 0);
|
||||
|
||||
while (!isalnum(c1 = getc(Sort_1)) && c1 != '\0')
|
||||
continue;
|
||||
while (!isalnum(c2 = getc(Sort_2)) && c2 != '\0')
|
||||
continue;
|
||||
|
||||
while (c1 != '\0' && c2 != '\0') {
|
||||
if (Iflag) {
|
||||
if (isupper(c1))
|
||||
c1 = tolower(c1);
|
||||
if (isupper(c2))
|
||||
c2 = tolower(c2);
|
||||
}
|
||||
if (c1 != c2)
|
||||
return c1 - c2;
|
||||
c1 = getc(Sort_1);
|
||||
c2 = getc(Sort_2);
|
||||
}
|
||||
return c1 - c2;
|
||||
}
|
||||
|
||||
/*
|
||||
* randomize:
|
||||
* Randomize the order of the string table. We must be careful
|
||||
* not to randomize across delimiter boundaries. All
|
||||
* randomization is done within each block.
|
||||
*/
|
||||
void randomize(long *seekpts)
|
||||
{
|
||||
register int cnt, i, j, start;
|
||||
register long tmp;
|
||||
register long *origsp;
|
||||
|
||||
Tbl.str_flags |= STR_RANDOM;
|
||||
srandom(time((long *) NULL) + getpid());
|
||||
origsp = seekpts;
|
||||
for (j = 0; j <= Delim; j++) {
|
||||
|
||||
/*
|
||||
* get the starting place for the block
|
||||
*/
|
||||
|
||||
if (j == 0)
|
||||
start = 0;
|
||||
else
|
||||
start = Tbl.str_delims[j - 1];
|
||||
|
||||
/*
|
||||
* get the ending point
|
||||
*/
|
||||
|
||||
if (j == Delim)
|
||||
cnt = Tbl.str_numstr;
|
||||
else
|
||||
cnt = Tbl.str_delims[j];
|
||||
|
||||
/*
|
||||
* move things around randomly
|
||||
*/
|
||||
|
||||
for (seekpts = &origsp[start]; cnt > start; cnt--, seekpts++) {
|
||||
i = random() % (cnt - start);
|
||||
tmp = seekpts[0];
|
||||
seekpts[0] = seekpts[i];
|
||||
seekpts[i] = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
register char *sp, dc;
|
||||
register long *lp;
|
||||
@@ -206,189 +390,3 @@ char **av;
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine evaluates arguments from the command line
|
||||
*/
|
||||
getargs(ac, av)
|
||||
register int ac;
|
||||
register char **av;
|
||||
{
|
||||
register char *sp;
|
||||
register int i;
|
||||
register int bad, j;
|
||||
|
||||
bad = 0;
|
||||
for (i = 1; i < ac; i++)
|
||||
if (*av[i] == '-' && av[i][1]) {
|
||||
for (sp = &av[i][1]; *sp; sp++)
|
||||
switch (*sp) {
|
||||
case 'c': /* new delimiting char */
|
||||
if ((Delimch = *++sp) == '\0') {
|
||||
--sp;
|
||||
Delimch = *av[++i];
|
||||
}
|
||||
if (Delimch <= 0 || Delimch > '~' ||
|
||||
Delimch == DELIM_CH) {
|
||||
printf("bad delimiting character: '\\%o\n'",
|
||||
Delimch);
|
||||
bad++;
|
||||
}
|
||||
break;
|
||||
case 's': /* silent */
|
||||
Sflag++;
|
||||
break;
|
||||
case 'v': /* verbose */
|
||||
Sflag = 0;
|
||||
break;
|
||||
case 'o': /* order strings */
|
||||
Oflag++;
|
||||
break;
|
||||
case 'i': /* ignore case in ordering */
|
||||
Iflag++;
|
||||
break;
|
||||
case 'r': /* ignore case in ordering */
|
||||
Rflag++;
|
||||
break;
|
||||
default: /* unknown flag */
|
||||
bad++;
|
||||
printf("bad flag: '%c'\n", *sp);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (*av[i] == '-') {
|
||||
for (j = 0; Usage[j]; j++)
|
||||
puts(Usage[j]);
|
||||
exit(0);
|
||||
}
|
||||
else if (Infile)
|
||||
(void) strcpy(Outfile, av[i]);
|
||||
else
|
||||
Infile = av[i];
|
||||
if (!Infile) {
|
||||
bad++;
|
||||
puts("No input file name");
|
||||
}
|
||||
if (*Outfile == '\0' && !bad) {
|
||||
(void) strcpy(Outfile, Infile);
|
||||
(void) strcat(Outfile, ".dat");
|
||||
}
|
||||
if (bad) {
|
||||
puts("use \"strfile -\" to get usage");
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* do_order:
|
||||
* Order the strings alphabetically (possibly ignoring case).
|
||||
*/
|
||||
do_order(seekpts, outf)
|
||||
long *seekpts;
|
||||
FILE *outf;
|
||||
{
|
||||
register int i;
|
||||
register long *lp;
|
||||
register STR *fp;
|
||||
extern int cmp_str();
|
||||
|
||||
(void) fflush(outf);
|
||||
Sort_1 = fopen(Outfile, "r");
|
||||
Sort_2 = fopen(Outfile, "r");
|
||||
Seekpts = seekpts;
|
||||
qsort((char *) Firstch, Tbl.str_numstr, sizeof *Firstch, cmp_str);
|
||||
i = Tbl.str_numstr;
|
||||
lp = seekpts;
|
||||
fp = Firstch;
|
||||
while (i--)
|
||||
*lp++ = fp++->pos;
|
||||
(void) fclose(Sort_1);
|
||||
(void) fclose(Sort_2);
|
||||
Tbl.str_flags |= STR_ORDERED;
|
||||
}
|
||||
|
||||
/*
|
||||
* cmp_str:
|
||||
* Compare two strings in the file
|
||||
*/
|
||||
cmp_str(p1, p2)
|
||||
STR *p1, *p2;
|
||||
{
|
||||
register int c1, c2;
|
||||
|
||||
c1 = p1->first;
|
||||
c2 = p2->first;
|
||||
if (c1 != c2)
|
||||
return c1 - c2;
|
||||
|
||||
(void) fseek(Sort_1, p1->pos, 0);
|
||||
(void) fseek(Sort_2, p2->pos, 0);
|
||||
|
||||
while (!isalnum(c1 = getc(Sort_1)) && c1 != '\0')
|
||||
continue;
|
||||
while (!isalnum(c2 = getc(Sort_2)) && c2 != '\0')
|
||||
continue;
|
||||
|
||||
while (c1 != '\0' && c2 != '\0') {
|
||||
if (Iflag) {
|
||||
if (isupper(c1))
|
||||
c1 = tolower(c1);
|
||||
if (isupper(c2))
|
||||
c2 = tolower(c2);
|
||||
}
|
||||
if (c1 != c2)
|
||||
return c1 - c2;
|
||||
c1 = getc(Sort_1);
|
||||
c2 = getc(Sort_2);
|
||||
}
|
||||
return c1 - c2;
|
||||
}
|
||||
|
||||
/*
|
||||
* randomize:
|
||||
* Randomize the order of the string table. We must be careful
|
||||
* not to randomize across delimiter boundaries. All
|
||||
* randomization is done within each block.
|
||||
*/
|
||||
randomize(seekpts)
|
||||
register long *seekpts;
|
||||
{
|
||||
register int cnt, i, j, start;
|
||||
register long tmp;
|
||||
register long *origsp;
|
||||
|
||||
Tbl.str_flags |= STR_RANDOM;
|
||||
srnd(time((long *) NULL) + getpid());
|
||||
origsp = seekpts;
|
||||
for (j = 0; j <= Delim; j++) {
|
||||
|
||||
/*
|
||||
* get the starting place for the block
|
||||
*/
|
||||
|
||||
if (j == 0)
|
||||
start = 0;
|
||||
else
|
||||
start = Tbl.str_delims[j - 1];
|
||||
|
||||
/*
|
||||
* get the ending point
|
||||
*/
|
||||
|
||||
if (j == Delim)
|
||||
cnt = Tbl.str_numstr;
|
||||
else
|
||||
cnt = Tbl.str_delims[j];
|
||||
|
||||
/*
|
||||
* move things around randomly
|
||||
*/
|
||||
|
||||
for (seekpts = &origsp[start]; cnt > start; cnt--, seekpts++) {
|
||||
i = rnd(cnt - start);
|
||||
tmp = seekpts[0];
|
||||
seekpts[0] = seekpts[i];
|
||||
seekpts[i] = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1
src/games/hangman/.gitignore
vendored
Normal file
1
src/games/hangman/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
hangman
|
||||
@@ -1,22 +1,28 @@
|
||||
OBJS= endgame.o extern.o getguess.o getword.o main.o playgame.o \
|
||||
prdata.o prman.o prword.o setup.o
|
||||
CFILES= endgame.c extern.c getguess.c getword.c main.c playgame.c \
|
||||
prdata.c prman.c prword.c setup.c
|
||||
HDRS= hangman.h
|
||||
CFLAGS= -O
|
||||
LDFLAGS=
|
||||
SEPFLAG= -i
|
||||
TOPSRC = $(shell cd ../../..; pwd)
|
||||
include $(TOPSRC)/target.mk
|
||||
#include $(TOPSRC)/cross.mk
|
||||
|
||||
all: hangman
|
||||
CFLAGS += -Werror -Wall
|
||||
|
||||
tags: $(HDRS) $(CFILES)
|
||||
ctags $(HDRS) $(CFILES)
|
||||
OBJS = endgame.o extern.o getguess.o getword.o main.o playgame.o \
|
||||
prdata.o prman.o prword.o setup.o
|
||||
MAN = hangman.0
|
||||
LIBS = -lcurses -ltermcap -lc
|
||||
|
||||
install: hangman
|
||||
install -s hangman $(DESTDIR)/usr/games/hangman
|
||||
|
||||
hangman: $(OBJS)
|
||||
$(CC) ${SEPFLAG} $(LDFLAGS) -o hangman $(OBJS) -lcurses -ltermlib
|
||||
all: hangman $(MAN)
|
||||
|
||||
hangman: $(OBJS)
|
||||
$(CC) $(LDFLAGS) -o $@.elf $(OBJS) $(LIBS)
|
||||
$(OBJDUMP) -S $@.elf > $@.dis
|
||||
$(SIZE) $@.elf
|
||||
$(ELF2AOUT) $@.elf $@ && rm $@.elf
|
||||
|
||||
$(MAN): hangman.6
|
||||
nroff -man $< > $@
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) hangman ? core
|
||||
rm -f *.o core hangman *.0 *.dis
|
||||
|
||||
install: all
|
||||
install hangman $(DESTDIR)/games/
|
||||
install -m 644 $(MAN) $(DESTDIR)/share/man/cat6/
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
# include "hangman.h"
|
||||
#include "hangman.h"
|
||||
|
||||
/*
|
||||
* endgame:
|
||||
* Do what's necessary at the end of the game
|
||||
*/
|
||||
void
|
||||
endgame()
|
||||
{
|
||||
register char ch;
|
||||
@@ -24,7 +25,7 @@ endgame()
|
||||
leaveok(stdscr, FALSE);
|
||||
refresh();
|
||||
if ((ch = readch()) == 'n')
|
||||
die();
|
||||
die(0);
|
||||
else if (ch == 'y')
|
||||
break;
|
||||
mvaddstr(MESGY + 2, MESGX, "Please type 'y' or 'n'");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# include "hangman.h"
|
||||
#include "hangman.h"
|
||||
|
||||
bool Guessed[26];
|
||||
|
||||
|
||||
@@ -1,9 +1,41 @@
|
||||
# include "hangman.h"
|
||||
#include <unistd.h>
|
||||
#include "hangman.h"
|
||||
|
||||
#ifndef CTRL
|
||||
# define CTRL(c) (c & 037)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* readch;
|
||||
* Read a character from the input
|
||||
*/
|
||||
int
|
||||
readch()
|
||||
{
|
||||
register int cnt;
|
||||
auto char ch;
|
||||
|
||||
cnt = 0;
|
||||
for (;;) {
|
||||
if (read(0, &ch, sizeof ch) <= 0)
|
||||
{
|
||||
if (++cnt > 100)
|
||||
die(0);
|
||||
}
|
||||
else if (ch == CTRL('L')) {
|
||||
wrefresh(curscr);
|
||||
mvcur(0, 0, curscr->_cury, curscr->_curx);
|
||||
}
|
||||
else
|
||||
return ch;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* getguess:
|
||||
* Get another guess
|
||||
*/
|
||||
void
|
||||
getguess()
|
||||
{
|
||||
register int i;
|
||||
@@ -23,8 +55,8 @@ getguess()
|
||||
else
|
||||
break;
|
||||
}
|
||||
else if (ch == CTRL(D))
|
||||
die();
|
||||
else if (ch == CTRL('D'))
|
||||
die(0);
|
||||
else
|
||||
mvprintw(MESGY, MESGX, "Not a valid guess: '%s'",
|
||||
unctrl(ch));
|
||||
@@ -43,28 +75,3 @@ getguess()
|
||||
if (!correct)
|
||||
Errors++;
|
||||
}
|
||||
|
||||
/*
|
||||
* readch;
|
||||
* Read a character from the input
|
||||
*/
|
||||
readch()
|
||||
{
|
||||
register int cnt, r;
|
||||
auto char ch;
|
||||
|
||||
cnt = 0;
|
||||
for (;;) {
|
||||
if (read(0, &ch, sizeof ch) <= 0)
|
||||
{
|
||||
if (++cnt > 100)
|
||||
die();
|
||||
}
|
||||
else if (ch == CTRL(L)) {
|
||||
wrefresh(curscr);
|
||||
mvcur(0, 0, curscr->_cury, curscr->_curx);
|
||||
}
|
||||
else
|
||||
return ch;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,26 @@
|
||||
# include "hangman.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "hangman.h"
|
||||
|
||||
# if pdp11
|
||||
# define RN (((off_t) rand() << 16) | (off_t) rand())
|
||||
# else
|
||||
# define RN rand()
|
||||
# endif
|
||||
/*
|
||||
* abs:
|
||||
* Return the absolute value of an integer
|
||||
*/
|
||||
off_t
|
||||
offabs(i)
|
||||
off_t i;
|
||||
{
|
||||
if (i < 0)
|
||||
return -(off_t) i;
|
||||
else
|
||||
return (off_t) i;
|
||||
}
|
||||
|
||||
/*
|
||||
* getword:
|
||||
* Get a valid word out of the dictionary file
|
||||
*/
|
||||
void
|
||||
getword()
|
||||
{
|
||||
register FILE *inf;
|
||||
@@ -17,7 +28,7 @@ getword()
|
||||
|
||||
inf = Dict;
|
||||
for (;;) {
|
||||
fseek(inf, abs(RN % Dict_size), 0);
|
||||
fseek(inf, offabs(random() % Dict_size), 0);
|
||||
if (fgets(Word, BUFSIZ, inf) == NULL)
|
||||
continue;
|
||||
if (fgets(Word, BUFSIZ, inf) == NULL)
|
||||
@@ -39,17 +50,3 @@ cont: ;
|
||||
}
|
||||
*gp = '\0';
|
||||
}
|
||||
|
||||
/*
|
||||
* abs:
|
||||
* Return the absolute value of an integer
|
||||
*/
|
||||
off_t
|
||||
abs(i)
|
||||
off_t i;
|
||||
{
|
||||
if (i < 0)
|
||||
return -(off_t) i;
|
||||
else
|
||||
return (off_t) i;
|
||||
}
|
||||
|
||||
@@ -1,26 +1,30 @@
|
||||
# include <curses.h>
|
||||
# include <sys/types.h>
|
||||
# include <sys/stat.h>
|
||||
# include <ctype.h>
|
||||
# include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <curses.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <signal.h>
|
||||
|
||||
# define MINLEN 6
|
||||
# define MAXERRS 7
|
||||
# define DICT "/usr/dict/words"
|
||||
|
||||
# define MESGY 12
|
||||
# define MESGX 0
|
||||
# define PROMPTY 11
|
||||
# define PROMPTX 0
|
||||
# define KNOWNY 10
|
||||
# define KNOWNX 1
|
||||
# define NUMBERY 4
|
||||
# define NUMBERX (COLS - 1 - 26)
|
||||
# define AVGY 5
|
||||
# define AVGX (COLS - 1 - 26)
|
||||
# define GUESSY 2
|
||||
# define GUESSX (COLS - 1 - 26)
|
||||
#define MINLEN 6
|
||||
#define MAXERRS 7
|
||||
#ifdef CROSS
|
||||
# define DICT "/usr/local/share/dict/words"
|
||||
#else
|
||||
# define DICT "/share/dict/words"
|
||||
#endif
|
||||
|
||||
#define MESGY 12
|
||||
#define MESGX 0
|
||||
#define PROMPTY 11
|
||||
#define PROMPTX 0
|
||||
#define KNOWNY 10
|
||||
#define KNOWNX 1
|
||||
#define NUMBERY 4
|
||||
#define NUMBERX (COLS - 1 - 26)
|
||||
#define AVGY 5
|
||||
#define AVGX (COLS - 1 - 26)
|
||||
#define GUESSY 2
|
||||
#define GUESSX (COLS - 1 - 26)
|
||||
|
||||
typedef struct {
|
||||
short y, x;
|
||||
@@ -41,6 +45,15 @@ extern FILE *Dict;
|
||||
|
||||
extern off_t Dict_size;
|
||||
|
||||
int die();
|
||||
void die(int);
|
||||
|
||||
off_t abs();
|
||||
off_t offabs(off_t);
|
||||
void prman(void);
|
||||
void prword(void);
|
||||
void prdata(void);
|
||||
void setup(void);
|
||||
void playgame(void);
|
||||
void getword(void);
|
||||
void getguess(void);
|
||||
void endgame(void);
|
||||
int readch(void);
|
||||
|
||||
@@ -1,9 +1,22 @@
|
||||
# include "hangman.h"
|
||||
#include <stdlib.h>
|
||||
#include "hangman.h"
|
||||
|
||||
/*
|
||||
* die:
|
||||
* Die properly.
|
||||
*/
|
||||
void die(int sig)
|
||||
{
|
||||
mvcur(0, COLS - 1, LINES - 1, 0);
|
||||
endwin();
|
||||
putchar('\n');
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* This game written by Ken Arnold.
|
||||
*/
|
||||
main()
|
||||
int main()
|
||||
{
|
||||
initscr();
|
||||
signal(SIGINT, die);
|
||||
@@ -15,15 +28,3 @@ main()
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
/*
|
||||
* die:
|
||||
* Die properly.
|
||||
*/
|
||||
die()
|
||||
{
|
||||
mvcur(0, COLS - 1, LINES - 1, 0);
|
||||
endwin();
|
||||
putchar('\n');
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
# include "hangman.h"
|
||||
#include <strings.h>
|
||||
#include "hangman.h"
|
||||
|
||||
/*
|
||||
* playgame:
|
||||
* play a game
|
||||
*/
|
||||
void
|
||||
playgame()
|
||||
{
|
||||
register bool *bp;
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
# include "hangman.h"
|
||||
#include "hangman.h"
|
||||
|
||||
/*
|
||||
* prdata:
|
||||
* Print out the current guesses
|
||||
*/
|
||||
void
|
||||
prdata()
|
||||
{
|
||||
register bool *bp;
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
# include "hangman.h"
|
||||
#include "hangman.h"
|
||||
|
||||
/*
|
||||
* prman:
|
||||
* Print out the man appropriately for the give number
|
||||
* of incorrect guesses.
|
||||
*/
|
||||
void
|
||||
prman()
|
||||
{
|
||||
register int i;
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
# include "hangman.h"
|
||||
#include "hangman.h"
|
||||
|
||||
/*
|
||||
* prword:
|
||||
* Print out the current state of the word
|
||||
*/
|
||||
void
|
||||
prword()
|
||||
{
|
||||
move(KNOWNY, KNOWNX + sizeof "Word: ");
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
# include "hangman.h"
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include "hangman.h"
|
||||
|
||||
/*
|
||||
* setup:
|
||||
* Set up the strings on the screen.
|
||||
*/
|
||||
void
|
||||
setup()
|
||||
{
|
||||
register char **sp;
|
||||
@@ -24,7 +28,7 @@ setup()
|
||||
addstr(*sp);
|
||||
}
|
||||
|
||||
srand(time(NULL) + getpid());
|
||||
srandom(time(NULL) + getpid());
|
||||
if ((Dict = fopen(DICT, "r")) == NULL) {
|
||||
perror(DICT);
|
||||
endwin();
|
||||
|
||||
1
src/games/mille/.gitignore
vendored
Normal file
1
src/games/mille/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
mille
|
||||
@@ -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/
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 */
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
unsigned avs[3];
|
||||
|
||||
if (strcmp(av[0], "a.out") == 0) {
|
||||
outf = fopen("q", "w");
|
||||
@@ -26,8 +41,7 @@ reg char *av[]; {
|
||||
}
|
||||
restore = FALSE;
|
||||
|
||||
getloadavg(avs, 3);
|
||||
if (avs[2] > 4.0) {
|
||||
if (getloadavg(avs, 3) >= 0 && avs[2] > 400) {
|
||||
printf("Sorry. The load average is too high.\n");
|
||||
printf("Please try again later\n");
|
||||
exit(1);
|
||||
@@ -108,21 +122,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 +135,3 @@ die() {
|
||||
endwin();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -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)());
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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--)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
1
src/games/monop/.gitignore
vendored
Normal file
1
src/games/monop/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
monop
|
||||
@@ -3,85 +3,57 @@
|
||||
# Program: Ken Arnold
|
||||
# Makefile: K.S.
|
||||
#
|
||||
DESTDIR=
|
||||
DATFILES=brd.dat mon.dat prop.dat
|
||||
CFILES= monop.c cards.c execute.c getinp.c houses.c jail.c misc.c morg.c \
|
||||
print.c prop.c rent.c roll.c spec.c strcmp.c trade.c
|
||||
OBJS= monop.o cards.o execute.o getinp.o houses.o jail.o misc.o morg.o \
|
||||
print.o prop.o rent.o roll.o spec.o strcmp.o trade.o strings.o
|
||||
HEADERS=monop.h deck.h
|
||||
BINDIR= ${DESTDIR}/usr/games
|
||||
LIBDIR= ${DESTDIR}/usr/games/lib
|
||||
LIB=
|
||||
CFLAGS= -O -w
|
||||
SEPFLAG= -i
|
||||
DAT= brd.dat monop.dat prop.dat
|
||||
CC= cc
|
||||
XSTR= xstr
|
||||
ED= ed
|
||||
AS= as
|
||||
RM= rm -f
|
||||
CTAGS= ctags
|
||||
TOPSRC = $(shell cd ../../..; pwd)
|
||||
include $(TOPSRC)/target.mk
|
||||
#include $(TOPSRC)/cross.mk
|
||||
#CFLAGS = -DCROSS -O
|
||||
|
||||
#
|
||||
# Be cool about compiling strings.
|
||||
#
|
||||
.c.o:
|
||||
${CC} -E ${CFLAGS} $*.c | ${XSTR} -c -
|
||||
${CC} -c ${CFLAGS} x.c
|
||||
mv x.o $*.o
|
||||
CFLAGS += -Werror -Wall
|
||||
LIBS = -lc
|
||||
|
||||
it: monop cards.pck
|
||||
OBJS = monop.o cards.o execute.o getinp.o houses.o jail.o misc.o \
|
||||
morg.o print.o prop.o rent.o roll.o spec.o trade.o
|
||||
MAN = monop.0
|
||||
MANSRC = monop.6
|
||||
|
||||
monop: ${OBJS}
|
||||
${CC} -o monop ${SEPFLAG} ${OBJS} ${LIB}
|
||||
all: monop $(MAN) cards.pck
|
||||
|
||||
install: monop cards.pck
|
||||
${RM} ${BINDIR}/monop ${LIBDIR}/cards.pck
|
||||
install -s monop ${BINDIR}
|
||||
mv cards.pck ${LIBDIR}
|
||||
monop: $(OBJS)
|
||||
$(CC) $(LDFLAGS) -o monop.elf $(OBJS) $(LIBS)
|
||||
$(OBJDUMP) -S monop.elf > monop.dis
|
||||
$(SIZE) monop.elf
|
||||
$(ELF2AOUT) monop.elf $@ && rm monop.elf
|
||||
|
||||
new: clean ctags monop
|
||||
initdeck: initdeck.c deck.h
|
||||
$(CC) -o initdeck $(LDFLAGS) $(CFLAGS) initdeck.c
|
||||
|
||||
strings.o: strings
|
||||
${XSTR}
|
||||
${CC} -S xs.c
|
||||
${ED} - < :rofix xs.s
|
||||
${AS} -o strings.o xs.s
|
||||
${RM} xs.s xs.c
|
||||
cards.pck: #initdeck cards.inp
|
||||
./initdeck
|
||||
|
||||
monop.o: ${DATFILES} monop.def
|
||||
${CC} -E ${CFLAGS} monop.c | ${XSTR} -c -
|
||||
${CC} -c ${CFLAGS} x.c
|
||||
mv x.o monop.o
|
||||
|
||||
cards.o: deck.h
|
||||
${CC} -E ${CFLAGS} cards.c | ${XSTR} -c -
|
||||
${CC} -c ${CFLAGS} x.c
|
||||
mv x.o cards.o
|
||||
|
||||
newone:
|
||||
${CC} ${SEPFLAG} -o monop ${CFLAGS} ${CFILES} ${LIB}
|
||||
|
||||
ctags:
|
||||
${CTAGS} ${CFILES} monop.h deck.h monop.def initdeck.c
|
||||
|
||||
cards.pck: initdeck cards.inp
|
||||
./initdeck
|
||||
|
||||
initdeck: initdeck.c deck.h
|
||||
${CC} -o initdeck ${CFLAGS} initdeck.c ${LIB}
|
||||
|
||||
monop.tar:
|
||||
tar crvf monop.tar ${CFILES} ${DATFILES} ${HEADERS} :rofix Makefile cards.inp initdeck.c monop.def monop.ext
|
||||
$(MAN): $(MANSRC)
|
||||
$(MANROFF) $< > $@
|
||||
|
||||
clean:
|
||||
${RM} ${OBJS} monop core tags x.c x.o monop.tar initdeck cards.pck errs
|
||||
cp /dev/null strings
|
||||
rm -f *.o *.0 *.elf $(MAN) monop initdeck *.elf *.dis tags *~
|
||||
|
||||
printall:
|
||||
-/usr/bin/eecs/pr monop.h deck.h monop.def monop.ext ${CFILES} ${DATFILES} | /usr/bin/lpr
|
||||
-/usr/bin/lpq
|
||||
|
||||
lint:
|
||||
lint ${CFILES} > lint.out ;
|
||||
install: all
|
||||
install monop $(DESTDIR)/games/
|
||||
cp $(MAN) $(DESTDIR)/share/man/cat6/
|
||||
cp cards.pck $(DESTDIR)/games/lib/
|
||||
###
|
||||
cards.o: cards.c extern.h monop.h deck.h
|
||||
execute.o: execute.c extern.h monop.h deck.h
|
||||
getinp.o: getinp.c
|
||||
houses.o: houses.c extern.h monop.h deck.h
|
||||
initdeck.o: initdeck.c deck.h
|
||||
jail.o: jail.c extern.h monop.h deck.h
|
||||
misc.o: misc.c extern.h monop.h deck.h
|
||||
monop.o: monop.c defines.h monop.h deck.h mon.dat.h prop.dat.h brd.dat.h
|
||||
morg.o: morg.c extern.h monop.h deck.h
|
||||
print.o: print.c extern.h monop.h deck.h
|
||||
prop.o: prop.c extern.h monop.h deck.h
|
||||
rent.o: rent.c extern.h monop.h deck.h
|
||||
roll.o: roll.c
|
||||
spec.o: spec.c extern.h monop.h deck.h
|
||||
strcmp.o: strcmp.c
|
||||
trade.o: trade.c extern.h monop.h deck.h
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
g/^[ ]*\.data/s//.text/
|
||||
w
|
||||
q
|
||||
@@ -1,43 +0,0 @@
|
||||
/* name (COLOR) owner type desc cost */
|
||||
|
||||
{"=== GO ===", -1, SAFE, 0 },
|
||||
{"Mediterranean ave. (P)", -1, PRPTY, &prop[0], 60 },
|
||||
{"Community Chest i", -1, CC, cc },
|
||||
{"Baltic ave. (P)", -1, PRPTY, &prop[1], 60 },
|
||||
{"Income Tax", -1, SPEC, inc_tax },
|
||||
{"Reading RR", -1, RR, &rr[0], 200 },
|
||||
{"Oriental ave. (L)", -1, PRPTY, &prop[2], 100 },
|
||||
{"Chance i", -1, CHANCE, chance },
|
||||
{"Vermont ave. (L)", -1, PRPTY, &prop[3], 100 },
|
||||
{"Connecticut ave. (L)", -1, PRPTY, &prop[4], 120 },
|
||||
{"Just Visiting", -1, SAFE, 0 },
|
||||
{"St. Charles pl. (V)", -1, PRPTY, &prop[5], 140 },
|
||||
{"Electric Co.", -1, UTIL, &util[0], 150 },
|
||||
{"States ave. (V)", -1, PRPTY, &prop[6], 140 },
|
||||
{"Virginia ave. (V)", -1, PRPTY, &prop[7], 160 },
|
||||
{"Pennsylvania RR", -1, RR, &rr[1], 200 },
|
||||
{"St. James pl. (O)", -1, PRPTY, &prop[8], 180 },
|
||||
{"Community Chest ii", -1, CC, cc },
|
||||
{"Tennessee ave. (O)", -1, PRPTY, &prop[9], 180 },
|
||||
{"New York ave. (O)", -1, PRPTY, &prop[10], 200 },
|
||||
{"Free Parking", -1, SAFE, 0 },
|
||||
{"Kentucky ave. (R)", -1, PRPTY, &prop[11], 220 },
|
||||
{"Chance ii", -1, CHANCE, chance },
|
||||
{"Indiana ave. (R)", -1, PRPTY, &prop[12], 220 },
|
||||
{"Illinois ave. (R)", -1, PRPTY, &prop[13], 240 },
|
||||
{"B&O RR", -1, RR, &rr[2], 200 },
|
||||
{"Atlantic ave. (Y)", -1, PRPTY, &prop[14], 260 },
|
||||
{"Ventnor ave. (Y)", -1, PRPTY, &prop[15], 260 },
|
||||
{"Water Works", -1, UTIL, &util[1], 150 },
|
||||
{"Marvin Gardens (Y)", -1, PRPTY, &prop[16], 280 },
|
||||
{"GO TO JAIL", -1, SPEC, goto_jail },
|
||||
{"Pacific ave. (G)", -1, PRPTY, &prop[17], 300 },
|
||||
{"N. Carolina ave. (G)", -1, PRPTY, &prop[18], 300 },
|
||||
{"Community Chest iii", -1, CC, cc },
|
||||
{"Pennsylvania ave. (G)", -1, PRPTY, &prop[19], 320 },
|
||||
{"Short Line RR", -1, RR, &rr[3], 200 },
|
||||
{"Chance iii", -1, CHANCE, chance },
|
||||
{"Park place (D)", -1, PRPTY, &prop[20], 350 },
|
||||
{"Luxury Tax", -1, SPEC, lux_tax },
|
||||
{"Boardwalk (D)", -1, PRPTY, &prop[21], 400 },
|
||||
{"JAIL", -1, SPEC }
|
||||
43
src/games/monop/brd.dat.h
Normal file
43
src/games/monop/brd.dat.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/* name (COLOR) owner type desc cost */
|
||||
|
||||
{"=== GO ===", -1, SAFE, 0 },
|
||||
{"Mediterranean ave. (P)", -1, PRPTY, (char*)&prop[0], 60 },
|
||||
{"Community Chest i", -1, CC, (char*)cc },
|
||||
{"Baltic ave. (P)", -1, PRPTY, (char*)&prop[1], 60 },
|
||||
{"Income Tax", -1, SPEC, (char*)inc_tax },
|
||||
{"Reading RR", -1, RR, (char*)&rr[0], 200 },
|
||||
{"Oriental ave. (L)", -1, PRPTY, (char*)&prop[2], 100 },
|
||||
{"Chance i", -1, CHANCE, (char*)chance },
|
||||
{"Vermont ave. (L)", -1, PRPTY, (char*)&prop[3], 100 },
|
||||
{"Connecticut ave. (L)", -1, PRPTY, (char*)&prop[4], 120 },
|
||||
{"Just Visiting", -1, SAFE, 0 },
|
||||
{"St. Charles pl. (V)", -1, PRPTY, (char*)&prop[5], 140 },
|
||||
{"Electric Co.", -1, UTIL, (char*)&util[0], 150 },
|
||||
{"States ave. (V)", -1, PRPTY, (char*)&prop[6], 140 },
|
||||
{"Virginia ave. (V)", -1, PRPTY, (char*)&prop[7], 160 },
|
||||
{"Pennsylvania RR", -1, RR, (char*)&rr[1], 200 },
|
||||
{"St. James pl. (O)", -1, PRPTY, (char*)&prop[8], 180 },
|
||||
{"Community Chest ii", -1, CC, (char*)cc },
|
||||
{"Tennessee ave. (O)", -1, PRPTY, (char*)&prop[9], 180 },
|
||||
{"New York ave. (O)", -1, PRPTY, (char*)&prop[10], 200 },
|
||||
{"Free Parking", -1, SAFE, 0 },
|
||||
{"Kentucky ave. (R)", -1, PRPTY, (char*)&prop[11], 220 },
|
||||
{"Chance ii", -1, CHANCE, (char*)chance },
|
||||
{"Indiana ave. (R)", -1, PRPTY, (char*)&prop[12], 220 },
|
||||
{"Illinois ave. (R)", -1, PRPTY, (char*)&prop[13], 240 },
|
||||
{"B&O RR", -1, RR, (char*)&rr[2], 200 },
|
||||
{"Atlantic ave. (Y)", -1, PRPTY, (char*)&prop[14], 260 },
|
||||
{"Ventnor ave. (Y)", -1, PRPTY, (char*)&prop[15], 260 },
|
||||
{"Water Works", -1, UTIL, (char*)&util[1], 150 },
|
||||
{"Marvin Gardens (Y)", -1, PRPTY, (char*)&prop[16], 280 },
|
||||
{"GO TO JAIL", -1, SPEC, (char*)goto_jail },
|
||||
{"Pacific ave. (G)", -1, PRPTY, (char*)&prop[17], 300 },
|
||||
{"N. Carolina ave. (G)", -1, PRPTY, (char*)&prop[18], 300 },
|
||||
{"Community Chest iii", -1, CC, (char*)cc },
|
||||
{"Pennsylvania ave. (G)", -1, PRPTY, (char*)&prop[19], 320 },
|
||||
{"Short Line RR", -1, RR, (char*)&rr[3], 200 },
|
||||
{"Chance iii", -1, CHANCE, (char*)chance },
|
||||
{"Park place (D)", -1, PRPTY, (char*)&prop[20], 350 },
|
||||
{"Luxury Tax", -1, SPEC, (char*)lux_tax },
|
||||
{"Boardwalk (D)", -1, PRPTY, (char*)&prop[21], 400 },
|
||||
{"JAIL", -1, SPEC }
|
||||
@@ -1,38 +1,24 @@
|
||||
# include "monop.ext"
|
||||
#include "extern.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
/*
|
||||
* These routine deal with the card decks
|
||||
*/
|
||||
|
||||
# define GOJF 'F' /* char for get-out-of-jail-free cards */
|
||||
#define GOJF 'F' /* char for get-out-of-jail-free cards */
|
||||
|
||||
# ifndef DEV
|
||||
static char *cardfile = "/usr/games/lib/cards.pck";
|
||||
# else
|
||||
#ifdef CROSS
|
||||
static char *cardfile = "cards.pck";
|
||||
# endif
|
||||
#else
|
||||
static char *cardfile = "/games/lib/cards.pck";
|
||||
#endif
|
||||
|
||||
static FILE *deckf;
|
||||
|
||||
/*
|
||||
* This routine initializes the decks from the data file,
|
||||
* which it opens.
|
||||
*/
|
||||
init_decks() {
|
||||
|
||||
if ((deckf=fopen(cardfile, "r")) == NULL) {
|
||||
file_err:
|
||||
perror(cardfile);
|
||||
exit(1);
|
||||
}
|
||||
if (fread(deck, sizeof (DECK), 2, deckf) != 2)
|
||||
goto file_err;
|
||||
set_up(&CC_D);
|
||||
set_up(&CH_D);
|
||||
}
|
||||
/*
|
||||
* This routine sets up the offset pointers for the given deck.
|
||||
*/
|
||||
static void
|
||||
set_up(dp)
|
||||
DECK *dp; {
|
||||
|
||||
@@ -56,9 +42,45 @@ DECK *dp; {
|
||||
dp->offsets[r1] = temp;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine initializes the decks from the data file,
|
||||
* which it opens.
|
||||
*/
|
||||
void
|
||||
init_decks() {
|
||||
|
||||
if ((deckf=fopen(cardfile, "r")) == NULL) {
|
||||
file_err:
|
||||
perror(cardfile);
|
||||
exit(1);
|
||||
}
|
||||
if (fread(deck, sizeof (DECK), 2, deckf) != 2)
|
||||
goto file_err;
|
||||
set_up(&CC_D);
|
||||
set_up(&CH_D);
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine prints out the message on the card
|
||||
*/
|
||||
static void
|
||||
printmes() {
|
||||
|
||||
reg char c;
|
||||
|
||||
printline();
|
||||
fflush(stdout);
|
||||
while ((c = getc(deckf)) != '\0')
|
||||
putchar(c);
|
||||
printline();
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine draws a card from the given deck
|
||||
*/
|
||||
void
|
||||
get_card(dp)
|
||||
DECK *dp; {
|
||||
|
||||
@@ -69,7 +91,8 @@ DECK *dp; {
|
||||
|
||||
do {
|
||||
fseek(deckf, dp->offsets[dp->last_card], 0);
|
||||
dp->last_card = ++(dp->last_card) % dp->num_cards;
|
||||
dp->last_card++;
|
||||
dp->last_card %= dp->num_cards;
|
||||
type_maj = getc(deckf);
|
||||
} while (dp->gojf_used && type_maj == GOJF);
|
||||
type_min = getc(deckf);
|
||||
@@ -135,11 +158,12 @@ DECK *dp; {
|
||||
}
|
||||
num_h = num_H = 0;
|
||||
for (op = cur_p->own_list; op; op = op->next)
|
||||
if (op->sqr->type == PRPTY)
|
||||
if (op->sqr->desc->houses == 5)
|
||||
if (op->sqr->type == PRPTY) {
|
||||
if (((PROP*)op->sqr->desc)->houses == 5)
|
||||
++num_H;
|
||||
else
|
||||
num_h += op->sqr->desc->houses;
|
||||
num_h += ((PROP*)op->sqr->desc)->houses;
|
||||
}
|
||||
num = per_h * num_h + per_H * num_H;
|
||||
printf("You had %d Houses and %d Hotels, so that cost you $%d\n", num_h, num_H, num);
|
||||
if (num == 0)
|
||||
@@ -154,17 +178,3 @@ DECK *dp; {
|
||||
}
|
||||
spec = FALSE;
|
||||
}
|
||||
/*
|
||||
* This routine prints out the message on the card
|
||||
*/
|
||||
printmes() {
|
||||
|
||||
reg char c;
|
||||
|
||||
printline();
|
||||
fflush(stdout);
|
||||
while ((c = getc(deckf)) != '\0')
|
||||
putchar(c);
|
||||
printline();
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
BIN
src/games/monop/cards.pck
Normal file
BIN
src/games/monop/cards.pck
Normal file
Binary file not shown.
@@ -11,3 +11,5 @@ struct dk_st { /* deck description structure */
|
||||
};
|
||||
|
||||
typedef struct dk_st DECK;
|
||||
|
||||
void get_card(DECK *dp);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# include "monop.h"
|
||||
# include "deck.h"
|
||||
#include "monop.h"
|
||||
#include "deck.h"
|
||||
|
||||
bool fixing, /* set if fixing up debt */
|
||||
trading, /* set if in process of trading */
|
||||
@@ -19,7 +19,7 @@ char *name_list[MAX_PL+2], /* list of players' names */
|
||||
"roll", /* 16 */ "", /* 17 */
|
||||
0
|
||||
},
|
||||
*yn[] = { /* list of commands for yes/no answers */
|
||||
*yesno[] = { /* list of commands for yes/no answers */
|
||||
"yes", /* 0 */ "no", /* 1 */
|
||||
"quit", /* 2 */ "print", /* 3 */
|
||||
"where", /* 4 */ "own holdings", /* 5 */
|
||||
@@ -43,11 +43,11 @@ int player, /* current player number */
|
||||
num_luck = sizeof lucky_mes / sizeof (char *),
|
||||
/* list of command functions */
|
||||
buy_houses(), card(), do_move(), do_move(), list(), list_all(),
|
||||
mortgage(), pay(), printboard(), quit(), resign(), restore(),
|
||||
mortgage(), pay(), printboard(), quitgame(), resign(), restore(),
|
||||
rub(), save(), sell_houses(), shell_out(), trade(),
|
||||
unmortgage(), where(),
|
||||
(*func[])() = { /* array of function calls for commands */
|
||||
quit, /* quit game |* 0 *| */
|
||||
quitgame, /* quit game |* 0 *| */
|
||||
printboard, /* print board |* 1 *| */
|
||||
where, /* where players are |* 2 *| */
|
||||
list, /* own holdings |* 3 *| */
|
||||
@@ -77,13 +77,13 @@ RR_S rr[N_RR]; /* raildroad descriptions */
|
||||
UTIL_S util[2]; /* utility descriptions */
|
||||
|
||||
MON mon[N_MON] = { /* monopoly descriptions */
|
||||
# include "mon.dat"
|
||||
#include "mon.dat.h"
|
||||
};
|
||||
|
||||
PROP prop[N_PROP] = { /* typical properties */
|
||||
# include "prop.dat"
|
||||
#include "prop.dat.h"
|
||||
};
|
||||
|
||||
SQUARE board[N_SQRS+1] = { /* board itself (+1 for Jail) */
|
||||
# include "brd.dat"
|
||||
#include "brd.dat.h"
|
||||
};
|
||||
@@ -1,24 +1,29 @@
|
||||
# include "monop.ext"
|
||||
# include <sys/types.h>
|
||||
# include <sys/stat.h>
|
||||
# include <sys/time.h>
|
||||
#include "extern.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
# define SEGSIZE 8192
|
||||
#define SEGSIZE 8192
|
||||
|
||||
typedef struct stat STAT;
|
||||
typedef struct tm TIME;
|
||||
|
||||
extern char etext[], /* end of text space */
|
||||
extern char __data_start[], /* beginning of data space */
|
||||
rub();
|
||||
|
||||
static char buf[257],
|
||||
*yn_only[] = { "yes", "no"};
|
||||
static char buf[257];
|
||||
|
||||
static bool new_play; /* set if move on to new player */
|
||||
|
||||
/*
|
||||
* This routine executes the given command by index number
|
||||
*/
|
||||
void
|
||||
execute(com_num)
|
||||
reg int com_num; {
|
||||
|
||||
@@ -31,9 +36,11 @@ reg int com_num; {
|
||||
else if (num_doub)
|
||||
printf("%s rolled doubles. Goes again\n", cur_p->name);
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine moves a piece around.
|
||||
*/
|
||||
void
|
||||
do_move() {
|
||||
|
||||
reg int r1, r2;
|
||||
@@ -62,30 +69,16 @@ do_move() {
|
||||
ret:
|
||||
return;
|
||||
}
|
||||
/*
|
||||
* This routine moves a normal move
|
||||
*/
|
||||
move(rl)
|
||||
reg int rl; {
|
||||
|
||||
reg int old_loc;
|
||||
|
||||
old_loc = cur_p->loc;
|
||||
cur_p->loc = (cur_p->loc + rl) % N_SQRS;
|
||||
if (cur_p->loc < old_loc && rl > 0) {
|
||||
cur_p->money += 200;
|
||||
printf("You pass %s and get $200\n", board[0].name);
|
||||
}
|
||||
show_move();
|
||||
}
|
||||
/*
|
||||
* This routine shows the results of a move
|
||||
*/
|
||||
static void
|
||||
show_move() {
|
||||
|
||||
reg SQUARE *sqp;
|
||||
|
||||
sqp = &board[cur_p->loc];
|
||||
sqp = &board[(int)cur_p->loc];
|
||||
printf("That puts you on %s\n", sqp->name);
|
||||
switch (sqp->type) {
|
||||
case SAFE:
|
||||
@@ -106,7 +99,7 @@ show_move() {
|
||||
cur_p->money -= sqp->cost;
|
||||
}
|
||||
else if (num_play > 2)
|
||||
bid(sqp);
|
||||
bid();
|
||||
}
|
||||
else if (sqp->owner == player)
|
||||
printf("You own it.\n");
|
||||
@@ -114,18 +107,37 @@ show_move() {
|
||||
rent(sqp);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine moves a normal move
|
||||
*/
|
||||
void
|
||||
move(rl)
|
||||
reg int rl; {
|
||||
|
||||
reg int old_loc;
|
||||
|
||||
old_loc = cur_p->loc;
|
||||
cur_p->loc = (cur_p->loc + rl) % N_SQRS;
|
||||
if (cur_p->loc < old_loc && rl > 0) {
|
||||
cur_p->money += 200;
|
||||
printf("You pass %s and get $200\n", board[0].name);
|
||||
}
|
||||
show_move();
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine saves the current game for use at a later date
|
||||
*/
|
||||
void
|
||||
save() {
|
||||
|
||||
reg char *sp;
|
||||
reg int outf, num;
|
||||
TIME tme, *tp;
|
||||
int *dat_end, junk[18];
|
||||
time_t tme;
|
||||
struct stat junk;
|
||||
unsgn start, end;
|
||||
|
||||
tp = &tme;
|
||||
printf("Which file do you wish to save it in? ");
|
||||
sp = buf;
|
||||
while ((*sp++=getchar()) != '\n' && !feof(stdin))
|
||||
@@ -137,9 +149,8 @@ save() {
|
||||
/*
|
||||
* check for existing files, and confirm overwrite if needed
|
||||
*/
|
||||
|
||||
if (stat(buf, junk) > -1
|
||||
&& getyn("File exists. Do you wish to overwrite? ", yn_only) > 0)
|
||||
if (stat(buf, &junk) >= 0
|
||||
&& getyn("File exists. Do you wish to overwrite? ") > 0)
|
||||
return;
|
||||
|
||||
if ((outf=creat(buf, 0644)) < 0) {
|
||||
@@ -147,28 +158,29 @@ save() {
|
||||
return;
|
||||
}
|
||||
printf("\"%s\" ", buf);
|
||||
time(tp); /* get current time */
|
||||
strcpy(buf, ctime(tp));
|
||||
time(&tme); /* get current time */
|
||||
strcpy(buf, ctime(&tme));
|
||||
for (sp = buf; *sp != '\n'; sp++)
|
||||
continue;
|
||||
*sp = '\0';
|
||||
# if 0
|
||||
start = (((int) etext + (SEGSIZE-1)) / SEGSIZE ) * SEGSIZE;
|
||||
# else
|
||||
start = 0;
|
||||
# endif
|
||||
end = sbrk(0);
|
||||
start = (unsigned) __data_start;
|
||||
end = (unsigned) sbrk(0);
|
||||
while (start < end) { /* write out entire data space */
|
||||
num = start + 16 * 1024 > end ? end - start : 16 * 1024;
|
||||
write(outf, start, num);
|
||||
if (write(outf, (void*)start, num) != num) {
|
||||
perror(buf);
|
||||
exit(-1);
|
||||
}
|
||||
start += num;
|
||||
}
|
||||
close(outf);
|
||||
printf("[%s]\n", buf);
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine restores an old game from a file
|
||||
*/
|
||||
void
|
||||
restore() {
|
||||
|
||||
reg char *sp;
|
||||
@@ -181,10 +193,12 @@ restore() {
|
||||
clearerr(stdin);
|
||||
rest_f(buf);
|
||||
}
|
||||
|
||||
/*
|
||||
* This does the actual restoring. It returns TRUE if the
|
||||
* backup was successful, else false.
|
||||
*/
|
||||
int
|
||||
rest_f(file)
|
||||
reg char *file; {
|
||||
|
||||
@@ -203,19 +217,22 @@ reg char *file; {
|
||||
perror(file);
|
||||
exit(1);
|
||||
}
|
||||
# if 0
|
||||
start = (((int) etext + (SEGSIZE-1)) / SEGSIZE ) * SEGSIZE;
|
||||
# else
|
||||
start = 0;
|
||||
# endif
|
||||
brk(end = start + sbuf.st_size);
|
||||
start = (unsigned) __data_start;
|
||||
end = start + sbuf.st_size;
|
||||
if (brk((void*) end) < 0) {
|
||||
perror("brk");
|
||||
exit(-1);
|
||||
}
|
||||
while (start < end) { /* write out entire data space */
|
||||
num = start + 16 * 1024 > end ? end - start : 16 * 1024;
|
||||
read(inf, start, num);
|
||||
if (read(inf, (void*) start, num) != num) {
|
||||
perror(file);
|
||||
exit(-1);
|
||||
}
|
||||
start += num;
|
||||
}
|
||||
close(inf);
|
||||
strcpy(buf, ctime(sbuf.st_mtime));
|
||||
strcpy(buf, ctime(&sbuf.st_mtime));
|
||||
for (sp = buf; *sp != '\n'; sp++)
|
||||
continue;
|
||||
*sp = '\0';
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
# include "monop.h"
|
||||
# include "deck.h"
|
||||
#include "monop.h"
|
||||
#include "deck.h"
|
||||
|
||||
extern bool trading, spec, fixing, told_em;
|
||||
|
||||
extern char *yn[], *comlist[], *name_list[], *lucky_mes[];
|
||||
extern char *yesno[], *comlist[], *name_list[], *lucky_mes[];
|
||||
|
||||
extern int num_play, player, num_doub, num_luck, (*func[])();
|
||||
|
||||
@@ -1,23 +1,41 @@
|
||||
# include <stdio.h>
|
||||
# include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
# define reg register
|
||||
#define reg register
|
||||
|
||||
# define LINE 70
|
||||
#define LINE 70
|
||||
|
||||
static char buf[257];
|
||||
|
||||
static int
|
||||
comp(s1)
|
||||
char *s1; {
|
||||
|
||||
reg char *sp, *tsp, c;
|
||||
|
||||
if (buf[0] != '\0')
|
||||
for (sp = buf, tsp = s1; *sp; ) {
|
||||
c = isupper(*tsp) ? tolower(*tsp) : *tsp;
|
||||
tsp++;
|
||||
if (c != *sp++)
|
||||
return 0;
|
||||
}
|
||||
else if (*s1 != '\0')
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
getinp(prompt, list)
|
||||
char *prompt, *list[]; {
|
||||
|
||||
reg int i, n_match, match;
|
||||
reg int i, n_match, match = 0;
|
||||
char *sp;
|
||||
int plen;
|
||||
|
||||
|
||||
for (;;) {
|
||||
inter:
|
||||
printf(prompt);
|
||||
printf("%s", prompt);
|
||||
for (sp = buf; (*sp=getchar()) != '\n' && !feof(stdin); )
|
||||
if (*sp == -1) /* check for interupted system call */
|
||||
goto inter;
|
||||
@@ -39,7 +57,7 @@ inter:
|
||||
printf("<RETURN>");
|
||||
}
|
||||
else
|
||||
printf(list[i]);
|
||||
printf("%s", list[i]);
|
||||
if (list[i+1])
|
||||
printf(", ");
|
||||
else
|
||||
@@ -63,21 +81,3 @@ inter:
|
||||
printf("Illegal response: \"%s\". Use '?' to get list of valid answers\n", buf);
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
comp(s1)
|
||||
char *s1; {
|
||||
|
||||
reg char *sp, *tsp, c;
|
||||
|
||||
if (buf[0] != '\0')
|
||||
for (sp = buf, tsp = s1; *sp; ) {
|
||||
c = isupper(*tsp) ? tolower(*tsp) : *tsp;
|
||||
tsp++;
|
||||
if (c != *sp++)
|
||||
return 0;
|
||||
}
|
||||
else if (*s1 != '\0')
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1,66 +1,29 @@
|
||||
# include "monop.ext"
|
||||
#include "extern.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
static char *names[N_MON+2],
|
||||
cur_prop[80];
|
||||
|
||||
static MON *monops[N_MON];
|
||||
|
||||
/*
|
||||
* These routines deal with buying and selling houses
|
||||
*/
|
||||
buy_houses() {
|
||||
static void
|
||||
list_cur(mp)
|
||||
reg MON *mp; {
|
||||
|
||||
reg int num_mon;
|
||||
reg MON *mp;
|
||||
reg OWN *op;
|
||||
bool good,got_morg;
|
||||
int i,p;
|
||||
reg int i;
|
||||
reg SQUARE *sqp;
|
||||
|
||||
over:
|
||||
num_mon = 0;
|
||||
good = TRUE;
|
||||
got_morg = FALSE;
|
||||
for (op = cur_p->own_list; op && op->sqr->type != PRPTY; op = op->next)
|
||||
continue;
|
||||
while (op)
|
||||
if (op->sqr->desc->monop) {
|
||||
mp = op->sqr->desc->mon_desc;
|
||||
names[num_mon] = (monops[num_mon]=mp)->name;
|
||||
num_mon++;
|
||||
got_morg = good = FALSE;
|
||||
for (i = 0; i < mp->num_in; i++) {
|
||||
if (op->sqr->desc->morg)
|
||||
got_morg++;
|
||||
if (op->sqr->desc->houses != 5)
|
||||
good++;
|
||||
op = op->next;
|
||||
}
|
||||
if (!good || got_morg)
|
||||
--num_mon;
|
||||
}
|
||||
for (i = 0; i < mp->num_in; i++) {
|
||||
sqp = mp->sq[i];
|
||||
if (((PROP*)sqp->desc)->houses == 5)
|
||||
printf("%s (H) ", sqp->name);
|
||||
else
|
||||
op = op->next;
|
||||
if (num_mon == 0) {
|
||||
if (got_morg)
|
||||
printf("You can't build on mortgaged monopolies.\n");
|
||||
else if (!good)
|
||||
printf("You can't build any more.\n");
|
||||
else
|
||||
printf("But you don't have any monopolies!!\n");
|
||||
return;
|
||||
}
|
||||
if (num_mon == 1)
|
||||
buy_h(monops[0]);
|
||||
else {
|
||||
names[num_mon++] = "done";
|
||||
names[num_mon--] = 0;
|
||||
if ((p=getinp("Which property do you wish to buy houses for? ", names)) == num_mon)
|
||||
return;
|
||||
buy_h(monops[p]);
|
||||
goto over;
|
||||
printf("%s (%d) ", sqp->name, ((PROP*)sqp->desc)->houses);
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
static void
|
||||
buy_h(mnp)
|
||||
MON *mnp; {
|
||||
|
||||
@@ -78,7 +41,7 @@ blew_it:
|
||||
printf("Houses will cost $%d\n", price);
|
||||
printf("How many houses do you wish to buy for\n");
|
||||
for (i = 0; i < mp->num_in; i++) {
|
||||
pp = mp->sq[i]->desc;
|
||||
pp = (PROP*) mp->sq[i]->desc;
|
||||
over:
|
||||
if (pp->houses == 5) {
|
||||
printf("%s (H):\n", mp->sq[i]->name);
|
||||
@@ -106,10 +69,124 @@ err: printf("That makes the spread too wide. Try again\n");
|
||||
tot += input[i];
|
||||
if (tot) {
|
||||
printf("You asked for %d houses for $%d\n", tot, tot * price);
|
||||
if (getyn("Is that ok? ", yn) == 0) {
|
||||
if (getyn("Is that ok? ") == 0) {
|
||||
cur_p->money -= tot * price;
|
||||
for (tot = i = 0; i < mp->num_in; i++)
|
||||
mp->sq[i]->desc->houses = temp[i];
|
||||
((PROP*)mp->sq[i]->desc)->houses = temp[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* These routines deal with buying and selling houses
|
||||
*/
|
||||
void
|
||||
buy_houses() {
|
||||
|
||||
reg int num_mon;
|
||||
reg MON *mp;
|
||||
reg OWN *op;
|
||||
bool good,got_morg;
|
||||
int i,p;
|
||||
|
||||
over:
|
||||
num_mon = 0;
|
||||
good = TRUE;
|
||||
got_morg = FALSE;
|
||||
for (op = cur_p->own_list; op && op->sqr->type != PRPTY; op = op->next)
|
||||
continue;
|
||||
while (op) {
|
||||
PROP *prop = (PROP*) op->sqr->desc;
|
||||
if (prop->monop) {
|
||||
mp = prop->mon_desc;
|
||||
names[num_mon] = (monops[num_mon]=mp)->name;
|
||||
num_mon++;
|
||||
got_morg = good = FALSE;
|
||||
for (i = 0; i < mp->num_in; i++) {
|
||||
if (prop->morg)
|
||||
got_morg++;
|
||||
if (prop->houses != 5)
|
||||
good++;
|
||||
op = op->next;
|
||||
}
|
||||
if (!good || got_morg)
|
||||
--num_mon;
|
||||
}
|
||||
else
|
||||
op = op->next;
|
||||
}
|
||||
if (num_mon == 0) {
|
||||
if (got_morg)
|
||||
printf("You can't build on mortgaged monopolies.\n");
|
||||
else if (!good)
|
||||
printf("You can't build any more.\n");
|
||||
else
|
||||
printf("But you don't have any monopolies!!\n");
|
||||
return;
|
||||
}
|
||||
if (num_mon == 1)
|
||||
buy_h(monops[0]);
|
||||
else {
|
||||
names[num_mon++] = "done";
|
||||
names[num_mon--] = 0;
|
||||
if ((p=getinp("Which property do you wish to buy houses for? ", names)) == num_mon)
|
||||
return;
|
||||
buy_h(monops[p]);
|
||||
goto over;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
sell_h(mnp)
|
||||
MON *mnp; {
|
||||
|
||||
reg int i;
|
||||
reg MON *mp;
|
||||
reg int price;
|
||||
shrt input[3],temp[3];
|
||||
int tot;
|
||||
PROP *pp;
|
||||
|
||||
mp = mnp;
|
||||
price = mp->h_cost * 25;
|
||||
blew_it:
|
||||
printf("Houses will get you $%d apiece\n", price);
|
||||
list_cur(mp);
|
||||
printf("How many houses do you wish to sell from\n");
|
||||
for (i = 0; i < mp->num_in; i++) {
|
||||
pp = (PROP*) mp->sq[i]->desc;
|
||||
over:
|
||||
if (pp->houses == 0) {
|
||||
printf("%s (0):\n", mp->sq[i]->name);
|
||||
input[i] = temp[i] = 0;
|
||||
continue;
|
||||
}
|
||||
if (pp->houses < 5)
|
||||
sprintf(cur_prop,"%s (%d): ", mp->sq[i]->name, pp->houses);
|
||||
else
|
||||
sprintf(cur_prop,"%s (H): ", mp->sq[i]->name);
|
||||
input[i] = get_int(cur_prop);
|
||||
temp[i] = pp->houses - input[i];
|
||||
if (temp[i] < 0) {
|
||||
printf("That's too many. The most you can sell is %d\n", pp->houses);
|
||||
goto over;
|
||||
}
|
||||
}
|
||||
if (mp->num_in == 3 && (abs(temp[0] - temp[1]) > 1 ||
|
||||
abs(temp[0] - temp[2]) > 1 || abs(temp[1] - temp[2]) > 1)) {
|
||||
err: printf("That makes the spread too wide. Try again\n");
|
||||
goto blew_it;
|
||||
}
|
||||
else if (mp->num_in == 2 && abs(temp[0] - temp[1]) > 1)
|
||||
goto err;
|
||||
for (tot = i = 0; i < mp->num_in; i++)
|
||||
tot += input[i];
|
||||
if (tot) {
|
||||
printf("You asked to sell %d houses for $%d\n",tot,tot * price);
|
||||
if (getyn("Is that ok? ") == 0) {
|
||||
cur_p->money += tot * price;
|
||||
for (tot = i = 0; i < mp->num_in; i++)
|
||||
((PROP*)mp->sq[i]->desc)->houses = temp[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -117,6 +194,7 @@ err: printf("That makes the spread too wide. Try again\n");
|
||||
/*
|
||||
* This routine sells houses.
|
||||
*/
|
||||
void
|
||||
sell_houses() {
|
||||
|
||||
reg int num_mon;
|
||||
@@ -129,15 +207,15 @@ over:
|
||||
num_mon = 0;
|
||||
good = TRUE;
|
||||
for (op = cur_p->own_list; op; op = op->next)
|
||||
if (op->sqr->type == PRPTY && op->sqr->desc->monop) {
|
||||
mp = op->sqr->desc->mon_desc;
|
||||
if (op->sqr->type == PRPTY && ((PROP*)op->sqr->desc)->monop) {
|
||||
mp = ((PROP*)op->sqr->desc)->mon_desc;
|
||||
names[num_mon] = (monops[num_mon]=mp)->name;
|
||||
num_mon++;
|
||||
good = 0;
|
||||
do
|
||||
if (!good && op->sqr->desc->houses != 0)
|
||||
if (!good && ((PROP*)op->sqr->desc)->houses != 0)
|
||||
good++;
|
||||
while (op->next && op->sqr->desc->mon_desc == mp
|
||||
while (op->next && ((PROP*)op->sqr->desc)->mon_desc == mp
|
||||
&& (op=op->next));
|
||||
if (!good)
|
||||
--num_mon;
|
||||
@@ -158,73 +236,3 @@ over:
|
||||
goto over;
|
||||
}
|
||||
}
|
||||
|
||||
sell_h(mnp)
|
||||
MON *mnp; {
|
||||
|
||||
reg int i;
|
||||
reg MON *mp;
|
||||
reg int price;
|
||||
shrt input[3],temp[3];
|
||||
int tot;
|
||||
PROP *pp;
|
||||
|
||||
mp = mnp;
|
||||
price = mp->h_cost * 25;
|
||||
blew_it:
|
||||
printf("Houses will get you $%d apiece\n", price);
|
||||
list_cur(mp);
|
||||
printf("How many houses do you wish to sell from\n");
|
||||
for (i = 0; i < mp->num_in; i++) {
|
||||
pp = mp->sq[i]->desc;
|
||||
over:
|
||||
if (pp->houses == 0) {
|
||||
printf("%s (0):\n", mp->sq[i]->name);
|
||||
input[i] = temp[i] = 0;
|
||||
continue;
|
||||
}
|
||||
if (pp->houses < 5)
|
||||
sprintf(cur_prop,"%s (%d): ",mp->sq[i]->name,pp->houses);
|
||||
else
|
||||
sprintf(cur_prop,"%s (H): ",mp->sq[i]->name,pp->houses);
|
||||
input[i] = get_int(cur_prop);
|
||||
temp[i] = pp->houses - input[i];
|
||||
if (temp[i] < 0) {
|
||||
printf("That's too many. The most you can sell is %d\n", pp->houses);
|
||||
goto over;
|
||||
}
|
||||
}
|
||||
if (mp->num_in == 3 && (abs(temp[0] - temp[1]) > 1 ||
|
||||
abs(temp[0] - temp[2]) > 1 || abs(temp[1] - temp[2]) > 1)) {
|
||||
err: printf("That makes the spread too wide. Try again\n");
|
||||
goto blew_it;
|
||||
}
|
||||
else if (mp->num_in == 2 && abs(temp[0] - temp[1]) > 1)
|
||||
goto err;
|
||||
for (tot = i = 0; i < mp->num_in; i++)
|
||||
tot += input[i];
|
||||
if (tot) {
|
||||
printf("You asked to sell %d houses for $%d\n",tot,tot * price);
|
||||
if (getyn("Is that ok? ", yn) == 0) {
|
||||
cur_p->money += tot * price;
|
||||
for (tot = i = 0; i < mp->num_in; i++)
|
||||
mp->sq[i]->desc->houses = temp[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
list_cur(mp)
|
||||
reg MON *mp; {
|
||||
|
||||
reg int i;
|
||||
reg SQUARE *sqp;
|
||||
|
||||
for (i = 0; i < mp->num_in; i++) {
|
||||
sqp = mp->sq[i];
|
||||
if (sqp->desc->houses == 5)
|
||||
printf("%s (H) ", sqp->name);
|
||||
else
|
||||
printf("%s (%d) ", sqp->name, sqp->desc->houses);
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# include <stdio.h>
|
||||
# include "deck.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "deck.h"
|
||||
|
||||
/*
|
||||
* This program initializes the card files for monopoly.
|
||||
@@ -12,11 +13,11 @@
|
||||
* string to print, terminated with a null byte.
|
||||
*/
|
||||
|
||||
# define TRUE 1
|
||||
# define FALSE 0
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
# define bool char
|
||||
# define reg register
|
||||
#define bool char
|
||||
#define reg register
|
||||
|
||||
char *infile = "cards.inp", /* input file */
|
||||
*outfile = "cards.pck"; /* "packed" file */
|
||||
@@ -27,42 +28,7 @@ DECK deck[2];
|
||||
|
||||
FILE *inf, *outf;
|
||||
|
||||
main(ac, av)
|
||||
int ac;
|
||||
char *av[]; {
|
||||
|
||||
getargs(ac, av);
|
||||
if ((inf = fopen(infile, "r")) == NULL) {
|
||||
perror(infile);
|
||||
exit(1);
|
||||
}
|
||||
count();
|
||||
/*
|
||||
* allocate space for pointers.
|
||||
*/
|
||||
CC_D.offsets = calloc(CC_D.num_cards + 1, sizeof (long));
|
||||
CH_D.offsets = calloc(CH_D.num_cards + 1, sizeof (long));
|
||||
fseek(inf, 0L, 0);
|
||||
if ((outf = fopen(outfile, "w")) == NULL) {
|
||||
perror(outfile);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
fwrite(deck, sizeof (DECK), 2, outf);
|
||||
fwrite(CC_D.offsets, sizeof (long), CC_D.num_cards, outf);
|
||||
fwrite(CH_D.offsets, sizeof (long), CH_D.num_cards, outf);
|
||||
putem();
|
||||
|
||||
fclose(inf);
|
||||
fseek(outf, 0, 0L);
|
||||
fwrite(deck, sizeof (DECK), 2, outf);
|
||||
fwrite(CC_D.offsets, sizeof (long), CC_D.num_cards, outf);
|
||||
fwrite(CH_D.offsets, sizeof (long), CH_D.num_cards, outf);
|
||||
fclose(outf);
|
||||
printf("There were %d com. chest and %d chance cards\n", CC_D.num_cards, CH_D.num_cards);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void
|
||||
getargs(ac, av)
|
||||
int ac;
|
||||
char *av[]; {
|
||||
@@ -73,9 +39,11 @@ char *av[]; {
|
||||
outfile = av[3];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* count the cards
|
||||
*/
|
||||
void
|
||||
count() {
|
||||
|
||||
reg bool newline;
|
||||
@@ -95,9 +63,11 @@ count() {
|
||||
newline = (c == '\n');
|
||||
in_deck->num_cards++;
|
||||
}
|
||||
|
||||
/*
|
||||
* put strings in the file
|
||||
*/
|
||||
void
|
||||
putem() {
|
||||
|
||||
reg bool newline;
|
||||
@@ -138,3 +108,40 @@ putem() {
|
||||
}
|
||||
putc('\0', outf);
|
||||
}
|
||||
|
||||
int
|
||||
main(ac, av)
|
||||
int ac;
|
||||
char *av[]; {
|
||||
|
||||
getargs(ac, av);
|
||||
if ((inf = fopen(infile, "r")) == NULL) {
|
||||
perror(infile);
|
||||
exit(1);
|
||||
}
|
||||
count();
|
||||
/*
|
||||
* allocate space for pointers.
|
||||
*/
|
||||
CC_D.offsets = calloc(CC_D.num_cards + 1, sizeof (long));
|
||||
CH_D.offsets = calloc(CH_D.num_cards + 1, sizeof (long));
|
||||
fseek(inf, 0L, 0);
|
||||
if ((outf = fopen(outfile, "w")) == NULL) {
|
||||
perror(outfile);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
fwrite(deck, sizeof (DECK), 2, outf);
|
||||
fwrite(CC_D.offsets, sizeof (long), CC_D.num_cards, outf);
|
||||
fwrite(CH_D.offsets, sizeof (long), CH_D.num_cards, outf);
|
||||
putem();
|
||||
|
||||
fclose(inf);
|
||||
fseek(outf, 0, 0L);
|
||||
fwrite(deck, sizeof (DECK), 2, outf);
|
||||
fwrite(CC_D.offsets, sizeof (long), CC_D.num_cards, outf);
|
||||
fwrite(CH_D.offsets, sizeof (long), CH_D.num_cards, outf);
|
||||
fclose(outf);
|
||||
printf("There were %d com. chest and %d chance cards\n", CC_D.num_cards, CH_D.num_cards);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
# include "monop.ext"
|
||||
#include "extern.h"
|
||||
|
||||
/*
|
||||
* This routine uses a get-out-of-jail-free card to get the
|
||||
* player out of jail.
|
||||
*/
|
||||
void
|
||||
card() {
|
||||
|
||||
if (cur_p->loc != JAIL) {
|
||||
@@ -18,10 +19,12 @@ card() {
|
||||
cur_p->loc = 10; /* just visiting */
|
||||
cur_p->in_jail = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine returns the players get-out-of-jail-free card
|
||||
* to a deck.
|
||||
*/
|
||||
void
|
||||
ret_card(plr)
|
||||
reg PLAY *plr; {
|
||||
|
||||
@@ -31,9 +34,11 @@ reg PLAY *plr; {
|
||||
else
|
||||
CH_D.gojf_used = FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine deals with paying your way out of jail.
|
||||
*/
|
||||
void
|
||||
pay() {
|
||||
|
||||
if (cur_p->loc != JAIL) {
|
||||
@@ -45,9 +50,11 @@ pay() {
|
||||
cur_p->in_jail = 0;
|
||||
printf("That cost you $50\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine deals with a move in jail
|
||||
*/
|
||||
int
|
||||
move_jail(r1, r2)
|
||||
reg int r1, r2; {
|
||||
|
||||
@@ -70,6 +77,8 @@ moveit:
|
||||
goto moveit;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
printturn() {
|
||||
|
||||
if (cur_p->loc != JAIL)
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
# include "monop.ext"
|
||||
# include <ctype.h>
|
||||
# include <signal.h>
|
||||
#include "extern.h"
|
||||
#include <ctype.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
# define execsh(sh) execl(sh, shell_name[roll(1, num_names)-1], 0)
|
||||
#define execsh(sh) execl(sh, shell_name[roll(1, num_names)-1], (char*)0)
|
||||
|
||||
static char *shell_def = "/bin/csh",
|
||||
*shell_name[] = {
|
||||
@@ -21,26 +26,27 @@ static char *shell_def = "/bin/csh",
|
||||
|
||||
static int num_names = sizeof shell_name / sizeof (char *);;
|
||||
|
||||
char *shell_in();
|
||||
|
||||
/*
|
||||
* This routine executes a truncated set of commands until a
|
||||
* "yes or "no" answer is gotten.
|
||||
*/
|
||||
int
|
||||
getyn(prompt)
|
||||
reg char *prompt; {
|
||||
|
||||
reg int com;
|
||||
|
||||
for (;;)
|
||||
if ((com=getinp(prompt, yn)) < 2)
|
||||
if ((com=getinp(prompt, yesno)) < 2)
|
||||
return com;
|
||||
else
|
||||
(*func[com-2])();
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine tells the player if he's out of money.
|
||||
*/
|
||||
void
|
||||
notify() {
|
||||
|
||||
if (cur_p->money < 0)
|
||||
@@ -52,19 +58,24 @@ notify() {
|
||||
told_em = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine switches to the next player
|
||||
*/
|
||||
void
|
||||
next_play() {
|
||||
|
||||
player = ++player % num_play;
|
||||
player++;
|
||||
player %= num_play;
|
||||
cur_p = &play[player];
|
||||
num_doub = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine gets an integer from the keyboard after the
|
||||
* given prompt.
|
||||
*/
|
||||
int
|
||||
get_int(prompt)
|
||||
reg char *prompt; {
|
||||
|
||||
@@ -74,7 +85,7 @@ reg char *prompt; {
|
||||
|
||||
for (;;) {
|
||||
inter:
|
||||
printf(prompt);
|
||||
printf("%s", prompt);
|
||||
num = 0;
|
||||
for (sp = buf; (*sp=getchar()) != '\n' && !feof(stdin); sp++)
|
||||
if (*sp == -1) /* check for interrupted system call */
|
||||
@@ -95,9 +106,28 @@ inter:
|
||||
printf("I can't understand that\n");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine sets things up as if it is a new monopoly
|
||||
*/
|
||||
static void
|
||||
is_monop(mp, pl)
|
||||
reg MON *mp;
|
||||
int pl; {
|
||||
|
||||
reg int i;
|
||||
|
||||
mp->owner = pl;
|
||||
mp->num_own = mp->num_in;
|
||||
for (i = 0; i < mp->num_in; i++)
|
||||
((PROP*)mp->sq[i]->desc)->monop = TRUE;
|
||||
mp->name = mp->mon_n;
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine sets the monopoly flag from the list given.
|
||||
*/
|
||||
void
|
||||
set_ownlist(pl)
|
||||
int pl; {
|
||||
|
||||
@@ -146,10 +176,10 @@ int pl; {
|
||||
#ifdef DEBUG
|
||||
printf(" case PRPTY:\n");
|
||||
#endif
|
||||
orig = op->sqr->desc->mon_desc;
|
||||
orig = ((PROP*)op->sqr->desc)->mon_desc;
|
||||
orig_op = op;
|
||||
num = 0;
|
||||
while (op && op->sqr->desc->mon_desc == orig) {
|
||||
while (op && ((PROP*)op->sqr->desc)->mon_desc == orig) {
|
||||
#ifdef DEBUG
|
||||
printf("iter: %d\n", num);
|
||||
#endif
|
||||
@@ -166,17 +196,17 @@ int pl; {
|
||||
printf("num = %d\n");
|
||||
#endif
|
||||
if (orig == 0) {
|
||||
printf("panic: bad monopoly descriptor: orig = %d\n", orig);
|
||||
printf("panic: bad monopoly descriptor: orig = %p\n", orig);
|
||||
printf("player # %d\n", pl+1);
|
||||
printhold(pl);
|
||||
printf("orig_op = %d\n", orig_op);
|
||||
printf("orig_op = %p\n", orig_op);
|
||||
printf("orig_op->sqr->type = %d (PRPTY)\n", op->sqr->type);
|
||||
printf("orig_op->next = %d\n", op->next);
|
||||
printf("orig_op->sqr->desc = %d\n", op->sqr->desc);
|
||||
printf("op = %d\n", op);
|
||||
printf("orig_op->next = %p\n", op->next);
|
||||
printf("orig_op->sqr->desc = %p\n", op->sqr->desc);
|
||||
printf("op = %p\n", op);
|
||||
printf("op->sqr->type = %d (PRPTY)\n", op->sqr->type);
|
||||
printf("op->next = %d\n", op->next);
|
||||
printf("op->sqr->desc = %d\n", op->sqr->desc);
|
||||
printf("op->next = %p\n", op->next);
|
||||
printf("op->sqr->desc = %p\n", op->sqr->desc);
|
||||
printf("num = %d\n", num);
|
||||
}
|
||||
#ifdef DEBUG
|
||||
@@ -190,104 +220,64 @@ int pl; {
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* This routine sets things up as if it is a new monopoly
|
||||
*/
|
||||
is_monop(mp, pl)
|
||||
reg MON *mp;
|
||||
int pl; {
|
||||
|
||||
reg char *sp;
|
||||
reg int i;
|
||||
|
||||
mp->owner = pl;
|
||||
mp->num_own = mp->num_in;
|
||||
for (i = 0; i < mp->num_in; i++)
|
||||
mp->sq[i]->desc->monop = TRUE;
|
||||
mp->name = mp->mon_n;
|
||||
}
|
||||
/*
|
||||
* This routine sets things up as if it is no longer a monopoly
|
||||
*/
|
||||
void
|
||||
isnot_monop(mp)
|
||||
reg MON *mp; {
|
||||
|
||||
reg char *sp;
|
||||
reg int i;
|
||||
|
||||
mp->owner = -1;
|
||||
for (i = 0; i < mp->num_in; i++)
|
||||
mp->sq[i]->desc->monop = FALSE;
|
||||
((PROP*)mp->sq[i]->desc)->monop = FALSE;
|
||||
mp->name = mp->not_m;
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine gives a list of the current player's routine
|
||||
*/
|
||||
void
|
||||
list() {
|
||||
|
||||
printhold(player);
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine gives a list of a given players holdings
|
||||
*/
|
||||
void
|
||||
list_all() {
|
||||
|
||||
reg int pl;
|
||||
|
||||
while ((pl=getinp("Whose holdings do you want to see? ", name_list)) < num_play)
|
||||
printhold(pl);
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine gives the players a chance before it exits.
|
||||
*/
|
||||
quit() {
|
||||
void
|
||||
quit(int sig) {
|
||||
|
||||
putchar('\n');
|
||||
if (getyn("Do you all really want to quit? ", yn) == 0)
|
||||
if (getyn("Do you all really want to quit? ") == 0)
|
||||
exit(0);
|
||||
signal(2, quit);
|
||||
}
|
||||
/*
|
||||
* This routine copies one structure to another
|
||||
*/
|
||||
cpy_st(s1, s2, size)
|
||||
reg int *s1, *s2, size; {
|
||||
|
||||
size /= 2;
|
||||
while (size--)
|
||||
*s1++ = *s2++;
|
||||
int
|
||||
quitgame()
|
||||
{
|
||||
quit(0);
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
* This routine forks off a shell. It uses the users login shell
|
||||
*/
|
||||
shell_out() {
|
||||
|
||||
static char *shell = NULL;
|
||||
|
||||
printline();
|
||||
if (shell == NULL)
|
||||
shell = shell_in();
|
||||
fflush();
|
||||
if (!fork()) {
|
||||
signal(SIGINT, SIG_DFL);
|
||||
execsh(shell);
|
||||
}
|
||||
ignoresigs();
|
||||
wait();
|
||||
resetsigs();
|
||||
putchar('\n');
|
||||
printline();
|
||||
}
|
||||
/*
|
||||
* This routine looks up the users login shell
|
||||
*/
|
||||
# include <pwd.h>
|
||||
|
||||
struct passwd *getpwuid();
|
||||
|
||||
char *getenv();
|
||||
|
||||
char *
|
||||
static char *
|
||||
shell_in() {
|
||||
|
||||
reg struct passwd *pp;
|
||||
@@ -303,24 +293,49 @@ shell_in() {
|
||||
}
|
||||
return sp;
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine sets things up to ignore all the signals.
|
||||
*/
|
||||
static void
|
||||
ignoresigs() {
|
||||
|
||||
reg int i;
|
||||
|
||||
for (i = 0; i < NSIG; i++)
|
||||
signal(i, SIG_IGN);
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine sets up things as they were before.
|
||||
*/
|
||||
static void
|
||||
resetsigs() {
|
||||
|
||||
reg int i;
|
||||
|
||||
for (i = 0; i < NSIG; i++)
|
||||
signal(i, SIG_DFL);
|
||||
signal(2, quit);
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine forks off a shell. It uses the users login shell
|
||||
*/
|
||||
void
|
||||
shell_out() {
|
||||
static char *shell = NULL;
|
||||
int status;
|
||||
|
||||
printline();
|
||||
if (shell == NULL)
|
||||
shell = shell_in();
|
||||
fflush(stdout);
|
||||
if (!fork()) {
|
||||
signal(SIGINT, SIG_DFL);
|
||||
execsh(shell);
|
||||
}
|
||||
ignoresigs();
|
||||
wait(&status);
|
||||
resetsigs();
|
||||
putchar('\n');
|
||||
printline();
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
/* name owner num_in num_own h_cost not_m mon_n sq */
|
||||
{0, -1, 2, 0, 1, "Purple", "PURPLE", {1,3}},
|
||||
{0, -1, 3, 0, 1, "Lt. Blue", "LT. BLUE", {6,8,9}},
|
||||
{0, -1, 3, 0, 2, "Violet", "VIOLET", {11,13,14}},
|
||||
{0, -1, 3, 0, 2, "Orange", "ORANGE", {16,18,19}},
|
||||
{0, -1, 3, 0, 3, "Red", "RED", {21,23,24}},
|
||||
{0, -1, 3, 0, 3, "Yellow", "YELLOW", {26,27,29}},
|
||||
{0, -1, 3, 0, 4, "Green", "GREEN", {31,32,34}},
|
||||
{0, -1, 2, 0, 4, "Dk. Blue", "DK. BLUE", {37,39}}
|
||||
9
src/games/monop/mon.dat.h
Normal file
9
src/games/monop/mon.dat.h
Normal file
@@ -0,0 +1,9 @@
|
||||
/* name owner num_in num_own h_cost not_m mon_n sq */
|
||||
{0, -1, 2, 0, 1, "Purple", "PURPLE", {(SQUARE*)1,(SQUARE*)3}},
|
||||
{0, -1, 3, 0, 1, "Lt. Blue", "LT. BLUE", {(SQUARE*)6,(SQUARE*)8,(SQUARE*)9}},
|
||||
{0, -1, 3, 0, 2, "Violet", "VIOLET", {(SQUARE*)11,(SQUARE*)13,(SQUARE*)14}},
|
||||
{0, -1, 3, 0, 2, "Orange", "ORANGE", {(SQUARE*)16,(SQUARE*)18,(SQUARE*)19}},
|
||||
{0, -1, 3, 0, 3, "Red", "RED", {(SQUARE*)21,(SQUARE*)23,(SQUARE*)24}},
|
||||
{0, -1, 3, 0, 3, "Yellow", "YELLOW", {(SQUARE*)26,(SQUARE*)27,(SQUARE*)29}},
|
||||
{0, -1, 3, 0, 4, "Green", "GREEN", {(SQUARE*)31,(SQUARE*)32,(SQUARE*)34}},
|
||||
{0, -1, 2, 0, 4, "Dk. Blue", "DK. BLUE", {(SQUARE*)37,(SQUARE*)39}}
|
||||
@@ -1,37 +1,14 @@
|
||||
# include "monop.def"
|
||||
#include "defines.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
|
||||
/*
|
||||
* This program implements a monopoly game
|
||||
*/
|
||||
main(ac, av)
|
||||
reg int ac;
|
||||
reg char *av[]; {
|
||||
|
||||
|
||||
srand(getpid());
|
||||
if (ac > 1) {
|
||||
if (!rest_f(av[1]))
|
||||
restore();
|
||||
}
|
||||
else {
|
||||
getplayers();
|
||||
init_players();
|
||||
init_monops();
|
||||
}
|
||||
num_luck = sizeof lucky_mes / sizeof (char *);
|
||||
init_decks();
|
||||
signal(2, quit);
|
||||
for (;;) {
|
||||
printf("\n%s (%d) (cash $%d) on %s\n", cur_p->name, player + 1,
|
||||
cur_p->money, board[cur_p->loc].name);
|
||||
printturn();
|
||||
force_morg();
|
||||
execute(getinp("-- Command: ", comlist));
|
||||
}
|
||||
}
|
||||
/*
|
||||
* This routine gets the names of the players
|
||||
*/
|
||||
void
|
||||
getplayers() {
|
||||
|
||||
reg char *sp;
|
||||
@@ -64,25 +41,27 @@ over:
|
||||
name_list[i] = 0;
|
||||
for (i = 0; i < num_play; i++)
|
||||
for (j = i + 1; j < num_play; j++)
|
||||
if (strcmp(name_list[i], name_list[j]) == 0) {
|
||||
if (strcasecmp(name_list[i], name_list[j]) == 0) {
|
||||
if (i != num_play - 1)
|
||||
printf("Hey!!! Some of those are IDENTICAL!! Let's try that again....\n");
|
||||
else
|
||||
printf("\"done\" is a reserved word. Please try again\n");
|
||||
for (i = 0; i < num_play; i++)
|
||||
cfree(play[i].name);
|
||||
cfree(play);
|
||||
free(play[i].name);
|
||||
free(play);
|
||||
goto blew_it;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine figures out who goes first
|
||||
*/
|
||||
void
|
||||
init_players() {
|
||||
|
||||
reg int i, rl, cur_max;
|
||||
bool over;
|
||||
int max_pl;
|
||||
bool over = 0;
|
||||
int max_pl = 0;
|
||||
|
||||
again:
|
||||
putchar('\n');
|
||||
@@ -105,9 +84,11 @@ again:
|
||||
cur_p = &play[max_pl];
|
||||
printf("%s (%d) goes first\n", cur_p->name, max_pl + 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine initalizes the monopoly structures.
|
||||
*/
|
||||
void
|
||||
init_monops() {
|
||||
|
||||
reg MON *mp;
|
||||
@@ -119,3 +100,34 @@ init_monops() {
|
||||
mp->sq[i] = &board[(int)(mp->sq[i])];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This program implements a monopoly game
|
||||
*/
|
||||
int
|
||||
main(ac, av)
|
||||
reg int ac;
|
||||
reg char *av[]; {
|
||||
|
||||
|
||||
srand(getpid());
|
||||
if (ac > 1) {
|
||||
if (!rest_f(av[1]))
|
||||
restore();
|
||||
}
|
||||
else {
|
||||
getplayers();
|
||||
init_players();
|
||||
init_monops();
|
||||
}
|
||||
num_luck = sizeof lucky_mes / sizeof (char *);
|
||||
init_decks();
|
||||
signal(2, quit);
|
||||
for (;;) {
|
||||
printf("\n%s (%d) (cash $%d) on %s\n", cur_p->name, player + 1,
|
||||
cur_p->money, board[(int)cur_p->loc].name);
|
||||
printturn();
|
||||
force_morg();
|
||||
execute(getinp("-- Command: ", comlist));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,4 +95,34 @@ typedef struct prp_st PROP;
|
||||
typedef struct rr_st RR_S;
|
||||
typedef struct rr_st UTIL_S;
|
||||
|
||||
int cc(), chance(), lux_tax(), goto_jail(), inc_tax();
|
||||
int rest_f(char *file);
|
||||
int get_int(char *prompt);
|
||||
int roll(int ndie, int nsides);
|
||||
int getinp(char *prompt, char *list[]);
|
||||
int move_jail(int r1, int r2);
|
||||
int getyn(char *prompt);
|
||||
int prop_worth(PLAY *plp);
|
||||
|
||||
void goto_jail(void);
|
||||
void inc_tax(void);
|
||||
void lux_tax(void);
|
||||
void cc(void);
|
||||
void chance(void);
|
||||
void init_decks(void);
|
||||
void quit(int sig);
|
||||
void printturn(void);
|
||||
void force_morg(void);
|
||||
void execute(int com_num);
|
||||
void move(int rl);
|
||||
void notify(void);
|
||||
void next_play(void);
|
||||
void buy(int player, SQUARE *sqrp);
|
||||
void bid(void);
|
||||
void rent(SQUARE *sqp);
|
||||
void ret_card(PLAY *plr);
|
||||
void printhold(int pl);
|
||||
void isnot_monop(MON *mp);
|
||||
void printsq(int sqn, bool eoln);
|
||||
void add_list(int plr, OWN **head, int op_sqr);
|
||||
void del_list(int plr, OWN **head, shrt op_sqr);
|
||||
void set_ownlist(int pl);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# include "monop.ext"
|
||||
#include "extern.h"
|
||||
|
||||
/*
|
||||
* These routines deal with mortgaging.
|
||||
@@ -29,11 +29,50 @@ static shrt square[MAX_PRP+2];
|
||||
|
||||
static int num_good,got_houses;
|
||||
|
||||
/*
|
||||
* This routine sets up the list of mortgageable property
|
||||
*/
|
||||
static int
|
||||
set_mlist() {
|
||||
|
||||
reg OWN *op;
|
||||
|
||||
num_good = 0;
|
||||
for (op = cur_p->own_list; op; op = op->next)
|
||||
if (! ((PROP*)op->sqr->desc)->morg) {
|
||||
if (op->sqr->type == PRPTY && ((PROP*)op->sqr->desc)->houses)
|
||||
got_houses++;
|
||||
else {
|
||||
names[num_good] = op->sqr->name;
|
||||
square[num_good++] = sqnum(op->sqr);
|
||||
}
|
||||
}
|
||||
names[num_good++] = "done";
|
||||
names[num_good--] = 0;
|
||||
return num_good;
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine actually mortgages the property.
|
||||
*/
|
||||
static void
|
||||
m(prop)
|
||||
reg int prop; {
|
||||
|
||||
reg int price;
|
||||
|
||||
price = board[prop].cost/2;
|
||||
((PROP*)board[prop].desc)->morg = TRUE;
|
||||
printf("That got you $%d\n",price);
|
||||
cur_p->money += price;
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine is the command level response the mortgage command.
|
||||
* it gets the list of mortgageable property and asks which are to
|
||||
* be mortgaged.
|
||||
*/
|
||||
void
|
||||
mortgage() {
|
||||
|
||||
reg int prop;
|
||||
@@ -56,47 +95,52 @@ mortgage() {
|
||||
if (prop == num_good)
|
||||
return;
|
||||
m(square[prop]);
|
||||
notify(cur_p);
|
||||
notify();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine sets up the list of mortgageable property
|
||||
* This routine sets up the list of mortgaged property
|
||||
*/
|
||||
set_mlist() {
|
||||
static int
|
||||
set_umlist() {
|
||||
|
||||
reg OWN *op;
|
||||
|
||||
num_good = 0;
|
||||
for (op = cur_p->own_list; op; op = op->next)
|
||||
if (!op->sqr->desc->morg)
|
||||
if (op->sqr->type == PRPTY && op->sqr->desc->houses)
|
||||
got_houses++;
|
||||
else {
|
||||
names[num_good] = op->sqr->name;
|
||||
square[num_good++] = sqnum(op->sqr);
|
||||
}
|
||||
if (((PROP*)op->sqr->desc)->morg) {
|
||||
names[num_good] = op->sqr->name;
|
||||
square[num_good++] = sqnum(op->sqr);
|
||||
}
|
||||
names[num_good++] = "done";
|
||||
names[num_good--] = 0;
|
||||
return num_good;
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine actually mortgages the property.
|
||||
* This routine actually unmortgages the property
|
||||
*/
|
||||
m(prop)
|
||||
static void
|
||||
unm(prop)
|
||||
reg int prop; {
|
||||
|
||||
reg int price;
|
||||
|
||||
price = board[prop].cost/2;
|
||||
board[prop].desc->morg = TRUE;
|
||||
printf("That got you $%d\n",price);
|
||||
cur_p->money += price;
|
||||
((PROP*)board[prop].desc)->morg = FALSE;
|
||||
price += price/10;
|
||||
printf("That cost you $%d\n",price);
|
||||
cur_p->money -= price;
|
||||
set_umlist();
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine is the command level repsponse to the unmortgage
|
||||
* command. It gets the list of mortgaged property and asks which are
|
||||
* to be unmortgaged.
|
||||
*/
|
||||
void
|
||||
unmortgage() {
|
||||
|
||||
reg int prop;
|
||||
@@ -118,52 +162,11 @@ unmortgage() {
|
||||
unm(square[prop]);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* This routine sets up the list of mortgaged property
|
||||
*/
|
||||
set_umlist() {
|
||||
|
||||
reg OWN *op;
|
||||
|
||||
num_good = 0;
|
||||
for (op = cur_p->own_list; op; op = op->next)
|
||||
if (op->sqr->desc->morg) {
|
||||
names[num_good] = op->sqr->name;
|
||||
square[num_good++] = sqnum(op->sqr);
|
||||
}
|
||||
names[num_good++] = "done";
|
||||
names[num_good--] = 0;
|
||||
return num_good;
|
||||
}
|
||||
/*
|
||||
* This routine actually unmortgages the property
|
||||
*/
|
||||
unm(prop)
|
||||
reg int prop; {
|
||||
|
||||
reg int price;
|
||||
|
||||
price = board[prop].cost/2;
|
||||
board[prop].desc->morg = FALSE;
|
||||
price += price/10;
|
||||
printf("That cost you $%d\n",price);
|
||||
cur_p->money -= price;
|
||||
set_umlist();
|
||||
}
|
||||
/*
|
||||
* This routine forces the indebted player to fix his
|
||||
* financial woes.
|
||||
*/
|
||||
force_morg() {
|
||||
|
||||
told_em = fixing = TRUE;
|
||||
while (cur_p->money <= 0)
|
||||
fix_ex(getinp("How are you going to fix it up? ",morg_coms));
|
||||
fixing = FALSE;
|
||||
}
|
||||
/*
|
||||
* This routine is a special execute for the force_morg routine
|
||||
*/
|
||||
static void
|
||||
fix_ex(com_num)
|
||||
reg int com_num; {
|
||||
|
||||
@@ -171,3 +174,16 @@ reg int com_num; {
|
||||
(*func[com_num])();
|
||||
notify();
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine forces the indebted player to fix his
|
||||
* financial woes.
|
||||
*/
|
||||
void
|
||||
force_morg() {
|
||||
|
||||
told_em = fixing = TRUE;
|
||||
while (cur_p->money <= 0)
|
||||
fix_ex(getinp("How are you going to fix it up? ",morg_coms));
|
||||
fixing = FALSE;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
# include "monop.ext"
|
||||
#include "extern.h"
|
||||
|
||||
static char buf[80], /* output buffer */
|
||||
*header = "Name Own Price Mg # Rent";
|
||||
static char *header = "Name Own Price Mg # Rent";
|
||||
|
||||
/*
|
||||
* This routine prints out the current board
|
||||
*/
|
||||
void
|
||||
printboard() {
|
||||
|
||||
reg int i;
|
||||
@@ -17,13 +17,14 @@ printboard() {
|
||||
printsq(i+N_SQRS/2, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine lists where each player is.
|
||||
*/
|
||||
void
|
||||
where() {
|
||||
|
||||
reg int i;
|
||||
char *bsp;
|
||||
|
||||
printf("%s Player\n", header);
|
||||
for (i = 0; i < num_play; i++) {
|
||||
@@ -34,9 +35,24 @@ where() {
|
||||
putchar('\n');
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine prints out the mortgage flag.
|
||||
*/
|
||||
static void
|
||||
printmorg(sqp)
|
||||
reg SQUARE *sqp; {
|
||||
|
||||
if (((PROP*)sqp->desc)->morg)
|
||||
printf(" * ");
|
||||
else
|
||||
printf(" ");
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine prints out an individual square
|
||||
*/
|
||||
void
|
||||
printsq(sqn, eoln)
|
||||
int sqn;
|
||||
reg bool eoln; {
|
||||
@@ -44,7 +60,6 @@ reg bool eoln; {
|
||||
reg int rnt;
|
||||
reg PROP *pp;
|
||||
reg SQUARE *sqp;
|
||||
int i;
|
||||
|
||||
sqp = &board[sqn];
|
||||
printf("%-10.10s", sqp->name);
|
||||
@@ -60,7 +75,7 @@ spec:
|
||||
printf(" ");
|
||||
break;
|
||||
case PRPTY:
|
||||
pp = sqp->desc;
|
||||
pp = (PROP*) sqp->desc;
|
||||
if (sqp->owner < 0) {
|
||||
printf(" - %-8.8s %3d", pp->mon_desc->name, sqp->cost);
|
||||
if (!eoln)
|
||||
@@ -74,7 +89,7 @@ spec:
|
||||
if (pp->houses < 5)
|
||||
if (pp->houses > 0)
|
||||
printf("%d %4d", pp->houses,
|
||||
pp->rent[pp->houses]);
|
||||
pp->rent[(int)pp->houses]);
|
||||
else
|
||||
printf("0 %4d", pp->rent[0] * 2);
|
||||
else
|
||||
@@ -92,7 +107,7 @@ spec:
|
||||
}
|
||||
printf(" %d 150", sqp->owner+1);
|
||||
printmorg(sqp);
|
||||
printf("%d", play[sqp->owner].num_util);
|
||||
printf("%d", play[(int)sqp->owner].num_util);
|
||||
if (!eoln)
|
||||
printf(" ");
|
||||
break;
|
||||
@@ -106,33 +121,23 @@ spec:
|
||||
printf(" %d Railroad 200", sqp->owner+1);
|
||||
printmorg(sqp);
|
||||
rnt = 25;
|
||||
rnt <<= play[sqp->owner].num_rr - 1;
|
||||
printf("%d %4d", play[sqp->owner].num_rr, 25 << (play[sqp->owner].num_rr - 1));
|
||||
rnt <<= play[(int)sqp->owner].num_rr - 1;
|
||||
printf("%d %4d", play[(int)sqp->owner].num_rr, 25 << (play[(int)sqp->owner].num_rr - 1));
|
||||
break;
|
||||
}
|
||||
if (eoln)
|
||||
putchar('\n');
|
||||
}
|
||||
/*
|
||||
* This routine prints out the mortgage flag.
|
||||
*/
|
||||
printmorg(sqp)
|
||||
reg SQUARE *sqp; {
|
||||
|
||||
if (sqp->desc->morg)
|
||||
printf(" * ");
|
||||
else
|
||||
printf(" ");
|
||||
}
|
||||
/*
|
||||
* This routine lists the holdings of the player given
|
||||
*/
|
||||
void
|
||||
printhold(pl)
|
||||
reg int pl; {
|
||||
|
||||
reg OWN *op;
|
||||
reg PLAY *pp;
|
||||
char *bsp;
|
||||
|
||||
pp = &play[pl];
|
||||
printf("%s's (%d) holdings (Total worth: $%d):\n", name_list[pl], pl+1,
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
# include "monop.ext"
|
||||
#include "extern.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
/*
|
||||
* This routine deals with buying property, setting all the
|
||||
* appropriate flags.
|
||||
*/
|
||||
void
|
||||
buy(player, sqrp)
|
||||
reg int player;
|
||||
reg SQUARE *sqrp; {
|
||||
@@ -12,77 +14,12 @@ reg SQUARE *sqrp; {
|
||||
sqrp->owner = player;
|
||||
add_list(player, &(play[player].own_list), cur_p->loc);
|
||||
}
|
||||
/*
|
||||
* This routine adds an item to the list.
|
||||
*/
|
||||
add_list(plr, head, op_sqr)
|
||||
int plr;
|
||||
OWN **head;
|
||||
int op_sqr; {
|
||||
|
||||
reg int val;
|
||||
reg OWN *tp, *last_tp;
|
||||
MON *mp;
|
||||
OWN *op;
|
||||
|
||||
op = calloc(1, sizeof (OWN));
|
||||
op->sqr = &board[op_sqr];
|
||||
val = value(op->sqr);
|
||||
last_tp = NULL;
|
||||
for (tp = *head; tp && value(tp->sqr) < val; tp = tp->next)
|
||||
if (val == value(tp->sqr)) {
|
||||
cfree(op);
|
||||
return;
|
||||
}
|
||||
else
|
||||
last_tp = tp;
|
||||
op->next = tp;
|
||||
if (last_tp != NULL)
|
||||
last_tp->next = op;
|
||||
else
|
||||
*head = op;
|
||||
if (!trading)
|
||||
set_ownlist(plr);
|
||||
}
|
||||
/*
|
||||
* This routine deletes property from the list.
|
||||
*/
|
||||
del_list(plr, head, op_sqr)
|
||||
int plr;
|
||||
OWN **head;
|
||||
shrt op_sqr; {
|
||||
|
||||
reg int i;
|
||||
reg OWN *op, *last_op;
|
||||
|
||||
switch (board[op_sqr].type) {
|
||||
case PRPTY:
|
||||
board[op_sqr].desc->mon_desc->num_own--;
|
||||
break;
|
||||
case RR:
|
||||
play[plr].num_rr--;
|
||||
break;
|
||||
case UTIL:
|
||||
play[plr].num_util--;
|
||||
break;
|
||||
}
|
||||
last_op = NULL;
|
||||
for (op = *head; op; op = op->next)
|
||||
if (op->sqr == &board[op_sqr])
|
||||
break;
|
||||
else
|
||||
last_op = op;
|
||||
if (last_op == NULL)
|
||||
*head = op->next;
|
||||
else {
|
||||
last_op->next = op->next;
|
||||
cfree(op);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* This routine calculates the value for sorting of the
|
||||
* given square.
|
||||
*/
|
||||
static int
|
||||
value(sqp)
|
||||
reg SQUARE *sqp; {
|
||||
|
||||
@@ -104,13 +41,84 @@ reg SQUARE *sqp; {
|
||||
case PRPTY:
|
||||
return 8 + (PROP *)(sqp->desc) - prop;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine adds an item to the list.
|
||||
*/
|
||||
void
|
||||
add_list(plr, head, op_sqr)
|
||||
int plr;
|
||||
OWN **head;
|
||||
int op_sqr; {
|
||||
|
||||
reg int val;
|
||||
reg OWN *tp, *last_tp;
|
||||
OWN *op;
|
||||
|
||||
op = calloc(1, sizeof (OWN));
|
||||
op->sqr = &board[op_sqr];
|
||||
val = value(op->sqr);
|
||||
last_tp = NULL;
|
||||
for (tp = *head; tp && value(tp->sqr) < val; tp = tp->next)
|
||||
if (val == value(tp->sqr)) {
|
||||
free(op);
|
||||
return;
|
||||
}
|
||||
else
|
||||
last_tp = tp;
|
||||
op->next = tp;
|
||||
if (last_tp != NULL)
|
||||
last_tp->next = op;
|
||||
else
|
||||
*head = op;
|
||||
if (!trading)
|
||||
set_ownlist(plr);
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine deletes property from the list.
|
||||
*/
|
||||
void
|
||||
del_list(plr, head, op_sqr)
|
||||
int plr;
|
||||
OWN **head;
|
||||
shrt op_sqr; {
|
||||
|
||||
reg OWN *op, *last_op;
|
||||
|
||||
switch (board[(int)op_sqr].type) {
|
||||
case PRPTY:
|
||||
((PROP*)board[(int)op_sqr].desc)->mon_desc->num_own--;
|
||||
break;
|
||||
case RR:
|
||||
play[plr].num_rr--;
|
||||
break;
|
||||
case UTIL:
|
||||
play[plr].num_util--;
|
||||
break;
|
||||
}
|
||||
last_op = NULL;
|
||||
for (op = *head; op; op = op->next)
|
||||
if (op->sqr == &board[(int)op_sqr])
|
||||
break;
|
||||
else
|
||||
last_op = op;
|
||||
if (last_op == NULL)
|
||||
*head = op->next;
|
||||
else {
|
||||
last_op->next = op->next;
|
||||
free(op);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine accepts bids for the current peice
|
||||
* of property.
|
||||
*/
|
||||
void
|
||||
bid() {
|
||||
|
||||
static bool in[MAX_PL];
|
||||
reg int i, num_in, cur_max;
|
||||
char buf[80];
|
||||
@@ -123,7 +131,8 @@ bid() {
|
||||
cur_max = 0;
|
||||
num_in = num_play;
|
||||
while (num_in > 1 || (cur_max == 0 && num_in > 0)) {
|
||||
i = ++i % num_play;
|
||||
i++;
|
||||
i %= num_play;
|
||||
if (in[i]) {
|
||||
do {
|
||||
sprintf(buf, "%s: ", name_list[i]);
|
||||
@@ -142,19 +151,23 @@ bid() {
|
||||
}
|
||||
}
|
||||
if (cur_max != 0) {
|
||||
while (!in[i])
|
||||
i = ++i % num_play;
|
||||
while (!in[i]) {
|
||||
i++;
|
||||
i %= num_play;
|
||||
}
|
||||
printf("It goes to %s (%d) for $%d\n",play[i].name,i+1,cur_max);
|
||||
buy(i, &board[cur_p->loc]);
|
||||
buy(i, &board[(int)cur_p->loc]);
|
||||
play[i].money -= cur_max;
|
||||
}
|
||||
else
|
||||
printf("Nobody seems to want it, so we'll leave it for later\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine calculates the value of the property
|
||||
* of given player.
|
||||
*/
|
||||
int
|
||||
prop_worth(plp)
|
||||
reg PLAY *plp; {
|
||||
|
||||
@@ -163,9 +176,9 @@ reg PLAY *plp; {
|
||||
|
||||
worth = 0;
|
||||
for (op = plp->own_list; op; op = op->next) {
|
||||
if (op->sqr->type == PRPTY && op->sqr->desc->monop)
|
||||
worth += op->sqr->desc->mon_desc->h_cost * 50 *
|
||||
op->sqr->desc->houses;
|
||||
if (op->sqr->type == PRPTY && ((PROP*)op->sqr->desc)->monop)
|
||||
worth += ((PROP*)op->sqr->desc)->mon_desc->h_cost * 50 *
|
||||
((PROP*)op->sqr->desc)->houses;
|
||||
worth += op->sqr->cost;
|
||||
}
|
||||
return worth;
|
||||
|
||||
@@ -1,33 +1,34 @@
|
||||
# include "monop.ext"
|
||||
#include "extern.h"
|
||||
|
||||
/*
|
||||
* This routine has the player pay rent
|
||||
*/
|
||||
void
|
||||
rent(sqp)
|
||||
reg SQUARE *sqp; {
|
||||
|
||||
reg int rnt;
|
||||
reg int rnt = 0;
|
||||
reg PROP *pp;
|
||||
PLAY *plp;
|
||||
|
||||
plp = &play[sqp->owner];
|
||||
plp = &play[(int)sqp->owner];
|
||||
printf("Owned by %s\n", plp->name);
|
||||
if (sqp->desc->morg) {
|
||||
if (((PROP*)sqp->desc)->morg) {
|
||||
lucky("The thing is mortgaged. ");
|
||||
return;
|
||||
}
|
||||
switch (sqp->type) {
|
||||
case PRPTY:
|
||||
pp = sqp->desc;
|
||||
pp = (PROP*) sqp->desc;
|
||||
if (pp->monop)
|
||||
if (pp->houses == 0)
|
||||
printf("rent is %d\n", rnt=pp->rent[0] * 2);
|
||||
else if (pp->houses < 5)
|
||||
printf("with %d houses, rent is %d\n",
|
||||
pp->houses, rnt=pp->rent[pp->houses]);
|
||||
pp->houses, rnt=pp->rent[(int)pp->houses]);
|
||||
else
|
||||
printf("with a hotel, rent is %d\n",
|
||||
rnt=pp->rent[pp->houses]);
|
||||
rnt=pp->rent[(int)pp->houses]);
|
||||
else
|
||||
printf("rent is %d\n", rnt = pp->rent[0]);
|
||||
break;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user