# Binary-file module? (also, rubychess)

**URL:** <https://www.ruby-forum.com/t/binary-file-module-also-rubychess/69178>\
**Category:** Ruby\
**Created:** [September 19, 2006, 5:45am UTC](https://www.ruby-forum.com/t/binary-file-module-also-rubychess/69178 "2006-09-19T05:45:56Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Glenn\_MSLewis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/57b2e6/32.png) [@Glenn\_MSLewis](https://www.ruby-forum.com/u/Glenn_MSLewis)\
**Post date:** [September 19, 2006, 5:45am UTC](https://www.ruby-forum.com/t/binary-file-module-also-rubychess/69178/1 "2006-09-19T05:45:56Z")

</div>

In Ruby, do we have a module that makes reading/parsing/writing  
binary files super-easy?

I’ve been reading Practical Common Lisp (ISBN 1-59059-239-5)  
(also available online: [Practical Common Lisp](http://www.gigamonkeys.com/book) ) and Chapter 24  
has a really nice package for handling binary files.

Before I spend the time porting it to Ruby, I was curious if  
anyone knows of anything similar for Ruby? Google “ruby parse binary  
files” didn’t come up with anything of interest.

Oh, and just as a teaser… I’ve been porting pythonchess-0.6  
to Ruby and barring any unforeseen difficulties, it should be finished  
in about another week or two. I’ll probably open up a Rubyforge project  
and put it in there so others can play with it.

– Glenn Lewis

---

<div class="post-metadata">

**Author:** ![Glenn\_MSLewis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/57b2e6/32.png) [@Glenn\_MSLewis](https://www.ruby-forum.com/u/Glenn_MSLewis)\
**Post date:** [September 19, 2006, 5:55am UTC](https://www.ruby-forum.com/t/binary-file-module-also-rubychess/69178/2 "2006-09-19T05:55:31Z")

</div>

Glenn M. Lewis wrote:

> Oh, and just as a teaser… I’ve been porting pythonchess-0.6  
> to Ruby and barring any unforeseen difficulties, it should be finished  
> in about another week or two. I’ll probably open up a Rubyforge project  
> and put it in there so others can play with it.

That would be awesome. Would you mind sending out an email when the  
Rubyforge project is available?

Thanks  
Jeff

---

<div class="post-metadata">

**Author:** ![Glenn\_MSLewis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/57b2e6/32.png) [@Glenn\_MSLewis](https://www.ruby-forum.com/u/Glenn_MSLewis)\
**Post date:** [September 19, 2006, 6:15am UTC](https://www.ruby-forum.com/t/binary-file-module-also-rubychess/69178/3 "2006-09-19T06:15:57Z")

</div>

On 9/18/06, Glenn M. Lewis [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> In Ruby, do we have a module that makes reading/parsing/writing  
> binary files super-easy?

Check out binaryparse (available as a gem). I wrote it to meet my  
needs (and those of my boss :-), but if there is something I could do  
to enhance it, let me know.

pth

---

<div class="post-metadata">

**Author:** ![Glenn\_MSLewis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/57b2e6/32.png) [@Glenn\_MSLewis](https://www.ruby-forum.com/u/Glenn_MSLewis)\
**Post date:** [September 19, 2006, 6:37am UTC](https://www.ruby-forum.com/t/binary-file-module-also-rubychess/69178/4 "2006-09-19T06:37:59Z")

</div>

Glenn M. Lewis wrote:

> In Ruby, do we have a module that makes reading/parsing/writing  
> binary files super-easy?

There’s [BitStruct](http://redshift.sourceforge.net/bit-struct), but it doesn’t help  
much with variable length fields (such as a field that includes a length  
specifier or terminator).

---

<div class="post-metadata">

**Author:** ![Glenn\_MSLewis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/57b2e6/32.png) [@Glenn\_MSLewis](https://www.ruby-forum.com/u/Glenn_MSLewis)\
**Post date:** [September 20, 2006, 6:01am UTC](https://www.ruby-forum.com/t/binary-file-module-also-rubychess/69178/5 "2006-09-20T06:01:46Z")

</div>

On 9/19/06, Ken B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > pth
> 
> You forgot the URL  
> [Google Code Archive - Long-term storage for Google Code Project Hosting.](http://code.google.com/p/binaryparse/)
> 
> –  
> Ken B… PhD candidate. Linguistic Cognition Laboratory.  
> Department of Computer Science. Illinois Institute of Technology.  
> [http://www.iit.edu/~kbloom1/](http://www.iit.edu/~kbloom1/)

Actually it’s primary home is rubyforge  
([http://rubyforge.org/projects/binaryparse/](http://rubyforge.org/projects/binaryparse/)) – I created the  
code.google account while waiting for the rubyforge  
confirmation/setup. But the easiest way to grab it is:

gem install binaryparse

let me know if you find it useful  
pth

---

<div class="post-metadata">

**Author:** ![Glenn\_MSLewis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/57b2e6/32.png) [@Glenn\_MSLewis](https://www.ruby-forum.com/u/Glenn_MSLewis)\
**Post date:** [September 20, 2006, 3:07am UTC](https://www.ruby-forum.com/t/binary-file-module-also-rubychess/69178/6 "2006-09-20T03:07:34Z")

</div>

On Tue, 19 Sep 2006 13:16:42 +0900, Patrick H. wrote:

> On 9/18/06, Glenn M. Lewis [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > In Ruby, do we have a module that makes reading/parsing/writing  
> > binary files super-easy?
> 
> Check out binaryparse (available as a gem). I wrote it to meet my  
> needs (and those of my boss :-), but if there is something I could do  
> to enhance it, let me know.
> 
> pth

You forgot the URL  
[http://code.google.com/p/binaryparse/](http://code.google.com/p/binaryparse/)

---

<div class="post-metadata">

**Author:** ![Glenn\_MSLewis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/57b2e6/32.png) [@Glenn\_MSLewis](https://www.ruby-forum.com/u/Glenn_MSLewis)\
**Post date:** [October 11, 2006, 7:49am UTC](https://www.ruby-forum.com/t/binary-file-module-also-rubychess/69178/7 "2006-10-11T07:49:50Z")

</div>

Glenn M. Lewis wrote:

> ```
> Now, rubychess will actually start playing a good game of chess,
> 
> ```
> 
> put the files in place.
> 
> ```
> Thank you in advance for those who will help me with this... and
> 
> ```
> 
> to the rest of the Ruby community, I apologize that I was not able to  
> bring this project 100% to completion before releasing it.

No apology necessary… how many projects out there have major  
version numbers less than 1? 🙂

When you say it crashes, do you mean that literally? Or what?

Is part of this in C?

Is Ruby’s performance acceptable (up till the time it dies)?

Hal

---

<div class="post-metadata">

**Author:** ![Glenn\_MSLewis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/57b2e6/32.png) [@Glenn\_MSLewis](https://www.ruby-forum.com/u/Glenn_MSLewis)\
**Post date:** [October 11, 2006, 1:38pm UTC](https://www.ruby-forum.com/t/binary-file-module-also-rubychess/69178/8 "2006-10-11T13:38:18Z")

</div>

> No apology necessary… how many projects out there have major  
> version numbers less than 1? 🙂

I think I might start the versioning of all my projects with letters of  
the alphabet or perhaps animal names, just to screw with your numerical  
assumptions 🙂

Nic

---

<div class="post-metadata">

**Author:** ![Glenn\_MSLewis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/57b2e6/32.png) [@Glenn\_MSLewis](https://www.ruby-forum.com/u/Glenn_MSLewis)\
**Post date:** [October 11, 2006, 7:25am UTC](https://www.ruby-forum.com/t/binary-file-module-also-rubychess/69178/9 "2006-10-11T07:25:48Z")

</div>

I have now been working on the port of pythonchess-0.6 to Ruby  
for over two months and have come to the point of diminishing returns.  
In other words, I’ve about exhausted my brain cells on this one.

```
Even though I have been programming in Ruby for over 5 years

```

and consider myself somewhat adept at it, this port has been an  
extremely challenging project (also, I didn’t know much about python  
when I started, except that I didn’t like its use of white space as  
part of the language syntax).

```
Now, rubychess will actually start playing a good game of chess,

```

but it will eventually crash as it gets closer to figuring out how to  
checkmate you. This is, obviously, unacceptable. But I need help in  
tracking down and fixing the remaining bug(s).

```
Therefore, I've decided to go ahead and make rubychess a Rubyforge

```

project and hopefully enlist the talent of some of you bright Rubyists  
to help me weed out the remaining bugs and polish this puppy up so that  
we can play chess with our favorite language without fear of crashing.  
🙂

```
Hopefully the Rubyforge project will get set up soon and I can

```

put the files in place.

```
Thank you in advance for those who will help me with this... and

```

to the rest of the Ruby community, I apologize that I was not able to  
bring this project 100% to completion before releasing it.

– Glenn Lewis

---

<div class="post-metadata">

**Author:** ![Glenn\_MSLewis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/57b2e6/32.png) [@Glenn\_MSLewis](https://www.ruby-forum.com/u/Glenn_MSLewis)\
**Post date:** [October 12, 2006, 5:40am UTC](https://www.ruby-forum.com/t/binary-file-module-also-rubychess/69178/10 "2006-10-12T05:40:44Z")

</div>

> No apology necessary… how many projects out there have major  
> version numbers less than 1? 🙂

```
         Thanks, Hal! I appreciate it.

```

> When you say it crashes, do you mean that literally? Or what?

```
         No, sorry. It exits with an error message, like this, for 

```

example:  
kingix is NIL!!! color=-1… about to crash  
./nchess6.rb:1924:in `[]': no implicit conversion from nil to integer (TypeError) from ./nchess6.rb:1924:in`Eval’  
from ./nchess6.rb:1918:in `each' from ./nchess6.rb:1918:in`Eval’  
from ./nchess6.rb:1781:in `Eval' from ./nchess6.rb:2407:in`ABnegaSearchZWTail’  
from ./nchess6.rb:2383:in `times' from ./nchess6.rb:2383:in`ABnegaSearchZWTail’  
from ./nchess6.rb:2457:in `ABnegaSearchZWTail' ... 11 levels... from board.rb:1028:in`PrepareForNextMoveWhenOpponentThinks’  
from board.rb:812:in `replaystart' from board.rb:230:in`build’  
from board.rb:1079

While I could easily prevent that particular ?crash? from happening, it  
is indicative of  
an error somewhere in the engine that needs to be fixed, so I?m not just  
plugging the hole,  
if that makes any sense.

> Is part of this in C?

```
         No, it is 100% pure Ruby. It is a line-by-line port of the 

```

Pythonchess-0.6, with  
only one tiny tweak I made myself because I had always wanted the python  
version to  
draw a red box around where it last moved from to where it last moved  
to, in case I was  
looking away when it moved. 🙂

> Is Ruby’s performance acceptable (up till the time it dies)?

```
         Well, that is an excellent question. At work, I?ve got a 

```

brand new screaming  
Core Duo machine, and the performance is great. But if you run the  
python version  
side-by-side with the Ruby version, the python version is easily 10x  
faster, and sometimes  
100x faster based purely on the ?number of nodes? it processes during  
the game, which  
it reports in the GUI. So most of the time Ruby will process ~200  
nodes/second while  
python would be processing ~4000 nodes/second. Sad, but true. I wish  
someone  
would just step in and make an ?-O? flag for ruby that either  
byte-compiled the script  
or native-compiled it and then ran it. 🙂

– Glenn

> Hal

---

<div class="post-metadata">

**Author:** ![Glenn\_MSLewis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/57b2e6/32.png) [@Glenn\_MSLewis](https://www.ruby-forum.com/u/Glenn_MSLewis)\
**Post date:** [October 11, 2006, 3:17pm UTC](https://www.ruby-forum.com/t/binary-file-module-also-rubychess/69178/11 "2006-10-11T15:17:55Z")

</div>

On Oct 11, 2006, at 12:25 AM, Glenn M. Lewis wrote:

> I have now been working on the port of pythonchess-0.6 to Ruby  
> for over two months and have come to the point of diminishing returns.  
> In other words, I’ve about exhausted my brain cells on this one.

I’m a chess nut, so at least interested in looking at the code. Drop  
a link when you get it up somewhere.

James Edward G. II

---

<div class="post-metadata">

**Author:** ![Glenn\_MSLewis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/57b2e6/32.png) [@Glenn\_MSLewis](https://www.ruby-forum.com/u/Glenn_MSLewis)\
**Post date:** [October 18, 2006, 10:40am UTC](https://www.ruby-forum.com/t/binary-file-module-also-rubychess/69178/12 "2006-10-18T10:40:50Z")

</div>

Glenn

Please let us know when you put up some files or open your  
repository, chess and programming is a nice quiz.

All the best  
JE
