class Shuriken::Xboard

Public Class Methods

new(variant, random_mode = false) click to toggle source
# File lib/shuriken/xboard.rb, line 10
def initialize(variant, random_mode = false)
        @variant = variant
        @random_mode = random_mode
        @engine = Shuriken::EngineCaparandom.new(variant, random_mode: random_mode)
        @movestogo_orig = 40
        @forcemode = false
        Signal.trap("SIGPIPE", "SYSTEM_DEFAULT") 
        trap("INT", "IGNORE") # no interruptions
end

Public Instance Methods

cmd_go() click to toggle source
# File lib/shuriken/xboard.rb, line 57
def cmd_go
        if @canmakemove
                puts "move #{play}"
                @canmakemove = false
        end
end
cmd_level(level) click to toggle source
# File lib/shuriken/xboard.rb, line 52
def cmd_level(level)
        @engine.movestogo = level.to_i
        @movestogo_orig = @engine.movestogo
end
cmd_move(move) click to toggle source
# File lib/shuriken/xboard.rb, line 64
def cmd_move(move)
        update_movestogo # update counter
        if @engine.make_move?(move)
                @canmakemove = true
                if @canmakemove && ! @engine.gameover
                        puts "move #{play}"
                        @canmakemove = false
                end
        end
end
cmd_new() click to toggle source
# File lib/shuriken/xboard.rb, line 46
def cmd_new
        @engine.history_reset
        @engine = Shuriken::EngineCaparandom.new(@variant, random_mode: @random_mode)
        @canmakemove = true
end
cmd_variant(variant) click to toggle source
# File lib/shuriken/xboard.rb, line 41
def cmd_variant(variant)
        @variant = variant
        @engine = Shuriken::EngineCaparandom.new(@variant, random_mode: @random_mode)
end
go() click to toggle source
# File lib/shuriken/xboard.rb, line 75
def go
        puts "#{Shuriken::NAME} #{Shuriken::VERSION} by #{Shuriken::AUTHOR}"
        @movestogo_orig = 40
        @canmakemove = true
        $stdin.each do |cmd|
                cmd.strip!
                case cmd     
                when "xboard" then
                when "hard" then
                when "easy" then
                when "random" then
                when "nopost" then
                when "post" then
                when "white" then
                when "black" then
                        # ignore
                when "remove" then
                        @engine.history_remove
                when "undo" then
                        @engine.history_undo
                when "?" then
                        @engine.move_now = true
                when /^computer/ then
                when /^st/ then
                when /^otim/ then
                when /^accepted/ then
                when /^result/ then
                        # ignore
                when /^protover/ then
                        print_xboard
                when /^ping\s+(.*)/ then 
                        puts "pong #{$1}"
                when /^variant\s+(.*)/ then
                        cmd_variant($1)
                when "new" then
                        cmd_new
                when "list" then
                        @engine.move_list
                when /^level\s+(.+)\s+.*/ then
                        cmd_level($1)
                when /^time\s+(.+)/ then 
                        @engine.time = 0.01 * $1.to_i
                when /^setboard\s+(.+)/ then
                        @engine.board.use_fen($1)
                when "quit" then
                        return
                when "p" then
                        @engine.board.print_board
                when "force" then
                        @forcemode = true
                when "go" then
                        cmd_go
                else # assume move
                        cmd_move(cmd)
                end
        end
end
play() click to toggle source
# File lib/shuriken/xboard.rb, line 29
def play
        @engine.think 
end
print_xboard() click to toggle source
update_movestogo() click to toggle source
# File lib/shuriken/xboard.rb, line 33
def update_movestogo
        if @engine.movestogo == 1
                @engine.movestogo =  @movestogo_orig
        elsif @engine.movestogo > 0
                @engine.movestogo -= 1 
        end
end