Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #16804 > unrolled thread
| Started by | luser- -droog <mijoryx@yahoo.com> |
|---|---|
| First post | 2012-02-05 13:56 -0800 |
| Last post | 2012-02-07 22:59 -0800 |
| Articles | 4 — 2 participants |
Back to article view | Back to comp.lang.c
card-counting program for blackjack luser- -droog <mijoryx@yahoo.com> - 2012-02-05 13:56 -0800
Re: card-counting program for blackjack pete <pfiland@mindspring.com> - 2012-02-07 10:32 -0500
Re: card-counting program for blackjack pete <pfiland@mindspring.com> - 2012-02-07 10:35 -0500
Re: card-counting program for blackjack luser- -droog <mijoryx@yahoo.com> - 2012-02-07 22:59 -0800
| From | luser- -droog <mijoryx@yahoo.com> |
|---|---|
| Date | 2012-02-05 13:56 -0800 |
| Subject | card-counting program for blackjack |
| Message-ID | <18e43b14-0c7a-41bf-84a8-dc27f0e199f2@c6g2000vbk.googlegroups.com> |
Sir, is that a keyboard in your sleeve?
692(1)03:51 PM:~ 0> cat bj.c && echo --------- && make bj && bj
#include <ctype.h>
#include <stdio.h>
#include <string.h>
enum { cards = 13, suits = 4, decks = 4 };
int count[cards];
int total;
char symbols[] = "234567890jqka";
void reset() {
int i;
total = 0;
for (i=0; i < cards; i++)
total += count[i] = suits * decks;
}
void sub(char c) {
if(c=='s')
reset();
else {
char *p = strchr(symbols, tolower(c));
if (p == NULL) return;
--count[ p - symbols ];
--total;
}
}
void show() {
int i;
for (i=0; i < cards; i++) printf(" %c ", toupper(symbols[i]));
puts("");
for (i=0; i < cards; i++) printf("%3d ", count[i]);
printf(" 10s:%d ", count[8]+count[9]+count[10]+count[11]);
printf(" Total:%d", total);
puts("");
for (i=0; i < cards; i++) printf("%3d ", (count[i]*100)/total);
printf(" 10s:%d ", ((count[8]+count[9]+count[10]+count[11])*100)/
total);
puts("");
}
char buf[99];
void readline() {
fgets(buf,99,stdin);
}
void doline() {
int i = 0;
while(buf[i]){
if (!isspace(buf[i]))
sub(buf[i]);
++i;
}
}
int main() {
reset();
while(1) {
show();
readline();
doline();
}
return 0;
}
---------
cc -g -Wall bj.c -o bj
2 3 4 5 6 7 8 9 0 J Q K A
16 16 16 16 16 16 16 16 16 16 16 16 16 10s:64 Total:
208
7 7 7 7 7 7 7 7 7 7 7 7 7 10s:30
460ak
2 3 4 5 6 7 8 9 0 J Q K A
16 16 15 16 15 16 16 16 15 16 16 15 15 10s:62 Total:
203
7 7 7 7 7 7 7 7 7 7 7 7 7 10s:30
3 9 q kaj
2 3 4 5 6 7 8 9 0 J Q K A
16 15 15 16 15 16 16 15 15 15 15 14 14 10s:59 Total:
197
8 7 7 8 7 8 8 7 7 7 7 7 7 10s:29
2 4q 48a
2 3 4 5 6 7 8 9 0 J Q K A
15 15 13 16 15 16 15 15 15 15 14 14 13 10s:58 Total:
191
7 7 6 8 7 8 7 7 7 7 7 7 6 10s:30
2 4 4 8 0 a q
2 3 4 5 6 7 8 9 0 J Q K A
14 15 11 16 15 16 14 15 14 15 13 14 12 10s:56 Total:
184
7 8 5 8 8 8 7 8 7 8 7 7 6 10s:30
4 4 8 ak
2 3 4 5 6 7 8 9 0 J Q K A
14 15 9 16 15 16 13 15 14 15 13 13 11 10s:55 Total:
179
7 8 5 8 8 8 7 8 7 8 7 7 6 10s:30
^C
693(1)03:52 PM:~ 130>
[toc] | [next] | [standalone]
| From | pete <pfiland@mindspring.com> |
|---|---|
| Date | 2012-02-07 10:32 -0500 |
| Message-ID | <4F314405.6A9F@mindspring.com> |
| In reply to | #16804 |
luser- -droog wrote:
>
> Sir, is that a keyboard in your sleeve?
>
> 692(1)03:51 PM:~ 0> cat bj.c && echo --------- && make bj && bj
> #include <ctype.h>
> #include <stdio.h>
> #include <string.h>
>
> enum { cards = 13, suits = 4, decks = 4 };
> int count[cards];
> int total;
> char symbols[] = "234567890jqka";
>
> void reset() {
> int i;
> total = 0;
> for (i=0; i < cards; i++)
> total += count[i] = suits * decks;
> }
>
> void sub(char c) {
> if(c=='s')
> reset();
> else {
> char *p = strchr(symbols, tolower(c));
> if (p == NULL) return;
> --count[ p - symbols ];
> --total;
> }
> }
>
> void show() {
> int i;
> for (i=0; i < cards; i++) printf(" %c ", toupper(symbols[i]));
> puts("");
> for (i=0; i < cards; i++) printf("%3d ", count[i]);
> printf(" 10s:%d ", count[8]+count[9]+count[10]+count[11]);
> printf(" Total:%d", total);
> puts("");
> for (i=0; i < cards; i++) printf("%3d ", (count[i]*100)/total);
> printf(" 10s:%d ", ((count[8]+count[9]+count[10]+count[11])*100)/
> total);
> puts("");
> }
>
> char buf[99];
>
> void readline() {
> fgets(buf,99,stdin);
> }
>
> void doline() {
> int i = 0;
> while(buf[i]){
> if (!isspace(buf[i]))
> sub(buf[i]);
> ++i;
> }
> }
>
> int main() {
> reset();
> while(1) {
> show();
> readline();
> doline();
> }
> return 0;
> }
>
> ---------
> cc -g -Wall bj.c -o bj
> 2 3 4 5 6 7 8 9 0 J Q K A
> 16 16 16 16 16 16 16 16 16 16 16 16 16 10s:64 Total:
> 208
> 7 7 7 7 7 7 7 7 7 7 7 7 7 10s:30
This point is where the output stops on my machine.
Either that,
or this is the point where the program runs too slowly
for me to continue waiting for more output.
> 460ak
> 2 3 4 5 6 7 8 9 0 J Q K A
> 16 16 15 16 15 16 16 16 15 16 16 15 15 10s:62 Total:
> 203
> 7 7 7 7 7 7 7 7 7 7 7 7 7 10s:30
> 3 9 q kaj
> 2 3 4 5 6 7 8 9 0 J Q K A
> 16 15 15 16 15 16 16 15 15 15 15 14 14 10s:59 Total:
> 197
> 8 7 7 8 7 8 8 7 7 7 7 7 7 10s:29
> 2 4q 48a
> 2 3 4 5 6 7 8 9 0 J Q K A
> 15 15 13 16 15 16 15 15 15 15 14 14 13 10s:58 Total:
> 191
> 7 7 6 8 7 8 7 7 7 7 7 7 6 10s:30
> 2 4 4 8 0 a q
> 2 3 4 5 6 7 8 9 0 J Q K A
> 14 15 11 16 15 16 14 15 14 15 13 14 12 10s:56 Total:
> 184
> 7 8 5 8 8 8 7 8 7 8 7 7 6 10s:30
> 4 4 8 ak
> 2 3 4 5 6 7 8 9 0 J Q K A
> 14 15 9 16 15 16 13 15 14 15 13 13 11 10s:55 Total:
> 179
> 7 8 5 8 8 8 7 8 7 8 7 7 6 10s:30
> ^C
> 693(1)03:52 PM:~ 130>
--
pete
[toc] | [prev] | [next] | [standalone]
| From | pete <pfiland@mindspring.com> |
|---|---|
| Date | 2012-02-07 10:35 -0500 |
| Message-ID | <4F3144CE.1B87@mindspring.com> |
| In reply to | #16839 |
pete wrote:
>
> luser- -droog wrote:
> >
> > Sir, is that a keyboard in your sleeve?
> >
> > 692(1)03:51 PM:~ 0> cat bj.c && echo --------- && make bj && bj
> > #include <ctype.h>
> > #include <stdio.h>
> > #include <string.h>
> >
> > enum { cards = 13, suits = 4, decks = 4 };
> > int count[cards];
> > int total;
> > char symbols[] = "234567890jqka";
> >
> > void reset() {
> > int i;
> > total = 0;
> > for (i=0; i < cards; i++)
> > total += count[i] = suits * decks;
> > }
> >
> > void sub(char c) {
> > if(c=='s')
> > reset();
> > else {
> > char *p = strchr(symbols, tolower(c));
> > if (p == NULL) return;
> > --count[ p - symbols ];
> > --total;
> > }
> > }
> >
> > void show() {
> > int i;
> > for (i=0; i < cards; i++) printf(" %c ", toupper(symbols[i]));
> > puts("");
> > for (i=0; i < cards; i++) printf("%3d ", count[i]);
> > printf(" 10s:%d ", count[8]+count[9]+count[10]+count[11]);
> > printf(" Total:%d", total);
> > puts("");
> > for (i=0; i < cards; i++) printf("%3d ", (count[i]*100)/total);
> > printf(" 10s:%d ", ((count[8]+count[9]+count[10]+count[11])*100)/
> > total);
> > puts("");
> > }
> >
> > char buf[99];
> >
> > void readline() {
> > fgets(buf,99,stdin);
> > }
> >
> > void doline() {
> > int i = 0;
> > while(buf[i]){
> > if (!isspace(buf[i]))
> > sub(buf[i]);
> > ++i;
> > }
> > }
> >
> > int main() {
> > reset();
> > while(1) {
> > show();
> > readline();
> > doline();
> > }
> > return 0;
> > }
> >
> > ---------
> > cc -g -Wall bj.c -o bj
> > 2 3 4 5 6 7 8 9 0 J Q K A
> > 16 16 16 16 16 16 16 16 16 16 16 16 16 10s:64 Total:
> > 208
> > 7 7 7 7 7 7 7 7 7 7 7 7 7 10s:30
>
> This point is where the output stops on my machine.
> Either that,
> or this is the point where the program runs too slowly
> for me to continue waiting for more output.
I think I'm supposed to input something at this point
but I haven't figured out what yet.
--
pete
[toc] | [prev] | [next] | [standalone]
| From | luser- -droog <mijoryx@yahoo.com> |
|---|---|
| Date | 2012-02-07 22:59 -0800 |
| Message-ID | <85125e2d-667b-4270-b643-c1d7991448dd@f30g2000yqh.googlegroups.com> |
| In reply to | #16840 |
On Feb 7, 9:35 am, pete <pfil...@mindspring.com> wrote:
> pete wrote:
>
> > luser- -droog wrote:
>
> > > Sir, is that a keyboard in your sleeve?
>
> > > 692(1)03:51 PM:~ 0> cat bj.c && echo --------- && make bj && bj
> > > #include <ctype.h>
> > > #include <stdio.h>
> > > #include <string.h>
>
> > > enum { cards = 13, suits = 4, decks = 4 };
> > > int count[cards];
> > > int total;
> > > char symbols[] = "234567890jqka";
>
> > > void reset() {
> > > int i;
> > > total = 0;
> > > for (i=0; i < cards; i++)
> > > total += count[i] = suits * decks;
> > > }
>
> > > void sub(char c) {
> > > if(c=='s')
> > > reset();
> > > else {
> > > char *p = strchr(symbols, tolower(c));
> > > if (p == NULL) return;
> > > --count[ p - symbols ];
> > > --total;
> > > }
> > > }
>
> > > void show() {
> > > int i;
> > > for (i=0; i < cards; i++) printf(" %c ", toupper(symbols[i]));
> > > puts("");
> > > for (i=0; i < cards; i++) printf("%3d ", count[i]);
> > > printf(" 10s:%d ", count[8]+count[9]+count[10]+count[11]);
> > > printf(" Total:%d", total);
> > > puts("");
> > > for (i=0; i < cards; i++) printf("%3d ", (count[i]*100)/total);
> > > printf(" 10s:%d ", ((count[8]+count[9]+count[10]+count[11])*100)/
> > > total);
> > > puts("");
> > > }
>
> > > char buf[99];
>
> > > void readline() {
> > > fgets(buf,99,stdin);
> > > }
>
> > > void doline() {
> > > int i = 0;
> > > while(buf[i]){
> > > if (!isspace(buf[i]))
> > > sub(buf[i]);
> > > ++i;
> > > }
> > > }
>
> > > int main() {
> > > reset();
> > > while(1) {
> > > show();
> > > readline();
> > > doline();
> > > }
> > > return 0;
> > > }
>
> > > ---------
> > > cc -g -Wall bj.c -o bj
> > > 2 3 4 5 6 7 8 9 0 J Q K A
> > > 16 16 16 16 16 16 16 16 16 16 16 16 16 10s:64 Total:
> > > 208
> > > 7 7 7 7 7 7 7 7 7 7 7 7 7 10s:30
>
> > This point is where the output stops on my machine.
> > Either that,
> > or this is the point where the program runs too slowly
> > for me to continue waiting for more output.
>
> I think I'm supposed to input something at this point
> but I haven't figured out what yet.
>
Point taken. I guess /some/ commentary really is necessary.
I've been hooked on the Kindle Blackjack game. So I wrote
this program to help me improve my guesses.
The program (initially and after each 's'huffle) maintains
the number of each rank of card contained in 4 standard
playing card decks. '0' means "10" on input and output.
The 'prompt' is a table showing the number of each card,
the number of "tens", the total number of cards left in
the shoe, and the integer percentages for each card and
for "tens".
So when any cards are played, type them in and hit enter.
This will show what's left in the deck after every hand.
Exit by Interrupt.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c
csiph-web