Can't figure out a bug.
Author |
Message |
Psychotogen
|
Posted: Tue May 06, 2008 1:15 pm Post subject: Can't figure out a bug. |
|
|
Hey,
I'm making a blackjack game everything works, or is going to, but I have a bug.
Sometimes when turing deals out the player's cards, it sonly deals one and not two.
Can someone try to figure it out, I've tried forever...
code: | var deck : array 1 .. 52 of int
var Totals : array 1 .. 2 of int
var card : int
var Ptotal, Dtotal, Dtota : int
var ace : boolean
var yesno : string
var suit, cardNo : string
for i : 1 .. 52
deck (i) := i
end for
proc showCard
randint (card, 1, 52)
if deck (card) not= -1 then
if deck (card) mod 13 = 0 then
cardNo := "Ace"
Ptotal := Ptotal + 11
Dtotal := Dtotal + 11
ace := true
elsif deck (card) mod 13 = 1 then
cardNo := "2"
Ptotal := Ptotal + 2
Dtotal := Dtotal + 2
elsif deck (card) mod 13 = 2 then
cardNo := "3"
Ptotal := Ptotal + 3
Ptotal := Ptotal + 3
elsif deck (card) mod 13 = 3 then
cardNo := "4"
Ptotal := Ptotal + 4
Dtotal := Dtotal + 4
elsif deck (card) mod 13 = 4 then
cardNo := "5"
Ptotal := Ptotal + 5
Dtotal := Dtotal + 5
elsif deck (card) mod 13 = 5 then
cardNo := "6"
Ptotal := Ptotal + 6
Dtotal := Dtotal + 6
elsif deck (card) mod 13 = 6 then
cardNo := "7"
Ptotal := Ptotal + 7
Dtotal := Dtotal + 7
elsif deck (card) mod 13 = 7 then
cardNo := "8"
Ptotal := Ptotal + 8
Dtotal := Dtotal + 8
elsif deck (card) mod 13 = 8 then
cardNo := "9"
Ptotal := Ptotal + 9
Dtotal := Dtotal + 9
elsif deck (card) mod 13 = 9 then
cardNo := "10"
Ptotal := Ptotal + 10
Dtotal := Dtotal + 10
elsif deck (card) mod 13 = 10 then
cardNo := "Jack"
Ptotal := Ptotal + 10
Dtotal := Dtotal + 10
elsif deck (card) mod 13 = 11 then
cardNo := "Queen"
Ptotal := Ptotal + 10
Dtotal := Dtotal + 10
elsif deck (card) mod 13 = 12 then
cardNo := "King"
Ptotal := Ptotal + 10
Dtotal := Dtotal + 10
end if
if deck (card) mod 4 = 0 then
suit := " of Diamonds"
elsif deck (card) mod 4 = 1 then
suit := " of Hearts"
elsif deck (card) mod 4 = 2 then
suit := " of Spades"
elsif deck (card) mod 4 = 3 then
suit := " of Clubs"
end if
put cardNo ..
put suit
end if
deck (card) := -1
end showCard
loop
ace := false
Dtotal := 0
Ptotal := 0
put "%%%%%%%%%%%%"
put "Dealer card"
showCard
put "%%%%%%%%%%%%"
put " "
Totals (1) := Dtotal
Ptotal := 0
%%%%%%%%%%%%%%
showCard
showCard
put " "
Dtotal := 0
put "Your total is ", Ptotal %%
%%%%%%%%
if Ptotal = 21 then
put "Blackjack!, you win!"
elsif Ptotal < 22 then
put "Hit (s) or Stand (s)"
get yesno
end if
if yesno = "s" then
exit
elsif yesno = "h" then
showCard
end if
Dtotal := 0
%%%%%%%%
if Ptotal = 21 then
put "Blackjack!, you win!"
elsif Ptotal < 22 then
put "Hit (s) or Stand (s)"
get yesno
end if
end loop |
|
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
jernst

|
Posted: Tue May 06, 2008 1:39 pm Post subject: Re: Can't figure out a bug. |
|
|
could be cuz of this line:
code: | if deck (card) not= -1 then |
it doesnt seem like theres an else for that if that handles when it is equal to -1. so maybe when that happens its not showing the card |
|
|
|
|
 |
btiffin

|
Posted: Tue May 06, 2008 1:52 pm Post subject: Re: Can't figure out a bug. |
|
|
I'll agree with jernst, if the deal is the same random card twice in a row or other already used card, the player will only get one shown (maybe no shown if both are already used).
Also, your "Hit (s) or Stand (s)" instructional seems wrong.
Cheers |
|
|
|
|
 |
|
|