class Romance::Position
Attributes
positions[R]
Public Instance Methods
after(move)
click to toggle source
# File lib/romance/position.rb, line 12 def after(move) hash = ::Qi.call(move, square: square, in_hand: in_hand) self.class.new(shape: shape, side_id: next_side_id, **hash) end
ally_king_on_the_board?()
click to toggle source
# File lib/romance/position.rb, line 17 def ally_king_on_the_board? ally_pieces.values.any? { |piece_name| piece_name.include?("-") } end
ally_pieces()
click to toggle source
The list of pieces on the board owned by the current player, with squares.
@return [Hash] Top-side's pieces if turn to topside, bottom-side's ones
otherwise.
# File lib/romance/position.rb, line 25 def ally_pieces turn_to_topside? ? square_topside_pieces : square_bottomside_pieces end
next_side_id()
click to toggle source
# File lib/romance/position.rb, line 29 def next_side_id side_id.next % players_count end
players_count()
click to toggle source
# File lib/romance/position.rb, line 33 def players_count 2 end
sha256()
click to toggle source
# File lib/romance/position.rb, line 37 def sha256 ::Digest::SHA256.hexdigest(to_feen) end
to_feen()
click to toggle source
# File lib/romance/position.rb, line 41 def to_feen ::FEEN::Dumper.call(**to_h) end
to_h()
click to toggle source
# File lib/romance/position.rb, line 45 def to_h { side_id: side_id, square: square, shape: shape, in_hand: in_hand } end
to_s()
click to toggle source
@note Faster than FEEN to calculate.
# File lib/romance/position.rb, line 55 def to_s [ side_id, square.keys.sort.inject("") { |s, key| s + "#{key}:#{square.fetch(key)}" }, shape.join("x"), in_hand.sort.join(";") ].join("--") end