Binary-file module? (also, rubychess)

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 ) 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

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

On 9/18/06, Glenn M. Lewis [email protected] 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

Glenn M. Lewis wrote:

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

There’s BitStruct, but it doesn’t help
much with variable length fields (such as a field that includes a length
specifier or terminator).

On 9/19/06, Ken B. [email protected] wrote:

pth

You forgot the URL
Google Code Archive - Long-term storage for Google Code Project Hosting.


Ken B… PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu/~kbloom1/

Actually it’s primary home is rubyforge
(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

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

On 9/18/06, Glenn M. Lewis [email protected] 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/

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? :slight_smile:

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

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

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 :slight_smile:

Nic

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.
:slight_smile:

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

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

         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:inEval’
from ./nchess6.rb:1918:in each' from ./nchess6.rb:1918:inEval’
from ./nchess6.rb:1781:in Eval' from ./nchess6.rb:2407:inABnegaSearchZWTail’
from ./nchess6.rb:2383:in times' from ./nchess6.rb:2383:inABnegaSearchZWTail’
from ./nchess6.rb:2457:in ABnegaSearchZWTail' ... 11 levels... from board.rb:1028:inPrepareForNextMoveWhenOpponentThinks’
from board.rb:812:in replaystart' from board.rb:230:inbuild’
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. :slight_smile:

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. :slight_smile:

– Glenn

Hal

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

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