software_challenge_client 22.1.0 → 23.0.2

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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +15 -15
  3. data/.rspec +3 -3
  4. data/.rubocop.yml +11 -11
  5. data/.ruby-version +1 -1
  6. data/.stickler.yml +7 -7
  7. data/.vscode/launch.json +40 -40
  8. data/.vscode/settings.json +9 -9
  9. data/AUTHORS +6 -6
  10. data/CODE_OF_CONDUCT.md +13 -13
  11. data/Dockerfile +3 -3
  12. data/Gemfile +5 -5
  13. data/Guardfile +45 -45
  14. data/README.md +172 -147
  15. data/RELEASES.md +144 -140
  16. data/Rakefile +7 -7
  17. data/bin/console +15 -15
  18. data/bin/setup +7 -7
  19. data/develop.sh +3 -3
  20. data/example/client.rb +35 -35
  21. data/example/main.rb +42 -42
  22. data/example/start.bat +2 -2
  23. data/generate-authors.sh +19 -19
  24. data/lib/software_challenge_client/board.rb +149 -127
  25. data/lib/software_challenge_client/client_interface.rb +19 -19
  26. data/lib/software_challenge_client/condition.rb +27 -27
  27. data/lib/software_challenge_client/coordinates.rb +71 -45
  28. data/lib/software_challenge_client/debug_hint.rb +17 -17
  29. data/lib/software_challenge_client/direction.rb +41 -0
  30. data/lib/software_challenge_client/field.rb +70 -69
  31. data/lib/software_challenge_client/game_rule_logic.rb +206 -136
  32. data/lib/software_challenge_client/game_state.rb +57 -29
  33. data/lib/software_challenge_client/invalid_move_exception.rb +15 -15
  34. data/lib/software_challenge_client/logging.rb +26 -26
  35. data/lib/software_challenge_client/move.rb +37 -41
  36. data/lib/software_challenge_client/network.rb +126 -126
  37. data/lib/software_challenge_client/piece.rb +43 -81
  38. data/lib/software_challenge_client/player.rb +31 -31
  39. data/lib/software_challenge_client/protocol.rb +103 -54
  40. data/lib/software_challenge_client/runner.rb +36 -36
  41. data/lib/software_challenge_client/team.rb +23 -25
  42. data/lib/software_challenge_client/util/constants.rb +9 -9
  43. data/lib/software_challenge_client/version.rb +5 -5
  44. data/lib/software_challenge_client.rb +23 -25
  45. data/lib/update_client_module.sh +15 -15
  46. data/push_image_production.sh +12 -12
  47. data/release.sh +9 -9
  48. data/software_challenge_client.gemspec +41 -41
  49. metadata +3 -5
  50. data/lib/software_challenge_client/color.rb +0 -26
  51. data/lib/software_challenge_client/has_hints.rb +0 -11
  52. data/lib/software_challenge_client/piece_type.rb +0 -16
@@ -1,45 +1,71 @@
1
- # frozen_string_literal: true
2
-
3
- # Einfache kartesische Koordinaten
4
- class Coordinates
5
- include Comparable
6
- attr_reader :x, :y
7
-
8
- # Erstellt neue leere Koordinaten.
9
- def initialize(x, y)
10
- @x = x
11
- @y = y
12
- end
13
-
14
- def ==(other)
15
- x == other.x && y == other.y
16
- end
17
-
18
- # Gibt die Ursprungs-Koordinaten (0, 0) zurück.
19
- def self.origin
20
- Coordinates.new(0, 0)
21
- end
22
-
23
- def <=>(other)
24
- xComp = x <=> other.x
25
- yComp = y <=> other.y
26
- if xComp == 0
27
- yComp
28
- else
29
- xComp
30
- end
31
- end
32
-
33
- def +(other)
34
- Coordinates.new(x + other.x, y + other.y)
35
- end
36
-
37
- # Gibt eine textuelle Repräsentation der Koordinaten aus.
38
- def to_s
39
- "(#{x}, #{y})"
40
- end
41
-
42
- def inspect
43
- to_s
44
- end
45
- end
1
+ # frozen_string_literal: true
2
+
3
+ # Einfache kartesische Koordinaten
4
+ class Coordinates
5
+ include Comparable
6
+ attr_reader :x, :y
7
+
8
+ # Erstellt neue leere Koordinaten.
9
+ def initialize(x, y)
10
+ @x = x
11
+ @y = y
12
+ end
13
+
14
+ def ==(other)
15
+ x == other.x && y == other.y
16
+ end
17
+
18
+ # Gibt die Ursprungs-Koordinaten (0, 0) zurück.
19
+ def self.origin
20
+ Coordinates.new(0, 0)
21
+ end
22
+
23
+ # Konvertiert (x, y) in das doubled Koordinatensystem.
24
+ # @param x [Integer] X-Koordinate aus dem odd-r System
25
+ # @param y [Integer] Y-Koordinate aus dem odd-r System
26
+ def self.oddr_to_doubled(c)
27
+ self.oddr_to_doubled_int(c.x, c.y)
28
+ end
29
+
30
+ # Konvertiert c in das doubled Koordinatensystem.
31
+ # @param c [Coordinates] Koordinaten aus dem odd-r System
32
+ def self.oddr_to_doubled_int(x, y)
33
+ Coordinates.new(x * 2 + y % 2, y)
34
+ end
35
+
36
+ # Konvertiert c in das odd-r Koordinatensystem.
37
+ # @param c [Coordinates] Koordinaten aus dem doubled System
38
+ def self.doubled_to_oddr(c)
39
+ self.doubled_to_oddr_int(c.x, c.y)
40
+ end
41
+
42
+ # Konvertiert (x, y) in das doubled Koordinatensystem.
43
+ # @param x [Integer] X-Koordinate aus dem doubled System
44
+ # @param y [Integer] Y-Koordinate aus dem doubled System
45
+ def self.doubled_to_oddr_int(x, y)
46
+ Coordinates.new((x / 2.0).ceil() - y % 2, y)
47
+ end
48
+
49
+ def <=>(other)
50
+ xComp = x <=> other.x
51
+ yComp = y <=> other.y
52
+ if xComp == 0
53
+ yComp
54
+ else
55
+ xComp
56
+ end
57
+ end
58
+
59
+ def +(other)
60
+ Coordinates.new(x + other.x, y + other.y)
61
+ end
62
+
63
+ # Gibt eine textuelle Repräsentation der Koordinaten aus.
64
+ def to_s
65
+ "(#{x}, #{y})"
66
+ end
67
+
68
+ def inspect
69
+ to_s
70
+ end
71
+ end
@@ -1,17 +1,17 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
-
4
- # Ein Hinweis, der zu einem Zug hinzugefügt werden kann. Z.B. zu
5
- # Diagnosezwecken. Der Hinweis wird in der grafischen Oberfläche angezeigt und
6
- # in Replay-Dateien gespeichert.
7
- class DebugHint
8
- # @!attribute [r] content
9
- # @return [String] Der Text des Hinweises.
10
- attr_reader :content
11
-
12
- # Erstellt einen neuen Hinweis.
13
- # @param content [Object] Inhalt des Hinweises. Wird zu String konvertiert.
14
- def initialize(content)
15
- @content = content.to_s
16
- end
17
- end
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ # Ein Hinweis, der zu einem Zug hinzugefügt werden kann. Z.B. zu
5
+ # Diagnosezwecken. Der Hinweis wird in der grafischen Oberfläche angezeigt und
6
+ # in Replay-Dateien gespeichert.
7
+ class DebugHint
8
+ # @!attribute [r] content
9
+ # @return [String] Der Text des Hinweises.
10
+ attr_reader :content
11
+
12
+ # Erstellt einen neuen Hinweis.
13
+ # @param content [Object] Inhalt des Hinweises. Wird zu String konvertiert.
14
+ def initialize(content)
15
+ @content = content.to_s
16
+ end
17
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'typesafe_enum'
4
+
5
+ # Eine der sechs Richtungen im hexagonalen Koordinatensystem:
6
+ #
7
+ # TOPLEFT,
8
+ # TOPRIGHT,
9
+ # RIGHT,
10
+ # BOTTOMRIGHT,
11
+ # BOTTOMLEFT,
12
+ # LEFT
13
+ #
14
+ # Zugriff z.B. mit Direction::BOTTOMLEFT
15
+ class Direction < TypesafeEnum::Base
16
+ new :TOPLEFT, 'tl'
17
+ new :TOPRIGHT, 'tr'
18
+ new :RIGHT, 'r'
19
+ new :BOTTOMRIGHT, 'br'
20
+ new :BOTTOMLEFT, 'bl'
21
+ new :LEFT, 'l'
22
+
23
+ # @return [Coordinates] Gibt den zugehörigen Vector als Koordinate zurück
24
+ def to_vec
25
+ if self.key == :TOPLEFT
26
+ Coordinates.new(-1, -1)
27
+ elsif self.key == :TOPRIGHT
28
+ Coordinates.new(1, -1)
29
+ elsif self.key == :RIGHT
30
+ Coordinates.new(2, 0)
31
+ elsif self.key == :BOTTOMRIGHT
32
+ Coordinates.new(1, 1)
33
+ elsif self.key == :BOTTOMLEFT
34
+ Coordinates.new(-1, 1)
35
+ elsif self.key == :LEFT
36
+ Coordinates.new(-2, 0)
37
+ else
38
+ Coordinates.new(0, 0)
39
+ end
40
+ end
41
+ end
@@ -1,69 +1,70 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
-
4
- # Ein Feld des Spielfelds. Ein Spielfeld ist durch die Koordinaten eindeutig
5
- # identifiziert.
6
- class Field
7
- # @!attribute [r] coordinates
8
- # @return [Coordinates] die X-Y-Koordinaten des Feldes
9
- attr_reader :coordinates
10
-
11
- # @!attribute [rw] piece
12
- # @return [Piece] das Piece auf diesem Feld, falls vorhanden, sonst nil
13
- attr_accessor :piece
14
-
15
- # Erstellt ein neues leeres Feld.
16
- #
17
- # @param x [Integer] X-Koordinate
18
- # @param y [Integer] Y-Koordinate
19
- # @param color [Color] Farbe des Spielsteins, der das Feld überdeckt, nil falls kein Spielstein es überdeckt
20
- def initialize(x, y, piece = nil)
21
- @piece = piece
22
- @coordinates = Coordinates.new(x, y)
23
- end
24
-
25
- # Vergleicht zwei Felder. Felder sind gleich, wenn sie gleiche Koordinaten und
26
- # den gleichen Spielstein haben.
27
- # @return [Boolean] true bei Gleichheit, sonst false.
28
- def ==(other)
29
- !other.nil? && coordinates == other.coordinates && piece == other.piece
30
- end
31
-
32
- # @return [Integer] X-Koordinate des Felds
33
- def x
34
- coordinates.x
35
- end
36
-
37
- # @return [Integer] Y-Koordinate des Felds
38
- def y
39
- coordinates.y
40
- end
41
-
42
- # @return [Team] Team des Pieces auf dem Feld
43
- def team
44
- if piece.nil?
45
- nil
46
- else
47
- piece.color.to_t
48
- end
49
- end
50
-
51
- # @return [PieceColor] Farbe des Pieces auf dem Feld
52
- def color
53
- if piece.nil?
54
- nil
55
- else
56
- piece.color
57
- end
58
- end
59
-
60
- # @return [Boolean] true, wenn das Feld nicht durch einen Spielstein überdeckt ist, sonst false
61
- def empty?
62
- piece.nil?
63
- end
64
-
65
- # @return [String] Textuelle Darstellung des Feldes.
66
- def to_s
67
- empty? ? '__' : piece.to_ss
68
- end
69
- end
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ # Ein Feld des Spielfelds. Ein Spielfeld ist durch die Koordinaten eindeutig
5
+ # identifiziert.
6
+ class Field
7
+ # @!attribute [r] coords
8
+ # @return [Coordinates] die X-Y-Koordinaten des Feldes
9
+ attr_reader :coords
10
+
11
+ # @!attribute [rw] piece
12
+ # @return [Piece] das Piece auf diesem Feld, falls vorhanden, sonst nil
13
+ attr_accessor :piece
14
+
15
+ # @!attribute [rw] fishes
16
+ # @return [Integer] die Menge an Fischen auf dem Feld
17
+ attr_accessor :fishes
18
+
19
+ # Erstellt ein neues leeres Feld.
20
+ #
21
+ # @param x [Integer] X-Koordinate
22
+ # @param y [Integer] Y-Koordinate
23
+ # @param color [Color] Farbe des Spielsteins, der das Feld überdeckt, nil falls kein Spielstein es überdeckt
24
+ def initialize(x, y, piece = nil, fishes = 0)
25
+ @piece = piece
26
+ @fishes = fishes
27
+ @coords = Coordinates.new(x, y)
28
+ end
29
+
30
+ # Vergleicht zwei Felder. Felder sind gleich, wenn sie gleiche Koordinaten und
31
+ # den gleichen Spielstein haben.
32
+ # @return [Boolean] true bei Gleichheit, sonst false.
33
+ def ==(other)
34
+ !other.nil? && coords == other.coords && piece == other.piece
35
+ end
36
+
37
+ # @return [Integer] X-Koordinate des Felds
38
+ def x
39
+ coords.x
40
+ end
41
+
42
+ # @return [Integer] Y-Koordinate des Felds
43
+ def y
44
+ coords.y
45
+ end
46
+
47
+ # @return [Team] Team des Pieces auf dem Feld
48
+ def team
49
+ if piece.nil?
50
+ nil
51
+ else
52
+ piece.team
53
+ end
54
+ end
55
+
56
+ # @return [Boolean] true, wenn auf dem Feld kein Spielstein und keine Fische sind, sonst false
57
+ def empty?
58
+ piece.nil? && fishes == 0
59
+ end
60
+
61
+ # @return [Boolean] true, wenn auf dem Feld kein Spielstein und mindestens ein Fisch ist, sonst false
62
+ def free?
63
+ piece.nil? && fishes != 0
64
+ end
65
+
66
+ # @return [String] Textuelle Darstellung des Feldes.
67
+ def to_s
68
+ piece.nil? ? fishes.to_s : piece.to_ss
69
+ end
70
+ end