Class: Swint::XmlrpcRobot

Inherits:
AbstractRobot show all
Defined in:
lib/swint/xmlrpc_robot.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractRobot

#calculate_view, #check_action, #check_direction, #has_energy?, #is_valid?, #restore, #to_s, #use_energy?

Constructor Details

#initialize(uri, pos) ⇒ XmlrpcRobot

Returns a new instance of XmlrpcRobot.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/swint/xmlrpc_robot.rb', line 14

def initialize(uri, pos)
	@uri = uri
	@server = XMLRPC::Client.new2(@uri)
	@gameid = @server.call('start_game')
	@speed = @server.call('get_speed', @gameid)
	@sight = @server.call('get_sight', @gameid)
	@power = @server.call('get_power', @gameid)
	@energy = @server.call('get_energy', @gameid)
	@weight = @server.call('get_weight', @gameid)
	@name = @server.call('get_name', @gameid)
	@owner = @server.call('get_owner', @gameid)
	@pos = pos
	restore
end

Instance Attribute Details

#energyObject (readonly)

Returns the value of attribute energy.



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

def energy
  @energy
end

#energy_leftObject (readonly)

Returns the value of attribute energy_left.



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

def energy_left
  @energy_left
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#ownerObject (readonly)

Returns the value of attribute owner.



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

def owner
  @owner
end

#posObject

Returns the value of attribute pos.



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

def pos
  @pos
end

#powerObject (readonly)

Returns the value of attribute power.



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

def power
  @power
end

#sightObject (readonly)

Returns the value of attribute sight.



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

def sight
  @sight
end

#speedObject (readonly)

Returns the value of attribute speed.



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

def speed
  @speed
end

#uriObject (readonly)

Returns the value of attribute uri.



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

def uri
  @uri
end

#weightObject (readonly)

Returns the value of attribute weight.



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

def weight
  @weight
end

Instance Method Details

#end_game(msg) ⇒ Object



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

def end_game(msg)
	@server.call('end_game', @gameid, msg)
end

#flagsObject



53
54
55
# File 'lib/swint/xmlrpc_robot.rb', line 53

def flags
	@server.call('flags', @gameid)
end

#listen(msg) ⇒ Object



45
46
47
# File 'lib/swint/xmlrpc_robot.rb', line 45

def listen(msg)
	@server.call('listen', @gameid, msg)
end

#moveObject



33
34
35
# File 'lib/swint/xmlrpc_robot.rb', line 33

def move
	check_direction(@server.call('move', @gameid))
end

#next(map) ⇒ Object



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

def next(map)
	check_action(@server.call('next', @gameid, calculate_view(map)).to_sym)
end

#pushObject



37
38
39
# File 'lib/swint/xmlrpc_robot.rb', line 37

def push
	check_direction(@server.call('push', @gameid))
end

#shoutObject



49
50
51
# File 'lib/swint/xmlrpc_robot.rb', line 49

def shout
	@server.call('shout', @gameid)
end