class RubyShogi::History

Public Class Methods

new() click to toggle source
# File lib/ruby_shogi/history.rb, line 10
def initialize
        reset
end

Public Instance Methods

add(board) click to toggle source
# File lib/ruby_shogi/history.rb, line 41
def add(board)
        @data.push(board)
        @pos += 1
end
debug() click to toggle source
# File lib/ruby_shogi/history.rb, line 19
def debug
        puts "@pos: #{@pos} .. @data: #{@data.length}"
end
draw_too_long?() click to toggle source
# File lib/ruby_shogi/history.rb, line 46
def draw_too_long?
        @data.length > 900 # I give up...
end
is_draw?(board, repsn = 4) click to toggle source
# File lib/ruby_shogi/history.rb, line 50
def is_draw?(board, repsn = 4)
        len, hash = @data.length, board.hash
        i, n, reps = len - 1, 0, 0
        while i > 0
                break if n >= 100 
                reps += 1 if hash == @data[i].hash
                n, i = n + 1, i - 1
                return true if reps >= repsn
        end
        false
end
remove() click to toggle source
# File lib/ruby_shogi/history.rb, line 23
def remove
        if @pos > 1
                board = @data[@pos - 2]
                @pos -= 2
                return board
        end
        @data.last
end
reset() click to toggle source
# File lib/ruby_shogi/history.rb, line 14
def reset
        @data = []
        @pos = -1
end
undo() click to toggle source
# File lib/ruby_shogi/history.rb, line 32
def undo
        if @pos > 0
                board = @data[@pos - 1]
                @pos -= 1
                return board
        end
        @data.last
end