just_chess 1.0.7 → 1.0.8
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/just_chess.gemspec +1 -1
- data/lib/just_chess/pieces/king.rb +3 -1
- data/lib/just_chess/square.rb +2 -28
- data/lib/just_chess/square_set.rb +0 -86
- data/lib/just_chess/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd9b8430fe1b330224a23bf84568883bf58d1266339db0feddb18e251f12f5bc
|
4
|
+
data.tar.gz: 65ecd066dc1df89fd55331836bd19a118830ec88658ed6f45aca9bbc82ee0f13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95155deb95f2ec9a3a5a63ea854e2c48aaa22a52a4f37e03259f7e57502c0e3dd97488b02b96d87dec3014f1dcda426f5a5a1d59d703b76b610e0eece210c073
|
7
|
+
data.tar.gz: 3b9db2efd203a5e29e0925dc5a420f3f8e7a0b1a7aa4c3bb80987172bc86f70db2717701f980deaf759c54759a63eddba750fac596c58dee715c4af9436bcf13
|
data/just_chess.gemspec
CHANGED
@@ -27,5 +27,5 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_development_dependency "rake", "~> 13.0.1"
|
28
28
|
spec.add_development_dependency "minitest", "~> 5.14.0"
|
29
29
|
|
30
|
-
spec.add_runtime_dependency "board_game_grid", "~> 0.1.
|
30
|
+
spec.add_runtime_dependency "board_game_grid", "~> 0.1.4"
|
31
31
|
end
|
@@ -72,6 +72,7 @@ module JustChess
|
|
72
72
|
# @return [SquareSet]
|
73
73
|
def checked_squares(square, game_state)
|
74
74
|
dup = game_state.clone
|
75
|
+
# set piece to nil to handle case where a piece threatens squares behind the king
|
75
76
|
dup.squares.find_king_for_player(player_number).piece = nil
|
76
77
|
dup.squares.threatened_by(opponent, dup)
|
77
78
|
end
|
@@ -94,4 +95,5 @@ module JustChess
|
|
94
95
|
end
|
95
96
|
end
|
96
97
|
end
|
97
|
-
end
|
98
|
+
end
|
99
|
+
|
data/lib/just_chess/square.rb
CHANGED
@@ -28,7 +28,7 @@ module JustChess
|
|
28
28
|
# id: 'a1',
|
29
29
|
# x: 1,
|
30
30
|
# y: 0,
|
31
|
-
# piece: {
|
31
|
+
# piece: { id: 1, player_number: 1, type: 'pawn' }
|
32
32
|
# })
|
33
33
|
def initialize(id: , x: , y: , piece: nil)
|
34
34
|
@id = id
|
@@ -37,20 +37,6 @@ module JustChess
|
|
37
37
|
@piece = PieceFactory.new(piece).build
|
38
38
|
end
|
39
39
|
|
40
|
-
# Is the square occupied by the specified player?
|
41
|
-
#
|
42
|
-
# @return [Boolean]
|
43
|
-
def occupied_by_player?(player_number)
|
44
|
-
piece && piece.player_number == player_number
|
45
|
-
end
|
46
|
-
|
47
|
-
# Is the square occupied by the opponent of the specified player?
|
48
|
-
#
|
49
|
-
# @return [Boolean]
|
50
|
-
def occupied_by_opponent?(player_number)
|
51
|
-
piece && piece.player_number != player_number
|
52
|
-
end
|
53
|
-
|
54
40
|
# returns the rank number of the square for the specified player
|
55
41
|
#
|
56
42
|
# @return [Fixnum]
|
@@ -68,17 +54,5 @@ module JustChess
|
|
68
54
|
def last_rank(player_number)
|
69
55
|
rank_number(player_number) == 8
|
70
56
|
end
|
71
|
-
|
72
|
-
# A serialized version of the square as a hash
|
73
|
-
#
|
74
|
-
# @return [Hash]
|
75
|
-
def as_json
|
76
|
-
{
|
77
|
-
id: id,
|
78
|
-
x: x,
|
79
|
-
y: y,
|
80
|
-
piece: piece && piece.as_json
|
81
|
-
}
|
82
|
-
end
|
83
57
|
end
|
84
|
-
end
|
58
|
+
end
|
@@ -31,26 +31,6 @@ module JustChess
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
# serializes the squares as a hash
|
35
|
-
#
|
36
|
-
# @return [Hash]
|
37
|
-
def as_json
|
38
|
-
squares.map(&:as_json)
|
39
|
-
end
|
40
|
-
|
41
|
-
# Find the square with the matching piece identifier
|
42
|
-
#
|
43
|
-
# @param [Fixnum] piece_id
|
44
|
-
# the unique identifier of the piece.
|
45
|
-
#
|
46
|
-
# @return [Square]
|
47
|
-
# ==== Example:
|
48
|
-
# # Find the square with a piece of id 4
|
49
|
-
# square_set.find_by_piece_id(4)
|
50
|
-
def find_by_piece_id(piece_id)
|
51
|
-
find { |s| s.piece && s.piece.id == piece_id }
|
52
|
-
end
|
53
|
-
|
54
34
|
# Find the square occupied by the player's king
|
55
35
|
#
|
56
36
|
# @param [Fixnum] player_number
|
@@ -64,72 +44,6 @@ module JustChess
|
|
64
44
|
find { |s| s.piece && s.piece.is_a?(JustChess::King) && s.occupied_by_player?(player_number) }
|
65
45
|
end
|
66
46
|
|
67
|
-
# Find all squares in the y direction of square
|
68
|
-
#
|
69
|
-
# @param [Square] square
|
70
|
-
# the originating square
|
71
|
-
#
|
72
|
-
# @param [Fixnum] direction_y
|
73
|
-
# the direction, either up (-1) or down (1)
|
74
|
-
#
|
75
|
-
# @return [SquareSet]
|
76
|
-
# ==== Example:
|
77
|
-
# # Get all squares up from square_a
|
78
|
-
# square_set.in_direction(square_a, -1)
|
79
|
-
def in_direction(square, direction_y)
|
80
|
-
select { |s| BoardGameGrid::Vector.new(square, s).direction.y == direction_y }
|
81
|
-
end
|
82
|
-
|
83
|
-
# Takes a player number and returns all squares occupied by the player
|
84
|
-
#
|
85
|
-
# @param [Fixnum] player_number
|
86
|
-
# the player's number.
|
87
|
-
#
|
88
|
-
# @return [SquareSet]
|
89
|
-
def occupied_by_player(player_number)
|
90
|
-
select { |s| s.occupied_by_player?(player_number) }
|
91
|
-
end
|
92
|
-
|
93
|
-
# Takes a player number and returns all squares occupied by the opponent of the player
|
94
|
-
#
|
95
|
-
# @param [Fixnum] player_number
|
96
|
-
# the player's number.
|
97
|
-
#
|
98
|
-
# @return [SquareSet]
|
99
|
-
def occupied_by_opponent(player_number)
|
100
|
-
select { |s| s.occupied_by_opponent?(player_number) }
|
101
|
-
end
|
102
|
-
|
103
|
-
# Takes a player number and returns all squares unoccupied or occupied by the opponent of the player
|
104
|
-
#
|
105
|
-
# @param [Fixnum] player_number
|
106
|
-
# the player's number.
|
107
|
-
#
|
108
|
-
# @return [SquareSet]
|
109
|
-
def unoccupied_or_occupied_by_opponent(player_number)
|
110
|
-
select { |s| s.unoccupied? || s.occupied_by_opponent?(player_number) }
|
111
|
-
end
|
112
|
-
|
113
|
-
# Find all squares occupied by a piece of a particular type
|
114
|
-
#
|
115
|
-
# @param [Class] piece_type
|
116
|
-
# the class of the piece.
|
117
|
-
#
|
118
|
-
# @return [SquareSet]
|
119
|
-
def occupied_by_piece(piece_type)
|
120
|
-
select { |s| s.piece && s.piece.is_a?(piece_type) }
|
121
|
-
end
|
122
|
-
|
123
|
-
# Find all squares occupied by a piece not of a particular type
|
124
|
-
#
|
125
|
-
# @param [Class] piece_type
|
126
|
-
# the class of the piece.
|
127
|
-
#
|
128
|
-
# @return [SquareSet]
|
129
|
-
def excluding_piece(piece_type)
|
130
|
-
select { |s| s.piece && !s.piece.is_a?(piece_type) }
|
131
|
-
end
|
132
|
-
|
133
47
|
# Returns all squares with pieces that haven't moved
|
134
48
|
#
|
135
49
|
# @return [SquareSet]
|
data/lib/just_chess/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: just_chess
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Humphreys
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.1.
|
61
|
+
version: 0.1.4
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.1.
|
68
|
+
version: 0.1.4
|
69
69
|
description: Provides a representation of a chess game complete with rules enforcement
|
70
70
|
and serialisation.
|
71
71
|
email:
|