Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with war program
#1
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
Reply
#2
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 :-)
hen they say it can't be done, THAT's when they call me ;-).

[Image: kaffee.gif]
[Image: mystikshadows.png]

need hosting: http://www.jc-hosting.net
All about ASCII: http://www.ascii-world.com
Reply
#3
rules of war are here When i run it it gives me a bunch of errors.
Reply
#4
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
Reply
#5
Excellent - when can we start shipping?
img]http://www.cdsoft.co.uk/misc/shiftlynx.png[/img]
Reply
#6
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.
Reply
#7
Yopu can always start the concept of service packs for your game ;-) lol
hen they say it can't be done, THAT's when they call me ;-).

[Image: kaffee.gif]
[Image: mystikshadows.png]

need hosting: http://www.jc-hosting.net
All about ASCII: http://www.ascii-world.com
Reply
#8
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
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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)