1. Assigning values to bitmaps in a sequence :)
- Posted by David Roach <roachd_76 at YAHOO.COM> Dec 02, 1999
- 365 views
Hello all, This stuff is finally starting to make since to me. Just a little problem. I am working on my first program, Black Jack. I have 52 bitmaps named "1-52.bmp". These are loaded into a sequence Deck. Now how do assign values to the elements in Deck. Lets say the ace of hearts is loaded into Deck[1] how do I assign it a value of 1 and still keep the bitmap loaded into that element. Or would I use another element like Deck[2] for the value of the card. Basicaly I need to have a value associated with a Bitmap in a sequence. Any help would be greatly apriciated. roachd_76 at yahoo.com
2. Re: Assigning values to bitmaps in a sequence :)
- Posted by Roderick Jackson <rjackson at CSIWEB.COM> Dec 02, 1999
- 364 views
David Roach wrote: >Hello all, >This stuff is finally starting to make since to me. Just a little problem. >I am working on my first program, Black Jack. I have 52 bitmaps named >"1-52.bmp". These are loaded into a sequence Deck. Now how do assign values >to the elements in Deck. Lets say the ace of hearts is loaded into >Deck[1] how do I assign it a value of 1 and still keep the bitmap loaded >into that element. Or would I use another element like Deck[2] for the >value of the card. Basicaly I need to have a value associated with a Bitmap >in a sequence. Any help would be greatly apriciated. David, My suggestion would be to use a second sequence for your values. If your card is stored in Deck[1], put the value of it in DeckValue[1]. For a game like yours, this is probably the most efficient way to do it. If for some reason you need to have them together, you can take this approach... -- instead of Deck[1] = {...} -- bitmap of the card -- use Deck[1] = {value, {...}} -- value, AND the bitmap -- now you access the value with Deck[1][1], -- and the bitmap with Deck[1][2]. You can use -- constants to simplify things: VALUE=1, BITMAP=2 -- so that you access Deck[1][VALUE] and -- Deck[1][BITMAP] Rod Jackson
3. Re: Assigning values to bitmaps in a sequence :)
- Posted by Everett Williams <rett at GVTC.COM> Dec 02, 1999
- 377 views
- Last edited Dec 03, 1999
On Thu, 2 Dec 1999 17:46:09 -0500, David Roach <roachd_76 at YAHOO.COM> wrote: >Hello all, >This stuff is finally starting to make since to me. Just a little problem. >I am working on my first program, Black Jack. I have 52 bitmaps named >"1-52.bmp". These are loaded into a sequence Deck. Now how do assign values >to the elements in Deck. Lets say the ace of hearts is loaded into >Deck[1] how do I assign it a value of 1 and still keep the bitmap loaded >into that element. Or would I use another element like Deck[2] for the >value of the card. Basicaly I need to have a value associated with a Bitmap >in a sequence. Any help would be greatly apriciated. > >roachd_76 at yahoo.com It is the first element of deck and may be referred to by deck[1]. In general, if you use any of the algorithms on this list that produce a shuffled sequence whose content is the numbers 1 thru 52 in no particular order, you will have the index into the deck sequence. If shuffled is the sequence representing the shuffled deck, then warning: untested code atom card object image sequence deck,shuffled .... for x = 1 to 52 do card = shuffled[x] -- take a card image = deck[card] -- select an image related to that card ... --- do what ever you need to display the image end for -- do it again This would display the 52 shuffled cards. The confusion you have seems to be between the index and the contents of the sequence. Though both have the range 1 thru 52, the index is merely a pointer to the currently referred to element of the sequence that contains one of the values 1 thru 52. If that doesn't confuse you further, nothing will. Everett L.(Rett) Williams rett at gvtc.com
4. Re: Assigning values to bitmaps in a sequence :)
- Posted by David Roach <roachd_76 at YAHOO.COM> Dec 02, 1999
- 361 views
- Last edited Dec 03, 1999
This pretty much what I have and what I think i can do with it. sequence Deck, cards Deck = {} -- make theDeck empty cards = {} for i = 1 to 52 do cards = sprintf( "%d.bmp", {i} ) -- build the cards Deck &= loadBitmapFromFile( cards ) -- append the bitmap handle to the list end for I didn't write this code Dave Cunny did. I understand what it does I think. When all the cards are loaded into Deck I have something like this... Deck[1] Deck[2] ..... Deck[51] Deck[52] The way I have my bmp names is that 1.bmp is a ace of hearts 2.bmp is the 2 of hearts all the way up to the king of hearts and then it starts again for a differnt suit. I believe I can add another element to the first in Deck named "value" or something. and use that to proces the cards value. I hope this is right. So this is what I would end up with. Deck[1(AH)][2(1 or 11)] Deck[2(2H)][2(2)] Deck[3(3H)][3(3)] And so on up to the 52nd card. If this is right someone let me know. I'm about get this stuff under my belt. Then I won't be asking so many questions. Thanks for all your help. roachd_76 at yahoo.com
5. Re: Assigning values to bitmaps in a sequence :)
- Posted by Everett Williams <rett at GVTC.COM> Dec 03, 1999
- 382 views
On Thu, 2 Dec 1999 22:15:37 -0500, David Roach <roachd_76 at YAHOO.COM> wrote: >This pretty much what I have and what I think i can do with it. > >sequence Deck, cards > Deck = {} -- make theDeck empty > cards = {} > > for i = 1 to 52 do > > cards = sprintf( "%d.bmp", {i} ) -- build the cards > Deck &= loadBitmapFromFile( cards ) -- append the bitmap >handle to the list > end for >I didn't write this code Dave Cunny did. I understand what it does I think. >When all the cards are loaded into Deck I have something like this... Actually, this is a minor point but important point. All the file handles to the bmp's are loaded into Deck rather than the bmp's themselves. >Deck[1] ---file handle for the ace of hearts >Deck[2] ---file handle for the two of hearts >..... --- no idea what your suit order is >Deck[51] ---file handle for the queen of spades >Deck[52] ---file handle for the king of spades >The way I have my bmp names is that 1.bmp is a ace of hearts 2.bmp is the >2 of hearts all the way up to the king of hearts and then it starts again >for a differnt suit. I believe I can add another element to the first in >Deck named "value" or something. and use that to proces the cards value. >I hope this is right. So this is what I would end up with. Since you are going to have an alternate value for aces, it would be wise to balance the array, by providing alternate values for all cards. It will make it easier to refer to the regular values of other cards when referring to the alternate value of an ace. -- TESTED CODE sequence card_values,deck -- build value sequence deck = repeat(0,52) card_values = repeat({0,0},13) -- initialize card_values[1] = {1,11} -- set ace to 1 or 11 for x =2 to 9 do card_values[x] = {x,x} -- set cards 2 thru 9 to (2 or 2) thru (9 or 9) end for card_values[10..13] = repeat({10,10},4) -- set 10 thru king to 10 or 10 for c = 1 to 52 do -- set a sequence into deck that represents deck[c] = c -- bmp loading - the bmp loading end for -- program should be put here in place of this for loop --- fill in deck with sequences that look like this --- ((1,1,11},{2,2,2}...{13,10,10},{14,1,11}...{51,10,10},{52,10,10)) --- where the first value of each triplet is the bitmap handle, the --- second value is the primary value, and the third value is the --- alternate value of the card for c = 1 to 13 do deck[c] &= card_values[c] deck[c+13] &= card_values[c] deck[c+26] &= card_values[c] deck[c+39] &= card_values[c] end for print(1, deck[1..13]) print(1, deck[14..26]) print(1, deck[27..39]) print(1, deck[40..52]) -- Run this code with ex.exe to see the output --TESTED CODE ABOVE >Deck[1(AH)][2(1 or 11)] >Deck[2(2H)][2(2)] >Deck[3(3H)][3(3)] >And so on up to the 52nd card. If this is right someone let me know. I'm >about get this stuff under my belt. Then I won't be asking so many >questions. >Thanks for all your help. > >roachd_76 at yahoo.com Everett L.(Rett) Williams rett at gvtc.com
6. Re: Assigning values to bitmaps in a sequence :)
- Posted by Irv Mullins <irv at ELLIJAY.COM> Dec 03, 1999
- 358 views
On Thu, 02 Dec 1999, you wrote: > Hello all, > This stuff is finally starting to make since to me. Just a little problem. > I am working on my first program, Black Jack. I have 52 bitmaps named > "1-52.bmp". These are loaded into a sequence Deck. Now how do assign values > to the elements in Deck. Lets say the ace of hearts is loaded into > Deck[1] how do I assign it a value of 1 and still keep the bitmap loaded > into that element. Or would I use another element like Deck[2] for the > value of the card. Basicaly I need to have a value associated with a Bitmap > in a sequence. Any help would be greatly apriciated. You'll need to keep track of each card's suit as well as its face value. This is best done with a structure. You can simulate a structure as follows: constant BMP_ERR = -- stuff to help when loading files {"Cannot open %d.bmp","Unexpected EOF in%d.bmp","Unsupported format in %d.bmp"} -- our deck of cards "structure" looks like this: constant VALUE = 1, SUIT = 2, GRAPH = 3, HEARTS = 1, DIAMONDS = 2, SPADES = 3, CLUBS = 4, ACE = 1, JACK = 11, QUEEN = 12, KING = 13 object cardrec cardrec = { 0, 0, {} } -- storage for value, suit, and graphic data object deck deck = repeat(cardrec ,52) -- 52 instances of cardrec -- end structure -- Now, load the card values and the actual bitmap (not the bmp. filename) -- into the deck. object temp -- must be object integer count count = 1 for suit = HEARTS to CLUBS do for card = ACE to KING do temp = read_bitmap(sprintf("%d.bmp", count )) -- read and store the bitmap -- if that doesn't work try: sprintf("\"%d.bmp\"",count) if atom(temp) then -- error reading file sprintf (1, BMP_ERR[temp], count ) -- display a diagnostic msg else -- store the card data deck[count] [VALUE] = card deck[count] [SUIT] = suit deck[count] [GRAPH] = temp[2] -- discard the palette end if count += 1 end for -- card end for -- suit Don't bother storing multiple values for the Ace, or other cards, that can be handled within your scoring logic. ( if card[VALUE] = ACE then count it as either 1 or 11 whichever is better) Regards, Irv