pgn 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 70f3a7855b4d29274f4393cdc84bac75792dad94
4
- data.tar.gz: 191c65ca1e5f3d7067629d2c167bdcfd495d8885
3
+ metadata.gz: d868495f784cc03dedf3465023bffe390d7228f5
4
+ data.tar.gz: d12ab910e19cac3c20cb2ed965fd460eadc1b657
5
5
  SHA512:
6
- metadata.gz: 475172b8b7b9b84031b0de1fc4010b5b63250ae586d1bc018e2d5e5bd59ffbc530f369989bea9406169d3f94be93ff67d0be88d1dcb535a28398538cb4e0d96e
7
- data.tar.gz: 78cc6d760518aaad4b0fa1a0d758199a037c29dd17877583eefaa6242f831c4f55c91d41750a8dfea2454cb73b5c264770edabb6c2775fe1a65a95523b534f28
6
+ metadata.gz: 790ce8940ab3aa672edb725073847d6c2154335afb9403d71acfdfa835a68658b6d2e2dced3d80f99291cafc361721482ae2f0982bd1221023bd9727b256a710
7
+ data.tar.gz: dac60e56ab33829619c706f2e4aab434b1fa4ef61833dd8ff1b1ed6e6547ab95557b72cb371d3462d9dc9cc78995ea73b91da1cb393dfb6717e6add315fcf7e1
@@ -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 = case self.move.piece
109
- when "K" then "KQ"
110
- when "k" then "kq"
111
- when "R"
112
- {"a1" => "Q", "h1" => "K"}[self.origin]
113
- when "r"
114
- {"a8" => "q", "h8" => "k"}[self.origin]
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
- restrict = "KQ" if ['K', 'Q'].include? move.castle
118
- restrict = "kq" if ['k', 'q'].include? move.castle
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
- restrict ||= ''
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.split('')
132
+ restrict.compact.uniq
128
133
  end
129
134
 
130
135
  # @return [Boolean] whether to increment the halfmove clock
@@ -1,3 +1,3 @@
1
1
  module PGN
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -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.0
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-02-16 00:00:00.000000000 Z
11
+ date: 2016-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: whittle