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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a08a78bd14dd02e33b72e6263f1b5f378490d29a3200d66b83664a6ee3eeeeb7
4
- data.tar.gz: b5bb2bf9b10e457d9a3a187025435cdda90d7b6010a079f5c7587d0ae134fdec
3
+ metadata.gz: 679cfef66fc6ad4179d34801147b0640e79e2930c607069c3da6e52c5ff00862
4
+ data.tar.gz: bf3dc2f6e06ed94e72328b8babc4741faad2c0510e965f144dcd94b9a80c66ee
5
5
  SHA512:
6
- metadata.gz: 99c7dfa3c94c0db8ff13448dc718502c15d98063c98a16ee8e9eb066a510f1405662a7b0e56d5323bc74e712f38690d3047fe096de192e387babd0318477aae2
7
- data.tar.gz: 2f011d42e30b16f40827c1a3411ceae2923490291faf4cfe63a295dfce7bc606ed755c4b028639c9d8f09eec2b3fdebba82bb077233856c360f5686022fdcd63
6
+ metadata.gz: d99e60671de8a35ad5901c46c418bce5b49ab1ef91551cccc17284bbdf82272719a3049dac3338fcd660c48eea21bc2e2ad8262c3d6803da7eab5251e33664ee
7
+ data.tar.gz: 2ef1c173e01c84cfdc37cd882aea28e04af7151cad00276b1d4a8d4d3f26243fd0e2f8e01584dd6f007954715b2ac6af5fed961aeb5cc0c2982788df296456eb
@@ -1,3 +1,7 @@
1
+ = 21.2.0
2
+
3
+ Adjustments for Backend version 21.2.0
4
+
1
5
  = 21.1.0
2
6
 
3
7
  Pieces are now mutable and `==` of pieces considers rotated shapes which result in the same covered board fields as equal.
@@ -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
- elsif !gamestate.undeployed_pieces(move.piece.color).include?(move.piece.kind)
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
- # Check whether the piece can be placed
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
- # @!attribute [rw] current_color_index
25
- # @return [Color] Der jetzige Index in der Zug Reihenfolge der Farben.
26
- attr_accessor :current_color_index
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 die ziehen können in
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
- @current_color = Color::RED
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
- if player.type == PlayerType::ONE
100
+ case player.type
101
+ when PlayerType::ONE
92
102
  @player_one = player
93
- elsif player.type == PlayerType::TWO
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 % 2 == 0 ? player_one : player_two
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 % 2 == 0 ? player_two : player_one
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] == :ordered_colors
66
- @gamestate.ordered_colors << Color.to_a.find {|s| s.key == @context[:last_text].to_sym }
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 'orderedColors'
137
- @context[:color] = :ordered_colors
138
- @gamestate.ordered_colors = []
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()
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
  # frozen_string_literal: true
3
3
  module SoftwareChallengeClient
4
- VERSION = '21.1.0'
4
+ VERSION = '21.2.0'
5
5
  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: 21.1.0
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-03 00:00:00.000000000 Z
13
+ date: 2020-12-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: builder