Posted: Sun Jun 11, 2006 7:40 pm Post subject: War
okay everone knows the card game war right well i am having serious problems with this game and since our teach gives us notes and well there very crappy notes i have no idea what i am doing so my first prob is how do i get it to deal the 26 cards to each player without having like 2kings of diamonds and how do i get the value to appear below so here is my code.
code:
%Amy Gilbank
%June 1 2006
%war1.t
%a game of war
var winMain : int := Window.Open ("graphics:800;600")
var font1,font2: int
var p1Randomcard,x1,x2,y1,y2,p2Randomcard:int
var cards:array 1..52 of int
var p1deck,p2deck :array 1..26 of int
var cardvalue :array 1..52 of int
drawfillbox(0,600,800,0,199)
%Battle area
drawfillbox(20,100,95,200,78)
drawfillbox(120,100,195,200,78)
drawfillbox(220,100,295,200,78)
drawfillbox(320,100,395,200,78)
drawfillbox(420,100,495,200,78)
drawfillbox(520,100,595,200,78)
drawfillbox(620,100,695,200,78)
drawfillbox(720,100,795,200,78)
%Deck and cards spot
drawfillbox(200,400,275,500,79)
drawfillbox(500,400,575,500,80)
drawfillbox(300,400,375,500,0)
drawfillbox(400,400,475,500,0)
%Scoreboard and card number spots
drawfillbox(320,360,360,380,0)
drawfillbox(420,360,460,380,0)
%Fonts
font1:=Font.New("Vineta BT:45: bold,underline")
Font.Draw ("WAR!",260,550,font1,red)
font2:=Font.New("New Times Roman :11:")
Font.Draw("Player 1" ,300,310,font2,27)
Font.Draw("Player 2",410,310,font2,27)
Font.Draw("Deck",220,510,font2,27)
Font.Draw("Deck",520,510,font2,27)
%Cards
cards(1):=Pic.FileNew("10C.jpg")
cards(2):=Pic.FileNew("10D.jpg")
cards(3):=Pic.FileNew("10H.jpg")
cards(4):=Pic.FileNew("10S.jpg")
cards(5):=Pic.FileNew("2C.jpg")
cards(6):=Pic.FileNew("2D.jpg")
cards(7):=Pic.FileNew("2H.jpg")
cards(8):=Pic.FileNew("2S.jpg")
cards(9):=Pic.FileNew("3C.jpg")
cards(10):=Pic.FileNew("3D.jpg")
cards(11):=Pic.FileNew("3H.jpg")
cards(12):=Pic.FileNew("3S.jpg")
cards(13):=Pic.FileNew("4C.jpg")
cards(14):=Pic.FileNew("4D.jpg")
cards(15):=Pic.FileNew("4H.jpg")
cards(16):=Pic.FileNew("4S.jpg")
cards(17):=Pic.FileNew("5C.jpg")
cards(18):=Pic.FileNew("5D.jpg")
cards(19):=Pic.FileNew("5H.jpg")
cards(20):=Pic.FileNew("5S.jpg")
cards(21):=Pic.FileNew("6C.jpg")
cards(22):=Pic.FileNew("6D.jpg")
cards(23):=Pic.FileNew("6H.jpg")
cards(24):=Pic.FileNew("6S.jpg")
cards(25):=Pic.FileNew("7C.jpg")
cards(26):=Pic.FileNew("7D.jpg")
cards(27):=Pic.FileNew("7H.jpg")
cards(28):=Pic.FileNew("7S.jpg")
cards(29):=Pic.FileNew("8C.jpg")
cards(30):=Pic.FileNew("8D.jpg")
cards(31):=Pic.FileNew("8H.jpg")
cards(32):=Pic.FileNew("8S.jpg")
cards(33):=Pic.FileNew("9C.jpg")
cards(34):=Pic.FileNew("9D.jpg")
cards(35):=Pic.FileNew("9H.jpg")
cards(36):=Pic.FileNew("9S.jpg")
cards(37):=Pic.FileNew("QC.jpg")
cards(38):=Pic.FileNew("QD.jpg")
cards(39):=Pic.FileNew("QH.jpg")
cards(40):=Pic.FileNew("QS.jpg")
cards(41):=Pic.FileNew("AC.jpg")
cards(42):=Pic.FileNew("AD.jpg")
cards(43):=Pic.FileNew("AH.jpg")
cards(44):=Pic.FileNew("AS.jpg")
cards(45):=Pic.FileNew("JC.jpg")
cards(46):=Pic.FileNew("JD.jpg")
cards(47):=Pic.FileNew("JH.jpg")
cards(48):=Pic.FileNew("JS.jpg")
cards(49):=Pic.FileNew("KC.jpg")
cards(50):=Pic.FileNew("KD.jpg")
cards(51):=Pic.FileNew("KH.jpg")
cards(52):=Pic.FileNew("KS.jpg")
x1:=300
y1:=400
x2:=400
y2:=400
p1Randomcard:=Rand.Int(1,52)
Pic.Draw(cards(p1Randomcard),x1,y1,picMerge)
p1Randomcard:=Rand.Int(1,52)
Pic.Draw(cards(p1Randomcard),x1,y1,picMerge)
p2Randomcard:=Rand.Int(1,26)
Pic.Draw(cards(p2Randomcard),x2,y2,picMerge)
cardvalue(1):=10
cardvalue(2):=10
cardvalue(3):=10
cardvalue(4):=10
cardvalue(5):=2
cardvalue(6):=2
cardvalue(7):=2
cardvalue(8):=2
cardvalue(9):=3
cardvalue(10):=3
cardvalue(11):=3
cardvalue(12):=3
cardvalue(13):=4
cardvalue(14):=4
cardvalue(15):=4
cardvalue(16):=4
cardvalue(17):=5
cardvalue(18):=5
cardvalue(19):=5
cardvalue(20):=5
cardvalue(21):=6
cardvalue(22):=6
cardvalue(23):=6
cardvalue(24):=6
cardvalue(25):=7
cardvalue(26):=7
cardvalue(27):=7
cardvalue(28):=7
cardvalue(29):=8
cardvalue(30):=8
cardvalue(31):=8
cardvalue(32):=8
cardvalue(33):=9
cardvalue(34):=9
cardvalue(35):=9
cardvalue(36):=9
cardvalue(37):=12
cardvalue(38):=12
cardvalue(39):=12
cardvalue(40):=12
cardvalue(41):=14
cardvalue(42):=14
cardvalue(43):=14
cardvalue(44):=14
cardvalue(45):=11
cardvalue(46):=11
cardvalue(47):=11
cardvalue(48):=11
cardvalue(49):=13
cardvalue(50):=13
cardvalue(51):=13
cardvalue(52):=13
strint(intstr(cardvalue))=cardvalue
Draw.Text(cardvalue,320,360,font2,27)
Sponsor Sponsor
TheOneTrueGod
Posted: Sun Jun 11, 2006 8:01 pm Post subject: (No subject)
A part of me dies inside every time someone does a card game without using math...
A lot of that can be easily optimized, simply by using div and mod
code:
strint(intstr(cardvalue))=cardvalue
This line does nothing. In fact, its a comparison anyways, so it'll give you an error... not to mention that cardvalue is an array, so it won't work anyways...
Allright, I wrote up a blurb on this in the [Turing FAQ], though I can't remember if I touched on dealing. Here goes
code:
for i : 0..51 %because an array from 0 to 51 makes math easier
cardvalue(i) := i
end for
Now, just shuffle that around. Please use a procedure for that... Shouldn't be too hard to figure out how to randomize where the cards go.
And then give each player a flexible array (because the number of cards for each player fluctuates) and alternate between giving each player a card. Use a procedure for the dealing too... You'll probably have to use the two players 'hands' as a global array in order to get the flexible arrays working properly.
From there, You can probably work it out for yourself. Post if you need more help.
Oh, and the loading pictures can be done easily with math as well. Use constants to declare some clever strings, and let for loops do the work for you. (Learn how to concatenate strings though)
gilbamy
Posted: Sun Jun 11, 2006 8:10 pm Post subject: (No subject)
i need each player to start off with 26 cards and then it needs to show below the card like say there was a king there in nedds to show the value of that card right so how do i get it to show up and dealing is confusing me
Bored
Posted: Sun Jun 11, 2006 8:12 pm Post subject: (No subject)
You may want to look into records for this one. You could have an array of records, each record holding the card value, and picture (suit can be excluded for this game). Then try using a loop to create all the necesary cards, probably a loop of 4 for each suit and a loop of 13 for the cards. Then what you do is create a deck array of 52 cards (array of records).
Now that you have a deck you need to shuffle it. There's meny ways to do this, the easiest is probably to have a large loop that randomly chooses two cards and switches them. Once there shuffled dealings simply putting the cards into two seperate arrays, one for each player. These will need to be flexible arrays (well atleast that makes it easier and better coding) as the amount of cards changes. Now the rest is up to you.
gilbamy
Posted: Sun Jun 11, 2006 8:31 pm Post subject: (No subject)
i am so lost i need it in like simple english i am really bad with turing
TheOneTrueGod
Posted: Sun Jun 11, 2006 8:36 pm Post subject: (No subject)
Go to the [Turing Walkthrough] and read up on the concepts that I bolded in my post. If you know how to use em, and you have a grade 10 math education, you should be able to figure it out with a bit of thought.
gilbamy
Posted: Sun Jun 11, 2006 8:54 pm Post subject: (No subject)
i may be in grade 10 but that dose not mean i listen well
TheOneTrueGod
Posted: Sun Jun 11, 2006 8:59 pm Post subject: (No subject)
Yarr, I just threw grade 10 as a random number. As long as you are willing to sit down and think about the problem, you can easily solve it. Not knowing the language is not an excuse, especially with a language like Turing, because theres tonnes of help on this site, and plenty in the help file.
Sponsor Sponsor
jamonathin
Posted: Sun Jun 11, 2006 9:02 pm Post subject: (No subject)
gilbamy wrote:
i may be in grade 10 but that dose not mean i listen well
Then why bother helping? You get out of life what you put into it - ever heard of garbage in, garbage out?
gilbamy
Posted: Mon Jun 12, 2006 2:02 pm Post subject: (No subject)
Alright i have figured out this so far that i need to use this code for p1 and p2 but i don't know where to go after this
code:
for i :1..26
loop
p1Randomnumber:=Rand.Int(1,52)
but what else do i add to this
Delos
Posted: Mon Jun 12, 2006 3:34 pm Post subject: (No subject)
Hmm...looking at your origial code, you have many of the necassary elements to solve your problem, but not quite implemented in the right way. If you reread TOTG's post, you'll notice that he does touch upon some important concepts that you ought to include to get your programme working efficiently.
As for what you have so far...
Using a loop nested in a for loop is not a bad idea. If I understand where you're going with this, you intend to pick a card (using Rand.Int()) and if that card has not already been dealt, then you'll add it to the player's stack?
Translate that into a bit of pseudocode:
psueudo:
- player requires 26 cards
- pick a card at random
- if card has not already been dealt, then give this card to player
- repeat for all 26 cards
Right now you need to figure out how to do the 'if card...' part.
If we take a look at your original code:
code:
var p1Randomcard,x1,x2,y1,y2,p2Randomcard:int
var cards:array 1..52 of int
var p1deck,p2deck :array 1..26 of int
These could all be used to your advantage. The array 'cards' could potentially be used as a set of indicators to note which cards have been dealt and which ones haven't (as a side note, if you do decide to do this, then I would rename the array 'dealt_cards' or something to that effect). Now you could set it up such that (for instance) a value of 0 means the card has not been dealt and a value of 1 means it has been. (Or you could change the array type to boolean and make your life even simpler).
Now, back to the if clause. You'll need to choose a card (using Rand.Int()) then see if that value in the deck (cards) has been taken or not (0 or 1). If it has not, then you can add that value to either p1deck or p2deck, depending on which you're using.
You should note that since you're using arrays of ints, you'll have to figure out how to indicate what suit the card just chosen is!
You're on the right track now, so keep at it and see this through. Once you get your basic algorithm working, you should think about procedurizing it in some form - but that will be for once it's working.
If any of this post did not make sense, then hit up the [Turing Walkthrough] again and look for the tuts on the topics mentioned.[/code]
Clayton
Posted: Mon Jun 12, 2006 8:32 pm Post subject: (No subject)
dont worry so much about the suits for now though, as war doesnt care what suit your card is, just get the shuffler and dealer working, if you are having trouble figuring out a shuffling algorithm, search "shuffle" or something to that effect in the Turing forums:D
gilbamy
Posted: Tue Jun 13, 2006 12:28 pm Post subject: (No subject)
alright so you want me to do something like this then right i changed one of my var and that one was the p1deck and the p2 deck they got changed to deckcheck
code:
for i : 1..26
loop
p1Randomcard:=Rand.Int(1,52)
exit when checkdeck1(p1Randomcard)=0
end loop
x1:=300
y1:=400
Pic.Draw(cards(p1Randomcard),x1,y1,picMerge)
end for
Delos
Posted: Tue Jun 13, 2006 3:26 pm Post subject: (No subject)
That's a great start, next you'll want to add to that so that you'll be able to keep track of which cards have been assigned to each player. Currently, you've picked all 26 cards and displayed them, but what if you needed to query which cards were held by each player? In that case you'll need to incorporate your player1_deck and player2_deck arrays.
BTW, please do indent your code before posting it. It make reading it so much easier!
gilbamy
Posted: Tue Jun 13, 2006 7:47 pm Post subject: (No subject)
well for this project i have to have a screen appear when i type in h and p1 or p2 and i will see there hands but i am not sure on how to do that though