|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T m
Length: 4690 (0x1252) Types: TextFile Names: »main.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987 └─⟦this⟧ »EUUGD18/General/Kriegspiel/main.c«
/* Kriegspiel written by David Wolfe based on a program by Bert Enderton May 5, 1986 */ /* main.c */ #include "externs.h" #include <ctype.h> #include <signal.h> char symbol [7] = { '-', 'P', 'K', 'N', 'B', 'R', 'Q' }; int whose [100]; int occupant [100]; char *colorname [2] = { "white", "black" }; int pawndir [2] = { -10, 10 }; LIST dirlist [7]; LIST piecelocs [2]; int kingloc [2]; MOVELIST movelist = (MOVELIST) NULL; int ourcolor = UNSET; int lastmovefrom = 0; int lastmoveto = 0; int virgin [100]; int drawok [2] = { FALSE, FALSE}; int resign = FALSE; int dead = FALSE; int option [NOPTIONS]; WINDOW *blanksq [89]; WINDOW *square [89]; WINDOW *win [23]; WINDOW *backupwin [23]; WINDOW *backupscreen; WINDOW *blankscreen; char sqcolor [2]; int vtterm; int dumbterm = FALSE; int reversescr; int sqheight; int sqwidth; int iamserver = UNSET; int sock; long random(); char **envp; main (argc, argv, envp_) int argc; char **argv, **envp_; { int i, j, port = 0, trap_sigint(); char *p, *malloc (); long time (); signal (SIGINT, SIG_IGN); signal (SIGPIPE, SIG_IGN); srandom (time((long *) NULL)); envp = envp_; if (!strcmp (argv [1], "help")) { execle(PRINT_FILE, PRINT_FILE, HELP_FILE, 0, envp); perror ("execle"); exit (1); } if (argc <= 1) { printf ("Usage: %s [-bwcaprsdh] user\n", argv[0]); printf ("Or for help: %s help\n", argv[0]); exit (0); } for (i = 0; i < NOPTIONS; i++) option [i] = UNSET; j = 0; for (i = 1; i < argc - 1; i++) { j = TRUE; for (p = argv [i]; *p != '\000'; p++) { if isupper (*p) *p = tolower (*p); if (*p == '-') j = FALSE; else if (*p == 'b') option [COLOR] = BLACK; else if (*p == 'w') option [COLOR] = WHITE; else if (*p == 'c') option [COLOR] = RANDOM; else if (*p == 'a') option [ANNOUNCETAKES] = j; else if (*p == 'p') option [ANNOUNCEPAWNS] = j; else if (*p == 'r') option [REVERSE] = j; else if (*p == 's') iamserver = j; else if (*p == 'd') dumbterm = j; else if (isdigit (*p)) port = port * 10 + (*p - '0'); else if (*p == 'h') { execle(PRINT_FILE, PRINT_FILE, HELP_FILE, 0, envp); perror ("execle"); exit (1); } } } initdirlists (); initpiecelocs (); initscreen (); refresh(); redraw(); signal (SIGINT, trap_sigint); p = argv [argc - 1]; waddstr (win [MESSAGE], "(connecting)"); refresh (); connectport (p, port); wclear (win [MESSAGE]); refresh (); p = malloc (MAXBUFF); if (send (sock, VERSION, strlen(VERSION), 0) < 0) error ("send in main"); while (recv (sock, p, strlen (VERSION), 0) < 0) if (errno != EINTR) error ("recv in main"); if (strncmp (p, VERSION, strlen (VERSION))) { if (!strncmp (p, VERSION, 3)) waddstr (win [MESSAGE], "different but\ncompatable\nversions."); else waddstr (win [MESSAGE], "different and\incompatable\nversions.\nI suggest\nyou quit!"); waddstr (win [PROMPT], "Quit? (y or n)"); waddstr (win [INPUT], ": "); move (win [INPUT]->_cury + win [INPUT]->_begy, win [INPUT]->_curx + win [INPUT]->_begx); refresh (); j = getchar(); while (j!='n' && j!='N' && j!='y' && j!='Y') { if (j == '\f') /* ^L */ redraw (); j = getchar(); } if (j == 'y') error ((char *) NULL); } if (iamserver) { while (recv (sock, p, NOPTIONS, 0) < 0) if (errno != EINTR) error ("recv in main"); for (i = 0; i < NOPTIONS; i++) { if (i == REVERSE) p [i] = option [i] = (option [COLOR] == BLACK && option [i] == TRUE) || (option [COLOR] == WHITE && p [i] == TRUE); if (option [i] == UNSET || p [i] == UNSET) p [i] = option [i] = option[i] + p[i] - UNSET; if (option [i] == UNSET) if (i == COLOR) option [i] = p [i] = RANDOM; else option [i] = p [i] = FALSE; else if (option [i] != p [i]) option [i] = p [i] = RANDOM; if (option [i] == RANDOM) option [i] = p [i] = random () & 01; } if (send (sock, p, NOPTIONS, 0) < 0) error ("send in main"); } else { for (i = 0; i < NOPTIONS; i++) p [i] = option [i]; if (p [COLOR] == WHITE || p [COLOR] == BLACK) p [COLOR] = ! option [COLOR]; if (send (sock, p, NOPTIONS, 0) < 0) error ("send in main"); while (recv (sock, p, NOPTIONS, 0) < 0) if (errno != EINTR) error ("recv in main"); for (i = 0; i < NOPTIONS; i++) option [i] = p [i]; option [COLOR] = ! p [COLOR]; } ourcolor = option [COLOR]; if (ourcolor == WHITE) waddstr(win [MYCOLOR], "--- WHITE ---"); else waddstr(win [MYCOLOR], "--- BLACK ---"); initboard (FALSE); for (i = 0; i < 100; i++) virgin [i] = TRUE; movecycle (); }