CARD COUNTING PROJECT

Ask questions about projects relating to: computer science or pure mathematics (such as probability, statistics, geometry, etc...).

Moderators: kgudger, bfinio, Moderators

Locked
CardCounting
Posts: 2
Joined: Sat Nov 01, 2008 4:04 pm
Occupation: Student
Project Question: Card Counting
Project Due Date: Soon!
Project Status: I am conducting my experiment

CARD COUNTING PROJECT

Post by CardCounting »

Ok so I saw another thread on this but didn't get much help out of it so decided to ask for help myself. I am doing the card counting project mention on this site and am trying to set up a program to simulate a Hi/Lo program. I am not very familiar with any computer programming but I have googled all the basics about QBasic.
The basics of it is to "count" the cards you simply give a card under 7 a value of -1, a card with 7 a 0, and a card over 7 a 1.
The program I have so far prints off the count of the cards throughout all thirteen cards of a suit, the problem I am having is getting it to not use the same number twice (Which is probably some easy fix i'm not aware of). I realize that this was probably not the easiest way to make the program but it's the only way I can really understand, so if you could help me with the problem that would be great :D .

CLS
RANDOMIZE TIMER
FOR x = 1 TO 10000
d = INT(RND * 13) + 1
a = 1
b = 0
c = -1
K = 0
IF d > 7 THEN K = K + a
IF d = 7 THEN K = K + b
IF d < 7 THEN K = K + c
NEXT
PRINT K
DO
e = INT(RND * 13) + 1
LOOP UNTIL e <> d
IF e > 7 THEN K = K + a
IF e = 7 THEN K = K + b
IF e < 7 THEN K = K + c
PRINT K
DO
f = INT(RND * 13) + 1
LOOP UNTIL f <> d OR e
IF f > 7 THEN K = K + a
IF f = 7 THEN K = K + b
IF f < 7 THEN K = K + c
PRINT K
DO
g = INT(RND * 13) + 1
LOOP UNTIL g <> f OR d OR e
IF g > 7 THEN K = K + a
IF g = 7 THEN K = K + b
IF g < 7 THEN K = K + c
PRINT K
DO
h = INT(RND * 13) + 1
LOOP UNTIL h <> d OR e OR f OR g
IF h > 7 THEN K = K + a
IF h = 7 THEN K = K + b
IF h < 7 THEN K = K + c
PRINT K
DO
i = INT(RND * 13) + 1
LOOP UNTIL i <> d OR e OR f OR g OR h
IF i > 7 THEN K = K + a
IF i = 7 THEN K = K + b
IF i < 7 THEN K = K + c
PRINT K
DO
j = INT(RND * 13) + 1
LOOP UNTIL j <> d OR e OR f OR g OR h OR i
IF j > 7 THEN K = K + a
IF j = 7 THEN K = K + b
IF j < 7 THEN K = K + c
PRINT K
DO
l = INT(RND * 13) + 1
LOOP UNTIL l <> d OR e OR f OR g OR h OR i OR j
IF l > 7 THEN K = K + a
IF l = 7 THEN K = K + b
IF l < 7 THEN K = K + c
PRINT K
DO
m = INT(RND * 13) + 1
LOOP UNTIL m <> d OR e OR f OR g OR h OR i OR j OR l
IF m > 7 THEN K = K + a
IF m = 7 THEN K = K + b
IF m < 7 THEN K = K + c
PRINT K
DO
n = INT(RND * 13) + 1
LOOP UNTIL n <> d OR e OR f OR g OR h OR i OR j OR l OR m
IF n > 7 THEN K = K + a
IF n = 7 THEN K = K + b
IF n < 7 THEN K = K + c
PRINT K
DO
o = INT(RND * 13) + 1
LOOP UNTIL o <> d OR e OR f OR g OR h OR i OR j OR l OR m OR n
IF o > 7 THEN K = K + a
IF o = 7 THEN K = K + b
IF o < 7 THEN K = K + c
PRINT K
DO
p = INT(RND * 13) + 1
LOOP UNTIL p <> d OR e OR f OR g OR h OR i OR j OR l OR m OR n OR o
IF p > 7 THEN K = K + a
IF p = 7 THEN K = K + b
IF p < 7 THEN K = K + c
PRINT K
DO
q = INT(RND * 13) + 1
LOOP UNTIL q <> d OR e OR f OR g OR h OR i OR j OR l OR m OR n OR o OR p
IF q > 7 THEN K = K + a
IF q = 7 THEN K = K + b
IF q < 7 THEN K = K + c
PRINT K

So yeah all I want is for it to not pick the same numbers from 1-13 (Still pick them randomly, but excluding the one before it) And i thought the DO...LOOP UNTIL would work but apparently it doesn't.
CardCounting
Posts: 2
Joined: Sat Nov 01, 2008 4:04 pm
Occupation: Student
Project Question: Card Counting
Project Due Date: Soon!
Project Status: I am conducting my experiment

Re: CARD COUNTING PROJECT

Post by CardCounting »

Ok so i found a lot wrong with my other one but I have a new program and cannot figure out whats going wrong.
First of all, to count the cards a card between 2-6 gets a +1, 7-9 gets a 0, and 10-K gets a -1. The higher the count the more higher cards there are left in the deck.
So all i'm trying to do is get the program to pick every number from 1-13, which if done correctly, should bring the count to 0 when all the cards are dealt (I'm only using one suit since it's virtually the same as using all 4).
Here's what i've got and can't figure out what i'm doing (Fast help would be much appreciated because I have a data check tomorrow).
1 CLS
2 RANDOMIZE TIMER
3 FOR X = 1 TO 19456
4 d = INT(RND * 13) + 1
5 a = -1
6 b = 0
7 c = 1
8 K = 0
9 IF d = (2 OR 3 OR 4 OR 5 OR 6) THEN ab = K + c ELSE GOTO 10
10 IF d = (7 OR 8 OR 9) THEN ab = K + b ELSE GOTO 11
11 IF d = (10 OR 11 OR 12 OR 13 OR 1) THEN ab = K + a
12 PRINT ab
13 e = INT(RND * 13) + 1
GOTO 100
100 IF e = d THEN GOTO 13 ELSE GOTO 14
14 IF e = (2 OR 3 OR 4 OR 5 OR 6) THEN ac = ab + c ELSE GOTO 15
15 IF e = (7 OR 8 OR 9) THEN ac = ab + b ELSE GOTO 16
16 IF e = (10 OR 11 OR 12 OR 13 OR 1) THEN ac = ab + a
17 PRINT ac
18 f = INT(RND * 13) + 1
GOTO 101
101 IF f = (d OR e) THEN GOTO 18 ELSE GOTO 19
19 IF f = (2 OR 3 OR 4 OR 5 OR 6) THEN ad = ac + c ELSE GOTO 20
20 IF f = (7 OR 8 OR 9) THEN ad = ac + b ELSE GOTO 21
21 IF f = (10 OR 11 OR 12 OR 13 OR 1) THEN ad = ac + a
22 PRINT ad
23 g = INT(RND * 13) + 1
GOTO 102
102 IF g = (d OR e OR f) THEN GOTO 23 ELSE GOTO 24
24 IF g = (2 OR 3 OR 4 OR 5 OR 6) THEN ae = ad + c ELSE GOTO 25
25 IF g = (7 OR 8 OR 9) THEN ae = ad + b ELSE GOTO 26
26 IF g = (10 OR 11 OR 12 OR 13 OR 1) THEN ae = ad + a
27 PRINT ae
28 h = INT(RND * 13) + 1
GOTO 103
103 IF h = (d OR e OR f OR g) THEN GOTO 28 ELSE GOTO 29
29 IF h = (2 OR 3 OR 4 OR 5 OR 6) THEN af = ae + c ELSE GOTO 30
30 IF h = (7 OR 8 OR 9) THEN af = ae + b ELSE GOTO 31
31 IF h = (10 OR 11 OR 12 OR 13 OR 1) THEN af = ae + a
32 PRINT af
33 i = INT(RND * 13) + 1
GOTO 104
104 IF i = (d OR e OR f OR g OR h) THEN GOTO 33 ELSE GOTO 34
34 IF i = (2 OR 3 OR 4 OR 5 OR 6) THEN ah = af + c ELSE GOTO 35
35 IF i = (7 OR 8 OR 9) THEN ah = af + b ELSE GOTO 36
36 IF i = (10 OR 11 OR 12 OR 13 OR 1) THEN ah = af + a
37 PRINT ah
38 j = INT(RND * 13) + 1
GOTO 105
105 IF j = (d OR e OR f OR g OR h OR i) THEN GOTO 38 ELSE GOTO 39
39 IF j = (2 OR 3 OR 4 OR 5 OR 6) THEN ai = ah + c ELSE GOTO 40
40 IF j = (7 OR 8 OR 9) THEN ai = ah + b ELSE GOTO 41
41 IF j = (10 OR 11 OR 12 OR 13 OR 1) THEN ai = ah + a
42 PRINT ai
43 l = INT(RND * 13) + 1
GOTO 106
106 IF l = (d OR e OR f OR g OR h OR i OR j) THEN GOTO 43 ELSE GOTO 44
44 IF l = (2 OR 3 OR 4 OR 5 OR 6) THEN aj = ai + c ELSE GOTO 45
45 IF l = (7 OR 8 OR 9) THEN aj = ai + b ELSE GOTO 46
46 IF l = (10 OR 11 OR 12 OR 13 OR 1) THEN aj = ai + a
47 PRINT aj
48 m = INT(RND * 13) + 1
GOTO 107
107 IF m = (d OR e OR f OR g OR h OR i OR j OR l) THEN GOTO 48 ELSE GOTO 49
49 IF m = (2 OR 3 OR 4 OR 5 OR 6) THEN ak = aj + c ELSE GOTO 50
50 IF m = (7 OR 8 OR 9) THEN ak = aj + b ELSE GOTO 51
51 IF m = (10 OR 11 OR 12 OR 13 OR 1) THEN ak = aj + a
52 PRINT ak
53 n = INT(RND * 13) + 1
GOTO 108
108 IF n = (d OR e OR f OR g OR h OR i OR j OR l OR m) THEN GOTO 53 ELSE GOTO 54
54 IF n = (2 OR 3 OR 4 OR 5 OR 6) THEN am = ak + c ELSE GOTO 55
55 IF n = (7 OR 8 OR 9) THEN am = ak + b ELSE GOTO 56
56 IF n = (10 OR 11 OR 12 OR 13 OR 1) THEN am = ak + a
57 PRINT am
58 o = INT(RND * 13) + 1
GOTO 109
109 IF o = (d OR e OR f OR g OR h OR i OR j OR l OR m OR n) THEN GOTO 58 ELSE GOTO 59
59 IF o = (2 OR 3 OR 4 OR 5 OR 6) THEN ao = am + c ELSE GOTO 60
60 IF o = (7 OR 8 OR 9) THEN ao = am + b ELSE GOTO 61
61 IF o = (10 OR 11 OR 12 OR 13 OR 1) THEN ao = am + a
62 PRINT ao
63 p = INT(RND * 13) + 1
GOTO 110
110 IF p = (d OR e OR f OR g OR h OR i OR j OR l OR m OR n OR o) THEN GOTO 63 ELSE GOTO 64
64 IF p = (2 OR 3 OR 4 OR 5 OR 6) THEN ap = ao + c ELSE GOTO 65
65 IF p = (7 OR 8 OR 9) THEN ap = ao + b ELSE GOTO 66
66 IF p = (10 OR 11 OR 12 OR 13 OR 1) THEN ap = ao + a
67 PRINT ap
68 q = INT(RND * 13) + 1
GOTO 111
111 IF q = (d OR e OR f OR g OR h OR i OR j OR l OR m OR n OR o OR p) THEN GOTO 68 ELSE GOTO 69
69 IF q = (2 OR 3 OR 4 OR 5 OR 6) THEN aq = ap + c ELSE GOTO 70
70 IF q = (7 OR 8 OR 9) THEN aq = ap + b ELSE GOTO 71
71 IF q = (10 OR 11 OR 12 OR 13 OR 1) THEN aq = ap + a
72 PRINT aq
NEXT X

I changed the K (Which was the count) into different variable because I thoughtt it was getting it mixed up, but now the whole thing is just differently messed up. (So i'm guessing i should just change them all back to K). But what I don't get is why the IF...THEN..ELSE isn't doing what I want it to do.

EDIT: THe current output is the numbers 1-13 repeated 13? times, and when I had all the variables as K I would get what looks like a count but it still wouldn't come out as zero (which it should).
ChrisG
Former Expert
Posts: 1019
Joined: Fri Oct 28, 2005 11:43 am
Occupation: Research Hydrologist
Project Question: n/a
Project Due Date: n/a
Project Status: Not applicable

Re: CARD COUNTING PROJECT

Post by ChrisG »

Hi,
I don't use Qbasic, so I'm not exactly sure, but could one problem be that you haven't initialized the variables ab, ac, ad, ae, etc? In my programming if variables aren't initialized, they can take on unpredictable values.
When you changed the count variable back to K, did you initialize the value of K as zero? What are you getting as starting, intermediate, and final values for K?

Chris
chizwiz
Former Expert
Posts: 4
Joined: Fri Sep 18, 2009 11:39 pm
Occupation: Engineer
Project Question: N/A
Project Due Date: N/A
Project Status: Not applicable

Re: CARD COUNTING PROJECT

Post by chizwiz »

When it comes to programming (in any language), a very important thing to keep in mind is variable naming conventions. When you have 20 variables floating around 200 lines of code and they are all being manipulated by various equations in various functions, it's impossible to keep track of them all when debugging. Naming your variables in consistent "plain english" will make it easier to troubleshoot random parts of the code when an error occurs. Take these two examples:

1) variables "a", "b" and "c", and in line 157 the following equation appears: [ a + b = c ] Where the heck did "a" and "b" come from? Why am I adding them together? There is no context to the variables, and thus it is very difficult to troubleshoot a problem!

2) with the variables defined as "first_card_value", "second_card_value" and "total_value", the equation makes much more sense! Now, I know exactly what I am adding, and what the result actually means.

Remember to NEVER use spaces or special characters (like $, #, @) in variable names because it will confuse the code compiler. Underscores are a GREAT way to have intelligently named variables without making them hard to read; "first_card_value" is easier to read than "firstcardvalue".

Also, I notice there are MANY MANY "IF OR OR OR OR OR" statements in your code. This can be tedious to write and keep track of (as I am sure you know), but it's also not a very efficient way to make a determination about where to GO TO in the code. Research a loop function... it's a great way to evaluate many cases in just a few lines of code.
Locked

Return to “Grades 9-12: Math and Computer Science”