class Shuriken::History

Public Class Methods

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

Public Instance Methods

add(board) click to toggle source
# File lib/shuriken/history.rb, line 41
def add(board)
        @data.push(board)
        @pos += 1
end
debug() click to toggle source
# File lib/shuriken/history.rb, line 19
def debug
        puts "@pos: #{@pos} .. @data: #{@data.length}"
end
is_draw?(board, repsn = 2) click to toggle source
# File lib/shuriken/history.rb, line 46
def is_draw?(board, repsn = 2)
        len, hash = @data.length, board.hash
        i, n, reps = len - 1, 0, 0
        return true if board.r50 >= 99
        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/shuriken/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/shuriken/history.rb, line 14
def reset
        @data = []
        @pos = -1
end
undo() click to toggle source
# File lib/shuriken/history.rb, line 32
def undo
        if @pos > 0
                board = @data[@pos - 1]
                @pos -= 1
                return board
        end
        @data.last
end