chess_rb 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chess_rb/notation.rb +7 -5
- data/lib/chess_rb/position.rb +8 -6
- 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: ec725359b2743656a3d31112e5d9a3735644f5ec
|
4
|
+
data.tar.gz: 06be1b022d68f92885c13e0478eeec92462f23be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 763cee97ef7d9da45c039e820d132af8669a72449c906dbab794e85ac9c47734bebb1545103d0103cd7ee5b85c61fac225b1ebfef1dfeb242994f81812e05be8
|
7
|
+
data.tar.gz: d89f6eb86d04ec9507a4fa3deb539df42beddfe45c9c3633e11e954b6a7a8207fa5ba41c1bb5a7cf8ab5a1b6c8b453638e378780a92ac5315df28d62dc43b3e1
|
data/lib/chess_rb/notation.rb
CHANGED
@@ -35,12 +35,14 @@ class ChessRB::Notation
|
|
35
35
|
|
36
36
|
san += "=#{move.promotion}" if move.promotion
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
data/lib/chess_rb/position.rb
CHANGED
@@ -38,13 +38,16 @@ class ChessRB::Position
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
def squares_with(
|
41
|
+
def squares_with(pieces)
|
42
42
|
squares = []
|
43
|
-
|
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
|
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.
|
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-
|
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
|