Class: Swint::AbstractRobot
- Inherits:
-
Object
- Object
- Swint::AbstractRobot
- Defined in:
- lib/swint/abstract_robot.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#energy ⇒ Object
readonly
Returns the value of attribute energy.
-
#energy_left ⇒ Object
readonly
Returns the value of attribute energy_left.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
-
#pos ⇒ Object
Returns the value of attribute pos.
-
#power ⇒ Object
readonly
Returns the value of attribute power.
-
#sight ⇒ Object
readonly
Returns the value of attribute sight.
-
#speed ⇒ Object
readonly
Returns the value of attribute speed.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
-
#weight ⇒ Object
readonly
Returns the value of attribute weight.
Instance Method Summary collapse
- #calculate_view(map) ⇒ Object
- #check_action(a) ⇒ Object
- #check_direction(d) ⇒ Object
- #end_game(msg) ⇒ Object
- #flags ⇒ Object
- #has_energy? ⇒ Boolean
-
#initialize(uri, pos) ⇒ AbstractRobot
constructor
——————————————————————————– — stub.
-
#is_valid? ⇒ Boolean
——————————————————————————–.
- #listen ⇒ Object
- #move ⇒ Object
- #next(map) ⇒ Object
- #push ⇒ Object
- #restore ⇒ Object
- #shout ⇒ Object
- #to_s ⇒ Object
- #use_energy? ⇒ Boolean
Constructor Details
#initialize(uri, pos) ⇒ AbstractRobot
— stub
17 18 19 20 21 |
# File 'lib/swint/abstract_robot.rb', line 17 def initialize(uri, pos) @uri = uri @pos = pos restore end |
Instance Attribute Details
#energy ⇒ Object (readonly)
Returns the value of attribute energy.
12 13 14 |
# File 'lib/swint/abstract_robot.rb', line 12 def energy @energy end |
#energy_left ⇒ Object (readonly)
Returns the value of attribute energy_left.
12 13 14 |
# File 'lib/swint/abstract_robot.rb', line 12 def energy_left @energy_left end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/swint/abstract_robot.rb', line 12 def name @name end |
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
12 13 14 |
# File 'lib/swint/abstract_robot.rb', line 12 def owner @owner end |
#pos ⇒ Object
Returns the value of attribute pos.
10 11 12 |
# File 'lib/swint/abstract_robot.rb', line 10 def pos @pos end |
#power ⇒ Object (readonly)
Returns the value of attribute power.
12 13 14 |
# File 'lib/swint/abstract_robot.rb', line 12 def power @power end |
#sight ⇒ Object (readonly)
Returns the value of attribute sight.
12 13 14 |
# File 'lib/swint/abstract_robot.rb', line 12 def sight @sight end |
#speed ⇒ Object (readonly)
Returns the value of attribute speed.
12 13 14 |
# File 'lib/swint/abstract_robot.rb', line 12 def speed @speed end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
12 13 14 |
# File 'lib/swint/abstract_robot.rb', line 12 def uri @uri end |
#weight ⇒ Object (readonly)
Returns the value of attribute weight.
12 13 14 |
# File 'lib/swint/abstract_robot.rb', line 12 def weight @weight end |
Instance Method Details
#calculate_view(map) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/swint/abstract_robot.rb', line 86 def calculate_view(map) # A centered hexagonal number, or hex number, is a centered figurate # number that represents a hexagon with a dot in the center and all # other dots surrounding the center dot in a hexagonal lattice. # 1, 7, 19, 37, 61, 91, 127, 169, 217, 271, 331, 397, 469, 547, 631, 721, 817, 919 # relative directions reld = [2, 3, 4, 5, 0, 1] data = [] cpos = pos.clone # that was tough! ### stef's version sight.times do |depth| cpos.add!(DIRV[0]) data << map.state_of_field(cpos) 5.times do |dir| (depth+1).times do |i| cpos.add!(DIRV[reld[dir]]) data << map.state_of_field(cpos) end end depth.times do |i| cpos.add!(DIRV[reld[5]]) data << map.state_of_field(cpos) end cpos.add!(DIRV[1]) end ### sight.times do |depth| ### cpos.add!(DIRV[0]) ### data << map.state_of_field(cpos) ### 6.times do |dir| ### (depth+1).times do |i| ### cpos.add!(DIRV[reld[dir]]) ### data << map.state_of_field(cpos) ### end ### end ### end data end |
#check_action(a) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/swint/abstract_robot.rb', line 59 def check_action(a) unless [:do_nothing, :move_to, :push_object, :shout].include?(a) puts "#{@name}, what is this? '#{a}' is not an action." exit end a end |
#check_direction(d) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/swint/abstract_robot.rb', line 51 def check_direction(d) unless (0..5).include?(d) puts "#{@name}, what is this? '#{d}' is not a drection." exit end d end |
#end_game(msg) ⇒ Object
33 34 |
# File 'lib/swint/abstract_robot.rb', line 33 def end_game(msg) end |
#flags ⇒ Object
36 37 |
# File 'lib/swint/abstract_robot.rb', line 36 def flags end |
#has_energy? ⇒ Boolean
78 79 80 |
# File 'lib/swint/abstract_robot.rb', line 78 def has_energy? @energy_left>0 end |
#is_valid? ⇒ Boolean
47 48 49 |
# File 'lib/swint/abstract_robot.rb', line 47 def is_valid? (@speed + @sight + @power + @energy + @weight) == 22 end |
#listen ⇒ Object
39 40 |
# File 'lib/swint/abstract_robot.rb', line 39 def listen end |
#move ⇒ Object
26 27 28 |
# File 'lib/swint/abstract_robot.rb', line 26 def move # check_direction(...) end |
#next(map) ⇒ Object
23 24 |
# File 'lib/swint/abstract_robot.rb', line 23 def next(map) end |
#push ⇒ Object
30 31 |
# File 'lib/swint/abstract_robot.rb', line 30 def push end |
#restore ⇒ Object
82 83 84 |
# File 'lib/swint/abstract_robot.rb', line 82 def restore @energy_left = @energy end |
#shout ⇒ Object
42 43 |
# File 'lib/swint/abstract_robot.rb', line 42 def shout end |
#to_s ⇒ Object
67 68 69 70 |
# File 'lib/swint/abstract_robot.rb', line 67 def to_s a = ["#{@name} (#{@owner})", @speed, @sight, @power, @weight, @energy] "%-30s [sp: % 2s, si: % 2s, po: % 2s, we: % 2s, en: % 2s]" % a end |
#use_energy? ⇒ Boolean
72 73 74 75 76 |
# File 'lib/swint/abstract_robot.rb', line 72 def use_energy? return false unless has_energy? @energy_left -= 1 true end |