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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e838f9143623b8cf79ce47acb7da0833dc30ec0
4
- data.tar.gz: e77ec1755cc3d589f7116f64b7e92cfd81996e54
3
+ metadata.gz: c862229413460f6c0a009c043f7b2f60a617cae8
4
+ data.tar.gz: b44b851efc9ba6cd81d9389d2bde719d91bbf6fb
5
5
  SHA512:
6
- metadata.gz: 83431e4f5cc6b6f0295800df9dd2c56032e3108a4525ae89052c11c081238e3cb481cdcbd553caa4550daf69fb43355c4380cec57fb53fe7cf44c5e883a09c89
7
- data.tar.gz: 73ec3749211e7bdeaa7f050717b630a594c1c56532777afa877419d3ceba7c814b9e88234935d5a18138c6e7db35b888f2ed8582880381537271c792a97b5b38
6
+ metadata.gz: bd88ad5bb24246e5fd603781a22bff4d45f3462a0edd21dc21518da724a13f4c4950a91816f00263d0b545b6bfce927190bde862938f8e9519221d1402090ed7
7
+ data.tar.gz: ea7d3f54825f1aae7ede6258b2eb4174409727dd05712a6af1a09dc0731cc2e05fd26a58b15c020bfdf98df0a5ba2d0e0c5f5101a4d96c766f578a63902e7801
@@ -40,5 +40,5 @@ or fork the project and send a pull request.
40
40
 
41
41
  == Copyright
42
42
 
43
- Copyright (c) 2012 {Enrico Pilotto (@pioz)}[https://github.com/pioz].
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
- #rd.options << '-f' << 'horo'
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
@@ -580,4 +580,4 @@ to_fen (Board *board)
580
580
  free (ep);
581
581
 
582
582
  return fen;
583
- }
583
+ }
@@ -104,4 +104,4 @@ int
104
104
  compare (const void *a, const void *b)
105
105
  {
106
106
  return strcmp (*(const char **) a, *(const char **) b);
107
- }
107
+ }
@@ -107,4 +107,4 @@ char* castling_to_s (short int castling);
107
107
  char* en_passant_to_s (short int en_passant);
108
108
  int compare (const void *a, const void *b);
109
109
 
110
- #endif
110
+ #endif
@@ -26,4 +26,4 @@ LIB_DIRS = [
26
26
 
27
27
  #dir_config('chess', INCLUDE_DIRS, LIB_DIRS)
28
28
 
29
- create_makefile('chess/chess')
29
+ create_makefile('chess/chess')
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;
@@ -2,4 +2,4 @@ require 'chess/exceptions'
2
2
  require 'chess/game'
3
3
  require 'chess/gnuchess'
4
4
  require 'chess/pgn'
5
- require 'chess/version'
5
+ require 'chess/version'
@@ -28,4 +28,3 @@ module Chess
28
28
  end
29
29
 
30
30
  end
31
-
@@ -168,4 +168,4 @@ module Chess
168
168
  end
169
169
 
170
170
  end
171
- end
171
+ end
@@ -117,4 +117,3 @@ module Chess
117
117
  end
118
118
 
119
119
  end
120
-
@@ -64,4 +64,4 @@ module Chess
64
64
  end
65
65
 
66
66
  end
67
- end
67
+ end
@@ -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)
@@ -1,5 +1,5 @@
1
1
  # The Chess library module.
2
2
  module Chess
3
3
  # The library version.
4
- VERSION = '0.0.6'
4
+ VERSION = '0.0.8'
5
5
  end
@@ -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-0', g.result
20
- assert_equal :white_won, g.status
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.6
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-13 00:00:00.000000000 Z
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