April 25, 2024, 10:26:45 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Console Automated BlackJack

Started by J B Wood (Zumwalt), December 07, 2006, 09:23:12 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

J B Wood (Zumwalt)

December 07, 2006, 09:23:12 AM Last Edit: December 07, 2006, 11:22:45 AM by Jonathan (zumwalt) Wood
This was inspired by AndrewB's post on arrays.
I got started in helping him and this is what I ended up with just because of curiosity.
Just past this into a new eba file and compile as a console application.
Enjoy..


Def array[8,8] As INT
Def number, zz As INT
def yy,xx as int
string output
number = Rand(11,20)
def coin as int
def results as int
def gamestate as int
string won,lost,blackjack
won="Game Won"
lost="Game Lost"
blackjack="BLACKJACK!"
def player,dealer,turn,finished,PlayerScore,DealerScore as int
player=0
dealer=1
PlayerScore=0
DealerScore=0

for turn=0 to 1
' determine if our rolls would be a valid roll
' obviously we decide that 16 is our stop roll point
finished=0
for xx = 0 to 1
number = Rand(11,20)
if finished=1 then breakfor
select (xx)
case 0
if number < 16 then
if number=11 then
coin = rand(0,1)
select (coin)
case 0
number=1
case 1
number=11
endselect
endif
if number < 10 then
output = output + " "
endif
array[zz,yy] = number
output = output + LTrim$(Str$(array[zz,yy])) + " | "
results=results+number
else
finished=1
array[zz,yy] = number
output = output + LTrim$(Str$(array[zz,yy])) + " | "
results=results+number
number=0
array[zz,yy] = number
output = output + LTrim$(Str$(array[zz,yy])) + " | "
endif
case 1
if number=11 then
coin = rand(0,1)
select (coin)
case 0
number=1
case 1
number=11
endselect
endif
if number < 10 then
output = output + " "
endif
array[zz,yy] = number
output = output + LTrim$(Str$(array[zz,yy])) + " | "
results=results+number
endselect
next xx

select (turn)
case 0
if results > 21 then
print output + " Total: " + Str$(results) + " | Player Bust"
else
if results = 21 then
print output + " Total: " + Str$(results) + " | Player " + blackjack
else
if results < 10 then
print output + " Total: " + Str$(results) + "  | Player "
else
print output + " Total: " + Str$(results) + " | Player "
endif
endif
endif
PlayerScore=results
case 1
if results > 21 then
print output + " Total: " + Str$(results) + " | Dealer Bust"
else
if results = 21 then
print output + " Total: " + Str$(results) + " | Dealer " + blackjack
else
if results < 10 then
print output + " Total: " + Str$(results) + "  | Dealer "
else
print output + " Total: " + Str$(results) + " | Dealer"
endif
endif
endif
DealerScore=results
endselect
results=0
output = ""
next turn

if PlayerScore > 21 then
if DealerScore > 21 then
print " Both Player and Dealer Bust"
else
print " Player Bust, Dealer Wins "
endif
else
if DealerScore > 21 then
print " Dealer Bust, Player Wins"
else
if PlayerScore = 21 then
if DealerScore = 21 then
print " Player and Dealer Tied on BLACKJACK! "
else
print " Player got BLACKJACK and beat Dealer! "
endif
else
if PlayerScore < DealerScore then
print " Player Lost to Dealer "
else
if PlayerScore = DealerScore then
print "Tie"
else
print " Player Beat Dealer "
endif
endif
endif
endif
endif


(by the way, I would have used elseif's if I knew what they were in EBasic, so this is why there are so many nested if's.)

EDIT: forgot the tie situation... added it