berlin-ai 0.0.32 → 0.0.33
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -3
- data/lib/ai/node_internal.rb +4 -2
- data/lib/version.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -10,14 +10,14 @@ Create your AI in a simple `.rb` file:
|
|
10
10
|
require 'berlin-ai' # Require the berlin-ai library.
|
11
11
|
|
12
12
|
class Berlin::AI::Player
|
13
|
-
def on_turn(game) # Implement the on_turn method of Berlin::AI::Player.
|
13
|
+
def self.on_turn(game) # Implement the on_turn method of Berlin::AI::Player.
|
14
14
|
# Do your magic here.
|
15
15
|
|
16
16
|
# Here's an AI that randomly moves soldiers from node to node.
|
17
17
|
game.map.controlled_nodes.each do |node|
|
18
18
|
node.adjacent_nodes.shuffle.each do |other_node|
|
19
|
-
rand(0..(node.available_soldiers))
|
20
|
-
game.add_move(node
|
19
|
+
soldiers = rand(0..(node.available_soldiers))
|
20
|
+
game.add_move(node, other_node, soldiers)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
data/lib/ai/node_internal.rb
CHANGED
@@ -29,8 +29,10 @@ module Berlin
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
def to_s
|
33
|
-
"<Berlin::AI::Node @id=#{@id} @player_id='#{@player_id}' @type='#{@type}' @points=#{@points} @soldiers_per_turn=#{@soldiers_per_turn} @number_of_soldiers=#{@number_of_soldiers} @incoming_soldiers=#{@incoming_soldiers} @available_soldiers=#{@available_soldiers} @adjacent_nodes=#{adjacent_nodes.map(&:id)}
|
32
|
+
def to_s(options={})
|
33
|
+
str = "<Berlin::AI::Node @id=#{@id} @player_id='#{@player_id}' @type='#{@type}' @points=#{@points} @soldiers_per_turn=#{@soldiers_per_turn} @number_of_soldiers=#{@number_of_soldiers} @incoming_soldiers=#{@incoming_soldiers} @available_soldiers=#{@available_soldiers} @adjacent_nodes=#{adjacent_nodes.map(&:id)}"
|
34
|
+
options.each { |key, val| str << " @#{key}=#{val}"}
|
35
|
+
str << ">"
|
34
36
|
end
|
35
37
|
|
36
38
|
# Reset information for new turn
|
data/lib/version.rb
CHANGED