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 +4 -4
- data/RELEASES.md +4 -0
- data/lib/software_challenge_client/condition.rb +10 -1
- data/lib/software_challenge_client/game_rule_logic.rb +19 -0
- data/lib/software_challenge_client/move.rb +1 -0
- data/lib/software_challenge_client/protocol.rb +5 -2
- data/lib/software_challenge_client/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5eac2f41124e1ee9f61d00d598895df4dd553c2c
|
4
|
+
data.tar.gz: 3d2d15d84c9363fe171a7a127998b7b673388508
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5ab4676a7e0a78e5c3a099a03b3983bcbb5a3a9a32386a89dff18b85f9a266ef896206541cedcf6bd870d2eaf416cc6191f47d3643c6ab32a34b0869d6b8b47
|
7
|
+
data.tar.gz: 02a1405157463238828852063aeab0da67c34ed2d2265fc21c7b830762d06d00699657db6fc0a15fae532190fe92d123c65777ae5781b44116c79e36b4061f2b
|
data/RELEASES.md
CHANGED
@@ -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
|
@@ -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
|
-
|
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
|
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
|
+
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-
|
13
|
+
date: 2018-12-20 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: typesafe_enum
|