pgn 0.1.0 → 0.1.1
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/lib/pgn/move_calculator.rb +21 -16
- data/lib/pgn/version.rb +1 -1
- data/spec/fen_spec.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d868495f784cc03dedf3465023bffe390d7228f5
|
4
|
+
data.tar.gz: d12ab910e19cac3c20cb2ed965fd460eadc1b657
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 790ce8940ab3aa672edb725073847d6c2154335afb9403d71acfdfa835a68658b6d2e2dced3d80f99291cafc361721482ae2f0982bd1221023bd9727b256a710
|
7
|
+
data.tar.gz: dac60e56ab33829619c706f2e4aab434b1fa4ef61833dd8ff1b1ed6e6547ab95557b72cb371d3462d9dc9cc78995ea73b91da1cb393dfb6717e6add315fcf7e1
|
data/lib/pgn/move_calculator.rb
CHANGED
@@ -105,26 +105,31 @@ module PGN
|
|
105
105
|
# @return [Array<String>] which castling moves are no longer available
|
106
106
|
#
|
107
107
|
def castling_restrictions
|
108
|
-
restrict =
|
109
|
-
|
110
|
-
when
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
108
|
+
restrict = []
|
109
|
+
|
110
|
+
# when a king or rook is moved
|
111
|
+
case self.move.piece
|
112
|
+
when 'K'
|
113
|
+
restrict += ['K', 'Q']
|
114
|
+
when 'k'
|
115
|
+
restrict += ['k', 'q']
|
116
|
+
when 'R'
|
117
|
+
restrict << {'a1' => 'Q', 'h1' => 'K'}[self.origin]
|
118
|
+
when 'r'
|
119
|
+
restrict << {'a8' => 'q', 'h8' => 'k'}[self.origin]
|
115
120
|
end
|
116
121
|
|
117
|
-
|
118
|
-
restrict
|
119
|
-
|
120
|
-
restrict += 'Q' if self.move.destination == 'a1' && !restrict.include?('Q')
|
121
|
-
restrict += 'q' if self.move.destination == 'a8' && !restrict.include?('q')
|
122
|
-
restrict += 'K' if self.move.destination == 'h1' && !restrict.include?('K')
|
123
|
-
restrict += 'k' if self.move.destination == 'h8' && !restrict.include?('k')
|
122
|
+
# when castling occurs
|
123
|
+
restrict += ['K', 'Q'] if ['K', 'Q'].include? move.castle
|
124
|
+
restrict += ['k', 'q'] if ['k', 'q'].include? move.castle
|
124
125
|
|
125
|
-
|
126
|
+
# when a rook is taken
|
127
|
+
restrict << 'Q' if self.move.destination == 'a1'
|
128
|
+
restrict << 'q' if self.move.destination == 'a8'
|
129
|
+
restrict << 'K' if self.move.destination == 'h1'
|
130
|
+
restrict << 'k' if self.move.destination == 'h8'
|
126
131
|
|
127
|
-
restrict.
|
132
|
+
restrict.compact.uniq
|
128
133
|
end
|
129
134
|
|
130
135
|
# @return [Boolean] whether to increment the halfmove clock
|
data/lib/pgn/version.rb
CHANGED
data/spec/fen_spec.rb
CHANGED
@@ -21,6 +21,12 @@ describe PGN::FEN do
|
|
21
21
|
next_pos.to_fen.castling.should match(/q/)
|
22
22
|
end
|
23
23
|
|
24
|
+
it "should remove one castling option when a rook is taken" do
|
25
|
+
pos = PGN::FEN.new("rn1qkbnr/pbpppppp/1p6/8/6P1/2N4P/PPPPPP2/R1BQKBNR b KQkq - 2 3").to_position
|
26
|
+
next_pos = pos.move("Bxh1")
|
27
|
+
next_pos.to_fen.castling.should_not match(/K/)
|
28
|
+
end
|
29
|
+
|
24
30
|
it "should change to a hyphen once no side can castle" do
|
25
31
|
pos = PGN::FEN.new("r1bq1rk1/pp1nbppp/3ppn2/8/2PP1N2/P1N5/1P2BPPP/R1BQK2R w KQ - 2 9").to_position
|
26
32
|
pos.to_fen.castling.should_not == "-"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pgn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stacey Touset
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: whittle
|