berlin-ai 0.0.19 → 0.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/ai/game.rb +15 -14
- data/lib/version.rb +1 -1
- metadata +2 -2
data/lib/ai/game.rb
CHANGED
@@ -25,13 +25,13 @@ module Berlin
|
|
25
25
|
else
|
26
26
|
game = (@@games[game_id] ||= Berlin::AI::Game.new( game_id, map, infos ))
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
if action == "game_over"
|
30
30
|
# Release the game to avoid memory leaks
|
31
31
|
@@games.delete game_id
|
32
|
-
elsif state
|
33
|
-
# Now, we want to update the current state of the game with the new content
|
34
|
-
game.update state
|
32
|
+
elsif infos && state
|
33
|
+
# Now, we want to update the current state of the game with the new content, as well as other infos
|
34
|
+
game.update infos, state
|
35
35
|
end
|
36
36
|
|
37
37
|
game
|
@@ -40,15 +40,11 @@ module Berlin
|
|
40
40
|
def initialize id, map, infos
|
41
41
|
@id = id
|
42
42
|
|
43
|
-
# Extract usefull informations
|
44
|
-
@player_id
|
45
|
-
@time_limit_per_turn
|
46
|
-
@
|
47
|
-
@
|
48
|
-
@number_of_players = infos['number_of_players']
|
49
|
-
|
50
|
-
# How many turns left?
|
51
|
-
@turns_left = @maximum_number_of_turns - @current_turn
|
43
|
+
# Extract usefull static informations
|
44
|
+
@player_id = infos['player_id']
|
45
|
+
@time_limit_per_turn = infos['time_limit_per_turn']
|
46
|
+
@maximum_number_of_turns = infos['maximum_number_of_turns'].to_i
|
47
|
+
@number_of_players = infos['number_of_players']
|
52
48
|
|
53
49
|
# Create the map
|
54
50
|
@map = Berlin::AI::Map.new map, infos
|
@@ -58,7 +54,12 @@ module Berlin
|
|
58
54
|
@moves << {:from=>from.to_i, :to=>to.to_i, :number_of_soldiers=>number_of_soldiers.to_i}
|
59
55
|
end
|
60
56
|
|
61
|
-
def update state
|
57
|
+
def update infos, state
|
58
|
+
# Update turn infos
|
59
|
+
@current_turn = infos['current_turn'].to_i
|
60
|
+
@turns_left = @maximum_number_of_turns - @current_turn
|
61
|
+
|
62
|
+
# Update map state
|
62
63
|
@map.update state
|
63
64
|
end
|
64
65
|
|
data/lib/version.rb
CHANGED