How are arrays used?


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2005
    Location
    Hendersonville NC
    Posts
    14

    Default How are arrays used?

    I am clueless as to how one uses arrays. My idea is to program a pic to do the Bingo game. Does anyone have any ideas on this?

  2. #2
    Join Date
    May 2007
    Posts
    26


    Did you find this post helpful? Yes | No

    Wink Thats a pretty general question.

    Quote Originally Posted by NO2K View Post
    I am clueless as to how one uses arrays. My idea is to program a pic to do the Bingo game. Does anyone have any ideas on this?

    Alright thats a general question but I'll try and answer.

    first off choose a length of array and type of data.

    nameofarray VAR unitsize[numberofunits]

    lets say you want row one to be 12 bytes wide.

    rowone var byte[12]

    Now okay thats all fine and dandy right? Now you want to populate it.

    There are two ways you can go one segment at a time like this.

    rowone[0] = "b"

    Or you can populate an array serially.

    serin pin,baud,[ STR rowone\1]

    this would wait until one byte is recieved and put it in the first position in the array. Lets say you wanted to put it in the second position.


    serin pin,baud,[ STR rowone(1)\1]

    This would take one byte serially, and transfer it into the second unit of the array.

    ill give one more example this time using more then one byte.

    serin pin,baud,[ STR rowone(6)\6]

    Now this will take the first six bytes it recieves, and will put it in the array starting at the 7th byte, basically byte one will go in rowone[5], byte two rowone[6], all the way up to rowone[11]

    Hopefully that helps.
    Last edited by gandora; - 29th May 2007 at 07:04. Reason: bad explanation.

  3. #3
    Join Date
    Dec 2005
    Location
    Hendersonville NC
    Posts
    14


    Did you find this post helpful? Yes | No

    Default Using Arrays

    Hi Gandora: Thanks for the reply. I was thinking I could make an array large enough to hold all the bingo numbers, then use the random number command to pick one of those spots, but after reading the number in a specific location in the array, store the number someplace else, rewrite it to zero (because it has already been used), then go to the next number. When bingo is reached, then need to go back and verify all the numbers that were used. Not real sure how to do that, but guess I'll have to experiment.
    regards, NO2K

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by NO2K View Post
    Hi Gandora: Thanks for the reply. I was thinking I could make an array large enough to hold all the bingo numbers, then use the random number command to pick one of those spots, but after reading the number in a specific location in the array, store the number someplace else, rewrite it to zero (because it has already been used), then go to the next number. When bingo is reached, then need to go back and verify all the numbers that were used. Not real sure how to do that, but guess I'll have to experiment.
    regards, NO2K
    Use a bit array instead of whole bytes...(warning, not 'REAL' code here)...using the bits as 'flags' as to whether or not a number has been called...

    b var bit[10]
    i var bit[10]
    n var bit[10]
    g var bit[10]
    o var bit[10]
    'all initially set to zero's

    'b1 is called
    b[1] = 1
    'b1 is set to 1, therefore it's used

    if b[2] = 1 then goto it's_used
    if b[2] = 0 then goto it's_not_used

    The only problem with this is you'll have to use 2 random numbers, one to pick which letter, and one to pick which number 'inside' that letter...

  5. #5
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    Use a bit array instead of whole bytes
    Nice idea

    Quote Originally Posted by skimask View Post
    The only problem with this is you'll have to use 2 random numbers, one to pick which letter, and one to pick which number 'inside' that letter...
    Not really, if there are 10 possible numbers for each letter. Use random number between 0 and 59. Then "tens" place becomes B·I·N·G·O (0·1·2·3·4·5), and the "ones" place becomes 1·2·3·...9·10. The algorithm would just need to add 1 to the the value. If there are more than 10 numbers for each letter, then it changes things. I just can't remember how many numbers each letter has. If it is a multiple of 10, you can extend the concept, so 0-19 is B1-B20, 20-39 is I1-I20, etc.

    Extending your idea further, you could use an array of bytes, that will encompass all possible numbers. If there are 6*30=180 possibilites, use:

    Total var BYTE[23] '180+4

    This puts all the possibilities in one continious block.
    Then, with one random number you can access an individual bit with

    Total.0(bit) 'Where bit is a number between 0 and 179, for 180 possible options. Here's the explaination for those who need it.

    Then code the algorithm to 'interpert' the bit as B5, I2, N7, etc.

    SteveB
    Last edited by SteveB; - 31st May 2007 at 01:26.

  6. #6
    Join Date
    Dec 2005
    Location
    Hendersonville NC
    Posts
    14


    Did you find this post helpful? Yes | No

    Default Bingo

    My thanks to Skimask and Steve B for their advice. For Bingo, there really is no need to use the letters. Each letter has 15 places, i.e. B goes from 1 to 15, I goes from 16 to 30, N 31 to 45, G 46 to 60, and finally O from 61 to 75. Of course, as with any other problem, there are probably a lot of ways to do the program, but I like the idea of bit arrays and will try to experiment with it.

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. Beginner trying to use arrays
    By captain in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 3rd November 2007, 07:20
  3. How to use Arrays Using Pic Basic Pro(need help)
    By MrSafe in forum mel PIC BASIC Pro
    Replies: 26
    Last Post: - 17th July 2007, 21:56
  4. SerOut and Arrays
    By shawn in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 4th July 2005, 17:32
  5. storing arrays and reading arrays
    By Yue in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 5th March 2004, 22:03

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts