<div dir="ltr">Squeak by Example is a great FREE book you can download.&nbsp; I use it as a kind of reference sometimes when programming, I think you should check it out. <a href="http://squeakbyexample.org">http://squeakbyexample.org</a><br>
<br><div class="gmail_quote">On Fri, Aug 22, 2008 at 12:18 PM, nicolas cellier <span dir="ltr">&lt;<a href="mailto:ncellier@ifrance.com">ncellier@ifrance.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<a href="mailto:Tcykgreis@aol.com" target="_blank">Tcykgreis@aol.com</a> a écrit :<div class="Ih2E3d"><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I have had a curiosity about Smalltalk for many years so I recently downloaded and installed Squeak. That&#39;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 &#39;words&#39; 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 &#39;Bridge&#39; 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 &quot;stack the deck.&quot; I will also need a counter to keep track of the deal number.<br>

&nbsp;I can&#39;t get started, and I mean zero progress, because I can&#39;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.<br>

</blockquote>
<br></div>
What kind of Object is a Bridge? to me it sounds more like a namespace than an Object.<br>
What kind of object is a Dealer? Maybe you mean a Deal?<br>
What are the instance variable of your class?<br>
What are its main methods (the messages than Dealer will respond to) you want to implement?<br>
<br>
You really have to think in term of Objects and messages, otherwise your Smalltalk experience won&#39;t be that nice.<br>
<br>
Maybe you want to create an initialize method in Dealer, assuming deck is an instance variable:<br>
<br>
initialize<br>
 &nbsp; &nbsp; &nbsp; &nbsp;deck := (1 to: 52) asOrderedCollection shuffled.<br>
<br>
Then, when you create a Dealer object (Dealer new), its instance variable will be initialized.<div class="Ih2E3d"><br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I know there is a word &#39;asByteArray:&#39; 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&#39;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.<br>

&nbsp;<br>
</blockquote>
<br></div>
| ba |<br>
ba := ByteArray new: 52. &quot;Create a ByteArray with 52 bytes&quot;<br>
ba at: 5 put: 23. &quot;set the fith element to 23&quot;<br>
<br>
(1 to: 52) asByteArray. &quot;Try to evaluate this...&quot;<br>
<br>
(1 to: 52) asByteArray shuffled. &quot;That might be of interest&quot;<br>
<br>
If you want to insert and remove, I recommend you begin with an OrderedCollection. OrderedCollection are growable and support adding and removing elements easily (you&#39;ll have to browse existing messages or get help from Squeak by example book which is excellent for beginners).<br>

<br>
An Array has a fixed size and must be copied if you want to insert/remove elements.<br>
You can inquire about #copyReplaceFrom:to:with:<br>
<br>
ba := ba copyReplaceFrom: 3 to: 4 with: ByteArray new. &quot;remove third and fourth elements&quot;<br>
<br>
ba := ba copyReplaceFrom: 3 to: 2 with: {11. 22.} asByteArray. &quot;insert 11 and 22 at third and fourth position&quot;<div class="Ih2E3d"><br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
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.<br>

&nbsp;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.<br>

<br>
</blockquote>
<br></div>
I strongly recommend you write a non optimized version to begin with.<br>
Squeak has enough support for collection to shuffle sort add remove select reject etc...<br>
<br>
Then only when you get used to objects and messages, you should inquire about optimizing space with bits in bit arrays.<br>
<br>
Note that it&#39;s absolutely doable in Squeak, but you&#39;ll may have to write some of the base methods. I think Yoshiki Oshima have quite an advanced implementation of BitArray, take a look at SqueakMap (from World menu Open...).<div class="Ih2E3d">
<br>
<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
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.<br>
&nbsp;Charlie<br>
&nbsp;&nbsp;<br>
</blockquote>
<br></div>
Maybe a look at free book Squeak by Example would be a good start to get acquainted to Smalltalk.<br>
<br>
Cheers<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
<br>
------------------------------------------------------------------------<br>
It&#39;s only a deal if it&#39;s where /you/ want to go. Find your travel deal *here* &lt;<a href="http://information.travel.aol.com/deals?ncid=aoltrv00050000000047" target="_blank">http://information.travel.aol.com/deals?ncid=aoltrv00050000000047</a>&gt;.<br>

<br>
<br>
------------------------------------------------------------------------<div class="Ih2E3d"><br>
<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@lists.squeakfoundation.org" target="_blank">Beginners@lists.squeakfoundation.org</a><br>
<a href="http://lists.squeakfoundation.org/mailman/listinfo/beginners" target="_blank">http://lists.squeakfoundation.org/mailman/listinfo/beginners</a><br>
</div></blockquote><div><div></div><div class="Wj3C7c">
<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@lists.squeakfoundation.org" target="_blank">Beginners@lists.squeakfoundation.org</a><br>
<a href="http://lists.squeakfoundation.org/mailman/listinfo/beginners" target="_blank">http://lists.squeakfoundation.org/mailman/listinfo/beginners</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>David Zmick<br>/dz0004455\<br><a href="http://dz0004455.googlepages.com">http://dz0004455.googlepages.com</a><br><a href="http://dz0004455.blogspot.com">http://dz0004455.blogspot.com</a><br>

</div>