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

Username:   Password: 
 RegisterRegister   
 Need help with 2D array problem
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Paul




PostPosted: Thu Apr 01, 2004 6:04 pm   Post subject: Need help with 2D array problem

Im suppose to make a program like the carnival ones, where you toss 10 coins onto a mat, the mat is numbered, so you get the same amount of points of the sum of the squares that the coins landed on, I can't seem to get the scoring right, I went to sleep at 3 am today lol, anyone help me find the problem? if you want to see how the squares are originally numbered more clearly, just look at the text file. Also if anyone has any suggestions as to how to make the check easier (other than restructuring my extra if statements), please post. oh yea X means the coin landed there once, Y means the coin landed there twice.


board.txt
 Description:

Download
 Filename:  board.txt
 Filesize:  76 Bytes
 Downloaded:  128 Time(s)


pennies.t
 Description:

Download
 Filename:  pennies.t
 Filesize:  2.03 KB
 Downloaded:  111 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Thu Apr 01, 2004 7:18 pm   Post subject: (No subject)

Here's a way easier sol'n to it...

Have 2 2-dim arrays. One of them handles the scores...so, you'd put the text file stuff into that one.

The second one handles the scoring. You do the tossing of coins into that one.

Then, you do something like this:
- check coinArray (using a, b)
- if an X is found, then score := 1 * numArray (a, b)
- else if a Y is found, then score := 2 * numArray (a, b)
- display score.

Methinks your problem was that your checking was too lengthy and inefficient, thus you may have missed a couple of boxes.

Using 2 arrays means you can increase/decrease the size of the boards and still get everything you need!
Paul




PostPosted: Thu Apr 01, 2004 7:24 pm   Post subject: (No subject)

omg thank you thank you thank you, that was the most obvious way of checking it, yet I hadn't thought about it! damn some kind of brain block, but then Im so spaced out, its like Im typing and I dunno I was typing...
Paul




PostPosted: Thu Apr 01, 2004 7:45 pm   Post subject: (No subject)

Ok I just figured it out, there was nothing wrong with my previous really tedious checking code I just figured it out... thanx for helping me reduce 50 lines to 6 lines though, thanx alot. But it all came down to the right checking but wrong display,
this code
code:

 for a : 1 .. 6
        for b : 1 .. 6
            if b = 1 then
                x := 195
            end if
            Font.Draw (board (a, b), x, y, font, black)
            x += 67
        end for
        y -= 66
    end for

goes after
code:

 if board (px, py) = "X" then
        board (px, py) := "Y"
    end if
    if board (px, py) not= "X" and board (px, py) not= "Y" then
        board (px, py) := "X"
    end if

this code, b4 that, they were switched, so the last X wouldn't get drawn, and I would think I got the freaking scoring wrong. God damn it I wish there was a way to stop making these damned stupid tiny mistakes that are so freaking time consuming.
Delos




PostPosted: Thu Apr 01, 2004 8:51 pm   Post subject: (No subject)

Oh, but there is!

It's called "not staying up until 3 am unless you're not going anywhere the next day (well, that day by then)"

Wink
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  [ 5 Posts ]
Jump to:   


Style:  
Search: