chess 0.0.9 → 0.1.0

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.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/Rakefile +1 -0
  4. data/doc/apple-touch-icon.png +0 -0
  5. data/doc/classes/Chess.html +162 -0
  6. data/doc/classes/Chess/BadNotationError.html +84 -0
  7. data/doc/classes/Chess/Board.html +795 -0
  8. data/doc/classes/Chess/CGame.html +1168 -0
  9. data/doc/classes/Chess/Game.html +775 -0
  10. data/doc/classes/Chess/Gnuchess.html +206 -0
  11. data/doc/classes/Chess/IllegalMoveError.html +82 -0
  12. data/doc/classes/Chess/InvalidFenFormatError.html +82 -0
  13. data/doc/classes/Chess/InvalidPgnFormatError.html +82 -0
  14. data/doc/classes/Chess/Pgn.html +332 -0
  15. data/doc/classes/Chess/UTF8Notation.html +175 -0
  16. data/doc/created.rid +15 -0
  17. data/doc/css/github.css +123 -0
  18. data/doc/css/main.css +323 -0
  19. data/doc/css/panel.css +384 -0
  20. data/doc/css/reset.css +48 -0
  21. data/doc/favicon.ico +0 -0
  22. data/doc/files/README_rdoc.html +122 -0
  23. data/doc/files/ext/bitboard_c.html +68 -0
  24. data/doc/files/ext/board_c.html +68 -0
  25. data/doc/files/ext/chess_c.html +68 -0
  26. data/doc/files/ext/common_c.html +68 -0
  27. data/doc/files/ext/game_c.html +68 -0
  28. data/doc/files/ext/special_c.html +68 -0
  29. data/doc/files/lib/chess/exceptions_rb.html +94 -0
  30. data/doc/files/lib/chess/game_rb.html +84 -0
  31. data/doc/files/lib/chess/gnuchess_rb.html +84 -0
  32. data/doc/files/lib/chess/pgn_rb.html +84 -0
  33. data/doc/files/lib/chess/utf8_notation_rb.html +84 -0
  34. data/doc/files/lib/chess/version_rb.html +85 -0
  35. data/doc/files/lib/chess_rb.html +84 -0
  36. data/doc/i/arrows.png +0 -0
  37. data/doc/i/results_bg.png +0 -0
  38. data/doc/i/tree_bg.png +0 -0
  39. data/doc/index.html +13 -0
  40. data/doc/js/highlight.pack.js +1 -0
  41. data/doc/js/jquery-1.3.2.min.js +19 -0
  42. data/doc/js/jquery-effect.js +593 -0
  43. data/doc/js/main.js +24 -0
  44. data/doc/js/navigation.js +142 -0
  45. data/doc/js/search_index.js +1 -0
  46. data/doc/js/searchdoc.js +449 -0
  47. data/doc/js/searcher.js +228 -0
  48. data/doc/panel/index.html +73 -0
  49. data/doc/panel/links.html +34 -0
  50. data/doc/panel/tree.js +1 -0
  51. data/ext/chess.c +82 -33
  52. data/ext/chess.h +1 -1
  53. data/ext/common.c +1 -1
  54. data/ext/common.h +1 -1
  55. data/ext/game.c +7 -6
  56. data/ext/game.h +1 -1
  57. data/lib/chess/exceptions.rb +2 -1
  58. data/lib/chess/game.rb +18 -5
  59. data/lib/chess/gnuchess.rb +1 -1
  60. data/lib/chess/utf8_notation.rb +1 -0
  61. data/lib/chess/version.rb +1 -1
  62. metadata +50 -3
@@ -20,7 +20,7 @@ VALUE game_draw (VALUE self);
20
20
  VALUE game_boards (VALUE self, VALUE index);
21
21
  VALUE game_current_board (VALUE self);
22
22
  VALUE game_moves (VALUE self);
23
- VALUE game_full_moves (VALUE self);
23
+ VALUE game_coord_moves (VALUE self);
24
24
  VALUE game_threefold_repetition (VALUE self);
25
25
  VALUE game_result (VALUE self);
26
26
  VALUE game_size (VALUE self);
@@ -36,7 +36,7 @@ square_to_coord (int square)
36
36
  }
37
37
 
38
38
  char*
39
- ft_to_full_move (int from, int to, char promote_in)
39
+ ft_to_coord_move (int from, int to, char promote_in)
40
40
  {
41
41
  char *s = (char *) malloc (7);
42
42
  s[0] = square_to_file (from);
@@ -101,7 +101,7 @@ char square_to_file (int square);
101
101
  char square_to_rank (int square);
102
102
  int coord_to_square (const char *coord);
103
103
  char* square_to_coord (int square);
104
- char* ft_to_full_move (int from, int to, char promote_in);
104
+ char* ft_to_coord_move (int from, int to, char promote_in);
105
105
  char* result_to_s (unsigned short int r);
106
106
  char* castling_to_s (short int castling);
107
107
  char* en_passant_to_s (short int en_passant);
data/ext/game.c CHANGED
@@ -34,7 +34,7 @@ free_game (Game *g)
34
34
  {
35
35
  free (g->boards[i]);
36
36
  free (g->moves[i]);
37
- free (g->full_moves[i]);
37
+ free (g->coord_moves[i]);
38
38
  }
39
39
  free (g);
40
40
  }
@@ -69,7 +69,7 @@ char*
69
69
  current_full_move (Game *g)
70
70
  {
71
71
  if (g->current > 0)
72
- return g->full_moves[g->current-1];
72
+ return g->coord_moves[g->current-1];
73
73
  return 0;
74
74
  }
75
75
 
@@ -101,7 +101,7 @@ apply_move (Game *g, int from, int to, char promote_in)
101
101
  new_board->halfmove_clock++;
102
102
  g->boards[g->current] = new_board;
103
103
  g->moves[g->current] = move_done;
104
- g->full_moves[g->current] = ft_to_full_move (from, to, promote_in);
104
+ g->coord_moves[g->current] = ft_to_coord_move (from, to, promote_in);
105
105
  g->current++;
106
106
  // Test check or checkmate of opponent king
107
107
  if (king_in_check (new_board, new_board->active_color))
@@ -128,10 +128,11 @@ rollback (Game *g)
128
128
  {
129
129
  if (g->current > 0)
130
130
  {
131
+ g->result = IN_PROGRESS;
131
132
  g->current--;
132
133
  free (g->boards[g->current]);
133
134
  free (g->moves[g->current]);
134
- free (g->full_moves[g->current]);
135
+ free (g->coord_moves[g->current]);
135
136
  }
136
137
  }
137
138
 
@@ -320,9 +321,9 @@ set_fen (Game *g, const char *fen)
320
321
  set_occupied (board);
321
322
  g->boards[g->current] = board;
322
323
  g->moves[g->current] = (char *) malloc (11);
323
- g->full_moves[g->current] = (char *) malloc (11);
324
+ g->coord_moves[g->current] = (char *) malloc (11);
324
325
  strcpy (g->moves[g->current], "SET BY FEN");
325
- strcpy (g->full_moves[g->current], "SET BY FEN");
326
+ strcpy (g->coord_moves[g->current], "SET BY FEN");
326
327
  g->current++;
327
328
 
328
329
  // check result
data/ext/game.h CHANGED
@@ -19,7 +19,7 @@ typedef struct
19
19
  {
20
20
  Board* boards[BUFFER_SIZE];
21
21
  char* moves[BUFFER_SIZE];
22
- char* full_moves[BUFFER_SIZE];
22
+ char* coord_moves[BUFFER_SIZE];
23
23
  int current;
24
24
  unsigned short result;
25
25
  } Game;
@@ -1,6 +1,7 @@
1
1
  module Chess
2
2
 
3
- # This exception will be raised when an invalid short algebraic chess notation string is passed to the Game#move function.
3
+ # This exception will be raised when an invalid short algebraic chess notation
4
+ # string is passed to the Game#move function.
4
5
  class BadNotationError < StandardError
5
6
  # :nodoc:
6
7
  # Create a new exception.
@@ -6,12 +6,14 @@ module Chess
6
6
  class Game < CGame
7
7
 
8
8
  # Create a new game. If an array of moves is provided, the moves will be performed.
9
+ #
9
10
  # May be raise an IllegalMoveError or BadNotationError.
10
11
  def initialize(moves = [])
11
12
  moves.each { |m| move(m) }
12
13
  end
13
14
 
14
15
  # Creates a new game from a file in PGN format.
16
+ #
15
17
  # May be raise an InvalidPgnFormatError or IllegalMoveError or BadNotationError.
16
18
  def self.load_pgn(file)
17
19
  pgn = Chess::Pgn.new(file)
@@ -34,7 +36,9 @@ module Chess
34
36
  end
35
37
 
36
38
  # Creates a new game from a FEN string.
39
+ #
37
40
  # May be raise an InvalidFenFormatError.
41
+ #
38
42
  # *Warning*: this game do not have history before the FEN placement.
39
43
  def self.load_fen(fen)
40
44
  if fen =~ /^((?:[PRNBQKprnbqk1-8]{1,8}\/){7}[RNBQKPrnbqkp1-8]{1,8})\s(w|b)\s(K?Q?k?q?|-)\s([a-h][1-8]|-)\s(\d+)\s(\d+)$/
@@ -47,11 +51,18 @@ module Chess
47
51
  end
48
52
 
49
53
  # Make a move. This add a new Board in the Storyboard.
50
- # The parameter +m+ represents the short algebraic chess notation string of the move.
51
- # +m+ can be <em>from_square</em> plus <em>to_square</em> <em>('e2e4', ..., 'b1c3')</em>.
52
- # This method returns a string that represents the short algebraic chess notation of the move.
54
+ #
55
+ # Parameters are:
56
+ # +m+:: represents the short algebraic chess notation string of the move.
57
+ # +m+ can be <em>from_square</em> plus <em>to_square</em>
58
+ # <em>('e2e4', ..., 'b1c3')</em> (coordinate chess notation).
59
+ #
60
+ # This method returns a string that represents the short algebraic chess
61
+ # notation of the move.
62
+ #
53
63
  # Raise an IllegalMoveError if the move is illegal.
54
- # Raise an BadNotationError if the short algebraic chess notation is malformed.
64
+ # Raise an BadNotationError if the short algebraic chess notation is
65
+ # malformed.
55
66
  def move(m)
56
67
  begin
57
68
  expand = expand_move(m)
@@ -61,7 +72,7 @@ module Chess
61
72
  super(expand[:name], expand[:dis], expand[:to], expand[:promotion])
62
73
  end
63
74
  rescue IllegalMoveError => e
64
- raise IllegalMoveError.new("Illegal move '#{m}'\n#{self.to_s}")
75
+ raise IllegalMoveError.new("Illegal move '#{m}'\n#{self.active_player} turn\n#{self.to_s}")
65
76
  end
66
77
  end
67
78
  alias :move= :move
@@ -83,6 +94,7 @@ module Chess
83
94
  end
84
95
 
85
96
  # Returns the status of the game.
97
+ #
86
98
  # Possible states are:
87
99
  # * +in_progress+:: the game is in progress.
88
100
  # * +white_won+:: white player has won with a checkmate.
@@ -140,6 +152,7 @@ module Chess
140
152
  private
141
153
 
142
154
  # Expand the short algebraic chess notation string +m+ in a hash like this:
155
+ #
143
156
  # Ngxe2 ==> { name: 'N', dis: 'g', from: nil, to: 'e2', promotion: '' }
144
157
  def expand_move(m)
145
158
  if match = m.match(/^([RNBQK])?([a-h]?[1-8]?)(?:x)?([a-h][1-8])(?:=?([RrNnBbQq]))?(?:ep)?(?:\+|\#)?$/)
@@ -17,7 +17,7 @@ module Chess
17
17
  begin
18
18
  pipe.puts('depth 1')
19
19
  pipe.puts('manual')
20
- self.full_moves.each do |m|
20
+ self.coord_moves.each do |m|
21
21
  pipe.puts(m)
22
22
  end
23
23
  pipe.puts('go')
@@ -7,6 +7,7 @@ module Chess
7
7
  # => true
8
8
  # :002 > 'Qf7#'.to_utf8
9
9
  # => '♕f7#'
10
+ #
10
11
  # To use this utility explicit require is needed:
11
12
  # <tt>require 'chess/utf8_notation'</tt>
12
13
  module UTF8Notation
@@ -1,5 +1,5 @@
1
1
  # The Chess library module.
2
2
  module Chess
3
3
  # The library version.
4
- VERSION = '0.0.9'
4
+ VERSION = '0.1.0'
5
5
  end
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.9
4
+ version: 0.1.0
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-06-04 00:00:00.000000000 Z
11
+ date: 2016-03-21 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:
@@ -24,6 +24,53 @@ files:
24
24
  - README.rdoc
25
25
  - Rakefile
26
26
  - chess.gemspec
27
+ - doc/apple-touch-icon.png
28
+ - doc/classes/Chess.html
29
+ - doc/classes/Chess/BadNotationError.html
30
+ - doc/classes/Chess/Board.html
31
+ - doc/classes/Chess/CGame.html
32
+ - doc/classes/Chess/Game.html
33
+ - doc/classes/Chess/Gnuchess.html
34
+ - doc/classes/Chess/IllegalMoveError.html
35
+ - doc/classes/Chess/InvalidFenFormatError.html
36
+ - doc/classes/Chess/InvalidPgnFormatError.html
37
+ - doc/classes/Chess/Pgn.html
38
+ - doc/classes/Chess/UTF8Notation.html
39
+ - doc/created.rid
40
+ - doc/css/github.css
41
+ - doc/css/main.css
42
+ - doc/css/panel.css
43
+ - doc/css/reset.css
44
+ - doc/favicon.ico
45
+ - doc/files/README_rdoc.html
46
+ - doc/files/ext/bitboard_c.html
47
+ - doc/files/ext/board_c.html
48
+ - doc/files/ext/chess_c.html
49
+ - doc/files/ext/common_c.html
50
+ - doc/files/ext/game_c.html
51
+ - doc/files/ext/special_c.html
52
+ - doc/files/lib/chess/exceptions_rb.html
53
+ - doc/files/lib/chess/game_rb.html
54
+ - doc/files/lib/chess/gnuchess_rb.html
55
+ - doc/files/lib/chess/pgn_rb.html
56
+ - doc/files/lib/chess/utf8_notation_rb.html
57
+ - doc/files/lib/chess/version_rb.html
58
+ - doc/files/lib/chess_rb.html
59
+ - doc/i/arrows.png
60
+ - doc/i/results_bg.png
61
+ - doc/i/tree_bg.png
62
+ - doc/index.html
63
+ - doc/js/highlight.pack.js
64
+ - doc/js/jquery-1.3.2.min.js
65
+ - doc/js/jquery-effect.js
66
+ - doc/js/main.js
67
+ - doc/js/navigation.js
68
+ - doc/js/search_index.js
69
+ - doc/js/searchdoc.js
70
+ - doc/js/searcher.js
71
+ - doc/panel/index.html
72
+ - doc/panel/links.html
73
+ - doc/panel/tree.js
27
74
  - ext/MakefileC
28
75
  - ext/bitboard.c
29
76
  - ext/bitboard.h
@@ -1272,7 +1319,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1272
1319
  version: '0'
1273
1320
  requirements: []
1274
1321
  rubyforge_project: chess
1275
- rubygems_version: 2.4.5
1322
+ rubygems_version: 2.5.1
1276
1323
  signing_key:
1277
1324
  specification_version: 4
1278
1325
  summary: A fast chess library to play chess with Ruby.