Class: Swint::AbstractRobot

Inherits:
Object
  • Object
show all
Defined in:
lib/swint/abstract_robot.rb

Direct Known Subclasses

ClassRobot, XmlrpcRobot

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#energyObject (readonly)

Returns the value of attribute energy.



12
13
14
# File 'lib/swint/abstract_robot.rb', line 12

def energy
  @energy
end

#energy_leftObject (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

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/swint/abstract_robot.rb', line 12

def name
  @name
end

#ownerObject (readonly)

Returns the value of attribute owner.



12
13
14
# File 'lib/swint/abstract_robot.rb', line 12

def owner
  @owner
end

#posObject

Returns the value of attribute pos.



10
11
12
# File 'lib/swint/abstract_robot.rb', line 10

def pos
  @pos
end

#powerObject (readonly)

Returns the value of attribute power.



12
13
14
# File 'lib/swint/abstract_robot.rb', line 12

def power
  @power
end

#sightObject (readonly)

Returns the value of attribute sight.



12
13
14
# File 'lib/swint/abstract_robot.rb', line 12

def sight
  @sight
end

#speedObject (readonly)

Returns the value of attribute speed.



12
13
14
# File 'lib/swint/abstract_robot.rb', line 12

def speed
  @speed
end

#uriObject (readonly)

Returns the value of attribute uri.



12
13
14
# File 'lib/swint/abstract_robot.rb', line 12

def uri
  @uri
end

#weightObject (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

#flagsObject



36
37
# File 'lib/swint/abstract_robot.rb', line 36

def flags
end

#has_energy?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/swint/abstract_robot.rb', line 78

def has_energy?
	@energy_left>0
end

#is_valid?Boolean


Returns:

  • (Boolean)


47
48
49
# File 'lib/swint/abstract_robot.rb', line 47

def is_valid?
	(@speed + @sight + @power + @energy + @weight) == 22
end

#listenObject



39
40
# File 'lib/swint/abstract_robot.rb', line 39

def listen
end

#moveObject



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

#pushObject



30
31
# File 'lib/swint/abstract_robot.rb', line 30

def push
end

#restoreObject



82
83
84
# File 'lib/swint/abstract_robot.rb', line 82

def restore
	@energy_left = @energy
end

#shoutObject



42
43
# File 'lib/swint/abstract_robot.rb', line 42

def shout
end

#to_sObject



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

Returns:

  • (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