| Rules Applied | JavaKeywordRule | app0.txt | PPspaceRule | PPifndefRule | PPRule | PPdefineRule.DefineReplacementRule | MissingFunctionTypeRule | snippets0.txt | snippets0b.txt | Typedef0Rule | StructRule | TypedefRule | TypedefRule.DefineReplacementRule | FunctionPointerReferenceRule | OneDeclarationPerLineRule | CommaOperatorRule | ArrayDeclaration0Rule | AddBracesRule | LabelRemoverRule | VoidArgumentRule.ModifyFunctionCallRule getYesOrNo | voidstarsnippet.txt | ConflictingVariableDeclarationRule | StaticVariablesRule | StaticFunctionsRule | MultipleAssignmentRule | ArrayDeclarationRule | StringRule | ZeroAssignmentRule | address.txt | DeclarationAssignmentRule | PointerRule | LossOfPrecisionRule | ArrayIndexRule | BooleanUsageRule | ForceToBooleanRule | ForceToBoolean2Rule | FalseToZeroRule | snippets2.txt | snippets3.txt | ElseIfRule | PrintfRule | stdin.txt | UninitializedVariableRule | InsertClassRule | (Final Version) | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| JavaKeywordRule app0.txt PPspaceRule PPifndefRule PPRule PPdefineRule.DefineReplacementRule MissingFunctionTypeRule snippets0.txt snippets0b.txt Typedef0Rule StructRule TypedefRule TypedefRule.DefineReplacementRule FunctionPointerReferenceRule OneDeclarationPerLineRule CommaOperatorRule ArrayDeclaration0Rule AddBracesRule LabelRemoverRule VoidArgumentRule.ModifyFunctionCallRule getYesOrNo voidstarsnippet.txt ConflictingVariableDeclarationRule StaticVariablesRule StaticFunctionsRule MultipleAssignmentRule ArrayDeclarationRule StringRule ZeroAssignmentRule address.txt DeclarationAssignmentRule PointerRule LossOfPrecisionRule ArrayIndexRule BooleanUsageRule ForceToBooleanRule ForceToBoolean2Rule FalseToZeroRule snippets2.txt snippets3.txt ElseIfRule PrintfRule stdin.txt UninitializedVariableRule InsertClassRule final | #ifndef lint
static char sccsid[] = "@(#)trade.c 5.5 (Berkeley) 6/1/90";
#endif
# include "monop.ext"
struct trd_st {
int trader;
int cash;
int gojf;
OWN * prop_list;
}
;
typedef struct trd_st TRADE;
static char * list[MAX_PRP + 2];
static int used[MAX_PRP];
static TRADE trades[2];
void trade(void) {
regint tradee,
i;
trading = TRUE;
for (i = 0;i < 2;i++) {
trades[i].cash = 0;
trades[i].gojf = FALSE;
trades[i].prop_list = NULL;
}
over:for (;;) {
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");
continue;
}
}
else tradee = 1 - player;
break;
}
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();
}
void get_list(int struct_no, int play_no) {
regint sn,
pn;
reg PLAY * pp;
int numin,
prop,
num_prp;
OWN * op;
TRADE * tp;
for (numin = 0;numin < MAX_PRP;numin++) used[numin] = FALSE;
sn = struct_no,
pn = play_no;
pp = & play[pn];
tp = & trades[sn];
tp->trader = pn;
printf("player %s (%d):\n", pp->name, pn + 1);
if (pp->own_list) {
numin = set_list(pp->own_list);
for (num_prp = numin;num_prp;) {
prop = getinp("Which property do you wish to trade? ", list);
if (prop == numin) break;
else if (used[prop]) printf("You've already allocated that.\n");
else {
num_prp--;
used[prop] = TRUE;
for (op = pp->own_list;prop--;op = op->next) continue;
add_list(pn, & (tp->prop_list) , sqnum(op->sqr));
}
}
}
if (pp->money > 0) {
printf("You have $%d. ", pp->money);
tp->cash = get_int("How much are you trading? ");
}
if (pp->num_gojf > 0) {
once_more:for (;;) {
printf("You have %d get-out-of-jail-free cards. ", pp->num_gojf);
tp->gojf = get_int("How many are you trading? ");
if (tp->gojf > pp->num_gojf) {
printf("You don't have that many. Try again.\n");
continue;
}
break;
}
}
}
set_list(register OWN * the_list) {
regint 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;
}
void summate(void) {
reg bool some;
regint i;
reg TRADE * tp;
OWN * op;
for (i = 0;i < 2;i++) {
tp = & trades[i];
some = FALSE;
printf("Player %s (%d) gives:\n", play[tp->trader].name, tp->trader + 1);
if (tp->cash > 0) printf("\t$%d\n", tp->cash) ,
some++;
if (tp->gojf > 0) printf("\t%d get-out-of-jail-free card(s)\n", tp->gojf) ,
some++;
if (tp->prop_list) {
for (op = tp->prop_list;op;op = op->next) putchar('\t') ,
printsq(sqnum(op->sqr) , TRUE);
some++;
}
if (!some) printf("\t-- Nothing --\n");
}
}
void do_trade(void) {
move_em( & trades[0], & trades[1]);
move_em( & trades[1], & trades[0]);
}
void move_em(TRADE * from, TRADE * to) {
reg PLAY * pl_fr,
* pl_to;
reg OWN * op;
pl_fr = & play[from->trader];
pl_to = & play[to->trader];
pl_fr->money -= from->cash;
pl_to->money += from->cash;
pl_fr->num_gojf -= from->gojf;
pl_to->num_gojf += from->gojf;
for (op = from->prop_list;op;op = op->next) {
add_list(to->trader, & (pl_to->own_list) , sqnum(op->sqr));
op->sqr->owner = to->trader;
del_list(from->trader, & (pl_fr->own_list) , sqnum(op->sqr));
}
set_ownlist(to->trader);
}
void resign(void) {
regint i,
new_own;
reg OWN * op;
SQUARE * sqp;
if (cur_p->money <= 0) {
switch (board[cur_p->loc].type) {
case UTIL:
case RR:
case PRPTY:
new_own = board[cur_p->loc].owner;
break;
default :
new_own = num_play;
break;
}
if (new_own == num_play) printf("You would resign to the bank\n");
else printf("You would resign to %s\n", name_list[new_own]);
}
else if (num_play == 1) {
new_own = num_play;
printf("You would resign to the bank\n");
}
else {
name_list[num_play] = "bank";
do {
new_own = getinp("Who do you wish to resign to? ", name_list);
if (new_own == player) printf("You can't resign to yourself!!\n");
}
while (new_own == player);
name_list[num_play] = "done";
}
if (getyn("Do you really want to resign? ", yn) != 0) return;
if (num_play == 1) {
printf("Then NOBODY wins (not even YOU!)\n");
exit(0);
}
if (new_own < num_play) {
printf("resigning to player\n");
trades[0].trader = new_own;
trades[0].cash = trades[0].gojf = 0;
trades[0].prop_list = NULL;
trades[1].trader = player;
trades[1].cash = cur_p->money > 0 ? cur_p->money:0;
trades[1].gojf = cur_p->num_gojf;
trades[1].prop_list = cur_p->own_list;
do_trade();
}
else {
printf("resigning to bank\n");
for (op = cur_p->own_list;op;op = op->next) {
sqp = op->sqr;
sqp->owner = - 1;
sqp->desc->morg = FALSE;
if (sqp->type == PRPTY) {
isnot_monop(sqp->desc->mon_desc);
sqp->desc->houses = 0;
}
}
if (cur_p->num_gojf) ret_card(cur_p);
}
for (i = player;i < num_play;i++) {
name_list[i] = name_list[i + 1];
if (i + 1 < num_play) play[i] = play[i + 1];
}
name_list[num_play--] = 0;
for (i = 0;i < N_SQRS;i++) if (board[i].owner > player)--board[i].owner;
player =--player < 0 ? num_play - 1:player;
next_play();
if (num_play < 2) {
printf("\nThen %s WINS!!!!!\n", play[0].name);
printhold(0);
printf("That's a grand worth of $%d.\n", play[0].money + prop_worth( & play[0]));
exit(0);
}
}
| #ifndef lint
static char sccsid[] = "@(#)trade.c 5.5 (Berkeley) 6/1/90";
#endif
# include "monop.ext"
struct TradeInfo {
int trader;
int cash;
int getOutOfJailFreeCount;
OWN * propertyList;
}
;
typedef struct TradeInfo TRADE;
static char * printHoldings[MAX_PROPERTIES + 2];
static int used[MAX_PROPERTIES];
static TRADE trades[2];
void trade(void) {
regint tradee,
i;
trading = TRUE;
for (i = 0;i < 2;i++) {
trades[i].cash = 0;
trades[i].getOutOfJailFreeCount = FALSE;
trades[i].propertyList = NULL;
}
over:for (;;) {
if (numberOfPlayers == 1) {
printf("There ain't no-one around to trade WITH!!\n");
return;
}
if (numberOfPlayers > 2) {
tradee = getinp("Which player do you wish to trade with? ", playerNames);
if (tradee == numberOfPlayers) return;
if (tradee == currentPlayerNumber) {
printf("You can't trade with yourself!\n");
continue;
}
}
else tradee = 1 - currentPlayerNumber;
break;
}
getList(0, currentPlayerNumber);
getList(1, tradee);
if (getYesOrNo("Do you wish a summary? ") == 0) summate();
if (getYesOrNo("Is the trade ok? ") == 0) doTrace();
}
void getList(int tradeIndex, int playerNumber) {
regint sn,
pn;
reg PLAY * property;
int numin,
properties,
propertyIndex;
OWN * propertyList;
TRADE * tempProperty;
for (numin = 0;numin < MAX_PROPERTIES;numin++) used[numin] = FALSE;
sn = tradeIndex,
pn = playerNumber;
property = & players[pn];
tempProperty = & trades[sn];
tempProperty->trader = pn;
printf("player %s (%d):\n", property->name, pn + 1);
if (property->ownedPropertyList) {
numin = setList(property->ownedPropertyList);
for (propertyIndex = numin;propertyIndex;) {
properties = getinp("Which property do you wish to trade? ", printHoldings);
if (properties == numin) break;
else if (used[properties]) printf("You've already allocated that.\n");
else {
propertyIndex--;
used[properties] = TRUE;
for (propertyList = property->ownedPropertyList;properties--;propertyList = propertyList->next) continue;
addToPropertyList(pn, & (tempProperty->propertyList) , getSquareIndex(propertyList->square1));
}
}
}
if (property->money > 0) {
printf("You have $%d. ", property->money);
tempProperty->cash = getInteger("How much are you trading? ");
}
if (property->getOutOfJailFreeCardCount > 0) {
once_more:for (;;) {
printf("You have %d get-out-of-jail-free cards. ", property->getOutOfJailFreeCardCount);
tempProperty->getOutOfJailFreeCount = getInteger("How many are you trading? ");
if (tempProperty->getOutOfJailFreeCount > property->getOutOfJailFreeCardCount) {
printf("You don't have that many. Try again.\n");
continue;
}
break;
}
}
}
setList(register OWN * the_list) {
regint i;
reg OWN * propertyList;
i = 0;
for (propertyList = the_list;propertyList;propertyList = propertyList->next) if (!used[i]) printHoldings[i++] = propertyList->square1->name;
printHoldings[i++] = "done";
printHoldings[i--] = 0;
return i;
}
void summate(void) {
reg bool some;
regint i;
reg TRADE * tempProperty;
OWN * propertyList;
for (i = 0;i < 2;i++) {
tempProperty = & trades[i];
some = FALSE;
printf("Player %s (%d) gives:\n", players[tempProperty->trader].name, tempProperty->trader + 1);
if (tempProperty->cash > 0) printf("\t$%d\n", tempProperty->cash) ,
some++;
if (tempProperty->getOutOfJailFreeCount > 0) printf("\t%d get-out-of-jail-free card(s)\n", tempProperty->getOutOfJailFreeCount) ,
some++;
if (tempProperty->propertyList) {
for (propertyList = tempProperty->propertyList;propertyList;propertyList = propertyList->next) putchar('\t') ,
printSquare(getSquareIndex(propertyList->square1) , TRUE);
some++;
}
if (!some) printf("\t-- Nothing --\n");
}
}
void doTrace(void) {
changePropertyOwners( & trades[0], & trades[1]);
changePropertyOwners( & trades[1], & trades[0]);
}
void changePropertyOwners(TRADE * from, TRADE * to) {
reg PLAY * pl_fr,
* pl_to;
reg OWN * propertyList;
pl_fr = & players[from->trader];
pl_to = & players[to->trader];
pl_fr->money -= from->cash;
pl_to->money += from->cash;
pl_fr->getOutOfJailFreeCardCount -= from->getOutOfJailFreeCount;
pl_to->getOutOfJailFreeCardCount += from->getOutOfJailFreeCount;
for (propertyList = from->propertyList;propertyList;propertyList = propertyList->next) {
addToPropertyList(to->trader, & (pl_to->ownedPropertyList) , getSquareIndex(propertyList->square1));
propertyList->square1->owner = to->trader;
deleteFromPropertyList(from->trader, & (pl_fr->ownedPropertyList) , getSquareIndex(propertyList->square1));
}
initializeOwnerList(to->trader);
}
void resign(void) {
regint i,
newOwner;
reg OWN * propertyList;
SQUARE * square;
if (currentPlayer->money <= 0) {
switch (board[currentPlayer->location].type) {
case TYPE_UTIL:
case TYPE_RAILROAD:
case TYPE_PROPERTY:
newOwner = board[currentPlayer->location].owner;
break;
default :
newOwner = numberOfPlayers;
break;
}
if (newOwner == numberOfPlayers) printf("You would resign to the bank\n");
else printf("You would resign to %s\n", playerNames[newOwner]);
}
else if (numberOfPlayers == 1) {
newOwner = numberOfPlayers;
printf("You would resign to the bank\n");
}
else {
playerNames[numberOfPlayers] = "bank";
do {
newOwner = getinp("Who do you wish to resign to? ", playerNames);
if (newOwner == currentPlayerNumber) printf("You can't resign to yourself!!\n");
}
while (newOwner == currentPlayerNumber);
playerNames[numberOfPlayers] = "done";
}
if (getYesOrNo("Do you really want to resign? ", yesNoChoices) != 0) return;
if (numberOfPlayers == 1) {
printf("Then NOBODY wins (not even YOU!)\n");
exit(0);
}
if (newOwner < numberOfPlayers) {
printf("resigning to player\n");
trades[0].trader = newOwner;
trades[0].cash = trades[0].getOutOfJailFreeCount = 0;
trades[0].propertyList = NULL;
trades[1].trader = currentPlayerNumber;
trades[1].cash = currentPlayer->money > 0 ? currentPlayer->money:0;
trades[1].getOutOfJailFreeCount = currentPlayer->getOutOfJailFreeCardCount;
trades[1].propertyList = currentPlayer->ownedPropertyList;
doTrace();
}
else {
printf("resigning to bank\n");
for (propertyList = currentPlayer->ownedPropertyList;propertyList;propertyList = propertyList->next) {
square = propertyList->square1;
square->owner = - 1;
square->description->isMortgaged = FALSE;
if (square->type == TYPE_PROPERTY) {
isNotMonopoly(square->description->monopolyDescription);
square->description->houseCount = 0;
}
}
if (currentPlayer->getOutOfJailFreeCardCount) returnCardToDeck(currentPlayer);
}
for (i = currentPlayerNumber;i < numberOfPlayers;i++) {
playerNames[i] = playerNames[i + 1];
if (i + 1 < numberOfPlayers) players[i] = players[i + 1];
}
playerNames[numberOfPlayers--] = 0;
for (i = 0;i < NUMBER_OF_SQUARES;i++) if (board[i].owner > currentPlayerNumber)--board[i].owner;
currentPlayerNumber =--currentPlayerNumber < 0 ? numberOfPlayers - 1:currentPlayerNumber;
nextPlayer();
if (numberOfPlayers < 2) {
printf("\nThen %s WINS!!!!!\n", players[0].name);
printHoldings(0);
printf("That's a grand worth of $%d.\n", players[0].money + getPropertyWorth( & players[0]));
exit(0);
}
}
| #ifndef lint
static char sccsid[] = "@(#)trade.c 5.5 (Berkeley) 6/1/90";
#endif
#include "monop.ext"
struct TradeInfo {
int trader;
int cash;
int getOutOfJailFreeCount;
OWN * propertyList;
}
;
typedef struct TradeInfo TRADE;
static char * printHoldings[MAX_PROPERTIES + 2];
static int used[MAX_PROPERTIES];
static TRADE trades[2];
void trade(void) {
regint tradee,
i;
trading = TRUE;
for (i = 0;i < 2;i++) {
trades[i].cash = 0;
trades[i].getOutOfJailFreeCount = FALSE;
trades[i].propertyList = NULL;
}
over:for (;;) {
if (numberOfPlayers == 1) {
printf("There ain't no-one around to trade WITH!!\n");
return;
}
if (numberOfPlayers > 2) {
tradee = getinp("Which player do you wish to trade with? ", playerNames);
if (tradee == numberOfPlayers) return;
if (tradee == currentPlayerNumber) {
printf("You can't trade with yourself!\n");
continue;
}
}
else tradee = 1 - currentPlayerNumber;
break;
}
getList(0, currentPlayerNumber);
getList(1, tradee);
if (getYesOrNo("Do you wish a summary? ") == 0) summate();
if (getYesOrNo("Is the trade ok? ") == 0) doTrace();
}
void getList(int tradeIndex, int playerNumber) {
regint sn,
pn;
reg PLAY * property;
int numin,
properties,
propertyIndex;
OWN * propertyList;
TRADE * tempProperty;
for (numin = 0;numin < MAX_PROPERTIES;numin++) used[numin] = FALSE;
sn = tradeIndex,
pn = playerNumber;
property = & players[pn];
tempProperty = & trades[sn];
tempProperty->trader = pn;
printf("player %s (%d):\n", property->name, pn + 1);
if (property->ownedPropertyList) {
numin = setList(property->ownedPropertyList);
for (propertyIndex = numin;propertyIndex;) {
properties = getinp("Which property do you wish to trade? ", printHoldings);
if (properties == numin) break;
else if (used[properties]) printf("You've already allocated that.\n");
else {
propertyIndex--;
used[properties] = TRUE;
for (propertyList = property->ownedPropertyList;properties--;propertyList = propertyList->next) continue;
addToPropertyList(pn, & (tempProperty->propertyList) , getSquareIndex(propertyList->square1));
}
}
}
if (property->money > 0) {
printf("You have $%d. ", property->money);
tempProperty->cash = getInteger("How much are you trading? ");
}
if (property->getOutOfJailFreeCardCount > 0) {
once_more:for (;;) {
printf("You have %d get-out-of-jail-free cards. ", property->getOutOfJailFreeCardCount);
tempProperty->getOutOfJailFreeCount = getInteger("How many are you trading? ");
if (tempProperty->getOutOfJailFreeCount > property->getOutOfJailFreeCardCount) {
printf("You don't have that many. Try again.\n");
continue;
}
break;
}
}
}
setList(register OWN * the_list) {
regint i;
reg OWN * propertyList;
i = 0;
for (propertyList = the_list;propertyList;propertyList = propertyList->next) if (!used[i]) printHoldings[i++] = propertyList->square1->name;
printHoldings[i++] = "done";
printHoldings[i--] = 0;
return i;
}
void summate(void) {
reg bool some;
regint i;
reg TRADE * tempProperty;
OWN * propertyList;
for (i = 0;i < 2;i++) {
tempProperty = & trades[i];
some = FALSE;
printf("Player %s (%d) gives:\n", players[tempProperty->trader].name, tempProperty->trader + 1);
if (tempProperty->cash > 0) printf("\t$%d\n", tempProperty->cash) ,
some++;
if (tempProperty->getOutOfJailFreeCount > 0) printf("\t%d get-out-of-jail-free card(s)\n", tempProperty->getOutOfJailFreeCount) ,
some++;
if (tempProperty->propertyList) {
for (propertyList = tempProperty->propertyList;propertyList;propertyList = propertyList->next) putchar('\t') ,
printSquare(getSquareIndex(propertyList->square1) , TRUE);
some++;
}
if (!some) printf("\t-- Nothing --\n");
}
}
void doTrace(void) {
changePropertyOwners( & trades[0], & trades[1]);
changePropertyOwners( & trades[1], & trades[0]);
}
void changePropertyOwners(TRADE * from, TRADE * to) {
reg PLAY * pl_fr,
* pl_to;
reg OWN * propertyList;
pl_fr = & players[from->trader];
pl_to = & players[to->trader];
pl_fr->money -= from->cash;
pl_to->money += from->cash;
pl_fr->getOutOfJailFreeCardCount -= from->getOutOfJailFreeCount;
pl_to->getOutOfJailFreeCardCount += from->getOutOfJailFreeCount;
for (propertyList = from->propertyList;propertyList;propertyList = propertyList->next) {
addToPropertyList(to->trader, & (pl_to->ownedPropertyList) , getSquareIndex(propertyList->square1));
propertyList->square1->owner = to->trader;
deleteFromPropertyList(from->trader, & (pl_fr->ownedPropertyList) , getSquareIndex(propertyList->square1));
}
initializeOwnerList(to->trader);
}
void resign(void) {
regint i,
newOwner;
reg OWN * propertyList;
SQUARE * square;
if (currentPlayer->money <= 0) {
switch (board[currentPlayer->location].type) {
case TYPE_UTIL:
case TYPE_RAILROAD:
case TYPE_PROPERTY:
newOwner = board[currentPlayer->location].owner;
break;
default :
newOwner = numberOfPlayers;
break;
}
if (newOwner == numberOfPlayers) printf("You would resign to the bank\n");
else printf("You would resign to %s\n", playerNames[newOwner]);
}
else if (numberOfPlayers == 1) {
newOwner = numberOfPlayers;
printf("You would resign to the bank\n");
}
else {
playerNames[numberOfPlayers] = "bank";
do {
newOwner = getinp("Who do you wish to resign to? ", playerNames);
if (newOwner == currentPlayerNumber) printf("You can't resign to yourself!!\n");
}
while (newOwner == currentPlayerNumber);
playerNames[numberOfPlayers] = "done";
}
if (getYesOrNo("Do you really want to resign? ", yesNoChoices) != 0) return;
if (numberOfPlayers == 1) {
printf("Then NOBODY wins (not even YOU!)\n");
exit(0);
}
if (newOwner < numberOfPlayers) {
printf("resigning to player\n");
trades[0].trader = newOwner;
trades[0].cash = trades[0].getOutOfJailFreeCount = 0;
trades[0].propertyList = NULL;
trades[1].trader = currentPlayerNumber;
trades[1].cash = currentPlayer->money > 0 ? currentPlayer->money:0;
trades[1].getOutOfJailFreeCount = currentPlayer->getOutOfJailFreeCardCount;
trades[1].propertyList = currentPlayer->ownedPropertyList;
doTrace();
}
else {
printf("resigning to bank\n");
for (propertyList = currentPlayer->ownedPropertyList;propertyList;propertyList = propertyList->next) {
square = propertyList->square1;
square->owner = - 1;
square->description->isMortgaged = FALSE;
if (square->type == TYPE_PROPERTY) {
isNotMonopoly(square->description->monopolyDescription);
square->description->houseCount = 0;
}
}
if (currentPlayer->getOutOfJailFreeCardCount) returnCardToDeck(currentPlayer);
}
for (i = currentPlayerNumber;i < numberOfPlayers;i++) {
playerNames[i] = playerNames[i + 1];
if (i + 1 < numberOfPlayers) players[i] = players[i + 1];
}
playerNames[numberOfPlayers--] = 0;
for (i = 0;i < NUMBER_OF_SQUARES;i++) if (board[i].owner > currentPlayerNumber)--board[i].owner;
currentPlayerNumber =--currentPlayerNumber < 0 ? numberOfPlayers - 1:currentPlayerNumber;
nextPlayer();
if (numberOfPlayers < 2) {
printf("\nThen %s WINS!!!!!\n", players[0].name);
printHoldings(0);
printf("That's a grand worth of $%d.\n", players[0].money + getPropertyWorth( & players[0]));
exit(0);
}
}
| #if !defined(lint)
static char sccsid[] = "@(#)trade.c 5.5 (Berkeley) 6/1/90";
#endif
#include "monop.ext"
struct TradeInfo {
int trader;
int cash;
int getOutOfJailFreeCount;
OWN * propertyList;
}
;
typedef struct TradeInfo TRADE;
static char * printHoldings[MAX_PROPERTIES + 2];
static int used[MAX_PROPERTIES];
static TRADE trades[2];
void trade(void) {
regint tradee,
i;
trading = TRUE;
for (i = 0;i < 2;i++) {
trades[i].cash = 0;
trades[i].getOutOfJailFreeCount = FALSE;
trades[i].propertyList = NULL;
}
over:for (;;) {
if (numberOfPlayers == 1) {
printf("There ain't no-one around to trade WITH!!\n");
return;
}
if (numberOfPlayers > 2) {
tradee = getinp("Which player do you wish to trade with? ", playerNames);
if (tradee == numberOfPlayers) return;
if (tradee == currentPlayerNumber) {
printf("You can't trade with yourself!\n");
continue;
}
}
else tradee = 1 - currentPlayerNumber;
break;
}
getList(0, currentPlayerNumber);
getList(1, tradee);
if (getYesOrNo("Do you wish a summary? ") == 0) summate();
if (getYesOrNo("Is the trade ok? ") == 0) doTrace();
}
void getList(int tradeIndex, int playerNumber) {
regint sn,
pn;
reg PLAY * property;
int numin,
properties,
propertyIndex;
OWN * propertyList;
TRADE * tempProperty;
for (numin = 0;numin < MAX_PROPERTIES;numin++) used[numin] = FALSE;
sn = tradeIndex,
pn = playerNumber;
property = & players[pn];
tempProperty = & trades[sn];
tempProperty->trader = pn;
printf("player %s (%d):\n", property->name, pn + 1);
if (property->ownedPropertyList) {
numin = setList(property->ownedPropertyList);
for (propertyIndex = numin;propertyIndex;) {
properties = getinp("Which property do you wish to trade? ", printHoldings);
if (properties == numin) break;
else if (used[properties]) printf("You've already allocated that.\n");
else {
propertyIndex--;
used[properties] = TRUE;
for (propertyList = property->ownedPropertyList;properties--;propertyList = propertyList->next) continue;
addToPropertyList(pn, & (tempProperty->propertyList) , getSquareIndex(propertyList->square1));
}
}
}
if (property->money > 0) {
printf("You have $%d. ", property->money);
tempProperty->cash = getInteger("How much are you trading? ");
}
if (property->getOutOfJailFreeCardCount > 0) {
once_more:for (;;) {
printf("You have %d get-out-of-jail-free cards. ", property->getOutOfJailFreeCardCount);
tempProperty->getOutOfJailFreeCount = getInteger("How many are you trading? ");
if (tempProperty->getOutOfJailFreeCount > property->getOutOfJailFreeCardCount) {
printf("You don't have that many. Try again.\n");
continue;
}
break;
}
}
}
setList(register OWN * the_list) {
regint i;
reg OWN * propertyList;
i = 0;
for (propertyList = the_list;propertyList;propertyList = propertyList->next) if (!used[i]) printHoldings[i++] = propertyList->square1->name;
printHoldings[i++] = "done";
printHoldings[i--] = 0;
return i;
}
void summate(void) {
reg bool some;
regint i;
reg TRADE * tempProperty;
OWN * propertyList;
for (i = 0;i < 2;i++) {
tempProperty = & trades[i];
some = FALSE;
printf("Player %s (%d) gives:\n", players[tempProperty->trader].name, tempProperty->trader + 1);
if (tempProperty->cash > 0) printf("\t$%d\n", tempProperty->cash) ,
some++;
if (tempProperty->getOutOfJailFreeCount > 0) printf("\t%d get-out-of-jail-free card(s)\n", tempProperty->getOutOfJailFreeCount) ,
some++;
if (tempProperty->propertyList) {
for (propertyList = tempProperty->propertyList;propertyList;propertyList = propertyList->next) putchar('\t') ,
printSquare(getSquareIndex(propertyList->square1) , TRUE);
some++;
}
if (!some) printf("\t-- Nothing --\n");
}
}
void doTrace(void) {
changePropertyOwners( & trades[0], & trades[1]);
changePropertyOwners( & trades[1], & trades[0]);
}
void changePropertyOwners(TRADE * from, TRADE * to) {
reg PLAY * pl_fr,
* pl_to;
reg OWN * propertyList;
pl_fr = & players[from->trader];
pl_to = & players[to->trader];
pl_fr->money -= from->cash;
pl_to->money += from->cash;
pl_fr->getOutOfJailFreeCardCount -= from->getOutOfJailFreeCount;
pl_to->getOutOfJailFreeCardCount += from->getOutOfJailFreeCount;
for (propertyList = from->propertyList;propertyList;propertyList = propertyList->next) {
addToPropertyList(to->trader, & (pl_to->ownedPropertyList) , getSquareIndex(propertyList->square1));
propertyList->square1->owner = to->trader;
deleteFromPropertyList(from->trader, & (pl_fr->ownedPropertyList) , getSquareIndex(propertyList->square1));
}
initializeOwnerList(to->trader);
}
void resign(void) {
regint i,
newOwner;
reg OWN * propertyList;
SQUARE * square;
if (currentPlayer->money <= 0) {
switch (board[currentPlayer->location].type) {
case TYPE_UTIL:
case TYPE_RAILROAD:
case TYPE_PROPERTY:
newOwner = board[currentPlayer->location].owner;
break;
default :
newOwner = numberOfPlayers;
break;
}
if (newOwner == numberOfPlayers) printf("You would resign to the bank\n");
else printf("You would resign to %s\n", playerNames[newOwner]);
}
else if (numberOfPlayers == 1) {
newOwner = numberOfPlayers;
printf("You would resign to the bank\n");
}
else {
playerNames[numberOfPlayers] = "bank";
do {
newOwner = getinp("Who do you wish to resign to? ", playerNames);
if (newOwner == currentPlayerNumber) printf("You can't resign to yourself!!\n");
}
while (newOwner == currentPlayerNumber);
playerNames[numberOfPlayers] = "done";
}
if (getYesOrNo("Do you really want to resign? ", yesNoChoices) != 0) return;
if (numberOfPlayers == 1) {
printf("Then NOBODY wins (not even YOU!)\n");
exit(0);
}
if (newOwner < numberOfPlayers) {
printf("resigning to player\n");
trades[0].trader = newOwner;
trades[0].cash = trades[0].getOutOfJailFreeCount = 0;
trades[0].propertyList = NULL;
trades[1].trader = currentPlayerNumber;
trades[1].cash = currentPlayer->money > 0 ? currentPlayer->money:0;
trades[1].getOutOfJailFreeCount = currentPlayer->getOutOfJailFreeCardCount;
trades[1].propertyList = currentPlayer->ownedPropertyList;
doTrace();
}
else {
printf("resigning to bank\n");
for (propertyList = currentPlayer->ownedPropertyList;propertyList;propertyList = propertyList->next) {
square = propertyList->square1;
square->owner = - 1;
square->description->isMortgaged = FALSE;
if (square->type == TYPE_PROPERTY) {
isNotMonopoly(square->description->monopolyDescription);
square->description->houseCount = 0;
}
}
if (currentPlayer->getOutOfJailFreeCardCount) returnCardToDeck(currentPlayer);
}
for (i = currentPlayerNumber;i < numberOfPlayers;i++) {
playerNames[i] = playerNames[i + 1];
if (i + 1 < numberOfPlayers) players[i] = players[i + 1];
}
playerNames[numberOfPlayers--] = 0;
for (i = 0;i < NUMBER_OF_SQUARES;i++) if (board[i].owner > currentPlayerNumber)--board[i].owner;
currentPlayerNumber =--currentPlayerNumber < 0 ? numberOfPlayers - 1:currentPlayerNumber;
nextPlayer();
if (numberOfPlayers < 2) {
printf("\nThen %s WINS!!!!!\n", players[0].name);
printHoldings(0);
printf("That's a grand worth of $%d.\n", players[0].money + getPropertyWorth( & players[0]));
exit(0);
}
}
| static char sccsid[] = "@(#)trade.c 5.5 (Berkeley) 6/1/90";
struct TradeInfo {
int trader;
int cash;
int getOutOfJailFreeCount;
OWN * propertyList;
}
;
typedef struct TradeInfo TRADE;
static char * printHoldings[MAX_PROPERTIES + 2];
static int used[MAX_PROPERTIES];
static TRADE trades[2];
void trade(void) {
regint tradee,
i;
trading = TRUE;
for (i = 0;i < 2;i++) {
trades[i].cash = 0;
trades[i].getOutOfJailFreeCount = FALSE;
trades[i].propertyList = NULL;
}
over:for (;;) {
if (numberOfPlayers == 1) {
printf("There ain't no-one around to trade WITH!!\n");
return;
}
if (numberOfPlayers > 2) {
tradee = getinp("Which player do you wish to trade with? ", playerNames);
if (tradee == numberOfPlayers) return;
if (tradee == currentPlayerNumber) {
printf("You can't trade with yourself!\n");
continue;
}
}
else tradee = 1 - currentPlayerNumber;
break;
}
getList(0, currentPlayerNumber);
getList(1, tradee);
if (getYesOrNo("Do you wish a summary? ") == 0) summate();
if (getYesOrNo("Is the trade ok? ") == 0) doTrace();
}
void getList(int tradeIndex, int playerNumber) {
regint sn,
pn;
reg PLAY * property;
int numin,
properties,
propertyIndex;
OWN * propertyList;
TRADE * tempProperty;
for (numin = 0;numin < MAX_PROPERTIES;numin++) used[numin] = FALSE;
sn = tradeIndex,
pn = playerNumber;
property = & players[pn];
tempProperty = & trades[sn];
tempProperty->trader = pn;
printf("player %s (%d):\n", property->name, pn + 1);
if (property->ownedPropertyList) {
numin = setList(property->ownedPropertyList);
for (propertyIndex = numin;propertyIndex;) {
properties = getinp("Which property do you wish to trade? ", printHoldings);
if (properties == numin) break;
else if (used[properties]) printf("You've already allocated that.\n");
else {
propertyIndex--;
used[properties] = TRUE;
for (propertyList = property->ownedPropertyList;properties--;propertyList = propertyList->next) continue;
addToPropertyList(pn, & (tempProperty->propertyList) , getSquareIndex(propertyList->square1));
}
}
}
if (property->money > 0) {
printf("You have $%d. ", property->money);
tempProperty->cash = getInteger("How much are you trading? ");
}
if (property->getOutOfJailFreeCardCount > 0) {
once_more:for (;;) {
printf("You have %d get-out-of-jail-free cards. ", property->getOutOfJailFreeCardCount);
tempProperty->getOutOfJailFreeCount = getInteger("How many are you trading? ");
if (tempProperty->getOutOfJailFreeCount > property->getOutOfJailFreeCardCount) {
printf("You don't have that many. Try again.\n");
continue;
}
break;
}
}
}
setList(register OWN * the_list) {
regint i;
reg OWN * propertyList;
i = 0;
for (propertyList = the_list;propertyList;propertyList = propertyList->next) if (!used[i]) printHoldings[i++] = propertyList->square1->name;
printHoldings[i++] = "done";
printHoldings[i--] = 0;
return i;
}
void summate(void) {
reg bool some;
regint i;
reg TRADE * tempProperty;
OWN * propertyList;
for (i = 0;i < 2;i++) {
tempProperty = & trades[i];
some = FALSE;
printf("Player %s (%d) gives:\n", players[tempProperty->trader].name, tempProperty->trader + 1);
if (tempProperty->cash > 0) printf("\t$%d\n", tempProperty->cash) ,
some++;
if (tempProperty->getOutOfJailFreeCount > 0) printf("\t%d get-out-of-jail-free card(s)\n", tempProperty->getOutOfJailFreeCount) ,
some++;
if (tempProperty->propertyList) {
for (propertyList = tempProperty->propertyList;propertyList;propertyList = propertyList->next) putchar('\t') ,
printSquare(getSquareIndex(propertyList->square1) , TRUE);
some++;
}
if (!some) printf("\t-- Nothing --\n");
}
}
void doTrace(void) {
changePropertyOwners( & trades[0], & trades[1]);
changePropertyOwners( & trades[1], & trades[0]);
}
void changePropertyOwners(TRADE * from, TRADE * to) {
reg PLAY * pl_fr,
* pl_to;
reg OWN * propertyList;
pl_fr = & players[from->trader];
pl_to = & players[to->trader];
pl_fr->money -= from->cash;
pl_to->money += from->cash;
pl_fr->getOutOfJailFreeCardCount -= from->getOutOfJailFreeCount;
pl_to->getOutOfJailFreeCardCount += from->getOutOfJailFreeCount;
for (propertyList = from->propertyList;propertyList;propertyList = propertyList->next) {
addToPropertyList(to->trader, & (pl_to->ownedPropertyList) , getSquareIndex(propertyList->square1));
propertyList->square1->owner = to->trader;
deleteFromPropertyList(from->trader, & (pl_fr->ownedPropertyList) , getSquareIndex(propertyList->square1));
}
initializeOwnerList(to->trader);
}
void resign(void) {
regint i,
newOwner;
reg OWN * propertyList;
SQUARE * square;
if (currentPlayer->money <= 0) {
switch (board[currentPlayer->location].type) {
case TYPE_UTIL:
case TYPE_RAILROAD:
case TYPE_PROPERTY:
newOwner = board[currentPlayer->location].owner;
break;
default :
newOwner = numberOfPlayers;
break;
}
if (newOwner == numberOfPlayers) printf("You would resign to the bank\n");
else printf("You would resign to %s\n", playerNames[newOwner]);
}
else if (numberOfPlayers == 1) {
newOwner = numberOfPlayers;
printf("You would resign to the bank\n");
}
else {
playerNames[numberOfPlayers] = "bank";
do {
newOwner = getinp("Who do you wish to resign to? ", playerNames);
if (newOwner == currentPlayerNumber) printf("You can't resign to yourself!!\n");
}
while (newOwner == currentPlayerNumber);
playerNames[numberOfPlayers] = "done";
}
if (getYesOrNo("Do you really want to resign? ", yesNoChoices) != 0) return;
if (numberOfPlayers == 1) {
printf("Then NOBODY wins (not even YOU!)\n");
exit(0);
}
if (newOwner < numberOfPlayers) {
printf("resigning to player\n");
trades[0].trader = newOwner;
trades[0].cash = trades[0].getOutOfJailFreeCount = 0;
trades[0].propertyList = NULL;
trades[1].trader = currentPlayerNumber;
trades[1].cash = currentPlayer->money > 0 ? currentPlayer->money:0;
trades[1].getOutOfJailFreeCount = currentPlayer->getOutOfJailFreeCardCount;
trades[1].propertyList = currentPlayer->ownedPropertyList;
doTrace();
}
else {
printf("resigning to bank\n");
for (propertyList = currentPlayer->ownedPropertyList;propertyList;propertyList = propertyList->next) {
square = propertyList->square1;
square->owner = - 1;
square->description->isMortgaged = FALSE;
if (square->type == TYPE_PROPERTY) {
isNotMonopoly(square->description->monopolyDescription);
square->description->houseCount = 0;
}
}
if (currentPlayer->getOutOfJailFreeCardCount) returnCardToDeck(currentPlayer);
}
for (i = currentPlayerNumber;i < numberOfPlayers;i++) {
playerNames[i] = playerNames[i + 1];
if (i + 1 < numberOfPlayers) players[i] = players[i + 1];
}
playerNames[numberOfPlayers--] = 0;
for (i = 0;i < NUMBER_OF_SQUARES;i++) if (board[i].owner > currentPlayerNumber)--board[i].owner;
currentPlayerNumber =--currentPlayerNumber < 0 ? numberOfPlayers - 1:currentPlayerNumber;
nextPlayer();
if (numberOfPlayers < 2) {
printf("\nThen %s WINS!!!!!\n", players[0].name);
printHoldings(0);
printf("That's a grand worth of $%d.\n", players[0].money + getPropertyWorth( & players[0]));
exit(0);
}
}
| static char sccsid[] = "@(#)trade.c 5.5 (Berkeley) 6/1/90";
struct TradeInfo {
int trader;
int cash;
int getOutOfJailFreeCount;
OWN * propertyList;
}
;
typedef struct TradeInfo TRADE;
static char * printHoldings[MAX_PROPERTIES + 2];
static int used[MAX_PROPERTIES];
static TRADE trades[2];
void trade(void) {
register int tradee,
i;
trading = true;
for (i = 0;i < 2;i++) {
trades[i].cash = 0;
trades[i].getOutOfJailFreeCount = false;
trades[i].propertyList = NULL;
}
over:for (;;) {
if (numberOfPlayers == 1) {
printf("There ain't no-one around to trade WITH!!\n");
return;
}
if (numberOfPlayers > 2) {
tradee = getinp("Which player do you wish to trade with? ", playerNames);
if (tradee == numberOfPlayers) return;
if (tradee == currentPlayerNumber) {
printf("You can't trade with yourself!\n");
continue;
}
}
else tradee = 1 - currentPlayerNumber;
break;
}
getList(0, currentPlayerNumber);
getList(1, tradee);
if (getYesOrNo("Do you wish a summary? ") == 0) summate();
if (getYesOrNo("Is the trade ok? ") == 0) doTrace();
}
void getList(int tradeIndex, int playerNumber) {
register int sn,
pn;
register PLAY * property;
int numin,
properties,
propertyIndex;
OWN * propertyList;
TRADE * tempProperty;
for (numin = 0;numin < MAX_PROPERTIES;numin++) used[numin] = false;
sn = tradeIndex,
pn = playerNumber;
property = & players[pn];
tempProperty = & trades[sn];
tempProperty->trader = pn;
printf("player %s (%d):\n", property->name, pn + 1);
if (property->ownedPropertyList) {
numin = setList(property->ownedPropertyList);
for (propertyIndex = numin;propertyIndex;) {
properties = getinp("Which property do you wish to trade? ", printHoldings);
if (properties == numin) break;
else if (used[properties]) printf("You've already allocated that.\n");
else {
propertyIndex--;
used[properties] = true;
for (propertyList = property->ownedPropertyList;properties--;propertyList = propertyList->next) continue;
addToPropertyList(pn, & (tempProperty->propertyList) , getSquareIndex(propertyList->square1));
}
}
}
if (property->money > 0) {
printf("You have $%d. ", property->money);
tempProperty->cash = getInteger("How much are you trading? ");
}
if (property->getOutOfJailFreeCardCount > 0) {
once_more:for (;;) {
printf("You have %d get-out-of-jail-free cards. ", property->getOutOfJailFreeCardCount);
tempProperty->getOutOfJailFreeCount = getInteger("How many are you trading? ");
if (tempProperty->getOutOfJailFreeCount > property->getOutOfJailFreeCardCount) {
printf("You don't have that many. Try again.\n");
continue;
}
break;
}
}
}
setList(register OWN * the_list) {
register int i;
register OWN * propertyList;
i = 0;
for (propertyList = the_list;propertyList;propertyList = propertyList->next) if (!used[i]) printHoldings[i++] = propertyList->square1->name;
printHoldings[i++] = "done";
printHoldings[i--] = 0;
return i;
}
void summate(void) {
register boolean some;
register int i;
register TRADE * tempProperty;
OWN * propertyList;
for (i = 0;i < 2;i++) {
tempProperty = & trades[i];
some = false;
printf("Player %s (%d) gives:\n", players[tempProperty->trader].name, tempProperty->trader + 1);
if (tempProperty->cash > 0) printf("\t$%d\n", tempProperty->cash) ,
some++;
if (tempProperty->getOutOfJailFreeCount > 0) printf("\t%d get-out-of-jail-free card(s)\n", tempProperty->getOutOfJailFreeCount) ,
some++;
if (tempProperty->propertyList) {
for (propertyList = tempProperty->propertyList;propertyList;propertyList = propertyList->next) putchar('\t') ,
printSquare(getSquareIndex(propertyList->square1) , true);
some++;
}
if (!some) printf("\t-- Nothing --\n");
}
}
void doTrace(void) {
changePropertyOwners( & trades[0], & trades[1]);
changePropertyOwners( & trades[1], & trades[0]);
}
void changePropertyOwners(TRADE * from, TRADE * to) {
register PLAY * pl_fr,
* pl_to;
register OWN * propertyList;
pl_fr = & players[from->trader];
pl_to = & players[to->trader];
pl_fr->money -= from->cash;
pl_to->money += from->cash;
pl_fr->getOutOfJailFreeCardCount -= from->getOutOfJailFreeCount;
pl_to->getOutOfJailFreeCardCount += from->getOutOfJailFreeCount;
for (propertyList = from->propertyList;propertyList;propertyList = propertyList->next) {
addToPropertyList(to->trader, & (pl_to->ownedPropertyList) , getSquareIndex(propertyList->square1));
propertyList->square1->owner = to->trader;
deleteFromPropertyList(from->trader, & (pl_fr->ownedPropertyList) , getSquareIndex(propertyList->square1));
}
initializeOwnerList(to->trader);
}
void resign(void) {
register int i,
newOwner;
register OWN * propertyList;
SQUARE * square;
if (currentPlayer->money <= 0) {
switch (board[currentPlayer->location].type) {
case TYPE_UTIL:
case TYPE_RAILROAD:
case TYPE_PROPERTY:
newOwner = board[currentPlayer->location].owner;
break;
default :
newOwner = numberOfPlayers;
break;
}
if (newOwner == numberOfPlayers) printf("You would resign to the bank\n");
else printf("You would resign to %s\n", playerNames[newOwner]);
}
else if (numberOfPlayers == 1) {
newOwner = numberOfPlayers;
printf("You would resign to the bank\n");
}
else {
playerNames[numberOfPlayers] = "bank";
do {
newOwner = getinp("Who do you wish to resign to? ", playerNames);
if (newOwner == currentPlayerNumber) printf("You can't resign to yourself!!\n");
}
while (newOwner == currentPlayerNumber);
playerNames[numberOfPlayers] = "done";
}
if (getYesOrNo("Do you really want to resign? ", yesNoChoices) != 0) return;
if (numberOfPlayers == 1) {
printf("Then NOBODY wins (not even YOU!)\n");
exit(0);
}
if (newOwner < numberOfPlayers) {
printf("resigning to player\n");
trades[0].trader = newOwner;
trades[0].cash = trades[0].getOutOfJailFreeCount = 0;
trades[0].propertyList = NULL;
trades[1].trader = currentPlayerNumber;
trades[1].cash = currentPlayer->money > 0 ? currentPlayer->money:0;
trades[1].getOutOfJailFreeCount = currentPlayer->getOutOfJailFreeCardCount;
trades[1].propertyList = currentPlayer->ownedPropertyList;
doTrace();
}
else {
printf("resigning to bank\n");
for (propertyList = currentPlayer->ownedPropertyList;propertyList;propertyList = propertyList->next) {
square = propertyList->square1;
square->owner = - 1;
square->description->isMortgaged = false;
if (square->type == TYPE_PROPERTY) {
isNotMonopoly(square->description->monopolyDescription);
square->description->houseCount = 0;
}
}
if (currentPlayer->getOutOfJailFreeCardCount) returnCardToDeck(currentPlayer);
}
for (i = currentPlayerNumber;i < numberOfPlayers;i++) {
playerNames[i] = playerNames[i + 1];
if (i + 1 < numberOfPlayers) players[i] = players[i + 1];
}
playerNames[numberOfPlayers--] = 0;
for (i = 0;i < NUMBER_OF_SQUARES;i++) if (board[i].owner > currentPlayerNumber)--board[i].owner;
currentPlayerNumber =--currentPlayerNumber < 0 ? numberOfPlayers - 1:currentPlayerNumber;
nextPlayer();
if (numberOfPlayers < 2) {
printf("\nThen %s WINS!!!!!\n", players[0].name);
printHoldings(0);
printf("That's a grand worth of $%d.\n", players[0].money + getPropertyWorth( & players[0]));
exit(0);
}
}
| static char sccsid[] = "@(#)trade.c 5.5 (Berkeley) 6/1/90";
struct TradeInfo {
int trader;
int cash;
int getOutOfJailFreeCount;
OWN * propertyList;
}
;
typedef struct TradeInfo TRADE;
static char * printHoldings[MAX_PROPERTIES + 2];
static int used[MAX_PROPERTIES];
static TRADE trades[2];
void trade(void) {
register int tradee,
i;
trading = true;
for (i = 0;i < 2;i++) {
trades[i].cash = 0;
trades[i].getOutOfJailFreeCount = false;
trades[i].propertyList = NULL;
}
over:for (;;) {
if (numberOfPlayers == 1) {
printf("There ain't no-one around to trade WITH!!\n");
return;
}
if (numberOfPlayers > 2) {
tradee = getinp("Which player do you wish to trade with? ", playerNames);
if (tradee == numberOfPlayers) return;
if (tradee == currentPlayerNumber) {
printf("You can't trade with yourself!\n");
continue;
}
}
else tradee = 1 - currentPlayerNumber;
break;
}
getList(0, currentPlayerNumber);
getList(1, tradee);
if (getYesOrNo("Do you wish a summary? ") == 0) summate();
if (getYesOrNo("Is the trade ok? ") == 0) doTrace();
}
void getList(int tradeIndex, int playerNumber) {
register int sn,
pn;
register PLAY * property;
int numin,
properties,
propertyIndex;
OWN * propertyList;
TRADE * tempProperty;
for (numin = 0;numin < MAX_PROPERTIES;numin++) used[numin] = false;
sn = tradeIndex,
pn = playerNumber;
property = & players[pn];
tempProperty = & trades[sn];
tempProperty->trader = pn;
printf("player %s (%d):\n", property->name, pn + 1);
if (property->ownedPropertyList) {
numin = setList(property->ownedPropertyList);
for (propertyIndex = numin;propertyIndex;) {
properties = getinp("Which property do you wish to trade? ", printHoldings);
if (properties == numin) break;
else if (used[properties]) printf("You've already allocated that.\n");
else {
propertyIndex--;
used[properties] = true;
for (propertyList = property->ownedPropertyList;properties--;propertyList = propertyList->next) continue;
addToPropertyList(pn, & (tempProperty->propertyList) , getSquareIndex(propertyList->square1));
}
}
}
if (property->money > 0) {
printf("You have $%d. ", property->money);
tempProperty->cash = getInteger("How much are you trading? ");
}
if (property->getOutOfJailFreeCardCount > 0) {
once_more:for (;;) {
printf("You have %d get-out-of-jail-free cards. ", property->getOutOfJailFreeCardCount);
tempProperty->getOutOfJailFreeCount = getInteger("How many are you trading? ");
if (tempProperty->getOutOfJailFreeCount > property->getOutOfJailFreeCardCount) {
printf("You don't have that many. Try again.\n");
continue;
}
break;
}
}
}
int setList(register OWN * the_list) {
register int i;
register OWN * propertyList;
i = 0;
for (propertyList = the_list;propertyList;propertyList = propertyList->next) if (!used[i]) printHoldings[i++] = propertyList->square1->name;
printHoldings[i++] = "done";
printHoldings[i--] = 0;
return i;
}
void summate(void) {
register boolean some;
register int i;
register TRADE * tempProperty;
OWN * propertyList;
for (i = 0;i < 2;i++) {
tempProperty = & trades[i];
some = false;
printf("Player %s (%d) gives:\n", players[tempProperty->trader].name, tempProperty->trader + 1);
if (tempProperty->cash > 0) printf("\t$%d\n", tempProperty->cash) ,
some++;
if (tempProperty->getOutOfJailFreeCount > 0) printf("\t%d get-out-of-jail-free card(s)\n", tempProperty->getOutOfJailFreeCount) ,
some++;
if (tempProperty->propertyList) {
for (propertyList = tempProperty->propertyList;propertyList;propertyList = propertyList->next) putchar('\t') ,
printSquare(getSquareIndex(propertyList->square1) , true);
some++;
}
if (!some) printf("\t-- Nothing --\n");
}
}
void doTrace(void) {
changePropertyOwners( & trades[0], & trades[1]);
changePropertyOwners( & trades[1], & trades[0]);
}
void changePropertyOwners(TRADE * from, TRADE * to) {
register PLAY * pl_fr,
* pl_to;
register OWN * propertyList;
pl_fr = & players[from->trader];
pl_to = & players[to->trader];
pl_fr->money -= from->cash;
pl_to->money += from->cash;
pl_fr->getOutOfJailFreeCardCount -= from->getOutOfJailFreeCount;
pl_to->getOutOfJailFreeCardCount += from->getOutOfJailFreeCount;
for (propertyList = from->propertyList;propertyList;propertyList = propertyList->next) {
addToPropertyList(to->trader, & (pl_to->ownedPropertyList) , getSquareIndex(propertyList->square1));
propertyList->square1->owner = to->trader;
deleteFromPropertyList(from->trader, & (pl_fr->ownedPropertyList) , getSquareIndex(propertyList->square1));
}
initializeOwnerList(to->trader);
}
void resign(void) {
register int i,
newOwner;
register OWN * propertyList;
SQUARE * square;
if (currentPlayer->money <= 0) {
switch (board[currentPlayer->location].type) {
case TYPE_UTIL:
case TYPE_RAILROAD:
case TYPE_PROPERTY:
newOwner = board[currentPlayer->location].owner;
break;
default :
newOwner = numberOfPlayers;
break;
}
if (newOwner == numberOfPlayers) printf("You would resign to the bank\n");
else printf("You would resign to %s\n", playerNames[newOwner]);
}
else if (numberOfPlayers == 1) {
newOwner = numberOfPlayers;
printf("You would resign to the bank\n");
}
else {
playerNames[numberOfPlayers] = "bank";
do {
newOwner = getinp("Who do you wish to resign to? ", playerNames);
if (newOwner == currentPlayerNumber) printf("You can't resign to yourself!!\n");
}
while (newOwner == currentPlayerNumber);
playerNames[numberOfPlayers] = "done";
}
if (getYesOrNo("Do you really want to resign? ", yesNoChoices) != 0) return;
if (numberOfPlayers == 1) {
printf("Then NOBODY wins (not even YOU!)\n");
exit(0);
}
if (newOwner < numberOfPlayers) {
printf("resigning to player\n");
trades[0].trader = newOwner;
trades[0].cash = trades[0].getOutOfJailFreeCount = 0;
trades[0].propertyList = NULL;
trades[1].trader = currentPlayerNumber;
trades[1].cash = currentPlayer->money > 0 ? currentPlayer->money:0;
trades[1].getOutOfJailFreeCount = currentPlayer->getOutOfJailFreeCardCount;
trades[1].propertyList = currentPlayer->ownedPropertyList;
doTrace();
}
else {
printf("resigning to bank\n");
for (propertyList = currentPlayer->ownedPropertyList;propertyList;propertyList = propertyList->next) {
square = propertyList->square1;
square->owner = - 1;
square->description->isMortgaged = false;
if (square->type == TYPE_PROPERTY) {
isNotMonopoly(square->description->monopolyDescription);
square->description->houseCount = 0;
}
}
if (currentPlayer->getOutOfJailFreeCardCount) returnCardToDeck(currentPlayer);
}
for (i = currentPlayerNumber;i < numberOfPlayers;i++) {
playerNames[i] = playerNames[i + 1];
if (i + 1 < numberOfPlayers) players[i] = players[i + 1];
}
playerNames[numberOfPlayers--] = 0;
for (i = 0;i < NUMBER_OF_SQUARES;i++) if (board[i].owner > currentPlayerNumber)--board[i].owner;
currentPlayerNumber =--currentPlayerNumber < 0 ? numberOfPlayers - 1:currentPlayerNumber;
nextPlayer();
if (numberOfPlayers < 2) {
printf("\nThen %s WINS!!!!!\n", players[0].name);
printHoldings(0);
printf("That's a grand worth of $%d.\n", players[0].money + getPropertyWorth( & players[0]));
exit(0);
}
}
| static char sccsid[] = "@(#)trade.c 5.5 (Berkeley) 6/1/90";
struct TradeInfo {
int trader;
int cash;
int getOutOfJailFreeCount;
OWN * propertyList;
}
;
typedef struct TradeInfo TRADE;
static char * printHoldings[MAX_PROPERTIES + 2];
static int used[MAX_PROPERTIES];
static TRADE trades[2];
void trade(void) {
register int tradee,
i;
trading = true;
for (i = 0;i < 2;i++) {
trades[i].cash = 0;
trades[i].getOutOfJailFreeCount = false;
trades[i].propertyList = 0;
}
over:for (;;) {
if (numberOfPlayers == 1) {
printf("There ain't no-one around to trade WITH!!\n");
return;
}
if (numberOfPlayers > 2) {
tradee = getinp("Which player do you wish to trade with? ", playerNames);
if (tradee == numberOfPlayers) return;
if (tradee == currentPlayerNumber) {
printf("You can't trade with yourself!\n");
continue;
}
}
else tradee = 1 - currentPlayerNumber;
break;
}
getList(0, currentPlayerNumber);
getList(1, tradee);
if (getYesOrNo("Do you wish a summary? ") == 0) summate();
if (getYesOrNo("Is the trade ok? ") == 0) doTrace();
}
void getList(int tradeIndex, int playerNumber) {
register int sn,
pn;
register PLAY * property;
int numin,
properties,
propertyIndex;
OWN * propertyList;
TRADE * tempProperty;
for (numin = 0;numin < MAX_PROPERTIES;numin++) used[numin] = false;
sn = tradeIndex,
pn = playerNumber;
property = & players[pn];
tempProperty = & trades[sn];
tempProperty->trader = pn;
printf("player %s (%d):\n", property->name, pn + 1);
if (property->ownedPropertyList) {
numin = setList(property->ownedPropertyList);
for (propertyIndex = numin;propertyIndex;) {
properties = getinp("Which property do you wish to trade? ", printHoldings);
if (properties == numin) break;
else if (used[properties]) printf("You've already allocated that.\n");
else {
propertyIndex--;
used[properties] = true;
for (propertyList = property->ownedPropertyList;properties--;propertyList = propertyList->next) continue;
addToPropertyList(pn, & (tempProperty->propertyList) , getSquareIndex(propertyList->square1));
}
}
}
if (property->money > 0) {
printf("You have $%d. ", property->money);
tempProperty->cash = getInteger("How much are you trading? ");
}
if (property->getOutOfJailFreeCardCount > 0) {
once_more:for (;;) {
printf("You have %d get-out-of-jail-free cards. ", property->getOutOfJailFreeCardCount);
tempProperty->getOutOfJailFreeCount = getInteger("How many are you trading? ");
if (tempProperty->getOutOfJailFreeCount > property->getOutOfJailFreeCardCount) {
printf("You don't have that many. Try again.\n");
continue;
}
break;
}
}
}
int setList(register OWN * the_list) {
register int i;
register OWN * propertyList;
i = 0;
for (propertyList = the_list;propertyList;propertyList = propertyList->next) if (!used[i]) printHoldings[i++] = propertyList->square1->name;
printHoldings[i++] = "done";
printHoldings[i--] = 0;
return i;
}
void summate(void) {
register boolean some;
register int i;
register TRADE * tempProperty;
OWN * propertyList;
for (i = 0;i < 2;i++) {
tempProperty = & trades[i];
some = false;
printf("Player %s (%d) gives:\n", players[tempProperty->trader].name, tempProperty->trader + 1);
if (tempProperty->cash > 0) printf("\t$%d\n", tempProperty->cash) ,
some++;
if (tempProperty->getOutOfJailFreeCount > 0) printf("\t%d get-out-of-jail-free card(s)\n", tempProperty->getOutOfJailFreeCount) ,
some++;
if (tempProperty->propertyList) {
for (propertyList = tempProperty->propertyList;propertyList;propertyList = propertyList->next) putchar('\t') ,
printSquare(getSquareIndex(propertyList->square1) , true);
some++;
}
if (!some) printf("\t-- Nothing --\n");
}
}
void doTrace(void) {
changePropertyOwners( & trades[0], & trades[1]);
changePropertyOwners( & trades[1], & trades[0]);
}
void changePropertyOwners(TRADE * from, TRADE * to) {
register PLAY * pl_fr,
* pl_to;
register OWN * propertyList;
pl_fr = & players[from->trader];
pl_to = & players[to->trader];
pl_fr->money -= from->cash;
pl_to->money += from->cash;
pl_fr->getOutOfJailFreeCardCount -= from->getOutOfJailFreeCount;
pl_to->getOutOfJailFreeCardCount += from->getOutOfJailFreeCount;
for (propertyList = from->propertyList;propertyList;propertyList = propertyList->next) {
addToPropertyList(to->trader, & (pl_to->ownedPropertyList) , getSquareIndex(propertyList->square1));
propertyList->square1->owner = to->trader;
deleteFromPropertyList(from->trader, & (pl_fr->ownedPropertyList) , getSquareIndex(propertyList->square1));
}
initializeOwnerList(to->trader);
}
void resign(void) {
register int i,
newOwner;
register OWN * propertyList;
SQUARE * square;
if (currentPlayer->money <= 0) {
switch (board[currentPlayer->location].type) {
case TYPE_UTIL:
case TYPE_RAILROAD:
case TYPE_PROPERTY:
newOwner = board[currentPlayer->location].owner;
break;
default :
newOwner = numberOfPlayers;
break;
}
if (newOwner == numberOfPlayers) printf("You would resign to the bank\n");
else printf("You would resign to %s\n", playerNames[newOwner]);
}
else if (numberOfPlayers == 1) {
newOwner = numberOfPlayers;
printf("You would resign to the bank\n");
}
else {
playerNames[numberOfPlayers] = "bank";
do {
newOwner = getinp("Who do you wish to resign to? ", playerNames);
if (newOwner == currentPlayerNumber) printf("You can't resign to yourself!!\n");
}
while (newOwner == currentPlayerNumber);
playerNames[numberOfPlayers] = "done";
}
if (getYesOrNo("Do you really want to resign? ", yesNoChoices) != 0) return;
if (numberOfPlayers == 1) {
printf("Then NOBODY wins (not even YOU!)\n");
exit(0);
}
if (newOwner < numberOfPlayers) {
printf("resigning to player\n");
trades[0].trader = newOwner;
trades[0].cash = trades[0].getOutOfJailFreeCount = 0;
trades[0].propertyList = 0;
trades[1].trader = currentPlayerNumber;
trades[1].cash = currentPlayer->money > 0 ? currentPlayer->money:0;
trades[1].getOutOfJailFreeCount = currentPlayer->getOutOfJailFreeCardCount;
trades[1].propertyList = currentPlayer->ownedPropertyList;
doTrace();
}
else {
printf("resigning to bank\n");
for (propertyList = currentPlayer->ownedPropertyList;propertyList;propertyList = propertyList->next) {
square = propertyList->square1;
square->owner = - 1;
square->description->isMortgaged = false;
if (square->type == TYPE_PROPERTY) {
isNotMonopoly(square->description->monopolyDescription);
square->description->houseCount = 0;
}
}
if (currentPlayer->getOutOfJailFreeCardCount) returnCardToDeck(currentPlayer);
}
for (i = currentPlayerNumber;i < numberOfPlayers;i++) {
playerNames[i] = playerNames[i + 1];
if (i + 1 < numberOfPlayers) players[i] = players[i + 1];
}
playerNames[numberOfPlayers--] = 0;
for (i = 0;i < NUMBER_OF_SQUARES;i++) if (board[i].owner > currentPlayerNumber)--board[i].owner;
currentPlayerNumber =--currentPlayerNumber < 0 ? numberOfPlayers - 1:currentPlayerNumber;
nextPlayer();
if (numberOfPlayers < 2) {
printf("\nThen %s WINS!!!!!\n", players[0].name);
printHoldings(0);
printf("That's a grand worth of $%d.\n", players[0].money + getPropertyWorth( & players[0]));
exit(0);
}
}
| static char sccsid[] = "@(#)trade.c 5.5 (Berkeley) 6/1/90";
struct TradeInfo {
int trader;
int cash;
int getOutOfJailFreeCount;
OWN * propertyList;
}
;
typedef struct TradeInfo TRADE;
static char * printHoldings[MAX_PROPERTIES + 2];
static int used[MAX_PROPERTIES];
static TRADE trades[2];
void trade(void) {
int tradee,
i;
trading = true;
for (i = 0;i < 2;i++) {
trades[i].cash = 0;
trades[i].getOutOfJailFreeCount = false;
trades[i].propertyList = 0;
}
over:while (true) {
if (numberOfPlayers == 1) {
printf("There ain't no-one around to trade WITH!!\n");
return;
}
if (numberOfPlayers > 2) {
tradee = getinp("Which player do you wish to trade with? ", playerNames);
if (tradee == numberOfPlayers) return;
if (tradee == currentPlayerNumber) {
printf("You can't trade with yourself!\n");
continue;
}
}
else tradee = 1 - currentPlayerNumber;
break;
}
getList(0, currentPlayerNumber);
getList(1, tradee);
if (getYesOrNo("Do you wish a summary? ") == 0) summate();
if (getYesOrNo("Is the trade ok? ") == 0) doTrace();
}
void getList(int tradeIndex, int playerNumber) {
int sn,
pn;
PLAY * property;
int numin,
properties,
propertyIndex;
OWN * propertyList;
TRADE * tempProperty;
for (numin = 0;numin < MAX_PROPERTIES;numin++) used[numin] = false;
sn = tradeIndex,
pn = playerNumber;
property = & players[pn];
tempProperty = & trades[sn];
tempProperty->trader = pn;
printf("player %s (%d):\n", property->name, pn + 1);
if (property->ownedPropertyList) {
numin = setList(property->ownedPropertyList);
for (propertyIndex = numin;propertyIndex;) {
properties = getinp("Which property do you wish to trade? ", printHoldings);
if (properties == numin) break;
else if (used[properties]) printf("You've already allocated that.\n");
else {
propertyIndex--;
used[properties] = true;
for (propertyList = property->ownedPropertyList;properties--;propertyList = propertyList->next) continue;
addToPropertyList(pn, & (tempProperty->propertyList) , getSquareIndex(propertyList->square1));
}
}
}
if (property->money > 0) {
printf("You have $%d. ", property->money);
tempProperty->cash = getInteger("How much are you trading? ");
}
if (property->getOutOfJailFreeCardCount > 0) {
once_more:while (true) {
printf("You have %d get-out-of-jail-free cards. ", property->getOutOfJailFreeCardCount);
tempProperty->getOutOfJailFreeCount = getInteger("How many are you trading? ");
if (tempProperty->getOutOfJailFreeCount > property->getOutOfJailFreeCardCount) {
printf("You don't have that many. Try again.\n");
continue;
}
break;
}
}
}
int setList(OWN * the_list) {
int i;
OWN * propertyList;
i = 0;
for (propertyList = the_list;propertyList;propertyList = propertyList->next) if (!used[i]) printHoldings[i++] = propertyList->square1->name;
printHoldings[i++] = "done";
printHoldings[i--] = 0;
return i;
}
void summate(void) {
boolean some;
int i;
TRADE * tempProperty;
OWN * propertyList;
for (i = 0;i < 2;i++) {
tempProperty = & trades[i];
some = false;
printf("Player %s (%d) gives:\n", players[tempProperty->trader].name, tempProperty->trader + 1);
if (tempProperty->cash > 0) printf("\t$%d\n", tempProperty->cash) ,
some++;
if (tempProperty->getOutOfJailFreeCount > 0) printf("\t%d get-out-of-jail-free card(s)\n", tempProperty->getOutOfJailFreeCount) ,
some++;
if (tempProperty->propertyList) {
for (propertyList = tempProperty->propertyList;propertyList;propertyList = propertyList->next) putchar('\t') ,
printSquare(getSquareIndex(propertyList->square1) , true);
some++;
}
if (!some) printf("\t-- Nothing --\n");
}
}
void doTrace(void) {
changePropertyOwners( & trades[0], & trades[1]);
changePropertyOwners( & trades[1], & trades[0]);
}
void changePropertyOwners(TRADE * from, TRADE * to) {
PLAY * pl_fr,
* pl_to;
OWN * propertyList;
pl_fr = & players[from->trader];
pl_to = & players[to->trader];
pl_fr->money -= from->cash;
pl_to->money += from->cash;
pl_fr->getOutOfJailFreeCardCount -= from->getOutOfJailFreeCount;
pl_to->getOutOfJailFreeCardCount += from->getOutOfJailFreeCount;
for (propertyList = from->propertyList;propertyList;propertyList = propertyList->next) {
addToPropertyList(to->trader, & (pl_to->ownedPropertyList) , getSquareIndex(propertyList->square1));
propertyList->square1->owner = to->trader;
deleteFromPropertyList(from->trader, & (pl_fr->ownedPropertyList) , getSquareIndex(propertyList->square1));
}
initializeOwnerList(to->trader);
}
void resign(void) {
int i,
newOwner;
OWN * propertyList;
SQUARE * square;
if (currentPlayer->money <= 0) {
switch (board[currentPlayer->location].type) {
case TYPE_UTIL:
case TYPE_RAILROAD:
case TYPE_PROPERTY:
newOwner = board[currentPlayer->location].owner;
break;
default :
newOwner = numberOfPlayers;
break;
}
if (newOwner == numberOfPlayers) printf("You would resign to the bank\n");
else printf("You would resign to %s\n", playerNames[newOwner]);
}
else if (numberOfPlayers == 1) {
newOwner = numberOfPlayers;
printf("You would resign to the bank\n");
}
else {
playerNames[numberOfPlayers] = "bank";
do {
newOwner = getinp("Who do you wish to resign to? ", playerNames);
if (newOwner == currentPlayerNumber) printf("You can't resign to yourself!!\n");
}
while (newOwner == currentPlayerNumber);
playerNames[numberOfPlayers] = "done";
}
if (getYesOrNo("Do you really want to resign? ", yesNoChoices) != 0) return;
if (numberOfPlayers == 1) {
printf("Then NOBODY wins (not even YOU!)\n");
exit(0);
}
if (newOwner < numberOfPlayers) {
printf("resigning to player\n");
trades[0].trader = newOwner;
trades[0].cash = trades[0].getOutOfJailFreeCount = 0;
trades[0].propertyList = 0;
trades[1].trader = currentPlayerNumber;
trades[1].cash = Math.max(currentPlayer->money, 0);
trades[1].getOutOfJailFreeCount = currentPlayer->getOutOfJailFreeCardCount;
trades[1].propertyList = currentPlayer->ownedPropertyList;
doTrace();
}
else {
printf("resigning to bank\n");
for (propertyList = currentPlayer->ownedPropertyList;propertyList;propertyList = propertyList->next) {
square = propertyList->square1;
square->owner = - 1;
square->description->isMortgaged = false;
if (square->type == TYPE_PROPERTY) {
isNotMonopoly(square->description->monopolyDescription);
square->description->houseCount = 0;
}
}
if (currentPlayer->getOutOfJailFreeCardCount) returnCardToDeck(currentPlayer);
}
for (i = currentPlayerNumber;i < numberOfPlayers;i++) {
playerNames[i] = playerNames[i + 1];
if (i + 1 < numberOfPlayers) players[i] = players[i + 1];
}
playerNames[numberOfPlayers--] = 0;
for (i = 0;i < NUMBER_OF_SQUARES;i++) if (board[i].owner > currentPlayerNumber)--board[i].owner;
currentPlayerNumber =--currentPlayerNumber < 0 ? numberOfPlayers - 1:currentPlayerNumber;
nextPlayer();
if (numberOfPlayers < 2) {
printf("\nThen %s WINS!!!!!\n", players[0].name);
printHoldings(0);
printf("That's a grand worth of $%d.\n", players[0].money + getPropertyWorth( & players[0]));
exit(0);
}
}
| static char sccsid[] = "@(#)trade.c 5.5 (Berkeley) 6/1/90";
struct TradeInfo {
int trader;
int cash;
int getOutOfJailFreeCount;
OWN * propertyList;
}
;
typedef TradeInfo TRADE;
static char * printHoldings[MAX_PROPERTIES + 2];
static int used[MAX_PROPERTIES];
static TRADE trades[2];
void trade(void) {
int tradee,
i;
trading = true;
for (i = 0;i < 2;i++) {
trades[i].cash = 0;
trades[i].getOutOfJailFreeCount = false;
trades[i].propertyList = 0;
}
over:while (true) {
if (numberOfPlayers == 1) {
printf("There ain't no-one around to trade WITH!!\n");
return;
}
if (numberOfPlayers > 2) {
tradee = getinp("Which player do you wish to trade with? ", playerNames);
if (tradee == numberOfPlayers) return;
if (tradee == currentPlayerNumber) {
printf("You can't trade with yourself!\n");
continue;
}
}
else tradee = 1 - currentPlayerNumber;
break;
}
getList(0, currentPlayerNumber);
getList(1, tradee);
if (getYesOrNo("Do you wish a summary? ") == 0) summate();
if (getYesOrNo("Is the trade ok? ") == 0) doTrace();
}
void getList(int tradeIndex, int playerNumber) {
int sn,
pn;
PLAY * property;
int numin,
properties,
propertyIndex;
OWN * propertyList;
TRADE * tempProperty;
for (numin = 0;numin < MAX_PROPERTIES;numin++) used[numin] = false;
sn = tradeIndex,
pn = playerNumber;
property = & players[pn];
tempProperty = & trades[sn];
tempProperty->trader = pn;
printf("player %s (%d):\n", property->name, pn + 1);
if (property->ownedPropertyList) {
numin = setList(property->ownedPropertyList);
for (propertyIndex = numin;propertyIndex;) {
properties = getinp("Which property do you wish to trade? ", printHoldings);
if (properties == numin) break;
else if (used[properties]) printf("You've already allocated that.\n");
else {
propertyIndex--;
used[properties] = true;
for (propertyList = property->ownedPropertyList;properties--;propertyList = propertyList->next) continue;
addToPropertyList(pn, & (tempProperty->propertyList) , getSquareIndex(propertyList->square1));
}
}
}
if (property->money > 0) {
printf("You have $%d. ", property->money);
tempProperty->cash = getInteger("How much are you trading? ");
}
if (property->getOutOfJailFreeCardCount > 0) {
once_more:while (true) {
printf("You have %d get-out-of-jail-free cards. ", property->getOutOfJailFreeCardCount);
tempProperty->getOutOfJailFreeCount = getInteger("How many are you trading? ");
if (tempProperty->getOutOfJailFreeCount > property->getOutOfJailFreeCardCount) {
printf("You don't have that many. Try again.\n");
continue;
}
break;
}
}
}
int setList(OWN * the_list) {
int i;
OWN * propertyList;
i = 0;
for (propertyList = the_list;propertyList;propertyList = propertyList->next) if (!used[i]) printHoldings[i++] = propertyList->square1->name;
printHoldings[i++] = "done";
printHoldings[i--] = 0;
return i;
}
void summate(void) {
boolean some;
int i;
TRADE * tempProperty;
OWN * propertyList;
for (i = 0;i < 2;i++) {
tempProperty = & trades[i];
some = false;
printf("Player %s (%d) gives:\n", players[tempProperty->trader].name, tempProperty->trader + 1);
if (tempProperty->cash > 0) printf("\t$%d\n", tempProperty->cash) ,
some++;
if (tempProperty->getOutOfJailFreeCount > 0) printf("\t%d get-out-of-jail-free card(s)\n", tempProperty->getOutOfJailFreeCount) ,
some++;
if (tempProperty->propertyList) {
for (propertyList = tempProperty->propertyList;propertyList;propertyList = propertyList->next) putchar('\t') ,
printSquare(getSquareIndex(propertyList->square1) , true);
some++;
}
if (!some) printf("\t-- Nothing --\n");
}
}
void doTrace(void) {
changePropertyOwners( & trades[0], & trades[1]);
changePropertyOwners( & trades[1], & trades[0]);
}
void changePropertyOwners(TRADE * from, TRADE * to) {
PLAY * pl_fr,
* pl_to;
OWN * propertyList;
pl_fr = & players[from->trader];
pl_to = & players[to->trader];
pl_fr->money -= from->cash;
pl_to->money += from->cash;
pl_fr->getOutOfJailFreeCardCount -= from->getOutOfJailFreeCount;
pl_to->getOutOfJailFreeCardCount += from->getOutOfJailFreeCount;
for (propertyList = from->propertyList;propertyList;propertyList = propertyList->next) {
addToPropertyList(to->trader, & (pl_to->ownedPropertyList) , getSquareIndex(propertyList->square1));
propertyList->square1->owner = to->trader;
deleteFromPropertyList(from->trader, & (pl_fr->ownedPropertyList) , getSquareIndex(propertyList->square1));
}
initializeOwnerList(to->trader);
}
void resign(void) {
int i,
newOwner;
OWN * propertyList;
SQUARE * square;
if (currentPlayer->money <= 0) {
switch (board[currentPlayer->location].type) {
case TYPE_UTIL:
case TYPE_RAILROAD:
case TYPE_PROPERTY:
newOwner = board[currentPlayer->location].owner;
break;
default :
newOwner = numberOfPlayers;
break;
}
if (newOwner == numberOfPlayers) printf("You would resign to the bank\n");
else printf("You would resign to %s\n", playerNames[newOwner]);
}
else if (numberOfPlayers == 1) {
newOwner = numberOfPlayers;
printf("You would resign to the bank\n");
}
else {
playerNames[numberOfPlayers] = "bank";
do {
newOwner = getinp("Who do you wish to resign to? ", playerNames);
if (newOwner == currentPlayerNumber) printf("You can't resign to yourself!!\n");
}
while (newOwner == currentPlayerNumber);
playerNames[numberOfPlayers] = "done";
}
if (getYesOrNo("Do you really want to resign? ", yesNoChoices) != 0) return;
if (numberOfPlayers == 1) {
printf("Then NOBODY wins (not even YOU!)\n");
exit(0);
}
if (newOwner < numberOfPlayers) {
printf("resigning to player\n");
trades[0].trader = newOwner;
trades[0].cash = trades[0].getOutOfJailFreeCount = 0;
trades[0].propertyList = 0;
trades[1].trader = currentPlayerNumber;
trades[1].cash = Math.max(currentPlayer->money, 0);
trades[1].getOutOfJailFreeCount = currentPlayer->getOutOfJailFreeCardCount;
trades[1].propertyList = currentPlayer->ownedPropertyList;
doTrace();
}
else {
printf("resigning to bank\n");
for (propertyList = currentPlayer->ownedPropertyList;propertyList;propertyList = propertyList->next) {
square = propertyList->square1;
square->owner = - 1;
square->description->isMortgaged = false;
if (square->type == TYPE_PROPERTY) {
isNotMonopoly(square->description->monopolyDescription);
square->description->houseCount = 0;
}
}
if (currentPlayer->getOutOfJailFreeCardCount) returnCardToDeck(currentPlayer);
}
for (i = currentPlayerNumber;i < numberOfPlayers;i++) {
playerNames[i] = playerNames[i + 1];
if (i + 1 < numberOfPlayers) players[i] = players[i + 1];
}
playerNames[numberOfPlayers--] = 0;
for (i = 0;i < NUMBER_OF_SQUARES;i++) if (board[i].owner > currentPlayerNumber)--board[i].owner;
currentPlayerNumber =--currentPlayerNumber < 0 ? numberOfPlayers - 1:currentPlayerNumber;
nextPlayer();
if (numberOfPlayers < 2) {
printf("\nThen %s WINS!!!!!\n", players[0].name);
printHoldings(0);
printf("That's a grand worth of $%d.\n", players[0].money + getPropertyWorth( & players[0]));
exit(0);
}
}
| static char sccsid[] = "@(#)trade.c 5.5 (Berkeley) 6/1/90";
typedef TradeInfo TRADE;
static char * printHoldings[MAX_PROPERTIES + 2];
static int used[MAX_PROPERTIES];
static TRADE trades[2];
void trade(void) {
int tradee,
i;
trading = true;
for (i = 0;i < 2;i++) {
trades[i].cash = 0;
trades[i].getOutOfJailFreeCount = false;
trades[i].propertyList = 0;
}
over:while (true) {
if (numberOfPlayers == 1) {
printf("There ain't no-one around to trade WITH!!\n");
return;
}
if (numberOfPlayers > 2) {
tradee = getinp("Which player do you wish to trade with? ", playerNames);
if (tradee == numberOfPlayers) return;
if (tradee == currentPlayerNumber) {
printf("You can't trade with yourself!\n");
continue;
}
}
else tradee = 1 - currentPlayerNumber;
break;
}
getList(0, currentPlayerNumber);
getList(1, tradee);
if (getYesOrNo("Do you wish a summary? ") == 0) summate();
if (getYesOrNo("Is the trade ok? ") == 0) doTrace();
}
void getList(int tradeIndex, int playerNumber) {
int sn,
pn;
PLAY * property;
int numin,
properties,
propertyIndex;
OWN * propertyList;
TRADE * tempProperty;
for (numin = 0;numin < MAX_PROPERTIES;numin++) used[numin] = false;
sn = tradeIndex,
pn = playerNumber;
property = & players[pn];
tempProperty = & trades[sn];
tempProperty->trader = pn;
printf("player %s (%d):\n", property->name, pn + 1);
if (property->ownedPropertyList) {
numin = setList(property->ownedPropertyList);
for (propertyIndex = numin;propertyIndex;) {
properties = getinp("Which property do you wish to trade? ", printHoldings);
if (properties == numin) break;
else if (used[properties]) printf("You've already allocated that.\n");
else {
propertyIndex--;
used[properties] = true;
for (propertyList = property->ownedPropertyList;properties--;propertyList = propertyList->next) continue;
addToPropertyList(pn, & (tempProperty->propertyList) , getSquareIndex(propertyList->square1));
}
}
}
if (property->money > 0) {
printf("You have $%d. ", property->money);
tempProperty->cash = getInteger("How much are you trading? ");
}
if (property->getOutOfJailFreeCardCount > 0) {
once_more:while (true) {
printf("You have %d get-out-of-jail-free cards. ", property->getOutOfJailFreeCardCount);
tempProperty->getOutOfJailFreeCount = getInteger("How many are you trading? ");
if (tempProperty->getOutOfJailFreeCount > property->getOutOfJailFreeCardCount) {
printf("You don't have that many. Try again.\n");
continue;
}
break;
}
}
}
int setList(OWN * the_list) {
int i;
OWN * propertyList;
i = 0;
for (propertyList = the_list;propertyList;propertyList = propertyList->next) if (!used[i]) printHoldings[i++] = propertyList->square1->name;
printHoldings[i++] = "done";
printHoldings[i--] = 0;
return i;
}
void summate(void) {
boolean some;
int i;
TRADE * tempProperty;
OWN * propertyList;
for (i = 0;i < 2;i++) {
tempProperty = & trades[i];
some = false;
printf("Player %s (%d) gives:\n", players[tempProperty->trader].name, tempProperty->trader + 1);
if (tempProperty->cash > 0) printf("\t$%d\n", tempProperty->cash) ,
some++;
if (tempProperty->getOutOfJailFreeCount > 0) printf("\t%d get-out-of-jail-free card(s)\n", tempProperty->getOutOfJailFreeCount) ,
some++;
if (tempProperty->propertyList) {
for (propertyList = tempProperty->propertyList;propertyList;propertyList = propertyList->next) putchar('\t') ,
printSquare(getSquareIndex(propertyList->square1) , true);
some++;
}
if (!some) printf("\t-- Nothing --\n");
}
}
void doTrace(void) {
changePropertyOwners( & trades[0], & trades[1]);
changePropertyOwners( & trades[1], & trades[0]);
}
void changePropertyOwners(TRADE * from, TRADE * to) {
PLAY * pl_fr,
* pl_to;
OWN * propertyList;
pl_fr = & players[from->trader];
pl_to = & players[to->trader];
pl_fr->money -= from->cash;
pl_to->money += from->cash;
pl_fr->getOutOfJailFreeCardCount -= from->getOutOfJailFreeCount;
pl_to->getOutOfJailFreeCardCount += from->getOutOfJailFreeCount;
for (propertyList = from->propertyList;propertyList;propertyList = propertyList->next) {
addToPropertyList(to->trader, & (pl_to->ownedPropertyList) , getSquareIndex(propertyList->square1));
propertyList->square1->owner = to->trader;
deleteFromPropertyList(from->trader, & (pl_fr->ownedPropertyList) , getSquareIndex(propertyList->square1));
}
initializeOwnerList(to->trader);
}
void resign(void) {
int i,
newOwner;
OWN * propertyList;
SQUARE * square;
if (currentPlayer->money <= 0) {
switch (board[currentPlayer->location].type) {
case TYPE_UTIL:
case TYPE_RAILROAD:
case TYPE_PROPERTY:
newOwner = board[currentPlayer->location].owner;
break;
default :
newOwner = numberOfPlayers;
break;
}
if (newOwner == numberOfPlayers) printf("You would resign to the bank\n");
else printf("You would resign to %s\n", playerNames[newOwner]);
}
else if (numberOfPlayers == 1) {
newOwner = numberOfPlayers;
printf("You would resign to the bank\n");
}
else {
playerNames[numberOfPlayers] = "bank";
do {
newOwner = getinp("Who do you wish to resign to? ", playerNames);
if (newOwner == currentPlayerNumber) printf("You can't resign to yourself!!\n");
}
while (newOwner == currentPlayerNumber);
playerNames[numberOfPlayers] = "done";
}
if (getYesOrNo("Do you really want to resign? ", yesNoChoices) != 0) return;
if (numberOfPlayers == 1) {
printf("Then NOBODY wins (not even YOU!)\n");
exit(0);
}
if (newOwner < numberOfPlayers) {
printf("resigning to player\n");
trades[0].trader = newOwner;
trades[0].cash = trades[0].getOutOfJailFreeCount = 0;
trades[0].propertyList = 0;
trades[1].trader = currentPlayerNumber;
trades[1].cash = Math.max(currentPlayer->money, 0);
trades[1].getOutOfJailFreeCount = currentPlayer->getOutOfJailFreeCardCount;
trades[1].propertyList = currentPlayer->ownedPropertyList;
doTrace();
}
else {
printf("resigning to bank\n");
for (propertyList = currentPlayer->ownedPropertyList;propertyList;propertyList = propertyList->next) {
square = propertyList->square1;
square->owner = - 1;
square->description->isMortgaged = false;
if (square->type == TYPE_PROPERTY) {
isNotMonopoly(square->description->monopolyDescription);
square->description->houseCount = 0;
}
}
if (currentPlayer->getOutOfJailFreeCardCount) returnCardToDeck(currentPlayer);
}
for (i = currentPlayerNumber;i < numberOfPlayers;i++) {
playerNames[i] = playerNames[i + 1];
if (i + 1 < numberOfPlayers) players[i] = players[i + 1];
}
playerNames[numberOfPlayers--] = 0;
for (i = 0;i < NUMBER_OF_SQUARES;i++) if (board[i].owner > currentPlayerNumber)--board[i].owner;
currentPlayerNumber =--currentPlayerNumber < 0 ? numberOfPlayers - 1:currentPlayerNumber;
nextPlayer();
if (numberOfPlayers < 2) {
printf("\nThen %s WINS!!!!!\n", players[0].name);
printHoldings(0);
printf("That's a grand worth of $%d.\n", players[0].money + getPropertyWorth( & players[0]));
exit(0);
}
}
| static char sccsid[] = "@(#)trade.c 5.5 (Berkeley) 6/1/90";
static char * printHoldings[MAX_PROPERTIES + 2];
static int used[MAX_PROPERTIES];
static TRADE trades[2];
void trade(void) {
int tradee,
i;
trading = true;
for (i = 0;i < 2;i++) {
trades[i].cash = 0;
trades[i].getOutOfJailFreeCount = false;
trades[i].propertyList = 0;
}
over:while (true) {
if (numberOfPlayers == 1) {
printf("There ain't no-one around to trade WITH!!\n");
return;
}
if (numberOfPlayers > 2) {
tradee = getinp("Which player do you wish to trade with? ", playerNames);
if (tradee == numberOfPlayers) return;
if (tradee == currentPlayerNumber) {
printf("You can't trade with yourself!\n");
continue;
}
}
else tradee = 1 - currentPlayerNumber;
break;
}
getList(0, currentPlayerNumber);
getList(1, tradee);
if (getYesOrNo("Do you wish a summary? ") == 0) summate();
if (getYesOrNo("Is the trade ok? ") == 0) doTrace();
}
void getList(int tradeIndex, int playerNumber) {
int sn,
pn;
PLAY * property;
int numin,
properties,
propertyIndex;
OWN * propertyList;
TRADE * tempProperty;
for (numin = 0;numin < MAX_PROPERTIES;numin++) used[numin] = false;
sn = tradeIndex,
pn = playerNumber;
property = & players[pn];
tempProperty = & trades[sn];
tempProperty->trader = pn;
printf("player %s (%d):\n", property->name, pn + 1);
if (property->ownedPropertyList) {
numin = setList(property->ownedPropertyList);
for (propertyIndex = numin;propertyIndex;) {
properties = getinp("Which property do you wish to trade? ", printHoldings);
if (properties == numin) break;
else if (used[properties]) printf("You've already allocated that.\n");
else {
propertyIndex--;
used[properties] = true;
for (propertyList = property->ownedPropertyList;properties--;propertyList = propertyList->next) continue;
addToPropertyList(pn, & (tempProperty->propertyList) , getSquareIndex(propertyList->square1));
}
}
}
if (property->money > 0) {
printf("You have $%d. ", property->money);
tempProperty->cash = getInteger("How much are you trading? ");
}
if (property->getOutOfJailFreeCardCount > 0) {
once_more:while (true) {
printf("You have %d get-out-of-jail-free cards. ", property->getOutOfJailFreeCardCount);
tempProperty->getOutOfJailFreeCount = getInteger("How many are you trading? ");
if (tempProperty->getOutOfJailFreeCount > property->getOutOfJailFreeCardCount) {
printf("You don't have that many. Try again.\n");
continue;
}
break;
}
}
}
int setList(OWN * the_list) {
int i;
OWN * propertyList;
i = 0;
for (propertyList = the_list;propertyList;propertyList = propertyList->next) if (!used[i]) printHoldings[i++] = propertyList->square1->name;
printHoldings[i++] = "done";
printHoldings[i--] = 0;
return i;
}
void summate(void) {
boolean some;
int i;
TRADE * tempProperty;
OWN * propertyList;
for (i = 0;i < 2;i++) {
tempProperty = & trades[i];
some = false;
printf("Player %s (%d) gives:\n", players[tempProperty->trader].name, tempProperty->trader + 1);
if (tempProperty->cash > 0) printf("\t$%d\n", tempProperty->cash) ,
some++;
if (tempProperty->getOutOfJailFreeCount > 0) printf("\t%d get-out-of-jail-free card(s)\n", tempProperty->getOutOfJailFreeCount) ,
some++;
if (tempProperty->propertyList) {
for (propertyList = tempProperty->propertyList;propertyList;propertyList = propertyList->next) putchar('\t') ,
printSquare(getSquareIndex(propertyList->square1) , true);
some++;
}
if (!some) printf("\t-- Nothing --\n");
}
}
void doTrace(void) {
changePropertyOwners( & trades[0], & trades[1]);
changePropertyOwners( & trades[1], & trades[0]);
}
void changePropertyOwners(TRADE * from, TRADE * to) {
PLAY * pl_fr,
* pl_to;
OWN * propertyList;
pl_fr = & players[from->trader];
pl_to = & players[to->trader];
pl_fr->money -= from->cash;
pl_to->money += from->cash;
pl_fr->getOutOfJailFreeCardCount -= from->getOutOfJailFreeCount;
pl_to->getOutOfJailFreeCardCount += from->getOutOfJailFreeCount;
for (propertyList = from->propertyList;propertyList;propertyList = propertyList->next) {
addToPropertyList(to->trader, & (pl_to->ownedPropertyList) , getSquareIndex(propertyList->square1));
propertyList->square1->owner = to->trader;
deleteFromPropertyList(from->trader, & (pl_fr->ownedPropertyList) , getSquareIndex(propertyList->square1));
}
initializeOwnerList(to->trader);
}
void resign(void) {
int i,
newOwner;
OWN * propertyList;
SQUARE * square;
if (currentPlayer->money <= 0) {
switch (board[currentPlayer->location].type) {
case TYPE_UTIL:
case TYPE_RAILROAD:
case TYPE_PROPERTY:
newOwner = board[currentPlayer->location].owner;
break;
default :
newOwner = numberOfPlayers;
break;
}
if (newOwner == numberOfPlayers) printf("You would resign to the bank\n");
else printf("You would resign to %s\n", playerNames[newOwner]);
}
else if (numberOfPlayers == 1) {
newOwner = numberOfPlayers;
printf("You would resign to the bank\n");
}
else {
playerNames[numberOfPlayers] = "bank";
do {
newOwner = getinp("Who do you wish to resign to? ", playerNames);
if (newOwner == currentPlayerNumber) printf("You can't resign to yourself!!\n");
}
while (newOwner == currentPlayerNumber);
playerNames[numberOfPlayers] = "done";
}
if (getYesOrNo("Do you really want to resign? ", yesNoChoices) != 0) return;
if (numberOfPlayers == 1) {
printf("Then NOBODY wins (not even YOU!)\n");
exit(0);
}
if (newOwner < numberOfPlayers) {
printf("resigning to player\n");
trades[0].trader = newOwner;
trades[0].cash = trades[0].getOutOfJailFreeCount = 0;
trades[0].propertyList = 0;
trades[1].trader = currentPlayerNumber;
trades[1].cash = Math.max(currentPlayer->money, 0);
trades[1].getOutOfJailFreeCount = currentPlayer->getOutOfJailFreeCardCount;
trades[1].propertyList = currentPlayer->ownedPropertyList;
doTrace();
}
else {
printf("resigning to bank\n");
for (propertyList = currentPlayer->ownedPropertyList;propertyList;propertyList = propertyList->next) {
square = propertyList->square1;
square->owner = - 1;
square->description->isMortgaged = false;
if (square->type == TYPE_PROPERTY) {
isNotMonopoly(square->description->monopolyDescription);
square->description->houseCount = 0;
}
}
if (currentPlayer->getOutOfJailFreeCardCount) returnCardToDeck(currentPlayer);
}
for (i = currentPlayerNumber;i < numberOfPlayers;i++) {
playerNames[i] = playerNames[i + 1];
if (i + 1 < numberOfPlayers) players[i] = players[i + 1];
}
playerNames[numberOfPlayers--] = 0;
for (i = 0;i < NUMBER_OF_SQUARES;i++) if (board[i].owner > currentPlayerNumber)--board[i].owner;
currentPlayerNumber =--currentPlayerNumber < 0 ? numberOfPlayers - 1:currentPlayerNumber;
nextPlayer();
if (numberOfPlayers < 2) {
printf("\nThen %s WINS!!!!!\n", players[0].name);
printHoldings(0);
printf("That's a grand worth of $%d.\n", players[0].money + getPropertyWorth( & players[0]));
exit(0);
}
}
| static char sccsid[] = "@(#)trade.c 5.5 (Berkeley) 6/1/90";
static char * printHoldings[MAX_PROPERTIES + 2];
static int used[MAX_PROPERTIES];
static TradeInfo trades[2];
void trade(void) {
int tradee,
i;
trading = true;
for (i = 0;i < 2;i++) {
trades[i].cash = 0;
trades[i].getOutOfJailFreeCount = false;
trades[i].propertyList = 0;
}
over:while (true) {
if (numberOfPlayers == 1) {
printf("There ain't no-one around to trade WITH!!\n");
return;
}
if (numberOfPlayers > 2) {
tradee = getinp("Which player do you wish to trade with? ", playerNames);
if (tradee == numberOfPlayers) return;
if (tradee == currentPlayerNumber) {
printf("You can't trade with yourself!\n");
continue;
}
}
else tradee = 1 - currentPlayerNumber;
break;
}
getList(0, currentPlayerNumber);
getList(1, tradee);
if (getYesOrNo("Do you wish a summary? ") == 0) summate();
if (getYesOrNo("Is the trade ok? ") == 0) doTrace();
}
void getList(int tradeIndex, int playerNumber) {
int sn,
pn;
Player * property;
int numin,
properties,
propertyIndex;
OwnedPropertyList * propertyList;
TradeInfo * tempProperty;
for (numin = 0;numin < MAX_PROPERTIES;numin++) used[numin] = false;
sn = tradeIndex,
pn = playerNumber;
property = & players[pn];
tempProperty = & trades[sn];
tempProperty->trader = pn;
printf("player %s (%d):\n", property->name, pn + 1);
if (property->ownedPropertyList) {
numin = setList(property->ownedPropertyList);
for (propertyIndex = numin;propertyIndex;) {
properties = getinp("Which property do you wish to trade? ", printHoldings);
if (properties == numin) break;
else if (used[properties]) printf("You've already allocated that.\n");
else {
propertyIndex--;
used[properties] = true;
for (propertyList = property->ownedPropertyList;properties--;propertyList = propertyList->next) continue;
addToPropertyList(pn, & (tempProperty->propertyList) , getSquareIndex(propertyList->square1));
}
}
}
if (property->money > 0) {
printf("You have $%d. ", property->money);
tempProperty->cash = getInteger("How much are you trading? ");
}
if (property->getOutOfJailFreeCardCount > 0) {
once_more:while (true) {
printf("You have %d get-out-of-jail-free cards. ", property->getOutOfJailFreeCardCount);
tempProperty->getOutOfJailFreeCount = getInteger("How many are you trading? ");
if (tempProperty->getOutOfJailFreeCount > property->getOutOfJailFreeCardCount) {
printf("You don't have that many. Try again.\n");
continue;
}
break;
}
}
}
int setList(OwnedPropertyList * the_list) {
int i;
OwnedPropertyList * propertyList;
i = 0;
for (propertyList = the_list;propertyList;propertyList = propertyList->next) if (!used[i]) printHoldings[i++] = propertyList->square1->name;
printHoldings[i++] = "done";
printHoldings[i--] = 0;
return i;
}
void summate(void) {
boolean some;
int i;
TradeInfo * tempProperty;
OwnedPropertyList * propertyList;
for (i = 0;i < 2;i++) {
tempProperty = & trades[i];
some = false;
printf("Player %s (%d) gives:\n", players[tempProperty->trader].name, tempProperty->trader + 1);
if (tempProperty->cash > 0) printf("\t$%d\n", tempProperty->cash) ,
some++;
if (tempProperty->getOutOfJailFreeCount > 0) printf("\t%d get-out-of-jail-free card(s)\n", tempProperty->getOutOfJailFreeCount) ,
some++;
if (tempProperty->propertyList) {
for (propertyList = tempProperty->propertyList;propertyList;propertyList = propertyList->next) putchar('\t') ,
printSquare(getSquareIndex(propertyList->square1) , true);
some++;
}
if (!some) printf("\t-- Nothing --\n");
}
}
void doTrace(void) {
changePropertyOwners( & trades[0], & trades[1]);
changePropertyOwners( & trades[1], & trades[0]);
}
void changePropertyOwners(TradeInfo * from, TradeInfo * to) {
Player * pl_fr,
* pl_to;
OwnedPropertyList * propertyList;
pl_fr = & players[from->trader];
pl_to = & players[to->trader];
pl_fr->money -= from->cash;
pl_to->money += from->cash;
pl_fr->getOutOfJailFreeCardCount -= from->getOutOfJailFreeCount;
pl_to->getOutOfJailFreeCardCount += from->getOutOfJailFreeCount;
for (propertyList = from->propertyList;propertyList;propertyList = propertyList->next) {
addToPropertyList(to->trader, & (pl_to->ownedPropertyList) , getSquareIndex(propertyList->square1));
propertyList->square1->owner = to->trader;
deleteFromPropertyList(from->trader, & (pl_fr->ownedPropertyList) , getSquareIndex(propertyList->square1));
}
initializeOwnerList(to->trader);
}
void resign(void) {
int i,
newOwner;
OwnedPropertyList * propertyList;
Square * square;
if (currentPlayer->money <= 0) {
switch (board[currentPlayer->location].type) {
case TYPE_UTIL:
case TYPE_RAILROAD:
case TYPE_PROPERTY:
newOwner = board[currentPlayer->location].owner;
break;
default :
newOwner = numberOfPlayers;
break;
}
if (newOwner == numberOfPlayers) printf("You would resign to the bank\n");
else printf("You would resign to %s\n", playerNames[newOwner]);
}
else if (numberOfPlayers == 1) {
newOwner = numberOfPlayers;
printf("You would resign to the bank\n");
}
else {
playerNames[numberOfPlayers] = "bank";
do {
newOwner = getinp("Who do you wish to resign to? ", playerNames);
if (newOwner == currentPlayerNumber) printf("You can't resign to yourself!!\n");
}
while (newOwner == currentPlayerNumber);
playerNames[numberOfPlayers] = "done";
}
if (getYesOrNo("Do you really want to resign? ", yesNoChoices) != 0) return;
if (numberOfPlayers == 1) {
printf("Then NOBODY wins (not even YOU!)\n");
exit(0);
}
if (newOwner < numberOfPlayers) {
printf("resigning to player\n");
trades[0].trader = newOwner;
trades[0].cash = trades[0].getOutOfJailFreeCount = 0;
trades[0].propertyList = 0;
trades[1].trader = currentPlayerNumber;
trades[1].cash = Math.max(currentPlayer->money, 0);
trades[1].getOutOfJailFreeCount = currentPlayer->getOutOfJailFreeCardCount;
trades[1].propertyList = currentPlayer->ownedPropertyList;
doTrace();
}
else {
printf("resigning to bank\n");
for (propertyList = currentPlayer->ownedPropertyList;propertyList;propertyList = propertyList->next) {
square = propertyList->square1;
square->owner = - 1;
square->description->isMortgaged = false;
if (square->type == TYPE_PROPERTY) {
isNotMonopoly(square->description->monopolyDescription);
square->description->houseCount = 0;
}
}
if (currentPlayer->getOutOfJailFreeCardCount) returnCardToDeck(currentPlayer);
}
for (i = currentPlayerNumber;i < numberOfPlayers;i++) {
playerNames[i] = playerNames[i + 1];
if (i + 1 < numberOfPlayers) players[i] = players[i + 1];
}
playerNames[numberOfPlayers--] = 0;
for (i = 0;i < NUMBER_OF_SQUARES;i++) if (board[i].owner > currentPlayerNumber)--board[i].owner;
currentPlayerNumber =--currentPlayerNumber < 0 ? numberOfPlayers - 1:currentPlayerNumber;
nextPlayer();
if (numberOfPlayers < 2) {
printf("\nThen %s WINS!!!!!\n", players[0].name);
printHoldings(0);
printf("That's a grand worth of $%d.\n", players[0].money + getPropertyWorth( & players[0]));
exit(0);
}
}
| static char sccsid[] = "@(#)trade.c 5.5 (Berkeley) 6/1/90";
static char * printHoldings[MAX_PROPERTIES + 2];
static int used[MAX_PROPERTIES];
static TradeInfo trades[2];
public static void trade(void) {
int tradee,
i;
trading = true;
for (i = 0;i < 2;i++) {
trades[i].cash = 0;
trades[i].getOutOfJailFreeCount = false;
trades[i].propertyList = 0;
}
over:while (true) {
if (numberOfPlayers == 1) {
printf("There ain't no-one around to trade WITH!!\n");
return;
}
if (numberOfPlayers > 2) {
tradee = getinp("Which player do you wish to trade with? ", playerNames);
if (tradee == numberOfPlayers) return;
if (tradee == currentPlayerNumber) {
printf("You can't trade with yourself!\n");
continue;
}
}
else tradee = 1 - currentPlayerNumber;
break;
}
getList(0, currentPlayerNumber);
getList(1, tradee);
if (getYesOrNo("Do you wish a summary? ") == 0) summate();
if (getYesOrNo("Is the trade ok? ") == 0) doTrace();
}
void getList(int tradeIndex, int playerNumber) {
int sn,
pn;
Player * property;
int numin,
properties,
propertyIndex;
OwnedPropertyList * propertyList;
TradeInfo * tempProperty;
for (numin = 0;numin < MAX_PROPERTIES;numin++) used[numin] = false;
sn = tradeIndex,
pn = playerNumber;
property = & players[pn];
tempProperty = & trades[sn];
tempProperty->trader = pn;
printf("player %s (%d):\n", property->name, pn + 1);
if (property->ownedPropertyList) {
numin = setList(property->ownedPropertyList);
for (propertyIndex = numin;propertyIndex;) {
properties = getinp("Which property do you wish to trade? ", printHoldings);
if (properties == numin) break;
else if (used[properties]) printf("You've already allocated that.\n");
else {
propertyIndex--;
used[properties] = true;
for (propertyList = property->ownedPropertyList;properties--;propertyList = propertyList->next) continue;
addToPropertyList(pn, & (tempProperty->propertyList) , getSquareIndex(propertyList->square1));
}
}
}
if (property->money > 0) {
printf("You have $%d. ", property->money);
tempProperty->cash = getInteger("How much are you trading? ");
}
if (property->getOutOfJailFreeCardCount > 0) {
once_more:while (true) {
printf("You have %d get-out-of-jail-free cards. ", property->getOutOfJailFreeCardCount);
tempProperty->getOutOfJailFreeCount = getInteger("How many are you trading? ");
if (tempProperty->getOutOfJailFreeCount > property->getOutOfJailFreeCardCount) {
printf("You don't have that many. Try again.\n");
continue;
}
break;
}
}
}
int setList(OwnedPropertyList * the_list) {
int i;
OwnedPropertyList * propertyList;
i = 0;
for (propertyList = the_list;propertyList;propertyList = propertyList->next) if (!used[i]) printHoldings[i++] = propertyList->square1->name;
printHoldings[i++] = "done";
printHoldings[i--] = 0;
return i;
}
void summate(void) {
boolean some;
int i;
TradeInfo * tempProperty;
OwnedPropertyList * propertyList;
for (i = 0;i < 2;i++) {
tempProperty = & trades[i];
some = false;
printf("Player %s (%d) gives:\n", players[tempProperty->trader].name, tempProperty->trader + 1);
if (tempProperty->cash > 0) printf("\t$%d\n", tempProperty->cash) ,
some++;
if (tempProperty->getOutOfJailFreeCount > 0) printf("\t%d get-out-of-jail-free card(s)\n", tempProperty->getOutOfJailFreeCount) ,
some++;
if (tempProperty->propertyList) {
for (propertyList = tempProperty->propertyList;propertyList;propertyList = propertyList->next) putchar('\t') ,
printSquare(getSquareIndex(propertyList->square1) , true);
some++;
}
if (!some) printf("\t-- Nothing --\n");
}
}
void doTrace(void) {
changePropertyOwners( & trades[0], & trades[1]);
changePropertyOwners( & trades[1], & trades[0]);
}
void changePropertyOwners(TradeInfo * from, TradeInfo * to) {
Player * pl_fr,
* pl_to;
OwnedPropertyList * propertyList;
pl_fr = & players[from->trader];
pl_to = & players[to->trader];
pl_fr->money -= from->cash;
pl_to->money += from->cash;
pl_fr->getOutOfJailFreeCardCount -= from->getOutOfJailFreeCount;
pl_to->getOutOfJailFreeCardCount += from->getOutOfJailFreeCount;
for (propertyList = from->propertyList;propertyList;propertyList = propertyList->next) {
addToPropertyList(to->trader, & (pl_to->ownedPropertyList) , getSquareIndex(propertyList->square1));
propertyList->square1->owner = to->trader;
deleteFromPropertyList(from->trader, & (pl_fr->ownedPropertyList) , getSquareIndex(propertyList->square1));
}
initializeOwnerList(to->trader);
}
public static void resign(void) {
int i,
newOwner;
OwnedPropertyList * propertyList;
Square * square;
if (currentPlayer->money <= 0) {
switch (board[currentPlayer->location].type) {
case TYPE_UTIL:
case TYPE_RAILROAD:
case TYPE_PROPERTY:
newOwner = board[currentPlayer->location].owner;
break;
default :
newOwner = numberOfPlayers;
break;
}
if (newOwner == numberOfPlayers) printf("You would resign to the bank\n");
else printf("You would resign to %s\n", playerNames[newOwner]);
}
else if (numberOfPlayers == 1) {
newOwner = numberOfPlayers;
printf("You would resign to the bank\n");
}
else {
playerNames[numberOfPlayers] = "bank";
do {
newOwner = getinp("Who do you wish to resign to? ", playerNames);
if (newOwner == currentPlayerNumber) printf("You can't resign to yourself!!\n");
}
while (newOwner == currentPlayerNumber);
playerNames[numberOfPlayers] = "done";
}
if (getYesOrNo("Do you really want to resign? ", yesNoChoices) != 0) return;
if (numberOfPlayers == 1) {
printf("Then NOBODY wins (not even YOU!)\n");
exit(0);
}
if (newOwner < numberOfPlayers) {
printf("resigning to player\n");
trades[0].trader = newOwner;
trades[0].cash = trades[0].getOutOfJailFreeCount = 0;
trades[0].propertyList = 0;
trades[1].trader = currentPlayerNumber;
trades[1].cash = Math.max(currentPlayer->money, 0);
trades[1].getOutOfJailFreeCount = currentPlayer->getOutOfJailFreeCardCount;
trades[1].propertyList = currentPlayer->ownedPropertyList;
doTrace();
}
else {
printf("resigning to bank\n");
for (propertyList = currentPlayer->ownedPropertyList;propertyList;propertyList = propertyList->next) {
square = propertyList->square1;
square->owner = - 1;
square->description->isMortgaged = false;
if (square->type == TYPE_PROPERTY) {
isNotMonopoly(square->description->monopolyDescription);
square->description->houseCount = 0;
}
}
if (currentPlayer->getOutOfJailFreeCardCount) returnCardToDeck(currentPlayer);
}
for (i = currentPlayerNumber;i < numberOfPlayers;i++) {
playerNames[i] = playerNames[i + 1];
if (i + 1 < numberOfPlayers) players[i] = players[i + 1];
}
playerNames[numberOfPlayers--] = 0;
for (i = 0;i < NUMBER_OF_SQUARES;i++) if (board[i].owner > currentPlayerNumber)--board[i].owner;
currentPlayerNumber =--currentPlayerNumber < 0 ? numberOfPlayers - 1:currentPlayerNumber;
nextPlayer();
if (numberOfPlayers < 2) {
printf("\nThen %s WINS!!!!!\n", players[0].name);
printHoldings(0);
printf("That's a grand worth of $%d.\n", players[0].money + getPropertyWorth( & players[0]));
exit(0);
}
}
| static char sccsid[] = "@(#)trade.c 5.5 (Berkeley) 6/1/90";
static char * printHoldings[MAX_PROPERTIES + 2];
static int used[MAX_PROPERTIES];
static TradeInfo trades[2];
public static void trade(void) {
int tradee;
int i;
trading = true;
for (i = 0;i < 2;i++) {
trades[i].cash = 0;
trades[i].getOutOfJailFreeCount = false;
trades[i].propertyList = 0;
}
over:while (true) {
if (numberOfPlayers == 1) {
printf("There ain't no-one around to trade WITH!!\n");
return;
}
if (numberOfPlayers > 2) {
tradee = getinp("Which player do you wish to trade with? ", playerNames);
if (tradee == numberOfPlayers) return;
if (tradee == currentPlayerNumber) {
printf("You can't trade with yourself!\n");
continue;
}
}
else tradee = 1 - currentPlayerNumber;
break;
}
getList(0, currentPlayerNumber);
getList(1, tradee);
if (getYesOrNo("Do you wish a summary? ") == 0) summate();
if (getYesOrNo("Is the trade ok? ") == 0) doTrace();
}
void getList(int tradeIndex, int playerNumber) {
int sn;
int pn;
Player * property;
int numin;
int properties;
int propertyIndex;
OwnedPropertyList * propertyList;
TradeInfo * tempProperty;
for (numin = 0;numin < MAX_PROPERTIES;numin++) used[numin] = false;
sn = tradeIndex,
pn = playerNumber;
property = & players[pn];
tempProperty = & trades[sn];
tempProperty->trader = pn;
printf("player %s (%d):\n", property->name, pn + 1);
if (property->ownedPropertyList) {
numin = setList(property->ownedPropertyList);
for (propertyIndex = numin;propertyIndex;) {
properties = getinp("Which property do you wish to trade? ", printHoldings);
if (properties == numin) break;
else if (used[properties]) printf("You've already allocated that.\n");
else {
propertyIndex--;
used[properties] = true;
for (propertyList = property->ownedPropertyList;properties--;propertyList = propertyList->next) continue;
addToPropertyList(pn, & (tempProperty->propertyList) , getSquareIndex(propertyList->square1));
}
}
}
if (property->money > 0) {
printf("You have $%d. ", property->money);
tempProperty->cash = getInteger("How much are you trading? ");
}
if (property->getOutOfJailFreeCardCount > 0) {
once_more:while (true) {
printf("You have %d get-out-of-jail-free cards. ", property->getOutOfJailFreeCardCount);
tempProperty->getOutOfJailFreeCount = getInteger("How many are you trading? ");
if (tempProperty->getOutOfJailFreeCount > property->getOutOfJailFreeCardCount) {
printf("You don't have that many. Try again.\n");
continue;
}
break;
}
}
}
int setList(OwnedPropertyList * the_list) {
int i;
OwnedPropertyList * propertyList;
i = 0;
for (propertyList = the_list;propertyList;propertyList = propertyList->next) if (!used[i]) printHoldings[i++] = propertyList->square1->name;
printHoldings[i++] = "done";
printHoldings[i--] = 0;
return i;
}
void summate(void) {
boolean some;
int i;
TradeInfo * tempProperty;
OwnedPropertyList * propertyList;
for (i = 0;i < 2;i++) {
tempProperty = & trades[i];
some = false;
printf("Player %s (%d) gives:\n", players[tempProperty->trader].name, tempProperty->trader + 1);
if (tempProperty->cash > 0) printf("\t$%d\n", tempProperty->cash) ,
some++;
if (tempProperty->getOutOfJailFreeCount > 0) printf("\t%d get-out-of-jail-free card(s)\n", tempProperty->getOutOfJailFreeCount) ,
some++;
if (tempProperty->propertyList) {
for (propertyList = tempProperty->propertyList;propertyList;propertyList = propertyList->next) putchar('\t') ,
printSquare(getSquareIndex(propertyList->square1) , true);
some++;
}
if (!some) printf("\t-- Nothing --\n");
}
}
void doTrace(void) {
changePropertyOwners( & trades[0], & trades[1]);
changePropertyOwners( & trades[1], & trades[0]);
}
void changePropertyOwners(TradeInfo * from, TradeInfo * to) {
Player * pl_fr;
Player * pl_to;
OwnedPropertyList * propertyList;
pl_fr = & players[from->trader];
pl_to = & players[to->trader];
pl_fr->money -= from->cash;
pl_to->money += from->cash;
pl_fr->getOutOfJailFreeCardCount -= from->getOutOfJailFreeCount;
pl_to->getOutOfJailFreeCardCount += from->getOutOfJailFreeCount;
for (propertyList = from->propertyList;propertyList;propertyList = propertyList->next) {
addToPropertyList(to->trader, & (pl_to->ownedPropertyList) , getSquareIndex(propertyList->square1));
propertyList->square1->owner = to->trader;
deleteFromPropertyList(from->trader, & (pl_fr->ownedPropertyList) , getSquareIndex(propertyList->square1));
}
initializeOwnerList(to->trader);
}
public static void resign(void) {
int i;
int newOwner;
OwnedPropertyList * propertyList;
Square * square;
if (currentPlayer->money <= 0) {
switch (board[currentPlayer->location].type) {
case TYPE_UTIL:
case TYPE_RAILROAD:
case TYPE_PROPERTY:
newOwner = board[currentPlayer->location].owner;
break;
default :
newOwner = numberOfPlayers;
break;
}
if (newOwner == numberOfPlayers) printf("You would resign to the bank\n");
else printf("You would resign to %s\n", playerNames[newOwner]);
}
else if (numberOfPlayers == 1) {
newOwner = numberOfPlayers;
printf("You would resign to the bank\n");
}
else {
playerNames[numberOfPlayers] = "bank";
do {
newOwner = getinp("Who do you wish to resign to? ", playerNames);
if (newOwner == currentPlayerNumber) printf("You can't resign to yourself!!\n");
}
while (newOwner == currentPlayerNumber);
playerNames[numberOfPlayers] = "done";
}
if (getYesOrNo("Do you really want to resign? ", yesNoChoices) != 0) return;
if (numberOfPlayers == 1) {
printf("Then NOBODY wins (not even YOU!)\n");
exit(0);
}
if (newOwner < numberOfPlayers) {
printf("resigning to player\n");
trades[0].trader = newOwner;
trades[0].cash = trades[0].getOutOfJailFreeCount = 0;
trades[0].propertyList = 0;
trades[1].trader = currentPlayerNumber;
trades[1].cash = Math.max(currentPlayer->money, 0);
trades[1].getOutOfJailFreeCount = currentPlayer->getOutOfJailFreeCardCount;
trades[1].propertyList = currentPlayer->ownedPropertyList;
doTrace();
}
else {
printf("resigning to bank\n");
for (propertyList = currentPlayer->ownedPropertyList;propertyList;propertyList = propertyList->next) {
square = propertyList->square1;
square->owner = - 1;
square->description->isMortgaged = false;
if (square->type == TYPE_PROPERTY) {
isNotMonopoly(square->description->monopolyDescription);
square->description->houseCount = 0;
}
}
if (currentPlayer->getOutOfJailFreeCardCount) returnCardToDeck(currentPlayer);
}
for (i = currentPlayerNumber;i < numberOfPlayers;i++) {
playerNames[i] = playerNames[i + 1];
if (i + 1 < numberOfPlayers) players[i] = players[i + 1];
}
playerNames[numberOfPlayers--] = 0;
for (i = 0;i < NUMBER_OF_SQUARES;i++) if (board[i].owner > currentPlayerNumber)--board[i].owner;
currentPlayerNumber =--currentPlayerNumber |