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.
Files changed (3) hide show
  1. data/lib/ai/game.rb +15 -14
  2. data/lib/version.rb +1 -1
  3. 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 = infos['player_id']
45
- @time_limit_per_turn = infos['time_limit_per_turn']
46
- @current_turn = infos['current_turn'].to_i
47
- @maximum_number_of_turns = infos['maximum_number_of_turns'].to_i
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
@@ -2,7 +2,7 @@ module Berlin
2
2
  module AI
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- BUILD = 19
5
+ BUILD = 20
6
6
 
7
7
  VERSION = "#{MAJOR}.#{MINOR}.#{BUILD}"
8
8
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 19
9
- version: 0.0.19
8
+ - 20
9
+ version: 0.0.20
10
10
  platform: ruby
11
11
  authors:
12
12
  - Christian Blais