class Romance::Game

Public Class Methods

load(db, starting_position_feen) click to toggle source
# File lib/romance/game.rb, line 9
def self.load(db, starting_position_feen)
  new(db, **::FEEN::Parser.call(starting_position_feen))
end
new(db, **starting_position_params) click to toggle source
# File lib/romance/game.rb, line 13
def initialize(db, **starting_position_params)
  @db = db

  @positions = [
    Position.new(**starting_position_params)
  ]
end

Public Instance Methods

current_position() click to toggle source
# File lib/romance/game.rb, line 25
def current_position
  @positions.fetch(-1)
end
inspect() click to toggle source
# File lib/romance/game.rb, line 37
def inspect
  "<Romance::Game##{object_id} position ##{@positions.length}>"
end
over?() click to toggle source
# File lib/romance/game.rb, line 33
def over?
  !current_position.ally_king_on_the_board?
end
play!(move) click to toggle source
# File lib/romance/game.rb, line 21
def play!(move)
  @positions << current_position.after(move) if legal?(*move)
end
sha256() click to toggle source
# File lib/romance/game.rb, line 29
def sha256
  ::Digest::SHA256.hexdigest(position_feens.join)
end

Private Instance Methods

position_feens() click to toggle source
# File lib/romance/game.rb, line 43
def position_feens
  @positions.map(&:to_feen).uniq.sort
end
repetition?(next_position) click to toggle source
# File lib/romance/game.rb, line 61
def repetition?(next_position)
  @positions.map(&:to_s).include?(next_position.to_s)
end