Class: Mjai::ArchivePlayer
Instance Attribute Summary
Attributes inherited from Player
#attributes, #extra_anpais, #furos, #game, #ho, #id, #name, #reach_ho_index, #reach_state, #score, #sutehais, #tehais
Instance Method Summary collapse
-
#initialize(archive_path) ⇒ ArchivePlayer
constructor
A new instance of ArchivePlayer.
- #respond_to_action(action) ⇒ Object
- #update_state(action) ⇒ Object
Methods inherited from Player
#anpais, #can_hora?, #can_reach?, #can_ryukyoku?, #context, #create_action, #delete_tehai, #double_reach?, #furiten?, #get_pais_combinations, #inspect, #ippatsu_chance?, #jikaze, #kuikae_dahais, #possible_actions, #possible_dahais, #possible_dahais_after_furo, #possible_furo_actions, #rank, #reach?, #rinshan?, #tenpai?
Constructor Details
#initialize(archive_path) ⇒ ArchivePlayer
Returns a new instance of ArchivePlayer.
9 10 11 12 13 |
# File 'lib/mjai/archive_player.rb', line 9 def initialize(archive_path) super() @archive = Archive.load(archive_path) @action_index = 0 end |
Instance Method Details
#respond_to_action(action) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/mjai/archive_player.rb', line 32 def respond_to_action(action) next_action = @archive.actions[@action_index] if next_action && next_action.actor && next_action.actor.id == 0 && [:dahai, :chi, :pon, :daiminkan, :kakan, :ankan, :reach, :hora].include?( next_action.type) return Action.from_json(next_action.to_json(), self.game) else return nil end end |
#update_state(action) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/mjai/archive_player.rb', line 15 def update_state(action) super(action) expected_action = @archive.actions[@action_index] if action.type == :start_game action = action.merge({:id => nil}) expected_action = expected_action.merge({:id => nil}) end if action.to_json() != expected_action.to_json() raise(( "live action doesn't match one in archive\n" + "actual: %s\n" + "expected: %s\n") % [action, expected_action]) end @action_index += 1 end |