Computer Science Canada War |
Author: | gilbamy [ 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.
|
Author: | TheOneTrueGod [ Sun Jun 11, 2006 8:01 pm ] | ||||
Post 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
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
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) |
Author: | gilbamy [ Sun Jun 11, 2006 8:10 pm ] |
Post 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 |
Author: | Bored [ Sun Jun 11, 2006 8:12 pm ] |
Post 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. |
Author: | gilbamy [ Sun Jun 11, 2006 8:31 pm ] |
Post subject: | |
i am so lost i need it in like simple english i am really bad with turing |
Author: | TheOneTrueGod [ Sun Jun 11, 2006 8:36 pm ] |
Post 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. |
Author: | gilbamy [ Sun Jun 11, 2006 8:54 pm ] |
Post subject: | |
i may be in grade 10 but that dose not mean i listen well |
Author: | TheOneTrueGod [ Sun Jun 11, 2006 8:59 pm ] |
Post 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. |
Author: | jamonathin [ Sun Jun 11, 2006 9:02 pm ] |
Post 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? |
Author: | gilbamy [ Mon Jun 12, 2006 2:02 pm ] | ||
Post 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
but what else do i add to this |
Author: | Delos [ Mon Jun 12, 2006 3:34 pm ] | ||||
Post 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:
Right now you need to figure out how to do the 'if card...' part. If we take a look at your original code:
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] |
Author: | Clayton [ Mon Jun 12, 2006 8:32 pm ] |
Post 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 |
Author: | gilbamy [ Tue Jun 13, 2006 12:28 pm ] | ||
Post 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
|
Author: | Delos [ Tue Jun 13, 2006 3:26 pm ] |
Post 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! |
Author: | gilbamy [ Tue Jun 13, 2006 7:47 pm ] |
Post 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 |
Author: | gilbamy [ Tue Jun 13, 2006 8:05 pm ] | ||
Post subject: | |||
iam having troubles with my dealing line of code here because it says that its the wrong type for my checkdeck1:=1 heres my code for dealing and checkdeck is an array 1..52 of int and i have tried changing the type then my exit when line gets messed up alright so i have the checkdeck1 to equal 1 because i need a value for that one but when i change it from being an array of int the exit when line becomes wrong i am not sure what to do here
|
Author: | Bored [ Tue Jun 13, 2006 8:41 pm ] | ||
Post subject: | |||
Well I still think your going about this nthe wrong way and making a simple problem overly complicated. First you should have a simple record, that contains both the card value and suit. You would then have three arrays of cards, one deck, and two hands. The deck would be a set 52 card size, whereas the hands would be flexible arrays that start at 26 cards each. You'd first use a shuffle procedure which would look something like this
Now that your cards are shuffled you simply have to deal them as is, no complicated algorithms, or consant checking of the arrays, you don't even have to take turns when dealing, just simply throw the first 26 to player ones hand, and the second 26 to player twos. I'd suggest using flexible arrays for the players hand though as they will change in size throughout the game, or atleast that's how I remember it being played. |
Author: | gilbamy [ Tue Jun 13, 2006 8:43 pm ] |
Post subject: | |
but when you play cards you deal one to yourself then one to the other player not just 26 to yourself then 26 to them |
Author: | Bored [ Tue Jun 13, 2006 8:53 pm ] |
Post subject: | |
Yes but does that matter if the cards are randomized anyways. Do you think someone is going to complain about it, I mean if they can read your code then they'd undertand that it's easier and does not compromise the legitimization of the randomization of the cards. In other words, the deck can't be stacked by a player so why does turn based dealing matter? |
Author: | gilbamy [ Tue Jun 13, 2006 8:57 pm ] |
Post subject: | |
i dunno thats what i am suppost to do anyway i think my code is not working because i need an array with something like deck2 right so that it reconizes when its used a card or not but how do i do this kinda stuff though |
Author: | Bored [ Tue Jun 13, 2006 9:02 pm ] |
Post subject: | |
Please read over my method, it works and is rather simple though you may need to check the Turing Walkthrough for information on records and flexible arrays if you do not already know them. |
Author: | gilbamy [ Tue Jun 13, 2006 9:03 pm ] |
Post subject: | |
alright i read my note it says that i can just deal them to one player at a time alright but how do i do that and my oringnl code srill does not work |
Author: | gilbamy [ Tue Jun 13, 2006 9:19 pm ] |
Post subject: | |
well with that code i have 5 problems the line var temp :cards it says something like compile time excepted. Then var a,b :int its like var expected .. then there is Randomcard(a,1,52) Randomcard(b,1,52)these two lines where it is like Randomcard cannot have subscripts but if i put into an array it causes 3 more problems |
Author: | Bored [ Tue Jun 13, 2006 9:20 pm ] | ||||||
Post subject: | |||||||
Well look at this first you declare checkdeck1 as an array:
Then you attempt to use it as an int:
Then when you make checkdeck1 an int, but this cause problems as your trying to use it as an array here
from the looks of your code checkdeck should be neither a int or an array of ints but a procedure that returns 0 if the card is not found. The way you seem to be doing this is by randomly choosing a card and then checking if that card has been already dealt, if not then dealing it. This is sorta fuzzy, unstable, and unpredicatable logic sorta of like stupid sort. i would recommend you relook over your logic, rather then randomly choosing cards, I would recomend you shuffle the deck then deal. I have even givin you a shuffle algorithm. i cannot help you further from what you have given me as your intentions are unclear through your code. |
Author: | gilbamy [ Tue Jun 13, 2006 9:22 pm ] |
Post subject: | |
i am going by what my teach told me when he was playing chess today in class |
Author: | Bored [ Tue Jun 13, 2006 9:27 pm ] | ||
Post subject: | |||
gilbamy wrote: well with that code i have 5 problems the line var temp :cards it says something like compile time excepted.
Well that's probably becuase you have not yet created a cards type. Add this at the top of your program.
After that you'll need to set the card values and suits but I'll leave that up to you. gilbamy wrote: Then var a,b :int its like var expected
Well that error I beleive stems from the error at the previous line and the way turing handled it. gilbamy wrote: .. then there is Randomcard(a,1,52)
Randomcard(b,1,52)these two lines where it is like Randomcard cannot have subscripts but if i put into an array it causes 3 more problems Well first of I had randint (a,1,52) not Randomcard whatever that is (whic I guess is some variable). Also i hope you copied the procedure and didn't try to incorporate my code into your or replace it. |
Author: | gilbamy [ Tue Jun 13, 2006 9:55 pm ] | ||
Post subject: | |||
well i got my oringanl code to stop having errors but now it the cards don't appear
|
Author: | gilbamy [ Tue Jun 13, 2006 10:59 pm ] | ||
Post subject: | |||
okay well i got my cards to appear but they are douvles of the same cards like same value and type how do i stop that from happening here is all my code
|
Author: | Clayton [ Wed Jun 14, 2006 6:05 pm ] | ||||
Post subject: | |||||
my heart breaks when i see code like this:
y not follow TheOneTrueGod's suggestion? if not do a nested for loop ex.
not as nice as TOTG's but gets the job done, do something similiar with the pictures (though u would only need one for loop) and your code would be much easier to read |
Author: | Clayton [ Wed Jun 14, 2006 6:07 pm ] | ||
Post subject: | |||
oops, also if you arent going to use a flexible array, you will need the nested for loops like such:
|
Author: | Bored [ Wed Jun 14, 2006 6:40 pm ] | ||
Post subject: | |||
Tsk, tsk, tsk. That won't work, that would make card 2 suit 1 be overwritten by card 1 suit 2. I think though that we should let glibany figure out why as he has had much information given to him, and we all know that they must learn to do on there own no matter how lost they may be. |
Author: | gilbamy [ Sun Jun 18, 2006 11:54 pm ] | ||
Post subject: | |||
i do believe i have what i need for dealing my cards
whats the point in telling people not to help me if you don't want to help me then don't post on my topics and also if i don't get help i well be even more confused then i already i' am |
Author: | gilbamy [ Sun Jun 18, 2006 11:55 pm ] | ||
Post subject: | |||
gilbamy wrote: i do believe i have what i need for dealing my cards
whats the point in telling people not to help me if you don't want to help me then don't post on my topics and also if i don't get help i well be even more confused then i already i' am by the way i'am not a guy so yeah |
Author: | Bored [ Mon Jun 19, 2006 10:43 am ] | ||||
Post subject: | |||||
gilbamy wrote: i do believe i have what i need for dealing my cards
Well actually that code is very flawed. You see the way you are doing it you could potentially never finish dealing the cards. It's about as useful as Stupid Sort, though a bit more likely to have a faster execution. You see with the fact that the dealing must happen when some condition is met at random then you have no idea how long it will take, it could take a second, an hour, a day. how about this you creat an array of integers with numbers from 1 to 52. Your have a sorting procedure that looks something like this.
You'd call your procedure to sort that array. Once it's sorted the first 26 cards are for player one, and the second 26 are for player two. You see the integers each index hold are from 1 to 52 therefore they are the indexes of the cards so say cardIndex (1) = 5 then player one would reseave card (cardIndex (1)) which is 5. I'd suggest using a loop for this. gilbany wrote: whats the point in telling people not to help me if you don't want to help me then don't post on my topics and also if i don't get help i well be even more confused then i already i' am
Everyone here is helping you, we are trying to give you as much instruction without actually telling you the ANSWER. You see by telling you the answer we'd be doing it for you. gilbany wrote: by the way i'am not a guy so yeah
And your point is?? |
Author: | gilbamy [ Mon Jun 19, 2006 8:14 pm ] |
Post subject: | |
you called me a guy in your one post |
Author: | Bored [ Mon Jun 19, 2006 8:45 pm ] |
Post subject: | |
Oh, OK, well sorry about that but I tend to assume that people on these forums are guys as the chances are 100-1 that they are. |