chess_rb 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8387c3c7b4b44a16284cf21d3598c9e6f1377fc9
4
- data.tar.gz: 9e9d8036aeb5e539135a2ea3f2fa7f6781dd5734
3
+ metadata.gz: ec725359b2743656a3d31112e5d9a3735644f5ec
4
+ data.tar.gz: 06be1b022d68f92885c13e0478eeec92462f23be
5
5
  SHA512:
6
- metadata.gz: 8e22e5ccee3e43694dcaafe311c3c76a84389b4235af5c5ea76857829cc1fad4d47c536abdcde4b0ebf112db7a7a6f5b0d426334b0a1deab9ac581443377a6e7
7
- data.tar.gz: b55e649dcf6243982b3493ce22ae99950b0770fe91fa628b98572c2d2d0c94866e13f7505beb491819730c450167b96c4f8393b2604a77ff68cde4bfe5022e25
6
+ metadata.gz: 763cee97ef7d9da45c039e820d132af8669a72449c906dbab794e85ac9c47734bebb1545103d0103cd7ee5b85c61fac225b1ebfef1dfeb242994f81812e05be8
7
+ data.tar.gz: d89f6eb86d04ec9507a4fa3deb539df42beddfe45c9c3633e11e954b6a7a8207fa5ba41c1bb5a7cf8ab5a1b6c8b453638e378780a92ac5315df28d62dc43b3e1
@@ -35,12 +35,14 @@ class ChessRB::Notation
35
35
 
36
36
  san += "=#{move.promotion}" if move.promotion
37
37
 
38
- undo_info = board.piece_on(move.to)
39
- board.make_move(move)
40
- if (board.check?)
41
- san += board.mate? ? "#" : "+"
38
+ if !board.squares_with(['WK', 'BK']).empty?
39
+ undo_info = board.piece_on(move.to)
40
+ board.make_move(move)
41
+ if (board.check?)
42
+ san += board.mate? ? "#" : "+"
43
+ end
44
+ board.undo_move(move, undo_info)
42
45
  end
43
- board.undo_move(move, undo_info)
44
46
 
45
47
  return san
46
48
  end
@@ -38,13 +38,16 @@ class ChessRB::Position
38
38
  end
39
39
  end
40
40
 
41
- def squares_with(piece)
41
+ def squares_with(pieces)
42
42
  squares = []
43
- code = ChessRB::Piece.const_get(piece)
43
+ codes = []
44
+ pieces.each do |piece|
45
+ codes << ChessRB::Piece.const_get(piece)
46
+ end
44
47
 
45
48
  @board.each_with_index do |r , i|
46
49
  r.each_with_index do |p, j|
47
- if p == code
50
+ if codes.include?(p)
48
51
  squares << [i, j]
49
52
  end
50
53
  end
@@ -59,7 +62,7 @@ class ChessRB::Position
59
62
 
60
63
  t = turn().upcase
61
64
  not_t = t == 'W' ? 'B' : 'W'
62
- king_vector = Vector[*(squares_with(t + 'K')[0])]
65
+ king_vector = Vector[*(squares_with([t + 'K'])[0])]
63
66
 
64
67
  # check pawn squares
65
68
  pawn_vectors = t == 'W' ? [[-1, -1], [1, -1]] : [[-1, 1], [1, 1]]
@@ -124,7 +127,7 @@ class ChessRB::Position
124
127
  return false if !check?
125
128
 
126
129
  t = turn().upcase
127
- king_vector = Vector[*(squares_with(t + 'K')[0])]
130
+ king_vector = Vector[*(squares_with([t + 'K'])[0])]
128
131
 
129
132
  around_vectors = [[1, 0], [0, 1], [-1, 0], [0, -1], [1, 1], [-1, 1],
130
133
  [1, -1], [-1, -1]]
@@ -227,7 +230,6 @@ class ChessRB::Position
227
230
  fen += count.to_s if count != 0
228
231
  end
229
232
 
230
- puts fen.to_s
231
233
  return fen
232
234
  end
233
235
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chess_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sabar Dasgupta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-22 00:00:00.000000000 Z
11
+ date: 2014-06-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Chess functions written in Ruby
14
14
  email: sabar.dasgupta@gmail.com