4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/gingham/move_simulator.rb', line 4
def next_step(current_step_index, actors)
actors.each do |actor|
actor.move_status = Gingham::MoveStatus::FINISHED unless actor.move_steps[current_step_index + 1]
end
grouped = actors.reject{ |actor| actor.move_end? }.group_by{ |actor| actor.move_steps[current_step_index + 1].cell }
grouped.each do |goal, group|
if actors.map{ |a| a.waypoint.cell }.include? goal
winner = actors.select{ |a| a.waypoint.cell == goal }.first
losers = group.reject{ |actor| actor.object_id == winner.object_id }
all_in_goal = [winner, losers].flatten.compact
else
max_weight = group.map(&:weight).max
winner = group.select{ |actor| actor.weight == max_weight }.sample
winner.waypoint = winner.move_steps[current_step_index + 1]
winner.move_status = Gingham::MoveStatus::DEFAULT
losers = group.reject{ |actor| actor.object_id == winner.object_id }
all_in_goal = [winner, losers].flatten.compact
end
if all_in_goal.map(&:team_id).uniq.size == 1
losers.each do |loser|
loser.move_status = Gingham::MoveStatus::STAY
loser.move_steps = loser.move_steps.insert(current_step_index, loser.move_steps[current_step_index])
end
else
winner.move_steps = winner.move_steps[0..(current_step_index + 1)]
winner.move_status = Gingham::MoveStatus::STOPPED
losers.each do |loser|
loser.move_status = Gingham::MoveStatus::STOPPED
loser.move_steps = loser.move_steps[0..current_step_index]
end
end
end
actors
end
|