Monop game done.

This commit is contained in:
Serge Vakulenko
2014-09-10 20:48:05 -07:00
parent d9d91365c0
commit 2ea9e02ba5
16 changed files with 264 additions and 244 deletions

View File

@@ -1,7 +1,7 @@
DESTDIR = /usr/local/retrobsd
MACHINE = mips
CC = gcc
CC = gcc -m32
AS = $(CC) -x assembler-with-cpp
LD = ld

View File

@@ -420,6 +420,7 @@ file /games/fish
file /games/fortune
file /games/hangman
file /games/mille
file /games/monop
file /games/morse
file /games/number
file /games/ppt
@@ -445,6 +446,8 @@ file /games/lib/cfscores
mode 0666
file /games/lib/fortunes.dat
mode 0444
file /games/lib/cards.pck
mode 0444
#
# Files: /include
@@ -733,6 +736,7 @@ 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/rain.0
file /share/man/cat6/rogue.0

View File

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

View File

@@ -4,11 +4,11 @@
# Makefile: K.S.
#
TOPSRC = $(shell cd ../../..; pwd)
#include $(TOPSRC)/target.mk
include $(TOPSRC)/cross.mk
CFLAGS = -DCROSS
include $(TOPSRC)/target.mk
#include $(TOPSRC)/cross.mk
#CFLAGS = -DCROSS -O
CFLAGS += -O -Werror -Wall
CFLAGS += -Werror -Wall
LIBS = -lc
OBJS = monop.o cards.o execute.o getinp.o houses.o jail.o misc.o \
@@ -27,14 +27,14 @@ monop: $(OBJS)
initdeck: initdeck.c deck.h
$(CC) -o initdeck $(LDFLAGS) $(CFLAGS) initdeck.c
cards.pck: initdeck cards.inp
cards.pck: #initdeck cards.inp
./initdeck
$(MAN): $(MANSRC)
$(MANROFF) $< > $@
clean:
rm -f *.o *.0 *.elf $(MAN) monop initdeck cards.pck *.elf *.dis tags *~
rm -f *.o *.0 *.elf $(MAN) monop initdeck *.elf *.dis tags *~
install: all
install monop $(DESTDIR)/games/

BIN
src/games/monop/cards.pck Normal file

Binary file not shown.

View File

@@ -11,3 +11,5 @@ struct dk_st { /* deck description structure */
};
typedef struct dk_st DECK;
void get_card(DECK *dp);

View File

@@ -28,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[]; {
@@ -74,9 +39,11 @@ char *av[]; {
outfile = av[3];
}
}
/*
* count the cards
*/
void
count() {
reg bool newline;
@@ -96,9 +63,11 @@ count() {
newline = (c == '\n');
in_deck->num_cards++;
}
/*
* put strings in the file
*/
void
putem() {
reg bool newline;
@@ -139,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;
}

View File

@@ -7,7 +7,7 @@
#include <sys/types.h>
#include <sys/wait.h>
#define execsh(sh) execl(sh, shell_name[roll(1, num_names)-1], NULL)
#define execsh(sh) execl(sh, shell_name[roll(1, num_names)-1], (char*)0)
static char *shell_def = "/bin/csh",
*shell_name[] = {
@@ -274,18 +274,6 @@ quitgame()
return 0;
}
/*
* This routine copies one structure to another
*/
void
cpy_st(s1, s2, size)
reg int *s1, *s2, size; {
size /= 2;
while (size--)
*s1++ = *s2++;
}
/*
* This routine looks up the users login shell
*/

View File

@@ -1,6 +1,7 @@
#include "defines.h"
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <signal.h>
@@ -46,8 +47,8 @@ over:
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;
}
}

View File

@@ -101,6 +101,7 @@ 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);
@@ -121,3 +122,7 @@ 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);

View File

@@ -29,6 +29,44 @@ 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
@@ -57,45 +95,44 @@ 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
*/
int
set_mlist() {
static int
set_umlist() {
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);
}
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
*/
void
m(prop)
static void
unm(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;
((PROP*)board[prop].desc)->morg = FALSE;
price += price/10;
printf("That cost you $%d\n",price);
cur_p->money -= price;
set_umlist();
}
/*
@@ -127,39 +164,15 @@ unmortgage() {
}
/*
* This routine sets up the list of mortgaged property
* This routine is a special execute for the force_morg routine
*/
int
set_umlist() {
static void
fix_ex(com_num)
reg int com_num; {
reg OWN *op;
num_good = 0;
for (op = cur_p->own_list; op; op = op->next)
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 unmortgages the property
*/
void
unm(prop)
reg int prop; {
reg int price;
price = board[prop].cost/2;
((PROP*)board[prop].desc)->morg = FALSE;
price += price/10;
printf("That cost you $%d\n",price);
cur_p->money -= price;
set_umlist();
told_em = FALSE;
(*func[com_num])();
notify();
}
/*
@@ -174,15 +187,3 @@ force_morg() {
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
*/
void
fix_ex(com_num)
reg int com_num; {
told_em = FALSE;
(*func[com_num])();
notify();
}

View File

@@ -1,7 +1,6 @@
#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
@@ -26,7 +25,6 @@ void
where() {
reg int i;
char *bsp;
printf("%s Player\n", header);
for (i = 0; i < num_play; i++) {
@@ -38,6 +36,19 @@ where() {
}
}
/*
* 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
*/
@@ -49,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);
@@ -79,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
@@ -97,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;
@@ -111,27 +121,14 @@ 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.
*/
void
printmorg(sqp)
reg SQUARE *sqp; {
if (((PROP*)sqp->desc)->morg)
printf(" * ");
else
printf(" ");
}
/*
* This routine lists the holdings of the player given
*/
@@ -141,7 +138,6 @@ 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,

View File

@@ -15,6 +15,35 @@ reg SQUARE *sqrp; {
add_list(player, &(play[player].own_list), cur_p->loc);
}
/*
* This routine calculates the value for sorting of the
* given square.
*/
static int
value(sqp)
reg SQUARE *sqp; {
reg int sqr;
sqr = sqnum(sqp);
switch (sqp->type) {
case SAFE:
return 0;
case SPEC:
return 1;
case UTIL:
if (sqr == 12)
return 2;
else
return 3;
case RR:
return 4 + sqr/10;
case PRPTY:
return 8 + (PROP *)(sqp->desc) - prop;
}
return 0;
}
/*
* This routine adds an item to the list.
*/
@@ -26,7 +55,6 @@ int op_sqr; {
reg int val;
reg OWN *tp, *last_tp;
MON *mp;
OWN *op;
op = calloc(1, sizeof (OWN));
@@ -35,7 +63,7 @@ int op_sqr; {
last_tp = NULL;
for (tp = *head; tp && value(tp->sqr) < val; tp = tp->next)
if (val == value(tp->sqr)) {
cfree(op);
free(op);
return;
}
else
@@ -58,12 +86,11 @@ int plr;
OWN **head;
shrt op_sqr; {
reg int i;
reg OWN *op, *last_op;
switch (board[op_sqr].type) {
switch (board[(int)op_sqr].type) {
case PRPTY:
((PROP*)board[op_sqr].desc)->mon_desc->num_own--;
((PROP*)board[(int)op_sqr].desc)->mon_desc->num_own--;
break;
case RR:
play[plr].num_rr--;
@@ -74,7 +101,7 @@ shrt op_sqr; {
}
last_op = NULL;
for (op = *head; op; op = op->next)
if (op->sqr == &board[op_sqr])
if (op->sqr == &board[(int)op_sqr])
break;
else
last_op = op;
@@ -82,34 +109,7 @@ shrt op_sqr; {
*head = op->next;
else {
last_op->next = op->next;
cfree(op);
}
}
/*
* This routine calculates the value for sorting of the
* given square.
*/
int
value(sqp)
reg SQUARE *sqp; {
reg int sqr;
sqr = sqnum(sqp);
switch (sqp->type) {
case SAFE:
return 0;
case SPEC:
return 1;
case UTIL:
if (sqr == 12)
return 2;
else
return 3;
case RR:
return 4 + sqr/10;
case PRPTY:
return 8 + (PROP *)(sqp->desc) - prop;
free(op);
}
}
@@ -131,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]);
@@ -150,10 +151,12 @@ 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

View File

@@ -7,11 +7,11 @@ 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 (((PROP*)sqp->desc)->morg) {
lucky("The thing is mortgaged. ");
@@ -25,10 +25,10 @@ reg SQUARE *sqp; {
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;

View File

@@ -1,6 +1,7 @@
/*
* This routine rolls ndie nside-sided dice.
*/
#include <stdlib.h>
int
roll(ndie, nsides)
@@ -10,6 +11,6 @@ int ndie, nsides; {
tot = 0;
while (ndie--)
tot += rand() % nsides + 1;
tot += random() % nsides + 1;
return tot;
}

View File

@@ -16,44 +16,30 @@ static int used[MAX_PRP];
static TRADE trades[2];
trade() {
/*
* This routine sets up the list of tradable property.
*/
static int
set_list(the_list)
reg OWN *the_list; {
reg int tradee, i;
reg int i;
reg OWN *op;
trading = TRUE;
for (i = 0; i < 2; i++) {
trades[i].cash = 0;
trades[i].gojf = FALSE;
trades[i].prop_list = NULL;
}
over:
if (num_play == 1) {
printf("There ain't no-one around to trade WITH!!\n");
return;
}
if (num_play > 2) {
tradee = getinp("Which player do you wish to trade with? ",
name_list);
if (tradee == num_play)
return;
if (tradee == player) {
printf("You can't trade with yourself!\n");
goto over;
}
}
else
tradee = 1 - player;
get_list(0, player);
get_list(1, tradee);
if (getyn("Do you wish a summary? ") == 0)
summate();
if (getyn("Is the trade ok? ") == 0)
do_trade();
i = 0;
for (op = the_list; op; op = op->next)
if (!used[i])
list[i++] = op->sqr->name;
list[i++] = "done";
list[i--] = 0;
return i;
}
/*
* This routine gets the list of things to be trader for the
* player, and puts in the structure given.
*/
static void
get_list(struct_no, play_no)
int struct_no, play_no; {
@@ -102,26 +88,11 @@ once_more:
}
}
}
/*
* This routine sets up the list of tradable property.
*/
set_list(the_list)
reg OWN *the_list; {
reg int i;
reg OWN *op;
i = 0;
for (op = the_list; op; op = op->next)
if (!used[i])
list[i++] = op->sqr->name;
list[i++] = "done";
list[i--] = 0;
return i;
}
/*
* This routine summates the trade.
*/
static void
summate() {
reg bool some;
@@ -148,17 +119,11 @@ summate() {
printf("\t-- Nothing --\n");
}
}
/*
* This routine actually executes the trade.
*/
do_trade() {
move_em(&trades[0], &trades[1]);
move_em(&trades[1], &trades[0]);
}
/*
* This routine does a switch from one player to another
*/
static void
move_em(from, to)
TRADE *from, *to; {
@@ -179,21 +144,69 @@ TRADE *from, *to; {
}
set_ownlist(to->trader);
}
/*
* This routine actually executes the trade.
*/
static void
do_trade() {
move_em(&trades[0], &trades[1]);
move_em(&trades[1], &trades[0]);
}
void
trade() {
reg int tradee, i;
trading = TRUE;
for (i = 0; i < 2; i++) {
trades[i].cash = 0;
trades[i].gojf = FALSE;
trades[i].prop_list = NULL;
}
over:
if (num_play == 1) {
printf("There ain't no-one around to trade WITH!!\n");
return;
}
if (num_play > 2) {
tradee = getinp("Which player do you wish to trade with? ",
name_list);
if (tradee == num_play)
return;
if (tradee == player) {
printf("You can't trade with yourself!\n");
goto over;
}
}
else
tradee = 1 - player;
get_list(0, player);
get_list(1, tradee);
if (getyn("Do you wish a summary? ") == 0)
summate();
if (getyn("Is the trade ok? ") == 0)
do_trade();
}
/*
* This routine lets a player resign
*/
void
resign() {
reg int i, new_own;
reg int i, new_own = 0;
reg OWN *op;
SQUARE *sqp;
if (cur_p->money <= 0) {
switch (board[cur_p->loc].type) {
switch (board[(int)cur_p->loc].type) {
case UTIL:
case RR:
case PRPTY:
new_own = board[cur_p->loc].owner;
new_own = board[(int)cur_p->loc].owner;
break;
case SPEC:
case CC:
@@ -220,7 +233,7 @@ resign() {
} while (new_own == player);
name_list[num_play] = "done";
}
if (getyn("Do you really want to resign? ", yesno) != 0)
if (getyn("Do you really want to resign? ") != 0)
return;
if (num_play == 1) {
printf("Then NOBODY wins (not even YOU!)\n");
@@ -254,7 +267,7 @@ resign() {
for (i = player; i < num_play; i++) {
name_list[i] = name_list[i+1];
if (i + 1 < num_play)
cpy_st(&play[i], &play[i+1], sizeof (PLAY));
play[i] = play[i+1];
}
name_list[num_play--] = 0;
for (i = 0; i < N_SQRS; i++)