Demonic Vampire (shadowconn) wrote in spods,
Demonic Vampire
shadowconn
spods

Anyone ever try to install connect4

I can't get the damn thing to compile. . . I have this strange feeling that DOWIN is actually supposed to be CONNECT4, but if I do that I get parse errors all over the place . . .
CONNECT4


/*
* EW-too base code addition by PeeKaBoo
* --------------------------------------------------------------------------
*
* Connect v3.1
*
* Copyright (C) 1999 PeeKaBoo
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/

#include
[Error: Irreparable invalid markup ('<stdio.h>') in entry. Owner must fix manually. Raw contents below.]

I can't get the damn thing to compile. . . I have this strange feeling that DOWIN is actually supposed to be CONNECT4, but if I do that I get parse errors all over the place . . .
CONNECT4
<lj-cut text="CONNECT4">

/*
* EW-too base code addition by PeeKaBoo
* --------------------------------------------------------------------------
*
* Connect v3.1
*
* Copyright (C) 1999 PeeKaBoo
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/

#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#include <ctype.h>
#include "include/config.h"
#include "include/player.h"
#include "include/proto.h"

#ifndef DOWIN
#define DOWIN
/* tell players which players won, how much, etc..
PeeKaBoo - May 18/98 */
void do_win (player *p, player *p2, int amount, char *gamestr) {
/* Player p won
* amount = 0 means a no-bet game
* amount = -1 means tie game
*/
if ( amount == 0 ) {
TELLPLAYER (p, " You win the %s game with %s.\n", gamestr, p2->name);
TELLPLAYER (p2, " You lose the %s game with %s.\n", gamestr, p->name) ;
} else if ( amount == -1 ) {
TELLPLAYER (p, " You tie with %s in the %s game.\n", p2->name, gamestr);
TELLPLAYER (p2, " You tie with %s in the %s game.\n", p->name, gamestr);
} else {
TELLPLAYER (p, " You win %d %s from %s in the %s game!\n",
amount, MONEY, p2->name, gamestr);
p->pennies += amount;
TELLPLAYER (p2, " You lose %d %s from %s in the %s game!\n",
amount, MONEY, p->name, gamestr);
/*
Make sure they don't go into debt by taking more pennies than
they have (this amount could have changed since the game started)
*/
if (amount > p2->pennies) p2->pennies = 0;
else p2->pennies -= amount;
}
}
#endif

void tell_con_format(player *p) {
if (p->con) TELLPLAYER(p, " Format: con <column> \n");
else TELLPLAYER(p, " Format: con <column> <player> [amount]\n");
}

void newcon (player *p, player *p2, int bet) {
/* p2 gets a bet of -5, indicating it's not their turn */
int i,j;
p->con = (game_type *) MALLOC (sizeof(game_type));
p2->con = (game_type *) MALLOC (sizeof(game_type));
p->con->opponent = (char *) MALLOC ((strlen(p2->name)+1)*sizeof(char));
p2->con->opponent = (char *) MALLOC ((strlen(p->name)+1)*sizeof(char));
p->con->info = (char **) MALLOC (6*sizeof(char *));
p->con->info[0] = (char *) MALLOC (7*sizeof(char));
p->con->info[1] = (char *) MALLOC (7*sizeof(char));
p->con->info[2] = (char *) MALLOC (7*sizeof(char));
p->con->info[3] = (char *) MALLOC (7*sizeof(char));
p->con->info[4] = (char *) MALLOC (7*sizeof(char));
p->con->info[5] = (char *) MALLOC (7*sizeof(char));
p2->con->info = p->con->info;

strcpy(p->con->opponent, p2->name);
strcpy(p2->con->opponent, p->name);

p->con->bet = bet;
p2->con->bet = -5;

p->con->type = 'X';
p2->con->type = 'O';

for (i=0;i!=6;i++) {
for (j=0;j!=7;j++) {
p->con->info[i][j] = 0;
}
}
return;
}

void con_view (player *p, player *p2, int wintype) {
int i,j,win;
char *oldstack = stack;
win=1;

ADDSTACK ("\n 1 2 3 4 5 6 7\n");
for (i=0;i!=6;i++) {
ADDSTACK (" ");
for (j=0;j!=7;j++,win++) {
if ( wintype != 0 && (
/* check for 4 down */
(wintype < 43 && ( wintype == win || wintype+7 == win ||
wintype+14 == win || wintype+21 == win )) ||
/* check for 4 across */
(wintype > 42 && wintype < 85 &&
( wintype == win+42 || wintype+1 == win+42 ||
wintype+2 == win+42 || wintype+3 == win+42 )) ||
/* check for 4 right-down */
(wintype > 84 && wintype < 127 &&
( wintype == win+84 || wintype+8 == win+84 ||
wintype+16 == win+84 || wintype+24 == win+84 )) ||
/* check for 4 right-up */
(wintype > 126 && wintype < 190 &&
( wintype+3 == win+126 || wintype+9 == win+126 ||
wintype+15 == win+126 || wintype+21 == win+126 ))
)) {
if (p2->con->info[i][j] == 'X')
ADDSTACK ("^G|^YX");
else ADDSTACK ("^G|^YO");
} else if (p2->con->info[i][j] == 0)
ADDSTACK ("^G| ");
else if (p2->con->info[i][j] == 'X')
ADDSTACK ("^G|^RX");
else if (p2->con->info[i][j] == 'O')
ADDSTACK ("^G|^CO");
}
ADDSTACK ("^G|");
if (i == 2) {
if (p->con->type =='X') {
ADDSTACK (" ^RX's: ^N%s", p->name);
} else {
ADDSTACK (" ^RX's: ^N%s", p->con->opponent);
}
}
if (i == 3 ) {
if (p->con->type =='O') {
ADDSTACK (" ^CO's: ^N%s", p->name);
} else {
ADDSTACK (" ^CO's: ^N%s", p->con->opponent);
}
}
ADDSTACK ("\n");
}
ADDSTACK (" ^G'-+-+-+-+-+-+-'\n");
if ( p2->con->bet == -5 && wintype == 0) {
ADDSTACK (" It's your turn...\n");
} else if ( p->con->bet == -5 && wintype == 0) {
ADDSTACK (" It's %s's turn...\n", p->con->opponent);
}
ENDSTACK("\n");
tell_player(p, oldstack);
stack = oldstack;
return;

}

void con_clear (player *p, player *p2) {
int i;
if (p->con) {
if (p->con->opponent) {
FREE (p->con->opponent);
p->con->opponent = NULL;
}
if (p->con->info) {
for (i=0;i<6;i++) {
if (p->con->info[i]) {
FREE (p->con->info[i]);
p->con->info[i] = NULL;
}
}
FREE (p->con->info);
}
if (p->con) {
FREE (p->con);
p->con = NULL;
}
}
p->con = NULL;
if (p2 && p2->con) {
if (p2->con->opponent) {
FREE (p2->con->opponent);
p2->con->opponent = NULL;
}
if (p2->con) {
FREE (p2->con);
p2->con = NULL;
}
}
return;
}

void con_win (player *p, player *p2) {

int wintype = 0;
int counter = 1;
int i,j;
for (i=0;i!=6;i++) {
for (j=0;j!=7;j++,counter++) {
/* check for 4 down */
if ( i < 3 && p->con->info[i][j] == p->con->info[i+1][j] &&
p->con->info[i+1][j] == p->con->info[i+2][j] &&
p->con->info[i+2][j] == p->con->info[i+3][j] &&
p->con->info[i][j] != 0 )
wintype = counter;
/* check for 4 across */
else if (j < 4 && p->con->info[i][j] == p->con->info[i][j+1] &&
p->con->info[i][j+1] == p->con->info[i][j+2] &&
p->con->info[i][j+2] == p->con->info[i][j+3] &&
p->con->info[i][j] != 0 )
wintype = counter+42;
/* check for 4 diagonal down-right */
else if (j < 4 && i < 3 &&
p->con->info[i][j] == p->con->info[i+1][j+1] &&
p->con->info[i+1][j+1] == p->con->info[i+2][j+2] &&
p->con->info[i+2][j+2] == p->con->info[i+3][j+3] &&
p->con->info[i][j] != 0 )
wintype = counter +84;
/* check for 4 diagonal down-left */
else if (j < 4 && i < 3 &&
p->con->info[i][j+3] == p->con->info[i+1][j+2] &&
p->con->info[i+1][j+2] == p->con->info[i+2][j+1] &&
p->con->info[i+2][j+1] == p->con->info[i+3][j] &&
p->con->info[i][j+3] != 0 )
wintype = counter +126;
}
}
/*check for tie game */
if (wintype == 0) {
wintype = 200; /*hehe...magic number *shrug* */
for (i=0;i!=6;i++) {
for (j=0;j!=7;j++,counter++) {
if (p->con->info[i][j] == 0) wintype = 0;
}
}
}
con_view(p, p2, wintype);
con_view(p2, p, wintype);
if (wintype == 0) return;

/* The game has ended, show who won, etc */
/*if tie game... */
if (wintype == 200) do_win (p, p2, -1, CONNECT4);
else {
do_win (p, p2, p2->con->bet, CONNECT4);
}
con_clear(p, p2);
return;

}

void do_con (player *p, player *p2, int col) {
int i=-1;
while (i < 5 && p->con->info[i+1][col] == 0) {
i++;
}
if (i==-1) {
TELLPLAYER (p, " That column is full.\n");
return;
}
p->con->info[i][col] = p->con->type;
/* Change whose turn it is */
p2->con->bet = p->con->bet;
p->con->bet = -5;
/*con_win shows the players the game */
con_win(p, p2);
return;
}

void con(player *p, char *str) {

player *p2;
char *scol, *sbet, *p2name;
int col = 0;
int bet = 0;
list_ent *l;

if (!*str) {
tell_con_format(p);
return;
}
if (!strcasecmp(str, "clear")||!strcasecmp(str, "quit")) {
if (!p->con || !p->con->opponent || !p->con->info) {
TELLPLAYER (p, " You're not playing %s though.\n", CONNECT4);
return;
}
TELLPLAYER (p, " You quit the %s game with %s.\n", CONNECT4,
p->con->opponent);
p2 = (player *)find_player_global_quiet(p->con->opponent);
if (p2) {
TELLPLAYER (p2, " %s quits the %s game with you.\n",
p->name, CONNECT4);
con_clear(p, p2);
} else {
con_clear(p, 0);
}
return;
}
if (!strcasecmp(str, "view")) {
if (!p->con || !p->con->opponent || !p->con->info) {
TELLPLAYER (p, " You're not playing %s though.\n", CONNECT4);
return;
}
p2 = (player *) find_player_global_quiet(p->con->opponent);
if (!p2) {
TELLPLAYER (p, " %s was not found, please clear"
" the %s game.\n", p->con->opponent, CONNECT4);
return;
}
con_view (p, p2, 0);
return;
}
if (p->misc_flags & NO_PRS) {
TELLPLAYER(p, " You cannot play %s when blocking game offers.\n", CONNECT4);
return;
}
/*parse the input */
scol = str;
p2name = next_space(scol);
if (*p2name) *p2name++ = 0; {
sbet = next_space ( p2name );
if ( *sbet ) *sbet++ = 0;
}
if ( !*scol ) {
tell_con_format(p);
return;
} else if (!isdigit(*scol)) {
TELLPLAYER (p, " The column must be a number [1-7].\n");
return;
}
col = atoi( scol ) -1;
if ( col < 0 || col > 6 ) {
TELLPLAYER (p, " Column must be a number [1-7]\n");
return;
}
/* col should be valid input at this point */
/* check if a game is already in progress */

if ( p->con && p->con->opponent && p->con->info) { /* game exists already */
p2 = (player *) find_player_global_quiet(p->con->opponent);
if (!p2) {
TELLPLAYER (p, " %s was not found, please clear the %s game.\n",
p->con->opponent, CONNECT4);
return;
} else if (!p2->con || !p2->con->opponent || !p2->con->info) {
TELLPLAYER (p, " %s apparently isn't playing %s, please clear the game.\n",
p->con->opponent, CONNECT4);
return;
}
if (p->con->bet == -5 ) {
TELLPLAYER (p, " It's %s's turn, not yours. You ask them to hurry up!\n", p->con->opponent);
TELLPLAYER (p2, " %s is waiting for you to take your turn in %s..\n",
p->name, CONNECT4);
return;
}
do_con (p, p2, col);
return;
}
/* We are starting a new game */

if (!*p2name) {
tell_con_format(p);
return;
}
p2 = (player *) find_player_global(p2name);
if (!p2) return;
if (p2->misc_flags & NO_PRS) {
TELLPLAYER(p, " That person doesn't like that game.\n");
return;
}
if (p2->saved) {
l = fle_from_save(p2->saved, p->lower_name);
if (l && l->flags & (IGNORE|BLOCK)) {
TELLPLAYER(p, " That person is ignoring you.\n");
return;
}
}
if (p==p2) {
TELLPLAYER(p, " Now where would the challenge in THAT be?\n");
return;
}
if ( p2->con && p2->con->opponent && p2->con->info) {
TELLPLAYER (p, " %s is already playing against %s.\n",
p2->name, p2->con->opponent);
TELLPLAYER (p2, " %s just tried to play %s against you.\n",
p->name, CONNECT4);
return;

}
/* p2 should be a valid player at this point */
if ( !*sbet ) bet = 0;
else if ( !isdigit(*sbet) ) {
TELLPLAYER(p, " Your wager must be a number!\n");
return;
} else {
bet = atoi (sbet);
}
if ( bet < 0 ) {
TELLPLAYER (p, " You must bet a positive amount!\n");
return;
} else if ( !(p2->residency) && bet!=0) {
TELLPLAYER (p, " %s cannot bet %s on a game since they are not a resident.\n", p2->name, MONEY);
return;
} else if ( !(p->residency) && bet!=0) {
TELLPLAYER (p, " Sorry, only residents can bet %s on a game.\n", MONEY);
return;
} else if ( bet > p->pennies ) {
TELLPLAYER (p, " You can't bet what you don't have!\n");
return;
} else if ( bet > p2->pennies ) {
TELLPLAYER (p, " Sorry, %s doesn't have that many %s!\n",
p2->name, MONEY);
return;
}
/* bet should be valid now */
/* initialize the game */
LOGF("connect", "%s vs. %s", p->name, p2->name);
newcon(p, p2, bet);
if ( bet !=0 ) {
TELLPLAYER (p, " You ask %s to play %s for %d %s.\n",
p2->name, CONNECT4, bet, MONEY);
TELLPLAYER (p2, " %s asks you to play %s for %d %s.\n",
p->name, CONNECT4, bet, MONEY);
} else {
TELLPLAYER (p, " You ask %s to play %s for fun.\n",
p2->name, CONNECT4);
TELLPLAYER (p2, " %s asks you to play %s for fun.\n",
p->name, CONNECT4);
}

/* done initializing - lets play now!! */
do_con (p, p2, col);
return;
}

void connect_version(void)
{
sprintf(stack, " -=*> Connect 4 v3.1 (by PeeKaBoo) enabled.\n");
stack = strchr(stack, 0);
}

void con_save_player(player *p, int fd) {
char *oldstack = stack, g[43];
player *p2;
int i,j;

p2 = find_player_absolute_quiet(p->con->opponent);

for (i=0;i<6;i++) {
for (j=0;j<7;j++) {
g[7*i+j] = p->con->info[i][j] ? p->con->info[i][j] : '.';
}
}

g[42] = 0;
ENDSTACK("%s %s %c %d %d %s\n", p->name, p->con->opponent,
p->con->type,p->con->bet, p2->con->bet, g);
write(fd, oldstack, strlen(oldstack));
stack = oldstack;
con_clear(p, p2);
}

void connect_save_all(void) {
player *scan;
int fd;

fd = open("junk/rebooting/con.dat", O_SYNC | O_WRONLY|O_CREAT,
S_IRUSR |S_IWUSR);
if (!fd) {
LOGF("error", "Error opening 'con.dat' for reboot");
return;
}

for (scan = flatlist_start; scan; scan = scan->flat_next) {
if (!scan->con || strcmp(scan->name, scan->con->opponent) > 0)
continue;
con_save_player(scan, fd);
} /* end for */

close(fd);
}

char *con_load_player(char *line) {
char *next;
player *p, *p2;
int num, i,j;

next = strchr(line, ' ');
*next++ =0;
p = find_player_absolute_quiet(line);
if (!p) return 0;

line = next; next = strchr(line, ' '); *next++ = 0;
p2 = find_player_absolute_quiet(line);
if (!p2) return 0;

line = next; next = strchr(line, ' '); *next++ = 0;

if (*line == 'X') newcon(p, p2, 0);
else newcon(p2, p, 0);

line = next; next = strchr(line, ' '); *next++ = 0;
num = atoi(line);
p->con->bet = num;

line = next; next = strchr(line, ' '); *next++ = 0;
num = atoi(line);
p2->con->bet = num;

for (i=0;i<6;i++) {
for (j=0;j<7;j++) {
if (*next == '.') p->con->info[i][j] = 0;
else p->con->info[i][j] = *next;
next++;
}
}
next++;
return next;
}

void connect_load_all(void) {
file con_dat;
char *f, *line;
int filelength;

con_dat = load_file("junk/rebooting/con.dat");

if (!(con_dat.where) || strlen(con_dat.where) == 0) return;

filelength = strlen(con_dat.where);
line = con_dat.where;
f = con_load_player(line);

while (f && (f - con_dat.where) < filelength) {
line = f;
f = con_load_player(line);
}
if (con_dat.where) FREE(con_dat.where);
}
Subscribe
  • Post a new comment

    Error

    default userpic
  • 5 comments