chess 0.2.0 → 0.3.2
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.
- checksums.yaml +5 -5
- data/.github/FUNDING.yml +12 -0
- data/.github/workflows/ruby.yml +58 -0
- data/.gitignore +2 -2
- data/.rubocop.yml +51 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +70 -0
- data/README.md +26 -22
- data/Rakefile +5 -4
- data/chess.gemspec +15 -11
- data/docs/Chess.html +157 -0
- data/docs/Chess/BadNotationError.html +237 -0
- data/docs/Chess/Board.html +1759 -0
- data/docs/Chess/CGame.html +2296 -0
- data/docs/Chess/Game.html +1277 -0
- data/docs/Chess/Gnuchess.html +366 -0
- data/docs/Chess/IllegalMoveError.html +137 -0
- data/docs/Chess/InvalidFenFormatError.html +237 -0
- data/docs/Chess/InvalidPgnFormatError.html +217 -0
- data/docs/Chess/Pgn.html +1477 -0
- data/docs/Chess/UTF8Notation.html +270 -0
- data/docs/_index.html +217 -0
- data/docs/class_list.html +51 -0
- data/docs/css/common.css +1 -0
- data/docs/css/full_list.css +58 -0
- data/docs/css/style.css +497 -0
- data/docs/file.README.html +116 -0
- data/docs/file_list.html +56 -0
- data/docs/frames.html +17 -0
- data/docs/index.html +116 -0
- data/docs/js/app.js +314 -0
- data/docs/js/full_list.js +216 -0
- data/docs/js/jquery.js +4 -0
- data/docs/method_list.html +531 -0
- data/docs/top-level-namespace.html +110 -0
- data/ext/bitboard.c +1 -1
- data/ext/bitboard.h +1 -1
- data/ext/board.c +1 -1
- data/ext/board.h +1 -1
- data/ext/chess.c +2 -2
- data/ext/chess.h +1 -1
- data/ext/common.c +1 -1
- data/ext/common.h +8 -4
- data/ext/extconf.rb +7 -6
- data/ext/game.c +2 -2
- data/ext/game.h +1 -1
- data/ext/special.c +10 -3
- data/ext/special.h +3 -2
- data/lib/chess/exceptions.rb +2 -5
- data/lib/chess/game.rb +55 -77
- data/lib/chess/gnuchess.rb +24 -27
- data/lib/chess/pgn.rb +32 -26
- data/lib/chess/utf8_notation.rb +3 -3
- data/lib/chess/version.rb +1 -1
- data/test/test_big_pgn_collection.rb +3 -4
- data/test/test_checkmate.rb +4 -6
- data/test/test_errors.rb +22 -0
- data/test/test_fifty_rule_move.rb +2 -4
- data/test/test_game.rb +82 -0
- data/test/test_helper.rb +16 -3
- data/test/test_illegal_moves.rb +1 -3
- data/test/test_insufficient_material.rb +6 -7
- data/test/test_load_fen.rb +11 -1
- data/test/test_move_generator.rb +13 -14
- data/test/test_particular_situations.rb +0 -2
- data/test/test_pgn.rb +82 -1
- data/test/test_pgn_collection.rb +2 -2
- data/test/test_stalemate.rb +1 -3
- data/test/test_threefold_repetition.rb +1 -3
- metadata +145 -15
@@ -0,0 +1,110 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>
|
7
|
+
Top Level Namespace
|
8
|
+
|
9
|
+
— Chess
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" />
|
16
|
+
|
17
|
+
<script type="text/javascript">
|
18
|
+
pathId = "";
|
19
|
+
relpath = '';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
|
23
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
24
|
+
|
25
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
26
|
+
|
27
|
+
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<div class="nav_wrap">
|
31
|
+
<iframe id="nav" src="class_list.html?1"></iframe>
|
32
|
+
<div id="resizer"></div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
38
|
+
|
39
|
+
<a href="_index.html">Index</a> »
|
40
|
+
|
41
|
+
|
42
|
+
<span class="title">Top Level Namespace</span>
|
43
|
+
|
44
|
+
</div>
|
45
|
+
|
46
|
+
<div id="search">
|
47
|
+
|
48
|
+
<a class="full_list_link" id="class_list_link"
|
49
|
+
href="class_list.html">
|
50
|
+
|
51
|
+
<svg width="24" height="24">
|
52
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
54
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
55
|
+
</svg>
|
56
|
+
</a>
|
57
|
+
|
58
|
+
</div>
|
59
|
+
<div class="clear"></div>
|
60
|
+
</div>
|
61
|
+
|
62
|
+
<div id="content"><h1>Top Level Namespace
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
</h1>
|
67
|
+
<div class="box_info">
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
</div>
|
80
|
+
|
81
|
+
<h2>Defined Under Namespace</h2>
|
82
|
+
<p class="children">
|
83
|
+
|
84
|
+
|
85
|
+
<strong class="modules">Modules:</strong> <span class='object_link'><a href="Chess.html" title="Chess (module)">Chess</a></span>
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
</p>
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
</div>
|
101
|
+
|
102
|
+
<div id="footer">
|
103
|
+
Generated on Thu Jan 28 17:31:40 2021 by
|
104
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
105
|
+
0.9.26 (ruby-2.6.1).
|
106
|
+
</div>
|
107
|
+
|
108
|
+
</div>
|
109
|
+
</body>
|
110
|
+
</html>
|
data/ext/bitboard.c
CHANGED
data/ext/bitboard.h
CHANGED
data/ext/board.c
CHANGED
data/ext/board.h
CHANGED
data/ext/chess.c
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
2
|
* chess - a fast library to play chess in Ruby
|
3
3
|
*
|
4
|
-
* Copyright (c) 2011-
|
4
|
+
* Copyright (c) 2011-2018, Enrico Pilotto <epilotto@gmx.com>
|
5
5
|
* This code is under LICENSE LGPLv3
|
6
6
|
*/
|
7
7
|
|
@@ -723,7 +723,7 @@ Init_chess ()
|
|
723
723
|
rb_define_method (board_klass, "stalemate?", board_stalemate, 0);
|
724
724
|
rb_define_method (board_klass, "insufficient_material?", board_insufficient_material, 0);
|
725
725
|
rb_define_method (board_klass, "only_kings?", board_only_kings, 0);
|
726
|
-
rb_define_method (board_klass, "
|
726
|
+
rb_define_method (board_klass, "fifty_move_rule?", board_fifty_move_rule, 0);
|
727
727
|
rb_define_method (board_klass, "active_color", board_active_color, 0);
|
728
728
|
rb_define_method (board_klass, "halfmove_clock", board_halfmove_clock, 0);
|
729
729
|
rb_define_method (board_klass, "fullmove_number", board_fullmove_number, 0);
|
data/ext/chess.h
CHANGED
data/ext/common.c
CHANGED
data/ext/common.h
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
2
|
* chess - a fast library to play chess in Ruby
|
3
3
|
*
|
4
|
-
* Copyright (c) 2011-
|
4
|
+
* Copyright (c) 2011-2018, Enrico Pilotto <epilotto@gmx.com>
|
5
5
|
* This code is under LICENSE LGPLv3
|
6
6
|
*/
|
7
7
|
|
@@ -13,9 +13,15 @@
|
|
13
13
|
#include <string.h>
|
14
14
|
#include <ctype.h>
|
15
15
|
|
16
|
-
//
|
16
|
+
// Boolean definition
|
17
|
+
|
18
|
+
#ifndef RUBY_BACKWARD2_BOOL_H
|
17
19
|
#define FALSE 0
|
18
20
|
#define TRUE 1
|
21
|
+
typedef unsigned short bool;
|
22
|
+
#endif
|
23
|
+
|
24
|
+
// Macros
|
19
25
|
|
20
26
|
#define A1 0
|
21
27
|
#define B1 1
|
@@ -95,8 +101,6 @@
|
|
95
101
|
#define DRAW 2
|
96
102
|
#define IN_PROGRESS 3
|
97
103
|
|
98
|
-
typedef unsigned short bool;
|
99
|
-
|
100
104
|
char square_to_file (int square);
|
101
105
|
char square_to_rank (int square);
|
102
106
|
int coord_to_square (const char *coord);
|
data/ext/extconf.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
ENV['RC_ARCHS'] = '' if RUBY_PLATFORM
|
1
|
+
ENV['RC_ARCHS'] = '' if RUBY_PLATFORM.include?('darwin')
|
2
2
|
|
3
3
|
require 'mkmf'
|
4
4
|
|
@@ -10,8 +10,8 @@ INCLUDE_DIRS = [
|
|
10
10
|
# Then search /usr/local for people that installed from source
|
11
11
|
'/usr/local/include',
|
12
12
|
# Finally fall back to /usr
|
13
|
-
'/usr/include'
|
14
|
-
]
|
13
|
+
'/usr/include'
|
14
|
+
].freeze
|
15
15
|
|
16
16
|
LIB_DIRS = [
|
17
17
|
# Check the ruby install locations
|
@@ -21,9 +21,10 @@ LIB_DIRS = [
|
|
21
21
|
# Then search /usr/local for people that installed from source
|
22
22
|
'/usr/local/lib',
|
23
23
|
# Finally fall back to /usr
|
24
|
-
'/usr/lib'
|
25
|
-
]
|
24
|
+
'/usr/lib'
|
25
|
+
].freeze
|
26
26
|
|
27
|
-
#dir_config('chess', INCLUDE_DIRS, LIB_DIRS)
|
27
|
+
# dir_config('chess', INCLUDE_DIRS, LIB_DIRS)
|
28
|
+
$CFLAGS << ' -std=c99'
|
28
29
|
|
29
30
|
create_makefile('chess/chess')
|
data/ext/game.c
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
2
|
* chess - a fast library to play chess in Ruby
|
3
3
|
*
|
4
|
-
* Copyright (c) 2011-
|
4
|
+
* Copyright (c) 2011-2018, Enrico Pilotto <epilotto@gmx.com>
|
5
5
|
* This code is under LICENSE LGPLv3
|
6
6
|
*/
|
7
7
|
|
@@ -98,7 +98,7 @@ apply_move (Game *g, int from, int to, char promote_in)
|
|
98
98
|
}
|
99
99
|
}
|
100
100
|
// Ok move is legal, update the game
|
101
|
-
update_castling (new_board, from);
|
101
|
+
update_castling (new_board, from, to);
|
102
102
|
update_en_passant (new_board, from, to);
|
103
103
|
if (new_board->active_color)
|
104
104
|
new_board->fullmove_number++;
|
data/ext/game.h
CHANGED
data/ext/special.c
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
2
|
* chess - a fast library to play chess in Ruby
|
3
3
|
*
|
4
|
-
* Copyright (c) 2011-
|
4
|
+
* Copyright (c) 2011-2018, Enrico Pilotto <epilotto@gmx.com>
|
5
5
|
* This code is under LICENSE LGPLv3
|
6
6
|
*/
|
7
7
|
|
@@ -9,9 +9,9 @@
|
|
9
9
|
|
10
10
|
// Update the board castling bits (FEN style).
|
11
11
|
void
|
12
|
-
|
12
|
+
update_castling_by_square (Board *board, int square)
|
13
13
|
{
|
14
|
-
switch (
|
14
|
+
switch (square)
|
15
15
|
{
|
16
16
|
case A1:
|
17
17
|
board->castling ^= board->castling & 0x0100;
|
@@ -34,6 +34,13 @@ update_castling (Board *board, int from)
|
|
34
34
|
}
|
35
35
|
}
|
36
36
|
|
37
|
+
// Update the board castling bits checking if squares from and to are involved.
|
38
|
+
void
|
39
|
+
update_castling (Board *board, int from, int to) {
|
40
|
+
update_castling_by_square (board, from);
|
41
|
+
update_castling_by_square (board, to);
|
42
|
+
}
|
43
|
+
|
37
44
|
// Returns the castling type for the move from-to. If not a castling move
|
38
45
|
// returns 0.
|
39
46
|
int
|
data/ext/special.h
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
2
|
* chess - a fast library to play chess in Ruby
|
3
3
|
*
|
4
|
-
* Copyright (c) 2011-
|
4
|
+
* Copyright (c) 2011-2018, Enrico Pilotto <epilotto@gmx.com>
|
5
5
|
* This code is under LICENSE LGPLv3
|
6
6
|
*/
|
7
7
|
|
@@ -11,7 +11,8 @@
|
|
11
11
|
#include "common.h"
|
12
12
|
#include "board.h"
|
13
13
|
|
14
|
-
void
|
14
|
+
void update_castling_by_square (Board *board, int square);
|
15
|
+
void update_castling (Board *board, int from, int to);
|
15
16
|
int castling_type (Board *board, int from, int to);
|
16
17
|
char* castling (Board *board, int castling_type, Board *new_board);
|
17
18
|
void update_en_passant (Board *board, int from, int to);
|
data/lib/chess/exceptions.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
module Chess
|
2
|
-
|
3
2
|
# This exception will be raised when an invalid short algebraic chess notation
|
4
3
|
# string is passed to the {Game#move} function.
|
5
4
|
class BadNotationError < StandardError
|
@@ -11,9 +10,8 @@ module Chess
|
|
11
10
|
|
12
11
|
# This exception will be raised when a malformed PGN file is loaded.
|
13
12
|
class InvalidPgnFormatError < StandardError
|
14
|
-
|
15
|
-
|
16
|
-
super("Invalid PGN file '#{filename}'")
|
13
|
+
def initialize
|
14
|
+
super('Invalid PGN format')
|
17
15
|
end
|
18
16
|
end
|
19
17
|
|
@@ -24,5 +22,4 @@ module Chess
|
|
24
22
|
super("Invalid FEN string '#{fen_string}'")
|
25
23
|
end
|
26
24
|
end
|
27
|
-
|
28
25
|
end
|
data/lib/chess/game.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '../../ext/chess')
|
2
2
|
|
3
3
|
module Chess
|
4
|
-
|
5
4
|
# This class rappresents a chess game.
|
6
5
|
class Game < CGame
|
7
|
-
|
8
6
|
# @param [Array<String>] moves If an array of moves is provided, the moves will be performed.
|
9
7
|
# @raise [IllegalMoveError]
|
10
8
|
# @raise [BadNotationError]
|
11
9
|
def initialize(moves = [])
|
10
|
+
super()
|
12
11
|
moves.each { |m| move(m) }
|
13
12
|
end
|
14
13
|
|
@@ -22,7 +21,7 @@ module Chess
|
|
22
21
|
pgn = Chess::Pgn.new(file)
|
23
22
|
game = Chess::Game.new
|
24
23
|
pgn.moves.each { |m| game.move(m) }
|
25
|
-
|
24
|
+
unless game.over?
|
26
25
|
case pgn.result
|
27
26
|
when '1-0'
|
28
27
|
game.resign(:black)
|
@@ -41,19 +40,17 @@ module Chess
|
|
41
40
|
# @raise [InvalidFenFormatError]
|
42
41
|
# @note This game do not have history before the FEN placement.
|
43
42
|
def self.load_fen(fen)
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
raise InvalidFenFormatError.new(fen)
|
50
|
-
end
|
43
|
+
raise InvalidFenFormatError.new(fen) unless /^((?:[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+)$/.match?(fen)
|
44
|
+
|
45
|
+
game = Chess::Game.new
|
46
|
+
game.set_fen!(fen)
|
47
|
+
return game
|
51
48
|
end
|
52
49
|
|
53
50
|
# Make a move.
|
54
51
|
# @note This add a new {Board} in the {Game}.
|
55
|
-
# @param [String]
|
56
|
-
# the move. `
|
52
|
+
# @param [String] notation Represents the short algebraic chess notation string of
|
53
|
+
# the move. `notation` can be also _from_square_ plus _to_square_ _('e2e4', ...,
|
57
54
|
# 'b1c3')_ (coordinate chess notation).
|
58
55
|
# @return [String] Returns a string that represents the short algebraic
|
59
56
|
# chess notation of the move.
|
@@ -61,24 +58,20 @@ module Chess
|
|
61
58
|
# @raise {IllegalMoveError} if the move is illegal.
|
62
59
|
# @raise {BadNotationError} if the short algebraic chess notation is
|
63
60
|
# malformed.
|
64
|
-
def move(
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
super(expand[:name], expand[:dis], expand[:to], expand[:promotion])
|
71
|
-
end
|
72
|
-
rescue IllegalMoveError
|
73
|
-
if ENV['DEBUG']
|
74
|
-
raise IllegalMoveError.new("Illegal move '#{m}'\nStatus: #{self.status}\nPlayer turn #{self.active_player}\n#{self.to_s}")
|
75
|
-
else
|
76
|
-
raise IllegalMoveError.new("Illegal move '#{m}'")
|
77
|
-
end
|
61
|
+
def move(notation)
|
62
|
+
expand = expand_move(notation)
|
63
|
+
if expand[:from]
|
64
|
+
move2(expand[:from], expand[:to], expand[:promotion])
|
65
|
+
else
|
66
|
+
super(expand[:name], expand[:dis], expand[:to], expand[:promotion])
|
78
67
|
end
|
68
|
+
rescue IllegalMoveError
|
69
|
+
raise IllegalMoveError.new("Illegal move '#{notation}'\nStatus: #{self.status}\nPlayer turn #{self.active_player}\n#{self}") if ENV['DEBUG']
|
70
|
+
|
71
|
+
raise IllegalMoveError.new("Illegal move '#{notation}'")
|
79
72
|
end
|
80
|
-
alias
|
81
|
-
alias
|
73
|
+
alias move= move
|
74
|
+
alias << move
|
82
75
|
|
83
76
|
# Make the array of moves.
|
84
77
|
# @param [Array<String>] moves The array of moves to performe.
|
@@ -110,38 +103,28 @@ module Chess
|
|
110
103
|
# * `black_won_resign`: black player has won for resign.
|
111
104
|
# * `stalemate`: draw for stalemate.
|
112
105
|
# * `insufficient_material`: draw for insufficient material to checkmate.
|
113
|
-
# * `
|
114
|
-
# * `threefold_repetition`: draw for
|
115
|
-
#
|
116
|
-
# @return [String]
|
106
|
+
# * `fifty_move_rule`: draw for fifty-move rule.
|
107
|
+
# * `threefold_repetition`: draw for threefold repetition.
|
108
|
+
# @return [Symbol]
|
117
109
|
def status
|
118
110
|
case self.result
|
119
111
|
when '*'
|
120
112
|
return :in_progress
|
121
113
|
when '1-0'
|
122
|
-
if self.board.checkmate?
|
123
|
-
|
124
|
-
|
125
|
-
return :white_won_resign
|
126
|
-
end
|
114
|
+
return :white_won if self.board.checkmate?
|
115
|
+
|
116
|
+
return :white_won_resign
|
127
117
|
when '0-1'
|
128
|
-
if self.board.checkmate?
|
129
|
-
|
130
|
-
|
131
|
-
return :black_won_resign
|
132
|
-
end
|
118
|
+
return :black_won if self.board.checkmate?
|
119
|
+
|
120
|
+
return :black_won_resign
|
133
121
|
when '1/2-1/2'
|
134
|
-
if self.board.stalemate?
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
return :fifty_rule_move
|
140
|
-
elsif self.threefold_repetition?
|
141
|
-
return :threefold_repetition
|
142
|
-
end
|
122
|
+
return :stalemate if self.board.stalemate?
|
123
|
+
return :insufficient_material if self.board.insufficient_material?
|
124
|
+
return :fifty_move_rule if self.board.fifty_move_rule?
|
125
|
+
|
126
|
+
return :threefold_repetition if self.threefold_repetition?
|
143
127
|
end
|
144
|
-
return :unknown
|
145
128
|
end
|
146
129
|
|
147
130
|
# Returns `true` if the game is over.
|
@@ -150,7 +133,7 @@ module Chess
|
|
150
133
|
end
|
151
134
|
|
152
135
|
# Returns the PGN rappresenting the game.
|
153
|
-
# @return [
|
136
|
+
# @return [Chess::Pgn]
|
154
137
|
def pgn
|
155
138
|
pgn = Chess::Pgn.new
|
156
139
|
pgn.moves = self.moves
|
@@ -160,41 +143,36 @@ module Chess
|
|
160
143
|
|
161
144
|
private
|
162
145
|
|
163
|
-
# Expand the short algebraic chess notation string `
|
146
|
+
# Expand the short algebraic chess notation string `notation` in a hash like this:
|
164
147
|
#
|
165
148
|
# Ngxe2 ==> { name: 'N', dis: 'g', from: nil, to: 'e2', promotion: nil }
|
166
|
-
def expand_move(
|
167
|
-
if match =
|
149
|
+
def expand_move(notation)
|
150
|
+
if (match = notation.match(MOVE_REGEXP))
|
168
151
|
expand = {
|
169
152
|
name: match[1] || 'P', # Piece name [RNBQK]
|
170
153
|
dis: match[2], # Disambiguating move
|
171
154
|
to: match[3], # Move to
|
172
|
-
promotion: match[4]
|
155
|
+
promotion: match[4] # Promote with
|
173
156
|
}
|
174
157
|
expand[:from] = match[2] if match[2] && match[2].size == 2
|
175
158
|
return expand
|
176
|
-
elsif
|
177
|
-
if self.board.active_color # black king short castling
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
return { name: 'K', dis: nil, from: 'e8', to: 'c8', promotion: nil }
|
185
|
-
else # white king long castling
|
186
|
-
return { name: 'K', dis: nil, from: 'e1', to: 'c1', promotion: nil }
|
187
|
-
end
|
159
|
+
elsif SHORT_CASTLING_REGEXP.match?(notation)
|
160
|
+
return { name: 'K', dis: nil, from: 'e8', to: 'g8', promotion: nil } if self.board.active_color # black king short castling
|
161
|
+
|
162
|
+
return { name: 'K', dis: nil, from: 'e1', to: 'g1', promotion: nil } # white king short castling
|
163
|
+
elsif LONG_CASTLING_REGEXP.match?(notation)
|
164
|
+
return { name: 'K', dis: nil, from: 'e8', to: 'c8', promotion: nil } if self.board.active_color # black king long castling
|
165
|
+
|
166
|
+
return { name: 'K', dis: nil, from: 'e1', to: 'c1', promotion: nil } # white king long castling
|
188
167
|
end
|
189
|
-
raise BadNotationError.new(
|
168
|
+
raise BadNotationError.new(notation)
|
190
169
|
end
|
191
|
-
|
192
170
|
end
|
193
171
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
172
|
+
MOVE_REGEXP = /^([RNBQK])?([a-h]|[1-8]|[a-h][1-8])?(?:x)?([a-h][1-8])(?:=?([RrNnBbQq]))?(?:ep)?(?:\+|\#)?$/.freeze
|
173
|
+
SHORT_CASTLING_REGEXP = /^([0O])-([0O])([+#])?$/.freeze
|
174
|
+
LONG_CASTLING_REGEXP = /^([0O])-([0O])-([0O])([+#])?$/.freeze
|
175
|
+
private_constant :MOVE_REGEXP
|
176
|
+
private_constant :SHORT_CASTLING_REGEXP
|
177
|
+
private_constant :LONG_CASTLING_REGEXP
|
200
178
|
end
|