video poker - slightly updated
Jay A. Konigsberg
jak at sactoh0.sac.ca.us
Tue May 28 10:09:23 AEST 1991
A cleaned up version of video poker.
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create:
# Makefile
# cleanup.c
# deal.c
# display_hand.c
# display_val.c
# draw.c
# draw_back.c
# hand_value.h
# id_hand.c
# main.c
# payoff_val.c
# rawmode.c
# setup_deck.c
# sort.c
# vid_curses.h
# vid_extern.h
# vid_local.h
# vid_poker.h
# This archive created: Mon May 27 17:06:18 1991
export PATH; PATH=/bin:/usr/bin:$PATH
if test -f 'Makefile'
then
echo shar: "will not over-write existing file 'Makefile'"
else
cat << \SHAR_EOF > 'Makefile'
#
# Copyright (C) 1991 by Jay Konigsberg. mail: jak at sactoh0
#
# Permission to use, copy, modify, and distribute this software and its
# documentation is hereby granted, provided that the above copyright
# notice appear in all copies and that both the copyright notice and
# this permission notice appear in supporting documentation. This software
# is provided "as is" without express or implied warranty. However, the
# author retains all Copyright priviliges and rights to renumeration if
# this software is sold.
#
# Also, and very important. This game is for recrecation ONLY and is NOT
# to be used for gambling in any way.
#
#
# Makefile for video_poker
#
# Select complier and options
#CC=gcc
#CFLAGS=-O -traditional -Wall
CC=cc
#CFLAGS=-g
CFLAGS=-O
# Select libraries
# Xenix
#LIBS=-ltcap -ltermlib
# SysV
LIBS=-lcurses
# Object files
OBJS=sort.o display_hand.o display_val.o rawmode.o cleanup.o payoff_val.o \
deal.o id_hand.o draw.o setup_deck.o main.o draw_back.o
# Exectuable
EXEC=video
$(EXEC): $(OBJS)
$(CC) $(CFLAGS) $(OBJS) $(LIBS) -o $(EXEC)
main.o: main.c vid_local.h vid_curses.h vid_poker.h
deal.o: deal.c vid_poker.h
id_hand.o: id_hand.c vid_poker.h vid_extern.h hand_value.h
draw.o: draw.c vid_poker.h vid_curses.h vid_local.h vid_extern.h
setup_deck.o: setup_deck.c vid_extern.h vid_poker.h
cleanup.o: cleanup.c vid_extern.h
display_hand.o: display_hand.c vid_poker.h vid_extern.h vid_curses.h
display_val.o: display_val.c hand_value.h vid_curses.h vid_poker.h
payoff_val.o: payoff_val.c vid_poker.h vid_curses.h
rawmode.o: rawmode.c vid_extern.h vid_local.h
sort: sort.c vid_poker.h
draw_back.o: draw_back.c vid_curses.h
clean:
rm -f $(OBJS) core make.out lint.out video.shar vidpoker.tar*
lint:
lint [a-z][a-z]*.c 2>&1 | tee lint.out
tar:
tar cvf vidpoker.tar *.[ch] Makefile
pack: tar
pack vidpoker.tar
compress: tar
compress vidpoker.tar
shar:
shar Makefile *.[ch] > video.shar
SHAR_EOF
fi
if test -f 'cleanup.c'
then
echo shar: "will not over-write existing file 'cleanup.c'"
else
cat << \SHAR_EOF > 'cleanup.c'
/*
* Copyright (C) 1991 by Jay Konigsberg. mail: jak at sactoh0
*
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, provided that the above copyright
* notice appear in all copies and that both the copyright notice and
* this permission notice appear in supporting documentation. This software
* is provided "as is" without express or implied warranty. However, the
* author retains all Copyright priviliges and rights to renumeration if
* this software is sold.
*
* Also, and very important. This game is for recrecation ONLY and is NOT
* to be used for gambling in any way.
*/
/*
* cleanup - resets port settings to what they were before entering
* raw mode.
*/
#include <stdio.h>
#include <termio.h>
#include "vid_extern.h"
extern int errno;
/* Global for interrupt routine: cleanup() */
extern struct termio ttyset; /* terminal settings */
extern unsigned short c_lflag_hold; /* hold original values for reset */
extern unsigned char VEOF_hold; /* hold original value for reset */
int (*cleanup()) /* Signal trap for SIGINT */
{
/* reset terminal charastics */
ttyset.c_lflag = c_lflag_hold;
ttyset.c_cc[4] = VEOF_hold;
if ( ioctl(0, TCSETAW, &ttyset) == -1) {
fprintf(stderr, "ioctl: error=%d\n", errno);
(void)exit(2);
}
puts("\nExiting Video Poker\t\t\t\t\t\t");
(void)exit(0);
return(0);
}
SHAR_EOF
fi
if test -f 'deal.c'
then
echo shar: "will not over-write existing file 'deal.c'"
else
cat << \SHAR_EOF > 'deal.c'
/*LINTLIBRARY*/
/*
* Copyright (C) 1991 by Jay Konigsberg. mail: jak at sactoh0
*
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, provided that the above copyright
* notice appear in all copies and that both the copyright notice and
* this permission notice appear in supporting documentation. This software
* is provided "as is" without express or implied warranty. However, the
* author retains all Copyright priviliges and rights to renumeration if
* this software is sold.
*
* Also, and very important. This game is for recrecation ONLY and is NOT
* to be used for gambling in any way.
*/
/*
* deal.c - generate the random numbers that will represent cards.
*/
#include "vid_poker.h"
#include <sys/types.h>
extern double drand48();
extern void srand48();
extern time_t time();
static time_t seed=0;
void deal(deck, numcards)
int *deck, /* 52 card deck */
numcards; /* number of cards requested */
{
int check, /* index for preventing dup cards */
count=0; /* count of cards already delt (0 or 5) */
if ( seed == (time_t)0 )
{
seed=time(&seed);
(void)srand48(seed);
}
if ( deck[0] != 0 )
numcards += (count=5); /* we are on the draw */
for (; count < numcards; ++count)
{
deck[count] = 52 * drand48()+1;
for ( check=0; check < count; ++check )
if ( deck[check] == deck[count] )
--count;
}
}
SHAR_EOF
fi
if test -f 'display_hand.c'
then
echo shar: "will not over-write existing file 'display_hand.c'"
else
cat << \SHAR_EOF > 'display_hand.c'
/*LINTLIBRARY*/
/*
* Copyright (C) 1991 by Jay Konigsberg. mail: jak at sactoh0
*
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, provided that the above copyright
* notice appear in all copies and that both the copyright notice and
* this permission notice appear in supporting documentation. This software
* is provided "as is" without express or implied warranty. However, the
* author retains all Copyright priviliges and rights to renumeration if
* this software is sold.
*
* Also, and very important. This game is for recrecation ONLY and is NOT
* to be used for gambling in any way.
*/
/*
* display_hand.c - draw the cards onto the screen
*/
#include "vid_extern.h"
#include "vid_curses.h"
#include "vid_poker.h"
void display_hand(value, suite, count)
int *value,
*suite,
count;
{
int cardinx;
for ( cardinx=0; cardinx < count; ++cardinx)
{
if ( suite[cardinx] == 0 )
{
mvaddstr(10, cardinx * 15, "|-----------|");
mvaddstr(11, cardinx * 15, "| __ |");
mvaddstr(12, cardinx * 15, "| /\\`'/\\ |");
mvaddstr(13, cardinx * 15, "| \\ ~~ / |");
mvaddstr(14, cardinx * 15, "| \\ / |");
mvaddstr(15, cardinx * 15, "| \\/ |");
mvaddstr(16, cardinx * 15, "| Spades |");
mvaddstr(17, cardinx * 15, "| |");
mvaddstr(18, cardinx * 15, "|-----------|");
}
else
if ( suite[cardinx] == 1 )
{
mvaddstr(10, cardinx * 15, "|-----------|");
mvaddstr(11, cardinx * 15, "| |");
mvaddstr(12, cardinx * 15, "| /\\/\\ |");
mvaddstr(13, cardinx * 15, "| ( ) |");
mvaddstr(14, cardinx * 15, "| \\ / |");
mvaddstr(15, cardinx * 15, "| \\/ |");
mvaddstr(16, cardinx * 15, "| Hearts |");
mvaddstr(17, cardinx * 15, "| |");
mvaddstr(18, cardinx * 15, "|-----------|");
}
else
if ( suite[cardinx] == 2 )
{
mvaddstr(10, cardinx * 15, "|-----------|");
mvaddstr(11, cardinx * 15, "| |");
mvaddstr(12, cardinx * 15, "| ^ |");
mvaddstr(13, cardinx * 15, "| _/ \\_ |");
mvaddstr(14, cardinx * 15, "| (__ __) |");
mvaddstr(15, cardinx * 15, "| /_\\ |");
mvaddstr(16, cardinx * 15, "| Clubs |");
mvaddstr(17, cardinx * 15, "| |");
mvaddstr(18, cardinx * 15, "|-----------|");
}
else
if ( suite[cardinx] == 3 )
{
mvaddstr(10, cardinx * 15, "|-----------|");
mvaddstr(11, cardinx * 15, "| |");
mvaddstr(12, cardinx * 15, "| /\\ |");
mvaddstr(13, cardinx * 15, "| / \\ |");
mvaddstr(14, cardinx * 15, "| \\ / |");
mvaddstr(15, cardinx * 15, "| \\/ |");
mvaddstr(16, cardinx * 15, "| Diamonds |");
mvaddstr(17, cardinx * 15, "| |");
mvaddstr(18, cardinx * 15, "|-----------|");
}
switch (value[cardinx])
{
case 1:
mvaddstr(11, cardinx*15+1, "A");
mvaddstr(14, cardinx*15+6, "AA");
mvaddstr(17, cardinx*15+10, "A");
break;
case 10:
mvaddstr(11, cardinx*15+1, "10");
mvaddstr(14, cardinx*15+6, "10");
mvaddstr(17, cardinx*15+10, "10");
break;
case 11:
mvaddstr(11, cardinx*15+1, "J ");
mvaddstr(14, cardinx*15+6, "JJ");
mvaddstr(17, cardinx*15+10, "J ");
break;
case 12:
mvaddstr(11, cardinx*15+1, "Q ");
mvaddstr(14, cardinx*15+6, "QQ");
mvaddstr(17, cardinx*15+10, "Q ");
break;
case 13:
mvaddstr(11, cardinx*15+1, "K ");
mvaddstr(14, cardinx*15+6, "KK");
mvaddstr(17, cardinx*15+10, "K ");
break;
default:
mvaddch(11, cardinx*15+1, '0' + value[cardinx]);
mvaddch(11, cardinx*15+2, ' ');
mvaddch(14, cardinx*15+6, '0' + value[cardinx]);
mvaddch(14, cardinx*15+7, '0' + value[cardinx]);
mvaddch(17, cardinx*15+10, '0' + value[cardinx]);
mvaddch(17, cardinx*15+11, ' ');
break;
}
refresh();
}
}
SHAR_EOF
fi
if test -f 'display_val.c'
then
echo shar: "will not over-write existing file 'display_val.c'"
else
cat << \SHAR_EOF > 'display_val.c'
/*LINTLIBRARY*/
/*
* Copyright (C) 1991 by Jay Konigsberg. mail: jak at sactoh0
*
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, provided that the above copyright
* notice appear in all copies and that both the copyright notice and
* this permission notice appear in supporting documentation. This software
* is provided "as is" without express or implied warranty. However, the
* author retains all Copyright priviliges and rights to renumeration if
* this software is sold.
*
* Also, and very important. This game is for recrecation ONLY and is NOT
* to be used for gambling in any way.
*/
/*
* display_val.c - places the value of the hand above the displayed cards.
* Also, this routine will return the number of coins the hand is worth.
*
* Ok, ok, the name isn't the greatest. But hey, its the best I could come
* up with.
*/
#include "hand_value.h"
#include "vid_curses.h"
#include "vid_poker.h"
int display_val(hand_value)
int hand_value;
{
int value; /* payoff value of this hand */
switch ( hand_value )
{
case PAIR:
mvaddstr(9, 29, " ONE PAIR ");
value=0;
break;
case JACKSOR:
mvaddstr(9, 29, "JACKS OR BETTER");
value=1;
break;
case TWOPAIR:
mvaddstr(9, 29, " TWO PAIR ");
value=2;
break;
case TRIPS:
mvaddstr(9, 29, "THREE OF A KIND");
value=3;
break;
case STRAIGHT:
mvaddstr(9, 29, " STRAIGHT ");
value=4;
break;
case FLUSH:
mvaddstr(9, 29, " FLUSH ");
value=5;
break;
case FULLHOUSE:
mvaddstr(9, 29, " FULL HOUSE ");
value=8;
break;
case FOUR:
mvaddstr(9, 29, " FOUR OF A KIND");
value=25;
break;
case STRAIGHTFLUSH:
mvaddstr(9, 29, " STRAIGHT FLUSH");
value=50;
break;
case ROYALFLUSH:
mvaddstr(9, 29, " ROYAL FLUSH ");
value=250;
break;
default:
mvaddstr(9, 29, " NO PAIR ");
value=0;
}
refresh();
return(value);
}
SHAR_EOF
fi
if test -f 'draw.c'
then
echo shar: "will not over-write existing file 'draw.c'"
else
cat << \SHAR_EOF > 'draw.c'
/*LINTLIBRARY*/
/*
* Copyright (C) 1991 by Jay Konigsberg. mail: jak at sactoh0
*
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, provided that the above copyright
* notice appear in all copies and that both the copyright notice and
* this permission notice appear in supporting documentation. This software
* is provided "as is" without express or implied warranty. However, the
* author retains all Copyright priviliges and rights to renumeration if
* this software is sold.
*
* Also, and very important. This game is for recrecation ONLY and is NOT
* to be used for gambling in any way.
*/
/*
* draw.c - Select which card to hold (You've got to know when to hold-um, ..
*/
#include "vid_local.h"
#include "vid_curses.h"
#include "vid_poker.h"
#include "vid_extern.h"
extern int bet;
extern int credits;
void draw(deck, value, suite)
int *deck,
*value;
char **suite;
{
int count, /* count of cards to be drawn */
index, /* loop index */
win, /* amount won on hand */
key = -1, /* keys pressed during draw */
draw_card=5, /* The first draw card */
hold[5]; /* mark the cards help */
for (index=0; index < 5; ++index)
hold[index] = 0;
mvaddstr(21,0,"Keys 1-5 to hold/cancel cards, D/d/space/return to draw: ");
move(21,57);
refresh();
while ( key != ' ' && key != '\r' && key != '\n' && key != 'D' && key != 'd' )
{
/*
* XXX - the echoback needs to be shut down here to prevent misplacement
* of the "HOLD" string. However, using 'noecho()' and 'echo()' will
* force buffering of all output until a CR is read.
*/
if( (key=mvgetch(21, 57)) >= '0' && key <= '5' )
{
addstr("\b ");
move(19, 4+(15 * ((key - '0')-1)));
if ( hold[(key - '0') - 1] )
{
addstr(" ");
hold[(key - '0' -1) ] = 0;
}
else
{
addstr("HOLD");
hold[ (key - '0' -1) ] = 1;
}
}
else
{
if ( key == 'r' || key == 'R' )
{
addstr(" \b ");
clearok(stdscr, TRUE);
refresh();
}
else
if ( key != '\r' && key != ' ' && key != '\n' &&
key != 'D' && key != 'd' && key != 'R' && key != 'r' )
{
putchar('\007');
fflush(stdout);
}
}
refresh();
}
/* cards selected, now draw */
count=0;
for(index=0; index < 5; ++index)
if ( hold[index] )
++count;
count = 5 - count;
deal(deck, count);
setup_deck(deck, value, suite, count);
/* Replace the discarded cards */
for( index=0; index < 5 && count; ++index )
{
if ( hold[index] == 0 ) /* card NOT held */
{
draw_back(index);
value[index] = value[draw_card];
suite[index] = suite[draw_card++];
--count;
}
}
sleep(1);
display_hand(value, suite, 5);
sort(value, suite, 5);
win = bet * display_val(id_hand(value, suite));
credits += win;
mvprintw(22, 65, "Credits %-6d ", credits);
mvprintw(23, 65, "Winner %-6d ", win);
refresh();
}
SHAR_EOF
fi
if test -f 'draw_back.c'
then
echo shar: "will not over-write existing file 'draw_back.c'"
else
cat << \SHAR_EOF > 'draw_back.c'
/*
* Copyright (C) 1991 by Jay Konigsberg. mail: jak at sactoh0
*
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, provided that the above copyright
* notice appear in all copies and that both the copyright notice and
* this permission notice appear in supporting documentation. This software
* is provided "as is" without express or implied warranty. However, the
* author retains all Copyright priviliges and rights to renumeration if
* this software is sold.
*
* Also, and very important. This game is for recrecation ONLY and is NOT
* to be used for gambling in any way.
*/
#include "vid_curses.h"
void draw_back(position)
int position;
{
mvaddstr(10, position * 15, "|-----------|");
mvaddstr(11, position * 15, "|* * * * * *|");
mvaddstr(12, position * 15, "| * * * * * |");
mvaddstr(13, position * 15, "|* * * * * *|");
mvaddstr(14, position * 15, "| * * * * * |");
mvaddstr(15, position * 15, "|* * * * * *|");
mvaddstr(16, position * 15, "| * * * * * |");
mvaddstr(17, position * 15, "|* * * * * *|");
mvaddstr(18, position * 15, "|-----------|");
refresh();
}
SHAR_EOF
fi
if test -f 'hand_value.h'
then
echo shar: "will not over-write existing file 'hand_value.h'"
else
cat << \SHAR_EOF > 'hand_value.h'
/*
* Copyright (C) 1991 by Jay Konigsberg. mail: jak at sactoh0
*
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, provided that the above copyright
* notice appear in all copies and that both the copyright notice and
* this permission notice appear in supporting documentation. This software
* is provided "as is" without express or implied warranty. However, the
* author retains all Copyright priviliges and rights to renumeration if
* this software is sold.
*
* Also, and very important. This game is for recrecation ONLY and is NOT
* to be used for gambling in any way.
*/
/*
* hand_value.h - just some tokens to make life simpler.
*/
#define NOPAIR 0000
#define PAIR 0001
#define JACKSOR 0002
#define TWOPAIR 0004
#define TRIPS 0010
#define STRAIGHT 0020
#define FLUSH 0040
#define FULLHOUSE 0100
#define FOUR 0200
#define STRAIGHTFLUSH 0400
#define ROYALFLUSH 1000
SHAR_EOF
fi
if test -f 'id_hand.c'
then
echo shar: "will not over-write existing file 'id_hand.c'"
else
cat << \SHAR_EOF > 'id_hand.c'
/*LINTLIBRARY*/
/*
* Copyright (C) 1991 by Jay Konigsberg. mail: jak at sactoh0
*
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, provided that the above copyright
* notice appear in all copies and that both the copyright notice and
* this permission notice appear in supporting documentation. This software
* is provided "as is" without express or implied warranty. However, the
* author retains all Copyright priviliges and rights to renumeration if
* this software is sold.
*
* Also, and very important. This game is for recrecation ONLY and is NOT
* to be used for gambling in any way.
*/
/*
* id_hand.c - Determins what value the hand is. I suppose it could be
* optimized further, but hey - how fast can you play this puppy?
*/
#include "vid_poker.h"
#include "vid_extern.h"
#include "hand_value.h"
int id_hand(value, suite)
int *value,
*suite;
{
int flush = FALSE,
straight = FALSE,
pair = FALSE,
jacksor = FALSE,
twopair = FALSE,
trips = FALSE,
fullhouse = FALSE,
four = FALSE,
straightflush = FALSE,
royalflush = FALSE;
int card, /* loop variable used while checking hand */
flush_check; /* temp for flush checking */
do
{ /* one pass only. a break may exit before its done */
/* check the first five cards only */
/* Flush ? */
flush=TRUE;
flush_check = suite[0];
for ( card=1; card < 5; ++card )
{
if ( suite[card] != flush_check )
{
flush=FALSE;
break;
}
}
/* Straight */
straight=FALSE;
straightflush=FALSE;
royalflush=FALSE;
if ( value[0] == value[1]-1 && value[0] == value[2]-2
&& value[0] == value[3]-3 && value[0] == value[4]-4 )
straight=TRUE;;
/* Ace high straight/ royal flush */
if ( value[0] == 1 && value[1] == 10 && value[2] == 11
&& value[3] == 12 && value[4] == 13 )
{
if ( flush )
{
straight=FALSE;
flush=FALSE;
royalflush=TRUE;
break; /* do */
}
else
{
straight=TRUE;;
}
}
/* Straight flush */
if ( straight && flush )
{
straight=FALSE;
flush=FALSE;
straightflush=TRUE;
/* return; */
}
if ( straight || flush || straightflush )
break; /* do */
/* Pair */
pair=FALSE;
for ( card=0; card < 4; ++card )
{
if (value[card]==value[card+1])
{
pair=TRUE;
break;
}
}
/* Jacks or better */
jacksor=FALSE;
if ( pair && (value[card] == 1 || value[card] >= 11) )
{
pair=FALSE;
jacksor=TRUE;
}
/* Trips */
trips=FALSE;
if ( (pair || jacksor) && card < 3 && value[card] == value[card+2] )
{
pair=FALSE;
jacksor=FALSE;
trips=TRUE;
}
/* Four of a kind */
four=FALSE;
if ( trips && card < 2 && value[card] == value[card+3] )
{
trips=FALSE;
four=TRUE;
break; /* do */
}
/* two pair */
twopair=FALSE;
if ( pair || jacksor )
for (card += 2; card < 4; ++card )
if (value[card]==value[card+1])
{
pair=FALSE;
jacksor=FALSE;
twopair=TRUE;
break;
}
/* full house */
fullhouse=FALSE;
if ( twopair && card == 2 && value[3] == value[4] )
{
twopair=FALSE;
fullhouse=TRUE;
break; /* do */
}
if ( trips && card == 0 && value[3] == value[4] )
{
trips=FALSE;
fullhouse=TRUE;
break; /* do */
}
}
while ( FALSE );
/* return the value of the hand */
if ( flush )
return(FLUSH);
if ( straight )
return(STRAIGHT);
if ( straightflush )
return(STRAIGHTFLUSH);
if ( royalflush )
return(ROYALFLUSH);
if ( pair )
return(PAIR);
if ( jacksor )
return(JACKSOR);
if ( twopair )
return(TWOPAIR);
if ( trips )
return(TRIPS);
if ( four )
return(FOUR);
if ( fullhouse )
return(FULLHOUSE);
else
return(0);
}
SHAR_EOF
fi
if test -f 'main.c'
then
echo shar: "will not over-write existing file 'main.c'"
else
cat << \SHAR_EOF > 'main.c'
/*LINTLIBRARY*/
/*
* Copyright (C) 1991 by Jay Konigsberg. mail: jak at sactoh0
*
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, provided that the above copyright
* notice appear in all copies and that both the copyright notice and
* this permission notice appear in supporting documentation. This software
* is provided "as is" without express or implied warranty. However, the
* author retains all Copyright priviliges and rights to renumeration if
* this software is sold.
*
* Also, and very important. This game is for recrecation ONLY and is NOT
* to be used for gambling in any way.
*/
/*
* main for "video_poker" - just like the ones in Nevada.
* Jay Konigsberg
* jak at sactoh0 - pacbel!sactoh0!jak
*/
#include "vid_local.h"
#include <signal.h>
#include "vid_curses.h"
#include "vid_poker.h"
int bet,
credits;
void main()
{
int deck[10], /* The random numbers as they were generated */
value[10], /* The card values - A, 2 ... 12=Q, 13=K */
s_value[10], /* Sorted card values - A, 2 ... 12=Q, 13=K */
loop, /* loop while bet is selected */
suite[10], /* Spades=0, Hearts=1, Clubs=2, Diamonds=3 */
s_suite[10]; /* sorted suites */
int cardinx; /* Just a loop variable */
credits=0;
rawmode(); /* set up char-at-a-time processing */
signal(SIGINT, cleanup);/* trap inturrepts (also in rawmode) */
initscr();
payoff_val(0); /* Put the payoff values on the screen */
for (cardinx=0; cardinx < 5; ++cardinx)
draw_back(cardinx);
for (;;)
{
for (cardinx=0; cardinx<10; ++cardinx)
{
deck[cardinx] = 0;
value[cardinx] = 0;
s_value[cardinx] = 0;
suite[cardinx] = 0;
s_suite[cardinx] = 0;
}
bet = 0;
loop = TRUE;
while (loop)
{
mvaddstr(21,0,"B/b=bet, M/m=max bet, D/d/Retrun=Draw, R/r=Refresh, Q/q=quit? ");
move(21,62);
refresh();
switch (getch())
{
case '\n':
case '\r':
case 'D':
case 'd':
loop=FALSE;
break;
case 'q':
case 'Q':
case 'n':
case 'N':
loop=FALSE;
cleanup();
break;
case 'M':
case 'm':
case ' ':
loop=FALSE;
credits -= (5 - bet);
bet = 5;
for (cardinx=0; cardinx < 5; ++cardinx)
draw_back(cardinx);
sleep(1);
mvprintw(21, 65, "Bet %-6d", bet);
mvaddstr( 9, 29, " ");
mvaddstr(19, 0, "\t\t\t\t\t\t\t\t\t\t");
payoff_val(bet); /* Put the payoff values on the screen */
break;
case 'b':
case 'B':
++bet;
if ( bet == 5 )
loop=FALSE;
else
loop=TRUE;
mvaddstr( 9, 29, " ");
mvaddstr(19, 0, "\t\t\t\t\t\t\t\t\t\t");
for (cardinx=0; cardinx < 5; ++cardinx)
draw_back(cardinx);
payoff_val(bet); /* Put the payoff values on the screen */
mvprintw(21, 65, "Bet %-6d", bet);
--credits;
break;
case 'R':
case 'r':
clearok(stdscr, TRUE);
refresh();
break;
}
mvprintw(22, 65, "Credits %-5d ", credits);
mvaddstr(23, 65, " ");
refresh();;
if (bet == 0)
loop=TRUE;
}
deal(deck, 5);
setup_deck(deck, value, suite, 5);
setup_deck(deck, s_value, s_suite, 5);
sort(s_value, s_suite, 5);
display_hand(value, suite, 5);
(void)display_val(id_hand(s_value, s_suite));
draw(deck, value, suite);
}
/*NOTREACHED*/
}
SHAR_EOF
fi
if test -f 'payoff_val.c'
then
echo shar: "will not over-write existing file 'payoff_val.c'"
else
cat << \SHAR_EOF > 'payoff_val.c'
/*LINTLIBRARY*/
/*
* Copyright (C) 1991 by Jay Konigsberg. mail: jak at sactoh0
*
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, provided that the above copyright
* notice appear in all copies and that both the copyright notice and
* this permission notice appear in supporting documentation. This software
* is provided "as is" without express or implied warranty. However, the
* author retains all Copyright priviliges and rights to renumeration if
* this software is sold.
*
* Also, and very important. This game is for recrecation ONLY and is NOT
* to be used for gambling in any way.
*/
/*
* payoff_val.c - dumb routine to show the payoffs
*/
#include "vid_curses.h"
#include "vid_poker.h"
void payoff_val(bet)
int bet;
{
if ( bet == 0 )
{
mvaddstr(1, 23, "VIDEO POKER - Standard Nevada odds");
mvaddstr(3, 10, "Jacks or better 1");
mvaddstr(4, 10, "Two Pair 2");
mvaddstr(5, 10, "Three of a kind 3");
mvaddstr(6, 10, "Straight 4");
mvaddstr(7, 10, "Flush 5");
mvaddstr(3, 45, "Full House 8");
mvaddstr(4, 45, "Four of a kind 25");
mvaddstr(5, 45, "Straight flush 50");
mvaddstr(6, 45, "Royal flush 250");
}
else
{
mvprintw(3, 27, "%4d", bet);
mvprintw(4, 27, "%4d", bet * 2);
mvprintw(5, 27, "%4d", bet * 3);
mvprintw(6, 27, "%4d", bet * 4);
mvprintw(7, 27, "%4d", bet * 5);
mvprintw(3, 62, "%4d", bet * 8);
mvprintw(4, 62, "%4d", bet * 25);
mvprintw(5, 62, "%4d", bet * 50);
mvprintw(6, 62, "%4d", bet * 250);
}
}
SHAR_EOF
fi
if test -f 'rawmode.c'
then
echo shar: "will not over-write existing file 'rawmode.c'"
else
cat << \SHAR_EOF > 'rawmode.c'
/*
* Copyright (C) 1991 by Jay Konigsberg. mail: jak at sactoh0
*
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, provided that the above copyright
* notice appear in all copies and that both the copyright notice and
* this permission notice appear in supporting documentation. This software
* is provided "as is" without express or implied warranty. However, the
* author retains all Copyright priviliges and rights to renumeration if
* this software is sold.
*
* Also, and very important. This game is for recrecation ONLY and is NOT
* to be used for gambling in any way.
*/
/*
* rawmode.c - enter character at a time processing. I ripped this off
* from one of my other programs because the one in curses didn't work
* the way _I_ wanted :-)
*/
#include <stdio.h>
#include <termio.h>
#include <signal.h>
#include "vid_extern.h"
#include "vid_local.h"
extern int errno;
/* Global for interrupt routine: cleanup() */
struct termio ttyset; /* terminal settings */
unsigned short c_lflag_hold; /* hold original values for reset */
unsigned char VEOF_hold; /* hold original value for reset */
/*
*enter raw mode
*/
void rawmode()
{
if ( ioctl(0, TCGETA, &ttyset) == -1 )
{
fprintf(stderr, "ioctl: error=%d\n", errno);
(void)exit(2);
}
c_lflag_hold=ttyset.c_lflag;
VEOF_hold = ttyset.c_cc[4];
ttyset.c_cc[4] = (unsigned char)1;
ttyset.c_lflag &= ~(ICANON | ECHO);
if ( ioctl(0, TCSETAW, &ttyset) == -1 )
{
fprintf(stderr, "ioctl: error=%d\n",errno);
}
signal(SIGINT, cleanup);
}
SHAR_EOF
fi
if test -f 'setup_deck.c'
then
echo shar: "will not over-write existing file 'setup_deck.c'"
else
cat << \SHAR_EOF > 'setup_deck.c'
/*
* Copyright (C) 1991 by Jay Konigsberg. mail: jak at sactoh0
*
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, provided that the above copyright
* notice appear in all copies and that both the copyright notice and
* this permission notice appear in supporting documentation. This software
* is provided "as is" without express or implied warranty. However, the
* author retains all Copyright priviliges and rights to renumeration if
* this software is sold.
*
* Also, and very important. This game is for recrecation ONLY and is NOT
* to be used for gambling in any way.
*/
/*
* setup_deck.c - converts the random numbers into 1-13 + suite.
*/
#include "vid_poker.h"
#include "vid_extern.h"
void setup_deck(deck, value, suite, count)
int *deck,
*value,
*suite,
count;
{
int cardinx=0;
if ( deck[5] == 0 )
{
cardinx=0;
}
else
{
cardinx=5;
count += 5;
}
for(; cardinx < count; ++cardinx)
{
/* Set the suite and card value */
if ( deck[cardinx] > 39 )
{
suite[cardinx] = 0; /* Spades */
value[cardinx] = deck[cardinx] - 39;
}
else
if ( deck[cardinx] > 26 )
{
suite[cardinx] = 1; /* Hearts */
value[cardinx] = deck[cardinx] - 26;
}
else
if ( deck[cardinx] > 13 )
{
suite[cardinx] = 2; /* Clubs */
value[cardinx] = deck[cardinx] - 13;
}
else
{
suite[cardinx] = 3; /* Diamonds */
value[cardinx] = deck[cardinx];
}
}
}
SHAR_EOF
fi
if test -f 'sort.c'
then
echo shar: "will not over-write existing file 'sort.c'"
else
cat << \SHAR_EOF > 'sort.c'
/*
* Copyright (C) 1991 by Jay Konigsberg. mail: jak at sactoh0
*
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, provided that the above copyright
* notice appear in all copies and that both the copyright notice and
* this permission notice appear in supporting documentation. This software
* is provided "as is" without express or implied warranty. However, the
* author retains all Copyright priviliges and rights to renumeration if
* this software is sold.
*
* Also, and very important. This game is for recrecation ONLY and is NOT
* to be used for gambling in any way.
*/
/*
* sort.c - sorts the hand into acending order. This is required for the
* id_hand routine.
*/
#include "vid_poker.h"
void sort(value, suite, count)
int *value,
*suite,
count;
{
int cardinx1,
cardinx2,
temp1,
temp2;
for ( cardinx1=0; cardinx1<count; ++cardinx1)
for (cardinx2=cardinx1+1; cardinx2<count; ++cardinx2)
if ( value[cardinx1] > value[cardinx2] )
{
temp1=value[cardinx2];
value[cardinx2] = value[cardinx1];
value[cardinx1] = temp1;
temp2=suite[cardinx2];
suite[cardinx2] = suite[cardinx1];
suite[cardinx1] = temp2;
}
}
SHAR_EOF
fi
if test -f 'vid_curses.h'
then
echo shar: "will not over-write existing file 'vid_curses.h'"
else
cat << \SHAR_EOF > 'vid_curses.h'
/*
* Copyright (C) 1991 by Jay Konigsberg. mail: jak at sactoh0
*
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, provided that the above copyright
* notice appear in all copies and that both the copyright notice and
* this permission notice appear in supporting documentation. This software
* is provided "as is" without express or implied warranty. However, the
* author retains all Copyright priviliges and rights to renumeration if
* this software is sold.
*
* Also, and very important. This game is for recrecation ONLY and is NOT
* to be used for gambling in any way.
*/
/*
* vid_curses.h - I just like to reduce the number of complier/lint
* complaints.
*/
#include <curses.h>
extern WINDOW *initscr();
extern int endwin();
extern int wmove();
extern int waddstr();
extern int waddch();
extern int wrefresh();
extern int printw();
extern int mvprintw();
extern int waddstr();
extern int wgetch();
extern int wclrtoeol();
extern int wmove();
extern int waddstr();
extern int waddch();
extern int wrefresh();
SHAR_EOF
fi
if test -f 'vid_extern.h'
then
echo shar: "will not over-write existing file 'vid_extern.h'"
else
cat << \SHAR_EOF > 'vid_extern.h'
/*
* Copyright (C) 1991 by Jay Konigsberg. mail: jak at sactoh0
*
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, provided that the above copyright
* notice appear in all copies and that both the copyright notice and
* this permission notice appear in supporting documentation. This software
* is provided "as is" without express or implied warranty. However, the
* author retains all Copyright priviliges and rights to renumeration if
* this software is sold.
*
* Also, and very important. This game is for recrecation ONLY and is NOT
* to be used for gambling in any way.
*/
/*
* vid_extern.h - external function declarations for vider_poker
*/
extern int printf();
extern int fprintf();
extern int puts();
extern int fputs();
extern int strlen();
extern int atoi();
extern int ioctl();
extern int strcmp();
extern char *strchr();
extern int exit();
extern int fflush();
extern int _flsbuf();
SHAR_EOF
fi
if test -f 'vid_local.h'
then
echo shar: "will not over-write existing file 'vid_local.h'"
else
cat << \SHAR_EOF > 'vid_local.h'
/*
* Copyright (C) 1991 by Jay Konigsberg. mail: jak at sactoh0
*
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, provided that the above copyright
* notice appear in all copies and that both the copyright notice and
* this permission notice appear in supporting documentation. This software
* is provided "as is" without express or implied warranty. However, the
* author retains all Copyright priviliges and rights to renumeration if
* this software is sold.
*
* Also, and very important. This game is for recrecation ONLY and is NOT
* to be used for gambling in any way.
*/
/*
* vid_local.h - Local function declarations
*/
void main(), /* Main driver */
deal(), /* deal cards - uses drand48 */
setup_deck(), /* determin cards and suites */
sort(), /* sorts A-low to K-high */
display_hand(), /* puts the hand on the screen */
payoff_val(), /* display the value of hands */
rawmode(), /* set for char processing */
draw_back(), /* Draw the backs of the cards */
draw(); /* Select which cards to keep */
int id_hand(), /* identifys value of the cards */
display_val(); /* Displays what the hand is */
extern int cleanup(); /* Cleanup curses and raw mode */
SHAR_EOF
fi
if test -f 'vid_poker.h'
then
echo shar: "will not over-write existing file 'vid_poker.h'"
else
cat << \SHAR_EOF > 'vid_poker.h'
/*
* Copyright (C) 1991 by Jay Konigsberg. mail: jak at sactoh0
*
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, provided that the above copyright
* notice appear in all copies and that both the copyright notice and
* this permission notice appear in supporting documentation. This software
* is provided "as is" without express or implied warranty. However, the
* author retains all Copyright priviliges and rights to renumeration if
* this software is sold.
*
* Also, and very important. This game is for recrecation ONLY and is NOT
* to be used for gambling in any way.
*/
/*
* vid_poker.h - Hmm, this is a rather meek .h file. I used to have more
* in it -- really it did.
*/
#include <stdio.h>
#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif
SHAR_EOF
fi
exit 0
# End of shell archive
--
-------------------------------------------------------------
Jay @ SAC-UNIX, Sacramento, Ca. UUCP=...pacbell!sactoh0!jak
If something is worth doing, it's worth doing correctly.
More information about the Alt.sources
mailing list