software_challenge_client 21.1.0 → 21.2.0
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 +4 -4
- data/RELEASES.md +4 -0
- data/lib/software_challenge_client/game_rule_logic.rb +12 -14
- data/lib/software_challenge_client/game_state.rb +31 -11
- data/lib/software_challenge_client/piece.rb +7 -0
- data/lib/software_challenge_client/protocol.rb +5 -6
- data/lib/software_challenge_client/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 679cfef66fc6ad4179d34801147b0640e79e2930c607069c3da6e52c5ff00862
|
4
|
+
data.tar.gz: bf3dc2f6e06ed94e72328b8babc4741faad2c0510e965f144dcd94b9a80c66ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d99e60671de8a35ad5901c46c418bce5b49ab1ef91551cccc17284bbdf82272719a3049dac3338fcd660c48eea21bc2e2ad8262c3d6803da7eab5251e33664ee
|
7
|
+
data.tar.gz: 2ef1c173e01c84cfdc37cd882aea28e04af7151cad00276b1d4a8d4d3f26243fd0e2f8e01584dd6f007954715b2ac6af5fed961aeb5cc0c2982788df296456eb
|
data/RELEASES.md
CHANGED
@@ -195,31 +195,30 @@ class GameRuleLogic
|
|
195
195
|
#
|
196
196
|
# @return ob der Zug zulässig ist
|
197
197
|
def self.valid_set_move?(gamestate, move)
|
198
|
-
# Check whether the color's move is currently active
|
199
198
|
return false if move.piece.color != gamestate.current_color
|
200
199
|
|
201
|
-
# Check whether the shape is valid
|
202
200
|
if gamestate.is_first_move?
|
201
|
+
# on first turn, only the start piece is allowed
|
203
202
|
return false if move.piece.kind != gamestate.start_piece
|
204
|
-
|
205
|
-
return false
|
203
|
+
# and it may only be placed in a corner
|
204
|
+
return false if move.piece.coords.none? { |it| corner?(it) }
|
205
|
+
else
|
206
|
+
# in all other turns, only unused pieces may be placed
|
207
|
+
return false unless gamestate.undeployed_pieces(move.piece.color).include?(move.piece.kind)
|
208
|
+
# and it needs to be connected to another piece of the same color
|
209
|
+
return false if move.piece.coords.none? { |it| corners_on_color?(gamestate.board, it, move.piece.color) }
|
206
210
|
end
|
207
211
|
|
208
|
-
#
|
212
|
+
# all parts of the piece need to be
|
209
213
|
move.piece.coords.each do |it|
|
214
|
+
# - on the board
|
210
215
|
return false unless gamestate.board.in_bounds?(it)
|
216
|
+
# - on a empty field
|
211
217
|
return false if obstructed?(gamestate.board, it)
|
218
|
+
# - not next to a field occupied by the same color
|
212
219
|
return false if borders_on_color?(gamestate.board, it, move.piece.color)
|
213
220
|
end
|
214
221
|
|
215
|
-
if gamestate.is_first_move?
|
216
|
-
# Check if it is placed correctly in a corner
|
217
|
-
return false if move.piece.coords.none? { |it| corner?(it) }
|
218
|
-
else
|
219
|
-
# Check if the piece is connected to at least one tile of same color by corner
|
220
|
-
return false if move.piece.coords.none? { |it| corners_on_color?(gamestate.board, it, move.piece.color) }
|
221
|
-
end
|
222
|
-
|
223
222
|
true
|
224
223
|
end
|
225
224
|
|
@@ -276,7 +275,6 @@ class GameRuleLogic
|
|
276
275
|
|
277
276
|
if move.instance_of? SetMove
|
278
277
|
gamestate.undeployed_pieces(move.piece.color).delete(move.piece)
|
279
|
-
# gamestate.deployed_pieces(move.piece.color).add(move.piece)
|
280
278
|
|
281
279
|
# Apply piece to board
|
282
280
|
move.piece.coords.each do |coord|
|
@@ -14,6 +14,7 @@ class GameState
|
|
14
14
|
# @!attribute [rw] turn
|
15
15
|
# @return [Integer] Aktuelle Zugnummer (von 0 beginnend)
|
16
16
|
attr_accessor :turn
|
17
|
+
|
17
18
|
# @!attribute [rw] round
|
18
19
|
# @return [Integer] Aktuelle Rundennummer (von 1 beginnend)
|
19
20
|
attr_accessor :round
|
@@ -21,11 +22,14 @@ class GameState
|
|
21
22
|
# @!attribute [rw] startColor
|
22
23
|
# @return [Color] Die Farbe, die zuerst legen darf
|
23
24
|
attr_accessor :start_color
|
24
|
-
|
25
|
-
#
|
26
|
-
|
25
|
+
|
26
|
+
# @!attribute [rw] valid_colors
|
27
|
+
# @return [Array<Color>] Ein Array aller Farben die ziehen können in
|
28
|
+
# der Reihenfolge in der sie drankommen
|
29
|
+
attr_accessor :valid_colors
|
30
|
+
|
27
31
|
# @!attribute [rw] ordered_colors
|
28
|
-
# @return [Array<Color>] Ein Array aller Farben
|
32
|
+
# @return [Array<Color>] Ein Array aller Farben in
|
29
33
|
# der Reihenfolge in der sie drankommen
|
30
34
|
attr_accessor :ordered_colors
|
31
35
|
|
@@ -48,19 +52,24 @@ class GameState
|
|
48
52
|
# @!attribute [r] player_one
|
49
53
|
# @return [Player] Der erste Spieler
|
50
54
|
attr_reader :player_one
|
55
|
+
|
51
56
|
# @!attribute [r] player_two
|
52
57
|
# @return [Player] Der zweite Spieler
|
53
58
|
attr_reader :player_two
|
59
|
+
|
54
60
|
# @!attribute [rw] board
|
55
61
|
# @return [Board] Das aktuelle Spielbrett
|
56
62
|
attr_accessor :board
|
63
|
+
|
57
64
|
# @!attribute [rw] startPiece
|
58
65
|
# @return [PieceShape] Der Stein, der im ersten Zug von allen Farben gelegt werden muss
|
59
66
|
attr_accessor :start_piece
|
67
|
+
|
60
68
|
# @!attribute [rw] last_move
|
61
69
|
# @return [Move] Der zuletzt gemachte Zug (ist nil vor dem ersten Zug, also
|
62
70
|
# bei turn == 0)
|
63
71
|
attr_accessor :last_move
|
72
|
+
|
64
73
|
# @!attribute [rw] condition
|
65
74
|
# @return [Condition] Gewinner und Gewinngrund, falls das Spiel bereits
|
66
75
|
# entschieden ist, sonst nil.
|
@@ -73,8 +82,7 @@ class GameState
|
|
73
82
|
|
74
83
|
# Erstellt einen neuen leeren Spielstand.
|
75
84
|
def initialize
|
76
|
-
@
|
77
|
-
@start_color = Color::RED
|
85
|
+
@ordered_colors = [Color::BLUE, Color::YELLOW, Color::RED, Color::GREEN]
|
78
86
|
@board = Board.new
|
79
87
|
@turn = 0
|
80
88
|
@undeployed_blue_pieces = PieceShape.to_a
|
@@ -82,27 +90,29 @@ class GameState
|
|
82
90
|
@undeployed_red_pieces = PieceShape.to_a
|
83
91
|
@undeployed_green_pieces = PieceShape.to_a
|
84
92
|
@start_piece = GameRuleLogic.get_random_pentomino
|
93
|
+
@start_color = Color::BLUE
|
85
94
|
end
|
86
95
|
|
87
96
|
# Fügt einen Spieler zum Spielzustand hinzu.
|
88
97
|
#
|
89
98
|
# @param player [Player] Der hinzuzufügende Spieler.
|
90
99
|
def add_player(player)
|
91
|
-
|
100
|
+
case player.type
|
101
|
+
when PlayerType::ONE
|
92
102
|
@player_one = player
|
93
|
-
|
103
|
+
when PlayerType::TWO
|
94
104
|
@player_two = player
|
95
105
|
end
|
96
106
|
end
|
97
107
|
|
98
108
|
# @return [Player] Spieler, der gerade an der Reihe ist.
|
99
109
|
def current_player
|
100
|
-
turn
|
110
|
+
turn.even? ? player_one : player_two
|
101
111
|
end
|
102
112
|
|
103
113
|
# @return [Player] Spieler, der gerade nicht an der Reihe ist.
|
104
114
|
def other_player
|
105
|
-
turn
|
115
|
+
turn.even? ? player_two : player_one
|
106
116
|
end
|
107
117
|
|
108
118
|
# @return [PlayerType] Typ des Spielers, der gerade nicht an der Reihe ist.
|
@@ -110,11 +120,21 @@ class GameState
|
|
110
120
|
other_player.type
|
111
121
|
end
|
112
122
|
|
123
|
+
# @return [Color] Der jetzige Index in der Zug Reihenfolge der Farben.
|
124
|
+
def current_color_index
|
125
|
+
turn % 4
|
126
|
+
end
|
127
|
+
|
113
128
|
# @return [Color] Farbe, der gerade an der Reihe ist.
|
114
129
|
def current_color
|
115
130
|
ordered_colors[current_color_index]
|
116
131
|
end
|
117
132
|
|
133
|
+
# @return [Color] Farbe des aktuellen Spielers, die gerade nicht an der Reihe ist.
|
134
|
+
def other_color
|
135
|
+
Color.find_by_ord((current_color.ord + 2) % 4)
|
136
|
+
end
|
137
|
+
|
118
138
|
# @return [Array<PieceShape>] Array aller Shapes, der gegebenen Farbe, die noch nicht gelegt wurden
|
119
139
|
def undeployed_pieces(color)
|
120
140
|
case color
|
@@ -153,7 +173,7 @@ class GameState
|
|
153
173
|
!condition.nil?
|
154
174
|
end
|
155
175
|
|
156
|
-
# Entfernt die jetzige Farbe aus der Farbrotation
|
176
|
+
# Entfernt die jetzige Farbe aus der Farbrotation
|
157
177
|
def remove_active_color
|
158
178
|
ordered_colors.delete current_color
|
159
179
|
end
|
@@ -22,6 +22,8 @@ class Piece
|
|
22
22
|
# @return [Coordinates]
|
23
23
|
attr_reader :position
|
24
24
|
|
25
|
+
# @!attribute [r] Ein Array der Positionsdaten aller Bestandteile von dem Stein in Board Koordinaten, also schon ggf. gedreht und um position versetzt.
|
26
|
+
# return [Array<Coordinates>]
|
25
27
|
attr_reader :coords
|
26
28
|
|
27
29
|
# Erstellt einen neuen leeren Spielstein.
|
@@ -59,6 +61,11 @@ class Piece
|
|
59
61
|
@coords = coords_priv
|
60
62
|
end
|
61
63
|
|
64
|
+
# Gibt die Fläche der transformierten Steinform von diesem Stein zurück
|
65
|
+
def area()
|
66
|
+
CoordinateSet.new(coords).area
|
67
|
+
end
|
68
|
+
|
62
69
|
def ==(other)
|
63
70
|
color == other.color &&
|
64
71
|
coords == other.coords
|
@@ -62,8 +62,8 @@ class Protocol
|
|
62
62
|
when 'board'
|
63
63
|
logger.debug @gamestate.board.to_s
|
64
64
|
when 'color'
|
65
|
-
if @context[:color] == :
|
66
|
-
@gamestate.
|
65
|
+
if @context[:color] == :valid_colors
|
66
|
+
@gamestate.valid_colors << Color.to_a.find {|s| s.key == @context[:last_text].to_sym }
|
67
67
|
end
|
68
68
|
when 'shape'
|
69
69
|
case @context[:piece_target]
|
@@ -116,7 +116,6 @@ class Protocol
|
|
116
116
|
when 'state'
|
117
117
|
logger.debug 'new gamestate'
|
118
118
|
@gamestate = GameState.new
|
119
|
-
@gamestate.current_color_index = attrs['currentColorIndex'].to_i
|
120
119
|
@gamestate.turn = attrs['turn'].to_i
|
121
120
|
@gamestate.round = attrs['round'].to_i
|
122
121
|
@gamestate.start_piece = PieceShape.to_a.find {|s| s.key == attrs['startPiece'].to_sym }
|
@@ -133,9 +132,9 @@ class Protocol
|
|
133
132
|
@gamestate.add_player(player)
|
134
133
|
@context[:player] = player
|
135
134
|
@context[:color] = :two
|
136
|
-
when '
|
137
|
-
@context[:color] = :
|
138
|
-
@gamestate.
|
135
|
+
when 'validColors'
|
136
|
+
@context[:color] = :valid_colors
|
137
|
+
@gamestate.valid_colors = []
|
139
138
|
when 'board'
|
140
139
|
logger.debug 'new board'
|
141
140
|
@gamestate.board = Board.new()
|
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: 21.
|
4
|
+
version: 21.2.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: 2020-12-
|
13
|
+
date: 2020-12-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: builder
|