Binary-file module? (also, rubychess)

G

Glenn M. Lewis

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

Jeff Cohen

Glenn said:
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
 
P

Patrick Hurley

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
 
G

Glenn M. Lewis

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
 
H

Hal Fulton

Glenn said:
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.

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
 
D

Dr Nic

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
 
J

James Edward Gray II

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 Gray II
 
G

Glenn M. Lewis

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
 
J

Jon Egil Strand

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
 
J

Jon Egil Strand

Greetings

On Windows XP I'm a happy user of the Fox toolkit through Lyle Johnsons
excellent fxruby library.

Now I'm trying to port some applications to linux(ubuntu 6.06, ruby
1.8.4 installed from ubuntu package), but face trouble with the fxruby
gem.

I compiled and installed the latest stable fox-toolkit (1.6.16) from
source. All fine.

I install the latest gem:

sudo gem install fxruby

All fine.



I try to run hello.rb, but it fails on require 'fox1.6'


irb(main):001:0> require 'fox1.6'
LoadError: no such file to load -- fox1.6
from (irb):1:in `require'
from (irb):1

Instead, I am able to use require_gem

irb(main):002:0> require 'rubygems'
=> true

irb(main):003:0> require_gem 'fxruby'
=> true

Unfortunately I'm not able to include the Fox module

irb(main):004:0> include Fox
NameError: uninitialized constant Fox
from (irb):4


Questions:
i) On WinXP I use: require 'fox1.6', shall I really use
require_gem 'fxruby' on linux(ubuntu)

ii) How can the include Fox problem be mended?


All the best
 
J

Joel VanderWerf

Jon Egil Strand wrote:
...
I try to run hello.rb, but it fails on require 'fox1.6'

Maybe that was a typo, but it should be

require 'fox16'

Does it still fail?

Does it really work on windows with

require 'fox1.6'

?
 
L

Lyle Johnson

I install the latest gem:

sudo gem install fxruby

All fine.

I try to run hello.rb, but it fails on require 'fox1.6'

As Joel noted in his reply, this should be 'fox16' and not 'fox1.6'.
But you're also going to have trouble installing FXRuby from a source
gem using the current release of RubyGems, due to a bug in the
RubyGems installer; see:

http://rubyforge.org/tracker/index.php?func=detail&aid=4948&group_id=126&atid=575

For that reason, I'd recommend installing FXRuby using the regular
source tarball.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top