software_challenge_client 21.0.0 → 21.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/RELEASES.md +4 -0
- data/lib/software_challenge_client/board.rb +1 -1
- data/lib/software_challenge_client/color.rb +0 -7
- data/lib/software_challenge_client/game_rule_logic.rb +19 -17
- data/lib/software_challenge_client/piece_shape.rb +26 -0
- data/lib/software_challenge_client/version.rb +1 -1
- data/software_challenge_client.gemspec +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb6f7046235b14fdf74c293c8c4f1b40a014373f949e9c9987f1ee36db6e579f
|
4
|
+
data.tar.gz: 95cb06324e9ae3ef77e7a76200bd45f47af3176f18f744f138c835d14ef7ade2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 382fe8164ebb55803018b0ebec3c04061d9fbc65e770702383190ea9a5279f5cb6e0ddcbb12e3a3b3057d31450f416f4388d3ddafb1e14447c15bd2fb16a937a
|
7
|
+
data.tar.gz: fa76ba63c8634597486a9b34665a0c731870a25ace4ddef3d4b9b05206b6c31e97077a2bf12106193e321dfec6225c99d3361435d8938229169e77ecad9b0c3a
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.5.5
|
data/RELEASES.md
CHANGED
@@ -100,7 +100,7 @@ class Board
|
|
100
100
|
def fields_of_color(color, fields = [Coordinates.new(0, 0),
|
101
101
|
Coordinates.new(0, BOARD_SIZE - 1),
|
102
102
|
Coordinates.new(BOARD_SIZE - 1, BOARD_SIZE - 1),
|
103
|
-
Coordinates.new(BOARD_SIZE - 1, 0)].
|
103
|
+
Coordinates.new(BOARD_SIZE - 1, 0)].select { |it| field_at(it).color == color })
|
104
104
|
copy = Array.new(fields)
|
105
105
|
|
106
106
|
copy.each do |field|
|
@@ -9,13 +9,6 @@ class Color < TypesafeEnum::Base
|
|
9
9
|
new :RED, 'R'
|
10
10
|
new :GREEN, 'G'
|
11
11
|
|
12
|
-
# Implementiert den [] Operator für diese Klasse
|
13
|
-
class << self
|
14
|
-
def [](digit)
|
15
|
-
constants.find { |const| const_get(const) == digit }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
12
|
# Gibt den color namen zurück
|
20
13
|
def to_s
|
21
14
|
self.key.to_s
|
@@ -70,10 +70,13 @@ class GameRuleLogic
|
|
70
70
|
moves.merge(moves_for_shape_on(color, shape, Coordinates.new(BOARD_SIZE - area1.x, BOARD_SIZE - area1.y)))
|
71
71
|
moves.merge(moves_for_shape_on(color, shape, Coordinates.new(BOARD_SIZE - area2.x, BOARD_SIZE - area2.y)))
|
72
72
|
|
73
|
-
moves.
|
73
|
+
moves.select { |m| valid_set_move?(gamestate, m) }.to_a
|
74
74
|
end
|
75
75
|
|
76
|
-
#
|
76
|
+
# Hilfsmethode um Legezüge für eine [PieceShape] zu berechnen.
|
77
|
+
# @param color [Color] Die Farbe der Spielsteine der Züge
|
78
|
+
# @param shape [PieceShape] Die Form der Spielsteine der Züge
|
79
|
+
# @param position [Coordinates] Die Position der Spielsteine der Züge
|
77
80
|
def self.moves_for_shape_on(color, shape, position)
|
78
81
|
moves = Set[]
|
79
82
|
Rotation.each do |r|
|
@@ -85,6 +88,7 @@ class GameRuleLogic
|
|
85
88
|
end
|
86
89
|
|
87
90
|
# Gib eine Liste aller möglichen Legezüge zurück, auch wenn es die erste Runde ist.
|
91
|
+
# @param gamestate [GameState] Der zu untersuchende Spielstand.
|
88
92
|
def self.all_possible_setmoves(gamestate)
|
89
93
|
moves = []
|
90
94
|
fields = valid_fields(gamestate)
|
@@ -95,7 +99,7 @@ class GameRuleLogic
|
|
95
99
|
end
|
96
100
|
|
97
101
|
# Gibt eine Liste aller möglichen SetMoves für diese Form zurück.
|
98
|
-
# @param gamestate Der
|
102
|
+
# @param gamestate [GameState] Der zu untersuchende Spielstand.
|
99
103
|
# @param shape Die [PieceShape], die die Züge nutzen sollen
|
100
104
|
#
|
101
105
|
# @return Alle möglichen Züge mit der Form
|
@@ -104,20 +108,18 @@ class GameRuleLogic
|
|
104
108
|
|
105
109
|
moves = Set[]
|
106
110
|
fields.each do |field|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
moves << SetMove.new(Piece.new(color, shape, r, f, Coordinates.new(field.x - pos.x, field.y - pos.y)))
|
112
|
-
end
|
111
|
+
shape.unique_transforms().each do |t|
|
112
|
+
piece = Piece.new(color, shape, t.r, t.f, Coordinates.new(0, 0))
|
113
|
+
piece.coords.each do |pos|
|
114
|
+
moves << SetMove.new(Piece.new(color, shape, t.r, t.f, Coordinates.new(field.x - pos.x, field.y - pos.y)))
|
113
115
|
end
|
114
116
|
end
|
115
117
|
end
|
116
|
-
moves.
|
118
|
+
moves.select { |m| valid_set_move?(gamestate, m) }.to_a
|
117
119
|
end
|
118
120
|
|
119
121
|
# Gibt eine Liste aller Felder zurück, an denen möglicherweise Züge gemacht werden kann.
|
120
|
-
# @param gamestate Der
|
122
|
+
# @param gamestate [GameState] Der zu untersuchende Spielstand.
|
121
123
|
def self.valid_fields(gamestate)
|
122
124
|
color = gamestate.current_color
|
123
125
|
board = gamestate.board
|
@@ -138,9 +140,9 @@ class GameRuleLogic
|
|
138
140
|
end
|
139
141
|
|
140
142
|
# Überprüft, ob das gegebene Feld ein Nachbarfeld mit der Farbe [color] hat
|
141
|
-
# @param board Das aktuelle Board
|
142
|
-
# @param field Das zu überprüfende Feld
|
143
|
-
# @param color Nach der zu suchenden Farbe
|
143
|
+
# @param board [Board] Das aktuelle Board
|
144
|
+
# @param field [Field] Das zu überprüfende Feld
|
145
|
+
# @param color [Color] Nach der zu suchenden Farbe
|
144
146
|
def self.neighbor_of_color?(board, field, color)
|
145
147
|
[Coordinates.new(field.x - 1, field.y),
|
146
148
|
Coordinates.new(field.x, field.y - 1),
|
@@ -175,7 +177,7 @@ class GameRuleLogic
|
|
175
177
|
# --- Move Validation ------------------------------------------------------------
|
176
178
|
|
177
179
|
# Prüft, ob der gegebene [Move] zulässig ist.
|
178
|
-
# @param gamestate
|
180
|
+
# @param gamestate [GameState] Der zu untersuchende Spielstand.
|
179
181
|
# @param move der zu überprüfende Zug
|
180
182
|
#
|
181
183
|
# @return ob der Zug zulässig ist
|
@@ -237,8 +239,8 @@ class GameRuleLogic
|
|
237
239
|
|
238
240
|
# Überprüft, ob das gegebene Feld ein diagonales Nachbarfeld mit der Farbe [color] hat
|
239
241
|
# @param board [Board] Das aktuelle Spielbrett
|
240
|
-
# @param
|
241
|
-
# @param color Nach der zu suchenden
|
242
|
+
# @param position [Field] Das zu überprüfende Feld
|
243
|
+
# @param color [Color] Nach der zu suchenden Farbe
|
242
244
|
def self.corners_on_color?(board, position, color)
|
243
245
|
[Coordinates.new(1, 1), Coordinates.new(1, -1), Coordinates.new(-1, -1), Coordinates.new(-1, 1)].any? do |it|
|
244
246
|
board.in_bounds?(position + it) && board[position + it].color == color
|
@@ -56,6 +56,9 @@ class PieceShape < TypesafeEnum::Base
|
|
56
56
|
new :PENTO_X, [c(1, 0), c(0, 1), c(1, 1), c(2, 1), c(1, 2)]
|
57
57
|
new :PENTO_Y, [c(0, 1), c(1, 0), c(1, 1), c(1, 2), c(1, 3)]
|
58
58
|
|
59
|
+
@transformations
|
60
|
+
Transform = Struct.new(:r, :f, :coords)
|
61
|
+
|
59
62
|
# Anzahl Felder, die der Stein belegt
|
60
63
|
def size
|
61
64
|
value.size
|
@@ -76,6 +79,29 @@ class PieceShape < TypesafeEnum::Base
|
|
76
79
|
coordinates.rotate(rotation).flip(flip)
|
77
80
|
end
|
78
81
|
|
82
|
+
# Gibt alle Kombinationen aus Rotation und Flipping zurück, welche zu einzigartigen
|
83
|
+
# Koordinatenmengen dieser Form führen.
|
84
|
+
# @return [Array<Transform>] Transform Structs mit Rotation r, Boolean f
|
85
|
+
def unique_transforms()
|
86
|
+
if not defined? @transformations then
|
87
|
+
existing_transforms = []
|
88
|
+
|
89
|
+
Rotation.each do |r|
|
90
|
+
[true, false].each do |f|
|
91
|
+
new_transform = Transform.new(r, f, transform(r, f))
|
92
|
+
|
93
|
+
if existing_transforms.none? { |t| t.coords == new_transform.coords } then
|
94
|
+
existing_transforms << new_transform
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
@transformations = existing_transforms
|
100
|
+
end
|
101
|
+
|
102
|
+
@transformations
|
103
|
+
end
|
104
|
+
|
79
105
|
# Gibt den Form Namen zurück
|
80
106
|
def to_s
|
81
107
|
self.key.to_s
|
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.required_ruby_version = '>= 2.
|
22
|
+
spec.required_ruby_version = '>= 2.5.5'
|
23
23
|
spec.add_dependency 'builder'
|
24
24
|
spec.add_dependency 'typesafe_enum'
|
25
25
|
|
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.0.
|
4
|
+
version: 21.0.1
|
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-11-
|
13
|
+
date: 2020-11-20 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: builder
|
@@ -321,14 +321,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
321
321
|
requirements:
|
322
322
|
- - ">="
|
323
323
|
- !ruby/object:Gem::Version
|
324
|
-
version:
|
324
|
+
version: 2.5.5
|
325
325
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
326
326
|
requirements:
|
327
327
|
- - ">="
|
328
328
|
- !ruby/object:Gem::Version
|
329
329
|
version: '0'
|
330
330
|
requirements: []
|
331
|
-
|
331
|
+
rubyforge_project:
|
332
|
+
rubygems_version: 2.7.6.2
|
332
333
|
signing_key:
|
333
334
|
specification_version: 4
|
334
335
|
summary: Provides functions to build a client for the coding competition Software-Challenge
|