Qbasicnews.com
February 20, 2020, 10:22:37 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Help with war program  (Read 2301 times)
Eddd6
New Member

Posts: 4


« on: July 27, 2005, 04:31:01 PM »

I was tring to make a program about the card game War
plz tell me whatz wrong

Code:

DECLARE SUB shuffle (deck$())
DECLARE SUB DBD (deck$(), p!)
DIM c(2)
DIM cards$(52)
DIM deck$(4, 52)
DIM discard(2)
DIM prize$(52)
DIM suit$(4)
DIM v(2)
CLS
CALL shuffle(deck$())
DO
round = round + 1
LOCATE 1, 1: PRINT "round:"; round
GOSUB playcards
IF v(1) > v(2) THEN FOR i = 1 TO prize: discard = discard + 1: deck$(3, discard) = prize$(i): NEXT i: prize = 0
IF v(1) < v(2) THEN FOR i = 1 TO prize: discard = discard + 1: deck$(4, discard) = prize$(i): NEXT i: prize = 0
       IF v(1) = v(2) THEN GOSUB playcards
LOOP
       


playcards:
IF deck$(1, 1) = "" OR deck$(2, 1) = "" THEN GOSUB nocards
c$(1) = deck$(1, 1)
c$(2) = deck$(2, 1)
prize = prize + 2
prize$(prize - 1) = c$(1)
prize$(prize) = c$(2)
FOR i = 1 TO 2
IF LEFT$(c$(i), 1) = "2" THEN v(i) = 2
IF LEFT$(c$(i), 1) = "3" THEN v(i) = 3
IF LEFT$(c$(i), 1) = "4" THEN v(i) = 4
IF LEFT$(c$(i), 1) = "5" THEN v(i) = 5
IF LEFT$(c$(i), 1) = "6" THEN v(i) = 6
IF LEFT$(c$(i), 1) = "7" THEN v(i) = 7
IF LEFT$(c$(i), 1) = "8" THEN v(i) = 8
IF LEFT$(c$(i), 1) = "9" THEN v(i) = 9
IF LEFT$(c$(i), 1) = "1" THEN v(i) = 10
IF LEFT$(c$(i), 1) = "J" THEN v(i) = 11
IF LEFT$(c$(i), 1) = "Q" THEN v(i) = 12
IF LEFT$(c$(i), 1) = "K" THEN v(i) = 13
IF LEFT$(c$(i), 1) = "A" THEN v(i) = 14
NEXT i
FOR a = 1 TO 2
FOR i = 1 TO 51
deck$(a, i) = deck$(a, i + 1)
NEXT i
deck$(a, 52) = ""
NEXT a

RETURN


nocards:
IF deck$(1, 1) = "" AND deck$(2, 1) <> "" AND deck$(3, 1) <> "" THEN p = 1: CALL DBD(deck$(), p)
IF deck$(1, 1) = "" AND deck$(2, 1) <> "" AND deck$(3, 1) = "" THEN PRINT "player 1 wins": END
IF deck$(1, 1) <> "" AND deck$(2, 1) = "" AND deck$(4, 1) <> "" THEN p = 2: CALL DBD(deck$(), p)
IF deck$(1, 1) <> "" AND deck$(2, 1) = "" AND deck$(4, 1) = "" THEN PRINT "player 2 wins": END
IF deck$(1, 1) = "" AND deck$(2, 1) = "" AND deck$(3, 1) = "" AND deck$(4, 1) = "" THEN PRINT "complete tie!!!": END
RETURN

SUB DBD (deck$(), p)
FOR i = 1 TO 52
deck$(p, i) = deck$(p + 2, i)
deck$(p + 2, i) = ""
NEXT i
END SUB

SUB shuffle (deck$())
CLS
RANDOMIZE TIMER
DIM cards$(52)
DIM suit$(4)
suit$(1) = "clubs"
suit$(2) = "spades"
suit$(3) = "diamonds"
suit$(4) = "hearts"
DIM type$(13)
FOR i = 1 TO 9
type$(i) = STR$(i + 1)
NEXT i
type$(10) = "Jack"
type$(11) = "Queen"
type$(12) = "King"
type$(13) = "Ace"
i = 0
FOR suit = 1 TO 4
FOR tyype = 1 TO 13
i = i + 1
    cards$(i) = "" + type$(tyype) + " of " + suit$(suit)
NEXT tyype
NEXT suit

FOR k = 1 TO (RND * 7) + 4
FOR i = 1 TO 52
     j = INT(RND * 52) + 1
     SWAP cards$(i), cards$(j)
NEXT i
NEXT k
j = 0
FOR i = 1 TO 52 STEP 2
j = j + 1
deck$(1, j) = cards$(i)
deck$(2, j) = cards$(i + 1)
NEXT i
END SUB

Logged
MystikShadows
Ancient Guru
****
Posts: 542



WWW
« Reply #1 on: July 27, 2005, 05:14:24 PM »

This doesn't say much about the problem.  Describe what happens and what you'd actually like to happen.  I'm asking this because I don't know that war card game so I can't tell you what's wrong with it just be looking at the code :-).  

So detail the situation a bit as in what it does and what it should be doing and we'll be able to help you alot more :-)
Logged

hen they say it can't be done, THAT's when they call me ;-).




need hosting:  http://www.jc-hosting.net
All about ASCII: http://www.ascii-world.com
Eddd6
New Member

Posts: 4


« Reply #2 on: July 27, 2005, 05:26:00 PM »

rules of war are here When i run it it gives me a bunch of errors.
Logged
DrV
Na_th_an
*****
Posts: 1553



WWW
« Reply #3 on: July 27, 2005, 05:30:04 PM »

Sory for being cynical, but here's a simpler War card game simulation:
Code:
RANDOMIZE TIMER
IF INT(RND * 2) = 1 THEN
  PRINT "You win."
ELSE
  PRINT "The computer wins."
END IF


I couldn't resist. Wink
Logged
shiftLynx
Wandering Guru
***
Posts: 340



WWW
« Reply #4 on: July 27, 2005, 05:44:24 PM »

Excellent - when can we start shipping?
Logged

img]http://www.cdsoft.co.uk/misc/shiftlynx.png[/img]
DrV
Na_th_an
*****
Posts: 1553



WWW
« Reply #5 on: July 27, 2005, 06:05:35 PM »

Well, once we sell thousands of copies of that, here's version 2, with extended gameplay capabilities:
Code:
RANDOMIZE TIMER
SELECT CASE INT(RND * 4)
  CASE 0: PRINT "You win."
  CASE 1: PRINT "The computer wins."
  CASE 2: PRINT "You give up."
  CASE 3: PRINT "The computer dies of boredom."
END SELECT



The first runtime error I get is on this line:
Code:
deck$(4, discard) = prize$(i)

Because discard = 53, which is beyond the size of the second dimension of the deck$ array.
Logged
MystikShadows
Ancient Guru
****
Posts: 542



WWW
« Reply #6 on: July 27, 2005, 07:28:27 PM »

Yopu can always start the concept of service packs for your game ;-) lol
Logged

hen they say it can't be done, THAT's when they call me ;-).




need hosting:  http://www.jc-hosting.net
All about ASCII: http://www.ascii-world.com
Pyrokid
Wandering Guru
***
Posts: 355



WWW
« Reply #7 on: July 30, 2005, 06:59:42 PM »

Code:

DIM discard(2)



IF v(1) > v(2) THEN FOR i = 1 TO prize: discard = discard + 1: deck$(3, discard) = prize$(i): NEXT i: prize = 0

you made it an array but you arent using it
Logged

his world has been connected...
Tied to the darkness.
Soon to be completely eclipsed.
There is so very much to learn...
You understand so little.
A meaningless  effort.
One who knows nothing can understand nothing.
-Ansem Bringer of darkness and creator of the heartless
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!