El 8/21/08 9:30 PM, "Tcykgreis@aol.com" Tcykgreis@aol.com escribió:
I have had a curiosity about Smalltalk for many years so I recently downloaded and installed Squeak. That's when the trouble began. I have written applications that deal bridge hands and either display the hands on screen or save them in a couple of different formats. I originally wrote the 'words' in Forth. I later tried Ruby and rewrote most of the programs in Ruby. I did it as a learning experience. I sat out to do the same thing in Squeak, again as a learning experience, but have made virtually no progress. I create the class 'Bridge' with the subclass of dealer. I try to initialize by filling a byteArray with 52 numbers, 0 through 51. I tended to create additional methods to shuffle and deal the cards to four more byte arrays named north, east, south, and west. Eventually I will need another method to "stack the deck." I will also need a counter to keep track of the deal number.
I can't get started, and I mean zero progress, because I can't create and load deck. It seems like the documentation is never quit up to date. I read about curly braces and tried deck := {0. 1. 2. ... }. When I try to accept it, first deck is questioned and then after deck I get something about not expecting anything else. I know there is a word 'asByteArray:' and I assume a number would specify the size of the array but nowhere can I find anything about the order in which the information should be provided. I tried deck asByteArray: 52 but I don't know if it worked. If it did work, how do I load the bytes into it? How do I look at a byte in a particular location in the array? Can I remove a byte from position x and/or insert a byte at position y and everything moves to accommodate the change.
In Forth and Ruby, I was able to store the hands as a 2D bit array, 4 suits and 13 bits. If the card was present the bit was set. When I dealt the cards, the appropriate bits were set.. This worked really well. The suits came out already sorted. The strength of a suit turned out to be related to the value stored for the suit. The number of cards in the suit could be found by counting set bits. I have yet to find bit-manipulating words in Squeak/Smalltalk.
As an aside, the least number of bits that must be used to store a complete deal is 104 or 13 bytes. The bits are arranged in 52 2-bit groups. The position in the array represents the value of the card and the bits determine which hands gets the card represented by that position. When you shuffle the 2-bit groups must be kept in tact. I could easily do this in Forth but could not do it in Ruby. If you are going to save a few million hands, it is nice to be able to do so in this most compact form.
If I could just figure out where to find the answers to these beginner question, I would really appreciate it. It would also be nice if I could see some examples of these methods.
Charlie
I see fellows with only Smalltalk as background try to help. The book they said, Squeak by Example, could be found and downloaded here http://squeakbyexample.org/
I began my journey in the amazing Smalltalk/Squeak world six years ago, coming from Pascal, Omnis 3 and the old beloved Mac Toolbox as only background, so I understand you.
A book nobody tell you is The CRC Card Book by David Bellin and Susan Simone. Here you could learn to start to think in Objects, messages, collaborations , etc. When you have your Bridge working on paper (the cards full with collaborations and messages), you could translate to Squeak.
If you try the wrong way (I do in my first six months) of doing same as you do in procedural programming, eventually the light turn on and illuminate the darkness.
But could be a long and frustrating experience.
Edgar