software_challenge_client 19.0.4 → 19.1.0

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: b38a977bd3ae77b818d3df9f602699eff0d6456f
4
- data.tar.gz: 9f001e402e2663e1d5f9069e0da31df4a6d662d9
3
+ metadata.gz: 5eac2f41124e1ee9f61d00d598895df4dd553c2c
4
+ data.tar.gz: 3d2d15d84c9363fe171a7a127998b7b673388508
5
5
  SHA512:
6
- metadata.gz: 9f7bac07ef13128ed2c51ef2fbfd54800676b50aedca88288b626c96e5f5c42b3f3bfacb10accf12ec17bce374b5692615ecd63fafa019d6ef5a605f6d7a1ca6
7
- data.tar.gz: 13874a9ce4fff4a3ddf5d778cdbcb259c15b3ad71e4388e6ceae936c40c4540a65fb0dbb874c1948a58df85c72e54a38ef3106c3d1a8d56fe0b9c3f111e59781
6
+ metadata.gz: f5ab4676a7e0a78e5c3a099a03b3983bcbb5a3a9a32386a89dff18b85f9a266ef896206541cedcf6bd870d2eaf416cc6191f47d3643c6ab32a34b0869d6b8b47
7
+ data.tar.gz: 02a1405157463238828852063aeab0da67c34ed2d2265fc21c7b830762d06d00699657db6fc0a15fae532190fe92d123c65777ae5781b44116c79e36b4061f2b
data/RELEASES.md CHANGED
@@ -1,3 +1,7 @@
1
+ = 19.1.0
2
+
3
+ - winning condition is now set when changing a gamestate with Move#perform!
4
+
1
5
  = 19.0.4
2
6
 
3
7
  - fixed one more bug in in Move#perform! (thanks to wollw!)
@@ -7,9 +7,18 @@ class Condition
7
7
  # @return [Player] Spieler, der das Spiel gewonnen hat.
8
8
  attr_reader :winner
9
9
 
10
+ # @!attribute [r] reason
11
+ # @return [String] Grund fuer Spielende
12
+ attr_reader :reason
13
+
10
14
  # Initializes the winning Condition with a player
11
15
  # @param winer [Player] winning player
12
- def initialize(winner)
16
+ def initialize(winner, reason)
13
17
  @winner = winner
18
+ @reason = reason
19
+ end
20
+
21
+ def draw?
22
+ @winner.nil?
14
23
  end
15
24
  end
@@ -228,4 +228,23 @@ class GameRuleLogic
228
228
  )
229
229
  end
230
230
  end
231
+
232
+ # Prueft, ob ein Spieler im gegebenen GameState gewonnen hat.
233
+ # @param gamestate [GameState] Der zu untersuchende GameState.
234
+ # @return [Condition] nil, if the game is not won or a Condition indicating the winning player
235
+ def self.winning_condition(gamestate)
236
+ winner_by_single_swarm = [PlayerColor::RED, PlayerColor::BLUE].select do |player_color|
237
+ GameRuleLogic.swarm_size(gamestate.board, player_color) ==
238
+ gamestate.board.fields_of_type(PlayerColor.field_type(player_color)).size
239
+ end
240
+ if winner_by_single_swarm.any? && gamestate.turn.even?
241
+ return Condition.new(nil, "Unentschieden.") if winner_by_single_swarm.size == 2
242
+ return Condition.new(winner_by_single_swarm.first, "Schwarm wurde vereint.")
243
+ end
244
+ player_with_biggest_swarm = [PlayerColor::RED, PlayerColor::BLUE].sort_by do |player_color|
245
+ GameRuleLogic.swarm_size(gamestate.board, player_color)
246
+ end.reverse.first
247
+ return Condition.new(player_with_biggest_swarm, "Rundenlimit erreicht, Schwarm mit den meisten Fischen gewinnt.") if gamestate.turn == 60
248
+ nil
249
+ end
231
250
  end
@@ -71,6 +71,7 @@ class Move
71
71
  gamestate.last_move = self
72
72
  gamestate.turn += 1
73
73
  gamestate.switch_current_player
74
+ gamestate.condition = GameRuleLogic.winning_condition(gamestate)
74
75
  end
75
76
 
76
77
 
@@ -85,6 +85,7 @@ class Protocol
85
85
  if attrs['class'] == 'result'
86
86
  logger.info 'Got game result'
87
87
  @network.disconnect
88
+ @gamestate.condition = Condition.new(nil, '')
88
89
  end
89
90
  when 'state'
90
91
  logger.debug 'new gamestate'
@@ -128,8 +129,10 @@ class Protocol
128
129
  @gamestate.last_move = Move.new(x, y, direction)
129
130
  when 'winner'
130
131
  winning_player = parsePlayer(attrs)
131
- @gamestate.condition = Condition.new(winning_player)
132
- @context[:player] = winning_player
132
+ @gamestate.condition = Condition.new(winning_player, @gamestate.condition.reason)
133
+ when 'score'
134
+ # there are two score tags in the result, but reason attribute should be equal on both
135
+ @gamestate.condition = Condition.new(@gamestate.condition.winner, attrs['reason'])
133
136
  when 'left'
134
137
  logger.debug 'got left event, terminating'
135
138
  @network.disconnect
@@ -1,4 +1,4 @@
1
1
  # encoding: UTF-8
2
2
  module SoftwareChallengeClient
3
- VERSION = "19.0.4"
3
+ VERSION = "19.1.0"
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: 19.0.4
4
+ version: 19.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - 'kwollw '
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2018-12-18 00:00:00.000000000 Z
13
+ date: 2018-12-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: typesafe_enum