Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Poker Code Messed Up
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
berf




PostPosted: Tue Jun 20, 2006 3:28 pm   Post subject: Poker Code Messed Up

I have a poker program started and have tried to debug it on my own but I can't find the problem. This is just the start, using mod and div to determine what the card is and what the suit of it is. I still need to add the different kind of hands but I should be able to do that on my own. Any help on this problem is greatly appreciated.


FINAL Clean Version.t
 Description:
here is my whole program

Download
 Filename:  FINAL Clean Version.t
 Filesize:  3.51 KB
 Downloaded:  59 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Bored




PostPosted: Tue Jun 20, 2006 4:00 pm   Post subject: (No subject)

Well first off welcome to CompSci. Now you say you have a problem, well what is your problem? We can't help you fix it if we don't know what it is. Asweel It's much more helpfull if you post the source code (remember to use the [code ] tags) so that we can see your program. Any information you can give us into your problem or your code will help us give you an answer.
Bored




PostPosted: Tue Jun 20, 2006 4:01 pm   Post subject: (No subject)

Well that was weird, the download didn't show the first time.
TheOneTrueGod




PostPosted: Tue Jun 20, 2006 6:45 pm   Post subject: (No subject)

Allright, first things first: Thank you for using the mathematical method You don't know how many people don't use it, and should. (Or maybe you do if you've seen some of my previous posts) That being said, I ran your program, and It took me a few runs to find your error. It claims that a certain variable doesn't have a value (playershand (show, h)
)

The problem is probably because you didn't initiate it. Using some Super duper debugging techniquesTM I found out that the error happened at (1,2) -- First player, second card. After tracing through your code, the only logical reason is that something went wrong with your deal procedure. You'll have to look more into that on your own though. In the future, please post a better description, rather than "I had a problem", as it'll help us help you.

This is a good example of why parameters are good. It would be MUCH easier to trace the variable in question if you passed it as a parameter to your procedures.

Now, theres one issue with your code that I saw:
code:

procedure Face_Cards
    for fc : 11 .. 14
        if fc = 11 then
            face (fc) := "Jack"
        elsif fc = 12 then
            face (fc) := "Queen"
        elsif fc = 13 then
            face (fc) := "King"
        elsif fc = 14 then
            face (fc) := "Ace"
        end if
    end for
end Face_Cards

Why? Why not just:

code:
face(11) := "Jack"
face(12) := "Queen"
face(13) := "King"
face(14) := "Ace"


or even better,
code:
const fName : array 11..14 of string := init("Jack","Queen","King","Ace")
for i : 11..14
face(i) := fName(i)
end for


Other than that, nice work with getting the cards working on a 0-51 system, though the procedures could use a little work. Try getting them to work with parameters, as it may make your life easier.
berf




PostPosted: Tue Jun 20, 2006 8:28 pm   Post subject: (No subject)

Im not sure how exactly I would use procedures in this. I'm not really new to turing, ive done it the last 2 years but my teacher doesnt really teach, or give help unless you're one of his wonder students. So I've done most of turing on my own. Hence I'm not familiar with all the short cuts as you could tell with my face card procedure. I had most of this program working before but without suits, and I didn't really do that well so i restarted. So any help on how to use the parameters would be greatly appreciated.
TheOneTrueGod




PostPosted: Tue Jun 20, 2006 9:38 pm   Post subject: (No subject)

Well, preferably read the [Turing Walkthrough]. It has some info on procedures + functions + parameters.
I'll write out some pseudo code for ya for a couple useful procedures.

code:

proc Shuffle (var deck : array 0..* of int)
   %Declare a temporary integer, to be able to shuffle properly
   %For each card in the deck, switch it with another random card
end Shuffle
proc DealCard (var hand : array 0..* of int,var cardsInHand : int,deck : array 0..* of int,var topOfDeck : int)
   %Increment cardsInHand
   %Set the highest element (cardsInHand) of the "hand" array to the top of the deck, if possible.
   %decrement the topOfDeck integer
end DealCard


If you've read the article it should be clear on what to do. If you have any other problems, feel free to post em up. Good luck.
berf




PostPosted: Thu Jun 22, 2006 1:13 pm   Post subject: (No subject)

I found the problem as to why i was getting a variable has no value.
code:
procedure Deal

    for d : 1 .. NUM_OF_PLAYERS
        for card : 1 .. NUM_CARDS
            loop
                randint (num, 0, 51) % Take random card out of shuffled deck puts it into the players hand
                exit when check_deck (num) = true
            end loop
            check_deck (num) := false            %Now the card is not in the deck

            playershand (d, card) := deck (num)          %Assigns the card to the players hand

        end for
    end for
end Deal

so on my original i just when
code:

randint (num,0,51)
if check_deck(num) = true then
check_deck := false
playershand(d,card) := deck(num)
end if

So i had no way if the same number was picked twice to re-select a new number. Just if anyone was wondering the solution to it
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: