software_challenge_client 0.3.3 → 0.3.4
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e078c2ea342feb8da789442c4ad6cdd3706ff15
|
4
|
+
data.tar.gz: 90bcc5974f4a1388655101874062157a4f817dcd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d673b541408a816e100fe286d370d661ac7991235049d610ecf855426c22f2548a425f0f77f82214db1c790e5b089b35bacdc5a3c083bbd85b91b0f2180d5182
|
7
|
+
data.tar.gz: ff79a54d09798ce8222711ace8b15db2e8e09ece78d27b4f7278ee21e4b4274a735819ee55677ed8266881b3894f327f8f2134222c4f71f0211b63816117e0c7
|
data/RELEASES.md
CHANGED
@@ -75,38 +75,38 @@ class Acceleration < Action
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
-
# Turn by {#
|
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 :
|
82
|
+
attr_reader :turn_steps
|
83
83
|
|
84
|
-
def initialize(
|
85
|
-
@
|
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
|
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 =
|
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 #{
|
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,
|
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.
|
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
|
10
|
+
# Initializes the winning Condition with a player
|
14
11
|
# @param winer [Player] winning player
|
15
|
-
|
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 '
|
54
|
-
|
55
|
-
|
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
|
-
|
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
|
-
|
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 '
|
127
|
-
@gamestate.condition = Condition.new(attrs
|
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(
|
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
|
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
|