chess 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/Rakefile +1 -0
- data/doc/apple-touch-icon.png +0 -0
- data/doc/classes/Chess.html +162 -0
- data/doc/classes/Chess/BadNotationError.html +84 -0
- data/doc/classes/Chess/Board.html +795 -0
- data/doc/classes/Chess/CGame.html +1168 -0
- data/doc/classes/Chess/Game.html +775 -0
- data/doc/classes/Chess/Gnuchess.html +206 -0
- data/doc/classes/Chess/IllegalMoveError.html +82 -0
- data/doc/classes/Chess/InvalidFenFormatError.html +82 -0
- data/doc/classes/Chess/InvalidPgnFormatError.html +82 -0
- data/doc/classes/Chess/Pgn.html +332 -0
- data/doc/classes/Chess/UTF8Notation.html +175 -0
- data/doc/created.rid +15 -0
- data/doc/css/github.css +123 -0
- data/doc/css/main.css +323 -0
- data/doc/css/panel.css +384 -0
- data/doc/css/reset.css +48 -0
- data/doc/favicon.ico +0 -0
- data/doc/files/README_rdoc.html +122 -0
- data/doc/files/ext/bitboard_c.html +68 -0
- data/doc/files/ext/board_c.html +68 -0
- data/doc/files/ext/chess_c.html +68 -0
- data/doc/files/ext/common_c.html +68 -0
- data/doc/files/ext/game_c.html +68 -0
- data/doc/files/ext/special_c.html +68 -0
- data/doc/files/lib/chess/exceptions_rb.html +94 -0
- data/doc/files/lib/chess/game_rb.html +84 -0
- data/doc/files/lib/chess/gnuchess_rb.html +84 -0
- data/doc/files/lib/chess/pgn_rb.html +84 -0
- data/doc/files/lib/chess/utf8_notation_rb.html +84 -0
- data/doc/files/lib/chess/version_rb.html +85 -0
- data/doc/files/lib/chess_rb.html +84 -0
- data/doc/i/arrows.png +0 -0
- data/doc/i/results_bg.png +0 -0
- data/doc/i/tree_bg.png +0 -0
- data/doc/index.html +13 -0
- data/doc/js/highlight.pack.js +1 -0
- data/doc/js/jquery-1.3.2.min.js +19 -0
- data/doc/js/jquery-effect.js +593 -0
- data/doc/js/main.js +24 -0
- data/doc/js/navigation.js +142 -0
- data/doc/js/search_index.js +1 -0
- data/doc/js/searchdoc.js +449 -0
- data/doc/js/searcher.js +228 -0
- data/doc/panel/index.html +73 -0
- data/doc/panel/links.html +34 -0
- data/doc/panel/tree.js +1 -0
- data/ext/chess.c +82 -33
- data/ext/chess.h +1 -1
- data/ext/common.c +1 -1
- data/ext/common.h +1 -1
- data/ext/game.c +7 -6
- data/ext/game.h +1 -1
- data/lib/chess/exceptions.rb +2 -1
- data/lib/chess/game.rb +18 -5
- data/lib/chess/gnuchess.rb +1 -1
- data/lib/chess/utf8_notation.rb +1 -0
- data/lib/chess/version.rb +1 -1
- metadata +50 -3
data/ext/chess.h
CHANGED
@@ -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
|
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);
|
data/ext/common.c
CHANGED
data/ext/common.h
CHANGED
@@ -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*
|
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->
|
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->
|
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->
|
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->
|
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->
|
324
|
+
g->coord_moves[g->current] = (char *) malloc (11);
|
324
325
|
strcpy (g->moves[g->current], "SET BY FEN");
|
325
|
-
strcpy (g->
|
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
data/lib/chess/exceptions.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Chess
|
2
2
|
|
3
|
-
# This exception will be raised when an invalid short algebraic chess notation
|
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.
|
data/lib/chess/game.rb
CHANGED
@@ -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
|
-
#
|
51
|
-
#
|
52
|
-
#
|
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
|
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)?(?:\+|\#)?$/)
|
data/lib/chess/gnuchess.rb
CHANGED
data/lib/chess/utf8_notation.rb
CHANGED
data/lib/chess/version.rb
CHANGED
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.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:
|
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.
|
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.
|