software_challenge_client 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8a644a842b10f9a526189f270555be151a047d65
4
- data.tar.gz: b4ec3d2bd0e31946d6b3209c5499147d81daa341
3
+ metadata.gz: 2e078c2ea342feb8da789442c4ad6cdd3706ff15
4
+ data.tar.gz: 90bcc5974f4a1388655101874062157a4f817dcd
5
5
  SHA512:
6
- metadata.gz: 9cb30c1e255d7dff22c42a43ee432a0de7fb03509f99ac722971e647484225d38773a5932261e8cdee8796c5038352a53e7eb1e5d35b490a44ccd824b020c520
7
- data.tar.gz: abac043218602d2b25e0cbfa1b0fc79d5fd931037f535edc46a215482f67594aa84d34c7b8543324ea971f3df5c354415debadcdb4c87393189729fc03d6f304
6
+ metadata.gz: d673b541408a816e100fe286d370d661ac7991235049d610ecf855426c22f2548a425f0f77f82214db1c790e5b089b35bacdc5a3c083bbd85b91b0f2180d5182
7
+ data.tar.gz: ff79a54d09798ce8222711ace8b15db2e8e09ece78d27b4f7278ee21e4b4274a735819ee55677ed8266881b3894f327f8f2134222c4f71f0211b63816117e0c7
data/RELEASES.md CHANGED
@@ -1,3 +1,8 @@
1
+ = 0.3.4
2
+
3
+ - Renamed Turn#direction to Turn#turn_steps to make clearer that a number should be given, not a Direction instance.
4
+ - Corrected generation of XML for Push-actions
5
+
1
6
  = 0.3.3
2
7
 
3
8
  - Corrected checking/updating of coal for decelerations.
@@ -75,38 +75,38 @@ class Acceleration < Action
75
75
  end
76
76
  end
77
77
 
78
- # Turn by {#direction}.
78
+ # Turn by {#turn_steps}.
79
79
  class Turn < Action
80
80
  # Number of steps to turn. Negative values for turning clockwise, positive for
81
81
  # counterclockwise.
82
- attr_reader :direction
82
+ attr_reader :turn_steps
83
83
 
84
- def initialize(direction)
85
- @direction = direction
84
+ def initialize(turn_steps)
85
+ @turn_steps = turn_steps
86
86
  end
87
87
 
88
88
  # (see Acceleration#perform!)
89
89
  def perform!(gamestate, current_player)
90
- invalid 'Drehung um 0 ist ungültig' if direction.zero?
90
+ invalid 'Drehung um 0 ist ungültig' if turn_steps.zero?
91
91
  if gamestate
92
92
  .board
93
93
  .field(current_player.x, current_player.y)
94
94
  .type == FieldType::SANDBANK
95
95
  invalid 'Drehung auf Sandbank nicht erlaubt'
96
96
  end
97
- needed_coal = direction.abs
97
+ needed_coal = turn_steps.abs
98
98
  needed_coal -= 1 if gamestate.free_turn?
99
99
  if needed_coal > 0 && gamestate.additional_free_turn_after_push?
100
100
  needed_coal -= 1
101
101
  gamestate.additional_free_turn_after_push = false
102
102
  end
103
103
  if needed_coal > current_player.coal
104
- invalid "Nicht genug Kohle für Drehung um #{direction}. "\
104
+ invalid "Nicht genug Kohle für Drehung um #{turn_steps}. "\
105
105
  "Habe #{current_player.coal}, brauche #{needed_coal}."
106
106
  end
107
107
 
108
108
  current_player.direction =
109
- Direction.get_turn_direction(current_player.direction, direction)
109
+ Direction.get_turn_direction(current_player.direction, turn_steps)
110
110
  current_player.coal -= [0, needed_coal].max
111
111
  gamestate.free_turn = false
112
112
  end
@@ -116,7 +116,7 @@ class Turn < Action
116
116
  end
117
117
 
118
118
  def ==(other)
119
- other.type == type && other.direction == direction
119
+ other.type == type && other.turn_steps == turn_steps
120
120
  end
121
121
  end
122
122
 
@@ -6,15 +6,10 @@ class Condition
6
6
  # @!attribute [r] winner
7
7
  # @return [Player] winning player
8
8
  attr_reader :winner
9
- # @!attribute [r] reason
10
- # @return [String] winning reason
11
- attr_reader :reason
12
9
 
13
- # Initializes the winning Condition with a player and a reason
10
+ # Initializes the winning Condition with a player
14
11
  # @param winer [Player] winning player
15
- # @param reason [String] winning reason
16
- def initialize(winner, reason)
12
+ def initialize(winner)
17
13
  @winner = winner
18
- @reason = reason
19
14
  end
20
15
  end
@@ -50,11 +50,9 @@ class Protocol
50
50
  case name
51
51
  when 'board'
52
52
  logger.debug @gamestate.board.to_s
53
- when 'data'
54
- if @context[:data_class] == 'result'
55
- logger.info 'Got game result'
56
- @network.disconnect
57
- end
53
+ when 'result'
54
+ logger.info 'Got game result'
55
+ @network.disconnect
58
56
  end
59
57
  end
60
58
 
@@ -91,10 +89,18 @@ class Protocol
91
89
  logger.debug "Turn: #{@gamestate.turn}"
92
90
  when 'red'
93
91
  logger.debug 'new red player'
94
- @gamestate.add_player(parsePlayer(PlayerColor::RED, attrs))
92
+ player = parsePlayer(attrs)
93
+ if player.color != PlayerColor::RED
94
+ throw new IllegalArgumentException("expected #{PlayerColor::RED} Player but got #{player.color}")
95
+ end
96
+ @gamestate.add_player(player)
95
97
  when 'blue'
96
98
  logger.debug 'new blue player'
97
- @gamestate.add_player(parsePlayer(PlayerColor::BLUE, attrs))
99
+ player = parsePlayer(attrs)
100
+ if player.color != PlayerColor::BLUE
101
+ throw new IllegalArgumentException("expected #{PlayerColor::BLUE} Player but got #{player.color}")
102
+ end
103
+ @gamestate.add_player(player)
98
104
  when 'board'
99
105
  logger.debug 'new board'
100
106
  @gamestate.board = Board.new
@@ -123,8 +129,8 @@ class Protocol
123
129
  @gamestate.lastMove.add_action_with_order(Turn.new(attrs['direction'].to_i), attrs['order'].to_i)
124
130
  when 'push'
125
131
  @gamestate.lastMove.add_action_with_order(Push.new(Direction.find_by_key(attrs['direction'].to_sym)), attrs['order'].to_i)
126
- when 'condition'
127
- @gamestate.condition = Condition.new(attrs['winner'], attrs['reason'])
132
+ when 'winner'
133
+ @gamestate.condition = Condition.new(parsePlayer(attrs))
128
134
  when 'left'
129
135
  logger.debug 'got left event, terminating'
130
136
  @network.disconnect
@@ -133,18 +139,13 @@ class Protocol
133
139
 
134
140
  # Converts XML attributes for a Player to a new Player object
135
141
  #
136
- # @param expectedColor [PlayerColor] Color the player should have. Method will
137
- # throw an exception when expectedColor and color in attributes don't match.
138
142
  # @param attributes [Hash] Attributes for the new Player.
139
143
  # @return [Player] The created Player object.
140
- def parsePlayer(expectedColor, attributes)
144
+ def parsePlayer(attributes)
141
145
  player = Player.new(
142
146
  PlayerColor.find_by_key(attributes['color'].to_sym),
143
147
  attributes['displayName']
144
148
  )
145
- if player.color != expectedColor
146
- throw new IllegalArgumentException("expected #{expectedColor} Player but got #{attributes['color']}")
147
- end
148
149
  player.points = attributes['points'].to_i
149
150
  player.direction = Direction.find_by_key(attributes['direction'].to_sym)
150
151
  player.x = attributes['x'].to_i
@@ -184,8 +185,10 @@ class Protocol
184
185
  attribute = case action.type
185
186
  when :acceleration
186
187
  { acc: action.acceleration }
187
- when :push, :turn
188
- { direction: action.direction }
188
+ when :push
189
+ { direction: action.direction.key }
190
+ when :turn
191
+ { direction: action.turn_steps }
189
192
  when :advance
190
193
  { distance: action.distance }
191
194
  when default
@@ -1,4 +1,4 @@
1
1
  # encoding: UTF-8
2
2
  module SoftwareChallengeClient
3
- VERSION = "0.3.3"
3
+ VERSION = "0.3.4"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: software_challenge_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - 'kwollw '