1. Deck of Cards Question...
- Posted by Ck Lester <cklester at YAHOO.COM> Nov 19, 2000
- 433 views
- Last edited Nov 20, 2000
Guys 'n' gals, When "using a deck of cards," what's the best way to manipulate the deck? For instance, is it best to let the functions operate on a global deck? shuffle(deck) I would think not... Should the deck sequence be passed to the function, then have the function return the new deck? deck = shuffle(deck) I don't mind this approach. Should I go OOP? deck.shuffle Any hints, tips, suggestions are appreciated! -ck P.S. I've got all the functionality ready... the shuffle algorithm itself is written. I just need to know how to best implement it for maintenance. Speed issues are of no concern to me, as most processors these days can handle what I'm going to be dishing out.
2. Re: Deck of Cards Question...
- Posted by Derek Parnell <derekp at solace.com.au> Nov 20, 2000
- 426 views
I like OOP so I'd tend towards that, but the second suggestion,... shuffled_deck = shuffle(deck) is okay too. Global variables, like GOTO, can easily be misused and cause weird bugs. Its a bit unfortunate that Euphoria encourages them, but until namespace and forward referencing issues are finalized, we have to live with this little "devil". Also, the function method makes it easier to implement non-standard decks (short or enlarged ones, for example.). shuffled_deck = shuffle(deck & deck) shuffled_deck = shuffle(deck[Spade04 .. SpadeAce] & deck[Club04 .. ClubAce]) ----- cheers, Derek Parnell >When "using a deck of cards," what's the best way to manipulate the deck? >For instance, is it best to let the functions operate on a global deck? > > shuffle(deck) > >I would think not... > >Should the deck sequence be passed to the function, then have the function >return the new deck? > > deck = shuffle(deck) > >I don't mind this approach. > >Should I go OOP? > > deck.shuffle
3. Re: Deck of Cards Question...
- Posted by Al Getz <xaxo at AOL.COM> Nov 19, 2000
- 432 views
- Last edited Nov 20, 2000
Hello Ck, One way to handle these kinds of problems is to use the 'pass the buck' method: pass the variables to the function, return the same variables, altered by the function's routines. This achieves encapsulation at the cost of an added global function name to the program (usually very tolerable). global function shuffle(sequence deck) --pass deck to be shuffled --place shuffle routine here: -- return deck --returns shuffled deck end function Good luck with it. --Al
4. Re: Deck of Cards Question...
- Posted by Ck Lester <cklester at YAHOO.COM> Nov 20, 2000
- 400 views
This is as non-standard a deck you can get... It's not actually a "poker" deck. Right now it has over 80 cards, composed of 7 types of cards, but that will be customizable, depending on what type of game the players want, and how playtesting plays out. If I were to implement it in OOP, can you (or any OOP guru) provide a template for a deck of cards? My initial brainwork in pseudo-OOP-speak: first, define the 'card' object second, create the types of cards using the 'card' template third, create a deck composed of card types fourth, create functions that operate on the deck Objects have methods and procedures, right? Fun fun fun! -ck > -----Original Message----- > From: Euphoria Programming for MS-DOS > [mailto:EUPHORIA at LISTSERV.MUOHIO.EDU]On Behalf Of Derek Parnell > Sent: Sunday, November 19, 2000 7:17 PM > To: EUPHORIA at LISTSERV.MUOHIO.EDU > Subject: Re: Deck of Cards Question... > > > I like OOP so I'd tend towards that, but the second suggestion,... > > shuffled_deck = shuffle(deck) > > is okay too. Global variables, like GOTO, can easily be misused and cause > weird bugs. Its a bit unfortunate that Euphoria encourages them, but until > namespace and forward referencing issues are finalized, we have > to live with > this little "devil". > > Also, the function method makes it easier to implement non-standard decks > (short or enlarged ones, for example.). > > shuffled_deck = shuffle(deck & deck) > > shuffled_deck = shuffle(deck[Spade04 .. SpadeAce] & deck[Club04 .. > ClubAce]) > > ----- > cheers, > Derek Parnell > > >When "using a deck of cards," what's the best way to manipulate the deck? > > > >Should I go OOP? > > > > deck.shuffle
5. Re: Deck of Cards Question...
- Posted by Al Getz <xaxo at AOL.COM> Nov 20, 2000
- 417 views
Ck, Why not simply {1,2,3,4,5...80} for the deck? If you need extra info with the deck, you can go two dimensional or just create a second list: {"Ace","King","Queen",...etc}. or even {{"Ace","Diamonds"},{"Ace","Hearts"}, etc} The first list acts as a pointer to the second list so you only have to shuffle the first list. Good luck with it. --Al
6. Re: Deck of Cards Question...
- Posted by George Henry <ghenryca at HOTMAIL.COM> Nov 21, 2000
- 433 views
OOP is based on the idea that "data knows what to do." If data knows what to do, then I am not needed as an implementor of algorithms. I will just decide what data are relevant, then describe my goals to them and let them do what needs to be done. 8^) Not that OOP is all bad (14 zillion programmers can't be wrong, can they?), but sometimes it's just silly. So, when OOP is successfully combined with "declarative programming" (ala Prolog, perhaps?) maybe I will like it better. Give me data that REALLY DOES know what to do! How does Euphoria encourage global variables? I don't feel encouraged to use them, except as simple control flags where "ctrl_flag=1" is equivalent to, but more straightforward than, "set_ctrl_flag()" (and similarly for "ctrl_flag=0" vs. "clear_ctrl_flag()"). Euphoria itself encourages me to use the function method. Euphoria doesn't let one pass a reference or pointer, so "append(seq1, seq2)" wouldn't do the job as a statement, it has to be a function, and following that model makes sense and is good practice. George Henry ----Original Message Follows---- From: Derek Parnell <derekp at SOLACE.COM.AU> Reply-To: derekp at solace.com.au To: EUPHORIA at LISTSERV.MUOHIO.EDU Subject: Re: Deck of Cards Question... Date: Mon, 20 Nov 2000 12:16:55 +1100 I like OOP so I'd tend towards that, but the second suggestion,... shuffled_deck = shuffle(deck) is okay too. Global variables, like GOTO, can easily be misused and cause weird bugs. Its a bit unfortunate that Euphoria encourages them, but until namespace and forward referencing issues are finalized, we have to live with this little "devil". Also, the function method makes it easier to implement non-standard decks (short or enlarged ones, for example.). shuffled_deck = shuffle(deck & deck) shuffled_deck = shuffle(deck[Spade04 .. SpadeAce] & deck[Club04 .. ClubAce]) ----- cheers, Derek Parnell _____________________________________________________________________________________ Get more from the Web. FREE MSN Explorer download : http://explorer.msn.com
7. Re: Deck of Cards Question...
- Posted by Derek Parnell <derekp at solace.com.au> Nov 21, 2000
- 419 views
>-----Original Message----- >From: George Henry [mailto:ghenryca at hotmail.com] >How does Euphoria encourage global variables? I don't feel >encouraged to use >them, except as simple control flags where "ctrl_flag=1" is equivalent to, >but more straightforward than, "set_ctrl_flag()" (and similarly for >"ctrl_flag=0" vs. "clear_ctrl_flag()"). I must admit that I said this just to see if somebody would bite. Euphoria is not much different than most other languages in its encouragement of global-scoped variables. The one situation where I'm forced to make the scope of a variable larger than required, is when a routine needs to use the value of variable that is only used by the routine, and was set by an earlier invocation of the routine. For example... integer CurVal CurVal = 0 function xyz(atom cmd) integer temp if cmd = 0 then CurVal = rand(100) else temp = rand(cmd) if temp > CurVal then CurVal = temp end if end if return CurVal end function If this function is inside a file with lots of others, then "CurVal" is exposed. If I put this function in its own include file and make xyz() a global function, I then have to be aware of potential name clashes with other (future) include files. >Euphoria itself encourages me to use the function method. Euphoria doesn't >let one pass a reference or pointer, so "append(seq1, seq2)" >wouldn't do the >job as a statement, it has to be a function, and following that >model makes >sense and is good practice. True it does. And won't it be nice when Robert allows pseudo pass-by-reference so that we can reduce typing such that append(&seq1, seq2) is syntactically identical to seq1 = append(seq1, seq2) Hey!, I can dream can't I ----- cheers, Derek Parnell