Class: Trial
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Trial
- Defined in:
- app/models/trial.rb
Overview
This class describes a trial.
Constant Summary
- MAX_DISTANCE =
Maximum distance among squads in fortress.
9999
Instance Attribute Summary (collapse)
-
- (Object) goal_was_occupied
Returns the value of attribute goal_was_occupied.
Instance Method Summary (collapse)
-
- (Array) active_guard_squads
Return all the guard squads which is not yet annihilated or escaped.
-
- (Array) active_intruder_squads
Return all the intruder squads which is not yet annihilated or escaped.
-
- (Array) active_squads
Return all the squads which is not yet annihilated or escaped.
-
- (Array) dex_sorted_squads
Return squads which were sorted by dex.
-
- (Array) fortress_exit_cells
Return exit cells of fortress.
-
- (Object) fortress_goal_point
Return fortress goal point.
-
- (Integer) fortress_random_point
Return random inside cell of fortress.
-
- (Integer) fortress_x_size
Return fortress x size.
-
- (Integer) fortress_y_size
Return fortress y size.
-
- (Boolean) goal_cell_guarded?
Return true if guard squad is existing on goal cell.
-
- (Boolean) guard_defeated?
Return true if all of guard squads are retreated or annihilated.
-
- (Boolean) intruder_defeated?
Return true if all of intruder squads are retreated or annihilated.
-
- (Array) nearest_fortress_exit_point(point)
Return squads which were sorted by dex.
Instance Attribute Details
- (Object) goal_was_occupied
Returns the value of attribute goal_was_occupied
11 12 13 |
# File 'app/models/trial.rb', line 11 def goal_was_occupied @goal_was_occupied end |
Instance Method Details
- (Array) active_guard_squads
Return all the guard squads which is not yet annihilated or escaped.
18 19 20 21 22 23 24 |
# File 'app/models/trial.rb', line 18 def active_guard_squads active_guard_squads = Array.new guard_mission.squads.each do |squad| active_guard_squads << squad if squad.entried and not squad.annihilated? and not squad.retreated_from_fortress end return active_guard_squads end |
- (Array) active_intruder_squads
Return all the intruder squads which is not yet annihilated or escaped.
28 29 30 31 32 33 34 |
# File 'app/models/trial.rb', line 28 def active_intruder_squads active_intruder_squads = Array.new intruder_mission.squads.each do |squad| active_intruder_squads << squad if squad.entried and not squad.annihilated? and not squad.retreated_from_fortress end return active_intruder_squads end |
- (Array) active_squads
Return all the squads which is not yet annihilated or escaped.
38 39 40 |
# File 'app/models/trial.rb', line 38 def active_squads return active_guard_squads + active_intruder_squads end |
- (Array) dex_sorted_squads
This method calls Tools.sort_by_dex(array, param)
Return squads which were sorted by dex.
45 46 47 |
# File 'app/models/trial.rb', line 45 def dex_sorted_squads return Tools.sort_by_dex(active_squads) end |
- (Array) fortress_exit_cells
Return exit cells of fortress.
77 78 79 |
# File 'app/models/trial.rb', line 77 def fortress_exit_cells FortressCell.where("mini_map_id = ? and (x = 0 or y = 0 or x = ? or y = ?) and symbol = ? and squad_id is null", mini_map.id, fortress_x_size, fortress_y_size, :concrete.to_s) end |
- (Object) fortress_goal_point
Return fortress goal point.
69 70 71 72 73 |
# File 'app/models/trial.rb', line 69 def fortress_goal_point trial_fortress_cells.each do |cell| return Point.new(cell.x, cell.y) if cell.goal_flg end end |
- (Integer) fortress_random_point
Return random inside cell of fortress.
63 64 65 |
# File 'app/models/trial.rb', line 63 def fortress_random_point FortressCell.where("mini_map_id=? and symbol=?", mini_map.id, :concrete.to_s).sample end |
- (Integer) fortress_x_size
Return fortress x size.
51 52 53 |
# File 'app/models/trial.rb', line 51 def fortress_x_size return FortressCell.where("mini_map_id=?", mini_map.id).maximum('x') end |
- (Integer) fortress_y_size
Return fortress y size.
57 58 59 |
# File 'app/models/trial.rb', line 57 def fortress_y_size return FortressCell.where("mini_map_id=?", mini_map.id).maximum('y') end |
- (Boolean) goal_cell_guarded?
Return true if guard squad is existing on goal cell.
99 100 101 102 103 104 |
# File 'app/models/trial.rb', line 99 def goal_cell_guarded? guard_mission.squads.each do |squad| return true if squad.current_point.equal?(fortress_goal_point) end return false end |
- (Boolean) guard_defeated?
Return true if all of guard squads are retreated or annihilated.
108 109 110 111 112 113 114 |
# File 'app/models/trial.rb', line 108 def guard_defeated? return true if @goal_was_occupied guard_mission.squads.each do |squad| return false if not squad.annihilated? and not squad.retreated_from_fortress and squad.entried end return true end |
- (Boolean) intruder_defeated?
Return true if all of intruder squads are retreated or annihilated.
118 119 120 121 122 123 |
# File 'app/models/trial.rb', line 118 def intruder_defeated? intruder_mission.squads.each do |squad| return false if not squad.annihilated? and not squad.retreated_from_fortress and squad.entried end return true end |
- (Array) nearest_fortress_exit_point(point)
Dex is normalized by standard deviation before sorting.
Return squads which were sorted by dex.
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'app/models/trial.rb', line 84 def nearest_fortress_exit_point(point) nearest_fortress_exit_cell = nil nearest_distance = MAX_DISTANCE fortress_exit_cells.each do |exit_cell| distance = Tools.calc_distance(point, exit_cell) if distance < nearest_distance nearest_distance = distance nearest_fortress_exit_cell = exit_cell end end return Point.new(nearest_fortress_exit_cell.x, nearest_fortress_exit_cell.y) end |