Hi, I'm Chris Moyer's Blog.

RubyKnight - Chess Engine in Ruby

I wrote this a while ago, while reading Behind Deep Blue (which is a great book). It's a chess engine written in ruby. The actual engine is implemented as a move generator, positional evaluator and a board class which handles the state as a set of bitboards and undoable move events.

Included are a command-line client and an xboard interface. The command-line interface accepts coordinate notation and a few commands:

e2e4 – coordinate notation, move a pawn
!play – tell the engine to play as the current color
!undo – roll back a move
!dump filename – store the current board state
!load filename – load a stored board
!reset – start a new game
!quit – end the game

You can cut the verbosity of the generator engine by editing line 121 of evaluator.rb:

@@ -118,7 +118,7 @@ module RubyKnight

                def time_it label

                        start = Time.now

                        res = yield

-                       puts "TIMING( '#{label}=>#{res}'): #{Time.now - start} seconds"

+                       #puts "TIMING( '#{label}=>#{res}'): #{Time.now - start} seconds"

                        res

                end

        end

The evaluator is very primitive, and only thinks one move ahead. Some sort of breadth-first time thinking mode was next on the to-do list.

You can grab the code via git:

git clone http://darkwing.inarow.net/git/rubyknight.git



Back to Blog Home »