chess 0.0.6 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +2 -2
- data/Rakefile +3 -2
- data/ext/board.c +1 -1
- data/ext/common.c +1 -1
- data/ext/common.h +1 -1
- data/ext/extconf.rb +1 -1
- data/ext/game.c +1 -1
- data/lib/chess.rb +1 -1
- data/lib/chess/exceptions.rb +0 -1
- data/lib/chess/game.rb +1 -1
- data/lib/chess/gnuchess.rb +0 -1
- data/lib/chess/pgn.rb +1 -1
- data/lib/chess/utf8_notation.rb +39 -0
- data/lib/chess/version.rb +1 -1
- data/test/test_load_fen.rb +11 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c862229413460f6c0a009c043f7b2f60a617cae8
|
4
|
+
data.tar.gz: b44b851efc9ba6cd81d9389d2bde719d91bbf6fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd88ad5bb24246e5fd603781a22bff4d45f3462a0edd21dc21518da724a13f4c4950a91816f00263d0b545b6bfce927190bde862938f8e9519221d1402090ed7
|
7
|
+
data.tar.gz: ea7d3f54825f1aae7ede6258b2eb4174409727dd05712a6af1a09dc0731cc2e05fd26a58b15c020bfdf98df0a5ba2d0e0c5f5101a4d96c766f578a63902e7801
|
data/README.rdoc
CHANGED
@@ -40,5 +40,5 @@ or fork the project and send a pull request.
|
|
40
40
|
|
41
41
|
== Copyright
|
42
42
|
|
43
|
-
Copyright (c)
|
44
|
-
See {LICENSE}[https://github.com/pioz/chess/blob/master/LICENSE] for details.
|
43
|
+
Copyright (c) 2015 {Enrico Pilotto (@pioz)}[https://github.com/pioz].
|
44
|
+
See {LICENSE}[https://github.com/pioz/chess/blob/master/LICENSE] for details.
|
data/Rakefile
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
2
|
|
3
3
|
require 'rdoc/task'
|
4
|
+
require 'sdoc'
|
4
5
|
Rake::RDocTask.new do |rd|
|
5
6
|
rd.title = 'Chess'
|
6
7
|
rd.main = 'README.rdoc'
|
7
8
|
rd.rdoc_dir = 'doc'
|
8
9
|
rd.rdoc_files.include('README.rdoc', 'lib/**/*.rb', 'ext/*.c')
|
9
|
-
|
10
|
+
rd.options << '-f' << 'sdoc'
|
10
11
|
end
|
11
12
|
|
12
13
|
require 'rake/testtask'
|
@@ -14,4 +15,4 @@ task :default => :test
|
|
14
15
|
Rake::TestTask.new do |test|
|
15
16
|
test.libs << 'test'
|
16
17
|
test.test_files = FileList["test/test_#{ENV['T'] || '*'}.rb"]
|
17
|
-
end
|
18
|
+
end
|
data/ext/board.c
CHANGED
data/ext/common.c
CHANGED
data/ext/common.h
CHANGED
data/ext/extconf.rb
CHANGED
data/ext/game.c
CHANGED
@@ -327,7 +327,7 @@ set_fen (Game *g, const char *fen)
|
|
327
327
|
|
328
328
|
// check result
|
329
329
|
if (king_in_checkmate (board, board->active_color))
|
330
|
-
g->result = board->active_color;
|
330
|
+
g->result = !board->active_color;
|
331
331
|
else
|
332
332
|
if (stalemate (board, board->active_color) || insufficient_material (board))
|
333
333
|
g->result = DRAW;
|
data/lib/chess.rb
CHANGED
data/lib/chess/exceptions.rb
CHANGED
data/lib/chess/game.rb
CHANGED
data/lib/chess/gnuchess.rb
CHANGED
data/lib/chess/pgn.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
module Chess
|
2
|
+
|
3
|
+
# With this module is possible call the method +to_utf8+ on a string. This
|
4
|
+
# method convert the chess piece identifier character into UTF8 chess
|
5
|
+
# character, for example:
|
6
|
+
# :001 > require 'chess/utf8_notation'
|
7
|
+
# => true
|
8
|
+
# :002 > 'Qf7#'.to_utf8
|
9
|
+
# => '♕f7#'
|
10
|
+
# To use this utility explicit require is needed:
|
11
|
+
# <tt>require 'chess/utf8_notation'</tt>
|
12
|
+
module UTF8Notation
|
13
|
+
|
14
|
+
# Map a piece identifier character with the corresponding UTF8 chess
|
15
|
+
# character
|
16
|
+
UTF8_MAP = {
|
17
|
+
'P' => '♙',
|
18
|
+
'R' => '♖',
|
19
|
+
'N' => '♘',
|
20
|
+
'B' => '♗',
|
21
|
+
'Q' => '♕',
|
22
|
+
'K' => '♔',
|
23
|
+
'p' => '♟',
|
24
|
+
'r' => '♜',
|
25
|
+
'n' => '♞',
|
26
|
+
'b' => '♝',
|
27
|
+
'q' => '♛',
|
28
|
+
'k' => '♚'
|
29
|
+
}
|
30
|
+
|
31
|
+
# Replace the piece identifier characters with UTF8 chess characters
|
32
|
+
def to_utf8
|
33
|
+
self.gsub(/[PRNBQKprnbqk]/, UTF8_MAP)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
String.prepend(Chess::UTF8Notation)
|
data/lib/chess/version.rb
CHANGED
data/test/test_load_fen.rb
CHANGED
@@ -12,12 +12,21 @@ class ChessTest < Minitest::Test
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_fen_white_won
|
15
|
+
g = Chess::Game.load_fen('rnbqkbnr/1ppp1Qpp/8/p3p3/2B1P3/8/PPPP1PPP/RNB1K1NR b KQkq - 1 3')
|
16
|
+
assert_equal 'Q', g.board['f7']
|
17
|
+
assert_equal 'p', g.board['e5']
|
18
|
+
assert_equal 'P', g.board[28]
|
19
|
+
assert_equal '1-0', g.result
|
20
|
+
assert_equal :white_won, g.status
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_fen_black_won
|
15
24
|
g = Chess::Game.load_fen('rnb1kbnr/pppp1ppp/4p3/8/5PPq/8/PPPPP2P/RNBQKBNR w KQkq - 1 3')
|
16
25
|
assert_equal 'q', g.board['h4']
|
17
26
|
assert_equal 'P', g.board['f4']
|
18
27
|
assert_equal 'p', g.board[44]
|
19
|
-
assert_equal '1
|
20
|
-
assert_equal :
|
28
|
+
assert_equal '0-1', g.result
|
29
|
+
assert_equal :black_won, g.status
|
21
30
|
end
|
22
31
|
|
23
32
|
def test_fen_stalemate
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chess
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Enrico Pilotto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A fast chess library that use bitboards to play chess with Ruby.
|
14
14
|
email:
|
@@ -43,6 +43,7 @@ files:
|
|
43
43
|
- lib/chess/game.rb
|
44
44
|
- lib/chess/gnuchess.rb
|
45
45
|
- lib/chess/pgn.rb
|
46
|
+
- lib/chess/utf8_notation.rb
|
46
47
|
- lib/chess/version.rb
|
47
48
|
- test/pgn_collection/checkmate/black_won/0001.pgn
|
48
49
|
- test/pgn_collection/checkmate/black_won/0002.pgn
|