home *** CD-ROM | disk | FTP | other *** search
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of archive 1 (of 1)."
- # Contents: README MANIFEST accordian.c accordian.man cards.c cards.h
- # help.c makefile
- # Wrapped by billr@saab on Sun Nov 29 18:05:07 1992
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'README' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'README'\"
- else
- echo shar: Extracting \"'README'\" \(1686 characters\)
- sed "s/^X//" >'README' <<'END_OF_FILE'
- X --------- ACCORDIAN SOLITAIRE ---------
- X
- XThis is the card game of Accordian Solitaire. A deck of cards is
- Xdealt to the playing table (either a card at a time, or the whole
- Xdeck at once), and the goal is to move stacks of cards around
- Xuntil a single stack of cards is left on the table.
- X
- XStacks of cards can only move 1 or 3 spaces up the line of cards,
- Xonto other stacks whose top card is of the same suit or rank as
- Xthe current stack's top card.
- X
- XIf you end up with a single stack, you win the game!
- X
- XThe book of card games I got this out of (but have since lost) said
- Xof this game something like the following:
- X
- X The response to this game after we published that it was basically
- X impossible to win was about half a dozen letters, typically saying
- X the following: `I have play Accordian every night for the last
- X 25 years, and have won no fewer than 3 times.'
- X
- XGiven the chance of winning the game, I felt it wise to write the program
- Xso I wouldn't tire out my hands reshuffling the deck after each defeat.
- X
- X
- XTo compile and run, edit "Makefile", and change file path, and compiler
- Xdefinitions to suit your machine. I have included the compiler setups
- Xfor BSD-ish and SysV-ish machines. I presume that it will compile under
- Xany other system that has an implementation of the "curses" package.
- X
- XI have successfully compiled and run the program under SunOS 4.1.1 (BSD-ish)
- Xon a Sun Sparc 1+, and under IRIX 4.0.5 (SysV-ish) on an SGI Crimson.
- X
- X
- XPlease send me any enhancements or modifications done to the program,
- Xso I can keep my copy up-to-date with any updated versions out there.
- X
- X
- XThis program is public domain.
- X
- X-Eric Lechner (ericl@xilinx.com) 19 November 1992
- END_OF_FILE
- if test 1686 -ne `wc -c <'README'`; then
- echo shar: \"'README'\" unpacked with wrong size!
- fi
- # end of 'README'
- fi
- if test -f 'MANIFEST' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'MANIFEST'\"
- else
- echo shar: Extracting \"'MANIFEST'\" \(362 characters\)
- sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
- X File Name Archive # Description
- X-----------------------------------------------------------
- X MANIFEST 1 This shipping list
- X README 1
- X accordian.c 1
- X accordian.man 1
- X cards.c 1
- X cards.h 1
- X help.c 1
- X makefile 1
- END_OF_FILE
- if test 362 -ne `wc -c <'MANIFEST'`; then
- echo shar: \"'MANIFEST'\" unpacked with wrong size!
- fi
- # end of 'MANIFEST'
- fi
- if test -f 'accordian.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'accordian.c'\"
- else
- echo shar: Extracting \"'accordian.c'\" \(13179 characters\)
- sed "s/^X//" >'accordian.c' <<'END_OF_FILE'
- X/*
- X * accordian - the solitaire card game
- X *
- X * Author: Eric Lechner (ericl@xilinx.com)
- X * Originally written: Summer 1990
- X * Minor enhancements: March 1991 and November 1992
- X */
- X
- X#include <stdio.h>
- X#include <stdlib.h>
- X#include <pwd.h>
- X#include <time.h>
- X#include <curses.h>
- X#include <signal.h>
- X#include "cards.h"
- X
- X#define BADCARD -1
- X#define NOTINDECK -2
- X#define STUCK -3
- X
- X#define MOVE1 1
- X#define MOVE3 2
- X
- X#define WIN 1
- X#define MOREMOVES 2
- X#define LOSE 3
- X
- X#define BUFFERLENGTH 256
- X
- Xint quit();
- X
- Xstruct save {
- X int position;
- X int num_spaces;
- X};
- X
- Xint save_nextcard, save_lastpile;
- Xint _face = 0, _suit = 0;
- Xint _msg[5];
- Xstruct card deck[52];
- Xstruct card save_deck[52];
- Xchar buffer[256];
- Xstruct save undo[52], save[52];
- Xint nummoves, save_moves;
- X
- X/*
- X * main -- the main program loop
- X */
- Xmain(argc,argv)
- Xint argc;
- Xchar *argv[];
- X{
- X int lastpile; /* last exposed "pile" position in the deck */
- X int nextcard; /* next "free" card in the deck */
- X int place; /* place of card to move in the deck*/
- X int playing;
- X int lastlast, thislast; /* last displayed card */
- X int i, ch, tmp, num;
- X int title;
- X FILE *fp, *pfp;
- X char *pager;
- X
- X if (argc > 1) {
- X pager = getenv("PAGER");
- X if (pager == NULL || *pager == '\0') pager = DEFAULT_PAGER;
- X
- X pfp = popen(pager, "w");
- X if (pfp == NULL) pfp = stdout;
- X
- X i = 0;
- X while (helplist[i] != 0)
- X fprintf(pfp, "%s\n",helplist[i++]);
- X
- X fp = fopen(ACCORDIAN_WINFILE, "r");
- X if (fp != NULL) {
- X fprintf(pfp, "\nAccordian winners:\n");
- X while ((ch = fgetc(fp)) != EOF) fputc(ch, pfp);
- X fclose(fp);
- X }
- X if (pfp != stdout) pclose(pfp);
- X exit(-1);
- X }
- X
- X SRANDOM(getpid());
- X
- X signal(SIGINT,quit);
- X
- X /* yap, if curses window couldn't be formed */
- X /* note: most curses implementations quit for you here */
- X if (initscr() == NULL) {
- X fprintf(stderr,"Couldn't initialize the screen.\n");
- X exit(-1);
- X }
- X
- X savetty();
- X
- XStartOfGame:
- X title = FALSE;
- X
- X for (i=0; i<5; i++) _msg[i] = 0;
- X
- X for (i=0; i<52; i++) {
- X undo[i].position = 0;
- X undo[i].num_spaces = 0;
- X }
- X nummoves = 0;
- X
- X newdeck();
- X shuffle();
- X
- X lastpile = 0;
- X nextcard = 1;
- X
- X savedeck(lastpile,nextcard);
- X
- X clear();
- X cbreak();
- X noecho();
- X
- X playing = TRUE;
- X
- X lastlast = -1;
- X while (playing) {
- X thislast = lastpile;
- X if (lastlast != thislast) display(lastlast+1,lastpile);
- X if (!title) {
- X move(2,23);
- X printw("Accordian Solitaire - by Eric Lechner");
- X title = TRUE;
- X }
- X lastlast = thislast;
- X move(8,50);
- X if (lastpile == 51 || nextcard == 52)
- X printw("All cards have been dealt.");
- X else
- X printw("Cards left : %d",52 - nextcard);
- X clrtoeol();
- X move(11,50);
- X printw("Your move : ");
- X move(11,62);
- X clrtoeol();
- X refresh();
- X ch = getch();
- X printch(ch);
- X switch (ch) {
- X case 'D' : /* deal the whole deck */
- X if (nextcard < 52) {
- X lastpile += 52 - nextcard;
- X nextcard = 52;
- X clearmsg();
- X } else {
- X putmsg("Out of cards.");
- X }
- X break;
- X case 'd' : /* deal another card */
- X if (nextcard < 52) {
- X nextcard++;
- X lastpile++;
- X clearmsg();
- X } else {
- X putmsg("Out of cards.");
- X }
- X break;
- X case 0x12 : /* redraw screen if a ^R or ^L */
- X case 0x1c:
- X clear();
- X display(0,lastpile);
- X title = FALSE;
- X for (i=0; i<5; i++) _msg[i] = 0;
- X break;
- X case 'x' :
- X case 'X' :
- X playing = FALSE;
- X break;
- X#ifdef DEBUG
- X case 'l' : /* kluge to test save_win() routine */
- X save_win();
- X break;
- X#endif
- X case ' ' :
- X clearmsg();
- X break;
- X case '?' :
- X help();
- X clear();
- X display(0,lastpile);
- X title = FALSE;
- X for (i=0; i<5; i++) _msg[i] = 0;
- X break;
- X case 'r' :
- X case 'R' :
- X restoredeck(&lastpile,&nextcard);
- X display(1,lastpile);
- X if (lastpile < 51) undisplay(lastpile+1,51);
- X putmsg("Deck restored.");
- X break;
- X case 's' :
- X case 'S' :
- X savedeck(lastpile,nextcard);
- X putmsg("Deck saved.");
- X break;
- X case 'f' :
- X case 'F' :
- X find_move(lastpile);
- X break;
- X case 'u' :
- X case 'U' : /* undo a move here */
- X clearmsg();
- X if (--nummoves < 0) {
- X nummoves = 0;
- X putmsg("No moves to undo!");
- X } else {
- X for (i=51; i>undo[nummoves].position; i--) {
- X swap(i,i-1);
- X }
- X swap(i,i - undo[nummoves].num_spaces);
- X lastpile++;
- X display( undo[nummoves].position - undo[nummoves].num_spaces, lastpile);
- X }
- X break;
- X case 'a' :
- X case 'A' :
- X case '1' :
- X case '2' :
- X case '3' :
- X case '4' :
- X case '5' :
- X case '6' :
- X case '7' :
- X case '8' :
- X case '9' :
- X case 'j' :
- X case 'J' :
- X case 'q' :
- X case 'Q' :
- X case 'k' :
- X case 'K' :
- X place = get_card(ch,lastpile);
- X switch (place) {
- X case BADCARD :
- X /* print "bad key" error message */
- X putmsg("Hit '?' for help.");
- X break;
- X case NOTINDECK :
- X /* print "not in deck" error message */
- X sprintf(buffer,"Couldn't find the %s of %s.",
- X cardnames[_face], suitnames[_suit]);
- X putmsg(buffer);
- X break;
- X default:
- X /* choose move for card, if any */
- X switch (check(place)) {
- X case MOVE1 :
- X tmp = '1';
- X break;
- X case MOVE3 :
- X tmp = '3';
- X break;
- X case (MOVE3 | MOVE1) :
- X putmsg("Move 1 or 3 spaces");
- X move(11,62);
- X clrtoeol();
- X refresh();
- X tmp = getch();
- X break;
- X default :
- X tmp = STUCK;
- X break;
- X }
- X switch (tmp) {
- X case '0' :
- X clearmsg();
- X break;
- X case '1' :
- X case '3' :
- X num = tmp - '0';
- X if (place < num) {
- X sprintf(buffer,"Can't swap up %d.",num);
- X putmsg(buffer);
- X break;
- X } else clearmsg();
- X undo[nummoves].num_spaces = num;
- X undo[nummoves].position = place;
- X nummoves++;
- X swap(place,place-num);
- X for(i=place; i<51; i++)
- X swap(i,i+1);
- X lastpile--;
- X display(place - num,lastpile);
- X undisplay(lastpile + 1,lastpile + 1);
- X switch(checkwin(lastpile,nextcard)) {
- X case WIN :
- X putmsg("You win! Congratulations!");
- X playing = FALSE;
- X save_win();
- X break;
- X case LOSE :
- X putmsg("No more moves. You lose!");
- X playing = FALSE;
- X break;
- X default :
- X break;
- X }
- X break;
- X case STUCK :
- X sprintf(buffer,"The %s of %s cannot move!",
- X cardnames[_face], suitnames[_suit]);
- X putmsg(buffer);
- X break;
- X default :
- X putmsg("Hit '?' for help.");
- X break;
- X }
- X }
- X break;
- X default :
- X putmsg("Hit '?' for help.");
- X break;
- X }
- X }
- X move(20,50);
- X printw("Play again? [y/n] ");
- XGetAnotherCh:
- X move(20,68);
- X refresh();
- X ch = getch();
- X switch (ch) {
- X case 'y' :
- X case 'Y' :
- X goto StartOfGame;
- X case 'n' :
- X case 'N' :
- X case 'x' :
- X case 'X' :
- X case 'q' :
- X case 'Q' :
- X break;
- X default:
- X goto GetAnotherCh;
- X }
- X move(20,0);
- X refresh();
- X resetty();
- X endwin();
- X}
- X
- X/*
- X * display -- print the deck onto the screen from position "start" to "end"
- X */
- Xdisplay(start,end)
- Xint start, end;
- X{
- X int i, hilite = NORMAL;
- X
- X for (i=start; i<=end; i++) {
- X move((i%13) + 5, (int) (i/13) * 10 + 10);
- X if (deck[i].face != 9) {
- X printw(" ");
- X }
- X switch (deck[i].suit) {
- X case CLUB :
- X case SPADE :
- X hilite = NORMAL;
- X break;
- X case HEART :
- X case DIAMOND :
- X standout();
- X hilite = REVERSE;
- X break;
- X }
- X printw("%s%s",cards[deck[i].face],suits[deck[i].suit]);
- X if (hilite == REVERSE) {
- X standend();
- X hilite = NORMAL;
- X }
- X if (!(i % 13) && i > 0) {
- X arrow(1,(int) i / 13);
- X }
- X }
- X}
- X
- X/*
- X * undisplay -- clear display from "place1" to "place2"
- X * (useful for clearing off the end card)
- X */
- Xundisplay(place1,place2)
- Xint place1, place2;
- X{
- X int i;
- X
- X for (i = place1; i <= place2; i++) {
- X move((i%13) + 5, (int) (i/13) * 10 + 10);
- X standend();
- X printw(" ");
- X standend();
- X if (!(i%13) && i > 0)
- X arrow(0,(int) i/13);
- X }
- X}
- X
- X/*
- X * arrow -- draw an arrow from one column to the preceding one
- X */
- Xarrow(on,row)
- Xint on,row;
- X{
- X int i;
- X move(5, row * 10 + 6);
- X printw("%s",on ? "---" : " ");
- X for(i=1;i<12;i++) {
- X move(5 + i, row * 10 + 6);
- X printw("%s",on ? "|" : " ");
- X }
- X move(17,row * 10 + 4);
- X printw("%s",on ? "<--" : " ");
- X}
- X
- X/*
- X * get_card -- get a card as input from the user, face value, and suit.
- X */
- Xget_card(ch,lastpile)
- Xint ch, lastpile;
- X{
- X int card, suit, i;
- X
- X /* get the card */
- X switch (ch) {
- X case 'a' :
- X case 'A' :
- X card = 0;
- X break;
- X case '2' :
- X case '3' :
- X case '4' :
- X case '5' :
- X case '6' :
- X case '7' :
- X case '8' :
- X case '9' :
- X card = ch - '1';
- X break;
- X case '1' :
- X if (getch() == '0') {
- X card = 9;
- X printch('0');
- X } else
- X return(BADCARD);
- X break;
- X case 'j' :
- X case 'J' :
- X card = 10;
- X break;
- X case 'q' :
- X case 'Q' :
- X card = 11;
- X break;
- X case 'k' :
- X case 'K' :
- X card = 12;
- X break;
- X default :
- X return (BADCARD);
- X }
- X _face = card;
- X
- X /* now get the suit */
- X switch(getch()) {
- X case 's' :
- X case 'S' :
- X suit = SPADE;
- X break;
- X case 'h' :
- X case 'H' :
- X suit = HEART;
- X break;
- X case 'c' :
- X case 'C' :
- X suit = CLUB;
- X break;
- X case 'd' :
- X case 'D' :
- X suit = DIAMOND;
- X break;
- X default :
- X return (BADCARD);
- X }
- X _suit = suit;
- X
- X /* now we've got the card. find it in the deck */
- X i = 0;
- X do {
- X if (card == deck[i].face && suit == deck[i].suit)
- X return(i);
- X } while (++i <= lastpile);
- X return(NOTINDECK);
- X}
- X
- X/*
- X * check -- return if the card in postion "place" can move up the deck
- X */
- Xcheck(place)
- Xint place;
- X{
- X int tmp = 0;
- X
- X if (place < 1)
- X return(tmp);
- X
- X if ((deck[place-1].face == deck[place].face) ||
- X (deck[place-1].suit == deck[place].suit)) {
- X tmp |= MOVE1;
- X }
- X
- X if (place < 3)
- X return(tmp);
- X
- X if ((deck[place-3].face == deck[place].face) ||
- X (deck[place-3].suit == deck[place].suit)) {
- X tmp |= MOVE3;
- X }
- X return(tmp);
- X}
- X
- X/*
- X * putmsg -- print a message to the message buffer space
- X */
- Xputmsg(buffer)
- Xchar *buffer;
- X{
- X int line = 0, pos, space, length;
- X char *text[5];
- X char tmpbuffer[BUFFERLENGTH];
- X char *msgbuffer;
- X
- X msgbuffer = tmpbuffer;
- X
- X strcpy(msgbuffer,buffer);
- X
- X while (line < 5) {
- X length = strlen(msgbuffer);
- X if (length >= 30) {
- X text[line] = msgbuffer;
- X
- X space = -1;
- X for (pos=0; pos<30; pos++)
- X if (msgbuffer[pos] == ' ')
- X space = pos;
- X
- X if (space != -1)
- X msgbuffer[space] = '\0';
- X else
- X space = 30;
- X
- X msgbuffer += space + 1;
- X } else if (length != 0) {
- X text[line] = msgbuffer;
- X msgbuffer += length;
- X } else text[line] = 0;
- X line++;
- X }
- X
- X for (line=0; line<5; line++) {
- X if (_msg[line] || text[line] != 0)
- X move(14+line,50);
- X
- X if (_msg[line]) clrtoeol();
- X
- X if (text[line] != 0) {
- X printw("%s",text[line]);
- X _msg[line] = TRUE;
- X }
- X }
- X}
- X
- X/*
- X * clearmsg -- clear the message buffer space
- X */
- Xclearmsg()
- X{
- X int i;
- X
- X for (i=0; i<5; i++) {
- X if (_msg[i]) {
- X move(14+i,50);
- X clrtoeol();
- X _msg[i] = FALSE;
- X }
- X }
- X}
- X
- X/*
- X * checkwin -- determine if the user has finished the game
- X */
- Xcheckwin(lastpile,nextcard)
- Xint lastpile, nextcard;
- X{
- X int i;
- X
- X if (nextcard != 52)
- X return(MOREMOVES);
- X
- X if (lastpile == 0)
- X return(WIN);
- X
- X for (i=0; i<=lastpile; i++)
- X if (check(i) != 0)
- X return(MOREMOVES);
- X
- X return(LOSE);
- X}
- X
- X/*
- X * find_move -- a "cheater" function, to find first available move
- X */
- Xfind_move(lastpile)
- X{
- X int i;
- X for (i=0; i<=lastpile; i++) {
- X if (check(i) != 0) {
- X sprintf(buffer,"The %s of %s can move.",
- X cardnames[deck[i].face],suitnames[deck[i].suit]);
- X putmsg(buffer);
- X return;
- X }
- X }
- X putmsg("Try dealing more cards.");
- X}
- X
- X/*
- X * quit -- the nice control-C handler
- X */
- Xquit()
- X{
- X move(21,0);
- X refresh();
- X resetty();
- X endwin();
- X
- X exit(0);
- X}
- X
- X/*
- X * savedeck -- save the deck into the "save" deck
- X */
- Xsavedeck(lastpile,nextcard)
- Xint lastpile, nextcard;
- X{
- X int i;
- X
- X for (i=0; i<52; i++) {
- X save_deck[i].face = deck[i].face;
- X save_deck[i].suit = deck[i].suit;
- X save[i].num_spaces = undo[i].num_spaces;
- X save[i].position = undo[i].position;
- X }
- X save_lastpile = lastpile;
- X save_nextcard = nextcard;
- X save_moves = nummoves;
- X}
- X
- X/*
- X * restoredeck -- restore the deck from the previously saved deck
- X */
- Xrestoredeck(lastpile,nextcard)
- Xint *lastpile, *nextcard;
- X{
- X int i;
- X
- X for (i=0; i<52; i++) {
- X deck[i].face = save_deck[i].face;
- X deck[i].suit = save_deck[i].suit;
- X undo[i].position = save[i].position;
- X undo[i].num_spaces = save[i].num_spaces;
- X }
- X *lastpile = save_lastpile;
- X *nextcard = save_nextcard;
- X nummoves = save_moves;
- X}
- X
- X/*
- X * printch -- print a character to the screen, filtering out
- X * all non-alphanumeric characters
- X */
- Xprintch(ch)
- Xint ch;
- X{
- X if ((ch >= 'a' && ch <= 'z') ||
- X (ch >= 'A' && ch <= 'Z') ||
- X (ch >= '0' && ch <= '9')) {
- X printw("%c",ch);
- X refresh();
- X }
- X}
- X
- X/*
- X * save_win -- save this win to the "win" file, for historical purposes
- X */
- Xsave_win()
- X{
- X time_t utime;
- X struct passwd *pw;
- X char *name;
- X FILE *fp;
- X
- X fp = fopen(ACCORDIAN_WINFILE,"a+");
- X if (!fp) return;
- X
- X time(&utime);
- X pw = getpwuid(getuid());
- X if (!pw)
- X name = "Someone with no name";
- X else
- X name = pw->pw_name;
- X
- X fprintf(fp,"%s won on %s",name,ctime(&utime));
- X
- X fclose(fp);
- X}
- X
- END_OF_FILE
- if test 13179 -ne `wc -c <'accordian.c'`; then
- echo shar: \"'accordian.c'\" unpacked with wrong size!
- fi
- # end of 'accordian.c'
- fi
- if test -f 'accordian.man' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'accordian.man'\"
- else
- echo shar: Extracting \"'accordian.man'\" \(1844 characters\)
- sed "s/^X//" >'accordian.man' <<'END_OF_FILE'
- X.TH ACCORDIAN 6 "16 November 1992"
- X.SH NAME
- Xaccordian
- X\- the ``Accordian'' solitaire card game
- X.SH SYNOPSIS
- X.B accordian
- X.SH DESCRIPTION
- XThe deck of cards is dealt either a card at a time, or the
- Xentire deck at once, depending on your playing style. After
- Xcards are dealt, each card, and the stack underneath it, can
- Xbe moved either 1 or 3 spaces, onto another stack where that
- Xhas the same rank or suit for the topmost card in the stack.
- X.PP
- XThe goal of the game is to move all the cards into a single
- Xstack, containing all the cards.
- X.SH COMMANDS
- X.RS
- XSelect cards by typing their face value and suit. The
- Xcards are 2 to 9, J, Q, K, and A. The suits are H, S, D, and C.
- XIf the card selected has only one choice for its move, it moves
- Xautomatically. You will be prompted for your move, if you have
- Xa choice between moving the card 1 or 3 spaces.
- X.IP `d'
- XDeal a single card from the deck.
- X.IP `D'
- XDeal the remainder of the deck.
- X.IP `f'
- XFind the first card that is still able to move.
- X.IP `s'
- XSave the current deck into memory, so it can be restored later.
- XThis is the only way to `redo' moves you have undone.
- X.IP `r'
- XRestore the most recently saved copy of the deck.
- X.IP `u'
- XUndo the last single move. `Undo' will save all the previous moves
- Xthat you have played, except for saving and restoring the deck.
- X.IP `x'
- XExit from Accordian.
- X.IP `^R'
- XRedraw the screen
- X.IP `?'
- XPrint a screen of instructions and help.
- X.RE
- X.SH OPTIONS
- X.RS
- XIf any command line options are specified,
- X.B accordian
- Xwill print the same help as found by typing `?' while playing the game.
- X.RE
- X.SH HISTORY
- XAccordian was originally written during Summer 1990. Minor enhancements
- Xwere made in March 1991, and November 1992.
- X.SH BUGS
- XThe game is almost impossible to win. This is a bug in the
- Xgame, not the implementation. :-)
- X.SH AUTHOR
- XEric Lechner, ericl@xilinx.com
- END_OF_FILE
- if test 1844 -ne `wc -c <'accordian.man'`; then
- echo shar: \"'accordian.man'\" unpacked with wrong size!
- fi
- # end of 'accordian.man'
- fi
- if test -f 'cards.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'cards.c'\"
- else
- echo shar: Extracting \"'cards.c'\" \(958 characters\)
- sed "s/^X//" >'cards.c' <<'END_OF_FILE'
- X/*
- X * cards.c - generic card utilities
- X */
- X
- X#include "cards.h"
- X
- Xchar *cards[] = {
- X "A",
- X "2",
- X "3",
- X "4",
- X "5",
- X "6",
- X "7",
- X "8",
- X "9",
- X "10",
- X "J",
- X "Q",
- X "K"
- X };
- X
- Xchar *cardnames[] = {
- X "Ace",
- X "Two",
- X "Three",
- X "Four",
- X "Five",
- X "Six",
- X "Seven",
- X "Eight",
- X "Nine",
- X "Ten",
- X "Jack",
- X "Queen",
- X "King"
- X };
- X
- Xchar *suits[] = {
- X "S",
- X "H",
- X "C",
- X "D"
- X };
- X
- Xchar *suitnames[] = {
- X "Spades",
- X "Hearts",
- X "Clubs",
- X "Diamonds"
- X };
- X
- Xshuffle()
- X{
- X int i;
- X for (i=0; i<52; i++) {
- X swap(i,RANDOM() % 52);
- X }
- X}
- X
- Xswap(card1,card2)
- Xint card1, card2;
- X{
- X int face, suit;
- X
- X face = deck[card1].face;
- X deck[card1].face = deck[card2].face;
- X deck[card2].face = face;
- X
- X suit = deck[card1].suit;
- X deck[card1].suit = deck[card2].suit;
- X deck[card2].suit = suit;
- X}
- X
- Xnewdeck()
- X{
- X int face;
- X int suit;
- X
- X for (face = 0; face < 13; face++) {
- X for (suit=0; suit<4; suit++) {
- X deck[suit*13+face].face = face;
- X deck[suit*13+face].suit = suit;
- X }
- X }
- X}
- END_OF_FILE
- if test 958 -ne `wc -c <'cards.c'`; then
- echo shar: \"'cards.c'\" unpacked with wrong size!
- fi
- # end of 'cards.c'
- fi
- if test -f 'cards.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'cards.h'\"
- else
- echo shar: Extracting \"'cards.h'\" \(634 characters\)
- sed "s/^X//" >'cards.h' <<'END_OF_FILE'
- X/*
- X * cards.h - the include library with all the definitions for card things
- X */
- X
- X#define REVERSE 1 /* the suit should be displayed in reverse */
- X#define NORMAL 0
- X
- X#define SPADE 0 /* the types of cards */
- X#define HEART 1 /* this should ALWAYS match the suits[] array */
- X#define CLUB 2
- X#define DIAMOND 3
- X
- X#ifndef TRUE
- X#define TRUE 1
- X#endif
- X#ifndef FALSE
- X#define FALSE 0
- X#endif
- X
- Xstruct card {
- X int face;
- X int suit;
- X};
- X
- Xextern char *cards[];
- Xextern char *cardnames[];
- Xextern char *suits[];
- Xextern char *suitnames[];
- Xextern char *helplist[];
- Xextern struct card deck[52];
- X
- Xextern newdeck();
- Xextern shuffle();
- Xextern swap();
- Xextern help();
- END_OF_FILE
- if test 634 -ne `wc -c <'cards.h'`; then
- echo shar: \"'cards.h'\" unpacked with wrong size!
- fi
- # end of 'cards.h'
- fi
- if test -f 'help.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'help.c'\"
- else
- echo shar: Extracting \"'help.c'\" \(1621 characters\)
- sed "s/^X//" >'help.c' <<'END_OF_FILE'
- X
- X/*
- X * the accordian help stuff
- X */
- X
- X#include <stdio.h>
- X#include <curses.h>
- X#include "cards.h"
- X
- X#define HELPHEIGHT 22
- X
- Xchar *helplist[] = {
- X " Welcome to Accordian Solitaire!",
- X "",
- X "The goal of the game is to deal all cards from the",
- X "deck, and stack them into a single pile of cards.",
- X "Cards can move onto other cards that are one or",
- X "three cards up in the deck. Cards can only stack",
- X "onto other cards of the same suit or rank.",
- X "",
- X "Select cards by typing their face value and suit.",
- X "The card moves automatically if it has only one move.",
- X "You must choose the move if there are multiple moves.",
- X "",
- X " Keys :",
- X " `d' : Deal a card from the deck",
- X " `D' : Deal the whole deck",
- X " `f' : Find a card that can move",
- X " `s' : Save a copy of the deck",
- X " `u' : Undo the last move",
- X " `r' : Restore the saved deck",
- X " `x' : Exit from Accordian",
- X " `^R' : Redraw the screen",
- X 0 };
- X
- Xhelp()
- X{
- X int c2, ch, done, start;
- X
- X clear();
- X
- X c2 = start = 0;
- X done = FALSE;
- X
- X while (!done) {
- XHelp: for (c2 = start; c2 < start + HELPHEIGHT; c2++) {
- X if (helplist[c2] == 0) {
- X done = TRUE;
- X break;
- X }
- X move(1 + (c2 % HELPHEIGHT),13);
- X printw("%s",helplist[c2]);
- X }
- X
- X move(23,26);
- X printw(" - hit any key - ");
- X move(23,48);
- X
- X refresh();
- X ch = getch();
- X switch (ch) {
- X case 0x12 :
- X case 0x0c :
- X clear();
- X c2 = start;
- X goto Help;
- X break;
- X case 'x' :
- X case 'X' :
- X case 'q' :
- X case 'Q' :
- X done = TRUE;
- X break;
- X }
- X start = c2;
- X }
- X}
- X
- END_OF_FILE
- if test 1621 -ne `wc -c <'help.c'`; then
- echo shar: \"'help.c'\" unpacked with wrong size!
- fi
- # end of 'help.c'
- fi
- if test -f 'makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'makefile'\"
- else
- echo shar: Extracting \"'makefile'\" \(1767 characters\)
- sed "s/^X//" >'makefile' <<'END_OF_FILE'
- X#
- X# makefile for accordian
- X#
- X
- X# The high score file:
- XWINFILE = /home/baggins/ericl/lib/accordian.wins
- X
- X# Where the program will live
- XDESTDIR = /home/baggins/ericl/bin
- X
- X# Where the manpage will live
- XMANDIR = /home/baggins/ericl/man
- X
- X
- X# Which random number generator your system uses
- X# these worked under SunOS (BSD-ish)
- XRANDOM = random
- XSRANDOM = srandom
- X# these worked under IRIX (SysV-ish)
- X#RANDOM = lrand48
- X#SRANDOM = srand48
- X
- X# where the default pager lives
- X# bsd-ish systems use;
- XPAGER = /usr/ucb/more
- X# irix uses:
- X#PAGER = /usr/bsd/more
- X# most SysV machines use:
- X#PAGER = /usr/bin/more
- X
- X
- X# compiler options
- XCC = cc
- X
- X# these worked under SunOS
- XLOCAL_CFLAGS = -g
- XLOCAL_LFLAGS = -g
- XLLIBS = -lcurses -ltermcap
- X
- X# these worked under SYS_V (SGI IRIX)
- X# (note: IRIX uses "-cckr" to make the compiler like K+R C.
- X# Your machine may need something different to specify this.)
- X#LOCAL_CFLAGS = -g -cckr
- X#LOCAL_LFLAGS = -g
- X#LLIBS = -lcurses
- X
- X
- XCFLAGS = $(LOCAL_CFLAGS) -DRANDOM=$(RANDOM) -DSRANDOM=$(SRANDOM) \
- X -DACCORDIAN_WINFILE=\"$(WINFILE)\" -DDEFAULT_PAGER=\"$(PAGER)\"
- XLFLAGS = $(LOCAL_LFLAGS)
- X
- X
- XOBJS = accordian.o \
- X cards.o \
- X help.o
- X
- Xaccordian: $(OBJS)
- X $(CC) $(LFLAGS) $(OBJS) -o $@ $(LLIBS)
- X
- X## Creating manpages.
- X.SUFFIXES: .6 .man
- X.man.6:
- X @rm -f $@
- X nroff -man $< > $@
- X chmod 444 $@
- X
- Xinstall: accordian accordian.6
- X cp accordian $(DESTDIR)
- X chmod 711 $(DESTDIR)/accordian
- X cp accordian.6 $(MANDIR)/accordian.6
- X chmod 644 $(MANDIR)/accordian.6
- X
- X$(OBJS) : cards.h makefile
- X
- Xclobber:
- X make clean
- X @ rm -f accordian accordian.6 accordian.sh
- Xclean:
- X @ rm -f $(OBJS)
- X
- X#
- X# all the stuff that gets packed into the archive file
- X#
- XSHARSTUFF = \
- X README \
- X makefile \
- X accordian.c \
- X help.c \
- X cards.c \
- X cards.h \
- X accordian.man
- X
- Xshar:
- X shar $(SHARSTUFF) > accordian.sh
- END_OF_FILE
- if test 1767 -ne `wc -c <'makefile'`; then
- echo shar: \"'makefile'\" unpacked with wrong size!
- fi
- # end of 'makefile'
- fi
- echo shar: End of archive 1 \(of 1\).
- cp /dev/null ark1isdone
- MISSING=""
- for I in 1 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have the archive.
- rm -f ark[1-9]isdone
- else
- echo You still need to unpack the following archives:
- echo " " ${MISSING}
- fi
- ## End of shell archive.
- exit 0
-
-
- unoryoryoS) syoryoryoS) syoryoryoS) syoryoryoS) syory
-