summaryrefslogtreecommitdiff
path: root/graphics/metapost/contrib/macros/mpchess/metapost
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2023-04-27 03:01:52 +0000
committerNorbert Preining <norbert@preining.info>2023-04-27 03:01:52 +0000
commite947b2310e888cd5b10265d596eb332da9f6bdec (patch)
treed588e275b670d69ec6f51a702fe678f8b504238f /graphics/metapost/contrib/macros/mpchess/metapost
parent1ea4eef62d24f4f0574afba646c635f677eeb7cc (diff)
CTAN sync 202304270301
Diffstat (limited to 'graphics/metapost/contrib/macros/mpchess/metapost')
-rw-r--r--graphics/metapost/contrib/macros/mpchess/metapost/mpchess-chessboard.mp105
-rw-r--r--graphics/metapost/contrib/macros/mpchess/metapost/mpchess-pgn.mp4
-rw-r--r--graphics/metapost/contrib/macros/mpchess/metapost/mpchess.mp40
3 files changed, 102 insertions, 47 deletions
diff --git a/graphics/metapost/contrib/macros/mpchess/metapost/mpchess-chessboard.mp b/graphics/metapost/contrib/macros/mpchess/metapost/mpchess-chessboard.mp
index d156438506..4e0fc3bed3 100644
--- a/graphics/metapost/contrib/macros/mpchess/metapost/mpchess-chessboard.mp
+++ b/graphics/metapost/contrib/macros/mpchess/metapost/mpchess-chessboard.mp
@@ -149,7 +149,7 @@ def _draw_step_chessboard(expr k) =
enddef;
-vardef _pawn_candidate(expr istart, jstart,iend,jend,wb,capture)=
+vardef _pawn_candidate(expr istart, jstart,iend,jend,wb,capture,ambiguity)=
% i int from letter, column
% j int for line
% return true if (istart,jstart) to (iend,jend)
@@ -163,33 +163,49 @@ vardef _pawn_candidate(expr istart, jstart,iend,jend,wb,capture)=
if(wb="white"):
if(jend=4): % on the line that allow 2 square move
if(((jstart=3) or (jstart=2)) and (iend=istart)):
- output:=true;
+ if((ambiguity=0) or ((ambiguity<>0) and (ambiguity=istart))):
+ output:=true;
+ fi
fi
if(((jstart=3) and ((istart=iend+1) or (istart=iend-1))) and (capture=1)): %capture
- output:=true;
+ if((ambiguity=0) or ((ambiguity<>0) and (ambiguity=istart))):
+ output:=true;
+ fi
fi
else:
if((jstart=jend-1) and (istart=iend)): % straight move
- output:=true;
+ if((ambiguity=0) or ((ambiguity<>0) and (ambiguity=istart))):
+ output:=true;
+ fi
fi
if(((jstart=jend-1) and ((istart=iend+1) or (istart=iend-1))) and (capture=1)): % capture
- output:=true;
+ if((ambiguity=0) or ((ambiguity<>0) and (ambiguity=istart))):
+ output:=true;
+ fi
fi
fi
else:
if(jend=5): % on the line that allow 2 square move
if(((jstart=6) or (jstart=7)) and (iend=istart)):
- output:=true;
+ if((ambiguity=0) or ((ambiguity<>0) and (ambiguity=istart))):
+ output:=true;
+ fi
fi
if(((jstart=6) and ((istart=iend+1) or (istart=iend-1))) and (capture=1)): %capture
- output:=true;
+ if((ambiguity=0) or ((ambiguity<>0) and (ambiguity=istart))):
+ output:=true;
+ fi
fi
else:
if((jstart=jend+1) and (istart=iend)): % straight move
- output:=true;
+ if((ambiguity=0) or ((ambiguity<>0) and (ambiguity=istart))):
+ output:=true;
+ fi
fi
if(((jstart=jend+1) and ((istart=iend+1) or (istart=iend-1))) and (capture=1)): % capture
- output:=true;
+ if((ambiguity=0) or ((ambiguity<>0) and (ambiguity=istart))):
+ output:=true;
+ fi
fi
fi
fi
@@ -197,7 +213,7 @@ vardef _pawn_candidate(expr istart, jstart,iend,jend,wb,capture)=
output
enddef;
-vardef _bishop_candidate(expr istart, jstart,iend,jend,wb)=
+vardef _bishop_candidate(expr istart, jstart,iend,jend,wb,ambiguity)=
% i int from letter, column
% j int for line
% return true if (istart,jstart) to (iend,jend)
@@ -208,13 +224,15 @@ vardef _bishop_candidate(expr istart, jstart,iend,jend,wb)=
output = false;
if((iend<=_chessSize) and (iend>=1) and (iend<=_chessSize) and (iend>=1)):
if(abs(iend-istart)=abs(jend-jstart)):
- output:=true;
+ if((ambiguity=0) or ((ambiguity<>0) and (ambiguity=istart))):
+ output:=true;
+ fi
fi
fi
output
enddef;
-vardef _rook_candidate(expr istart, jstart,iend,jend,wb)=
+vardef _rook_candidate(expr istart, jstart,iend,jend,wb,ambiguity)=
% i int from letter, column
% j int for line
% return true if (istart,jstart) to (iend,jend)
@@ -225,7 +243,9 @@ vardef _rook_candidate(expr istart, jstart,iend,jend,wb)=
output = false;
if((iend<=_chessSize) and (iend>=1) and (iend<=_chessSize) and (iend>=1)):
if((iend=istart) or (jend=jstart)):
- output:=true;
+ if((ambiguity=0) or ((ambiguity<>0) and (ambiguity=istart))):
+ output:=true;
+ fi
fi
fi
output
@@ -266,7 +286,7 @@ vardef _king_candidate(expr istart, jstart,iend,jend,wb)=
output
enddef;
-vardef _knight_candidate(expr istart, jstart,iend,jend,wb)=
+vardef _knight_candidate(expr istart, jstart,iend,jend,wb,ambiguity)=
% i int from letter, column
% j int for line
% return true if (istart,jstart) to (iend,jend)
@@ -276,31 +296,34 @@ vardef _knight_candidate(expr istart, jstart,iend,jend,wb)=
boolean output;
output = false;
if((iend<=_chessSize) and (iend>=1) and (iend<=_chessSize) and (iend>=1)):
- if(((abs(iend-istart)=2) and (abs(jend-jstart)=1)) or ((abs(iend-istart)=1) and (abs(jend-jstart)=2))):
- output:=true;
+ if(((abs(iend-istart)=2) and (abs(jend-jstart)=1)) or
+ ((abs(iend-istart)=1) and (abs(jend-jstart)=2))):
+ if((ambiguity=0) or ((ambiguity<>0) and (ambiguity=istart))):
+ output:=true;
+ fi
fi
fi
output
enddef;
-vardef _chess_candidate(expr type, istart, jstart, iend, jend,wb,capture)=
+vardef _chess_candidate(expr type, istart, jstart, iend, jend,wb,capture,ambiguity)=
numeric _pm;
_pm:=1;
if(wb="black"):
_pm:=-1;
fi
if(type=(_pm*_intWPawn)):
- _pawn_candidate(istart,jstart,iend,jend,wb,capture)
+ _pawn_candidate(istart,jstart,iend,jend,wb,capture,ambiguity)
elseif(type=_pm*_intWBishop):
- _bishop_candidate(istart,jstart,iend,jend,wb)
+ _bishop_candidate(istart,jstart,iend,jend,wb,ambiguity)
elseif(type=_pm*_intWKing):
_king_candidate(istart,jstart,iend,jend,wb)
elseif(type=_pm*_intWKnight):
- _knight_candidate(istart,jstart,iend,jend,wb)
+ _knight_candidate(istart,jstart,iend,jend,wb,ambiguity)
elseif(type=_pm*_intWQueen):
_queen_candidate(istart,jstart,iend,jend,wb)
elseif(type=_pm*_intWRook):
- _rook_candidate(istart,jstart,iend,jend,wb)
+ _rook_candidate(istart,jstart,iend,jend,wb,ambiguity)
fi
enddef;
@@ -352,11 +375,42 @@ def _build_all_chessboards=
_wb:="white";
else:
_wb:="black";
- fi
+ fi
+ % castling
+ if(_piecetype=100): % short castling
+ if(_pm=1):
+ _tmp_line:=1;
+ else:
+ _tmp_line:=8;
+ fi
+ if((chessboard_table[k][5][_tmp_line]=_pm*_intWKing) and
+ (chessboard_table[k][8][_tmp_line]=_pm*_intWRook)): % if king and
+ % in the right places
+ chessboard_table[k][5][_tmp_line]:=0;
+ chessboard_table[k][8][_tmp_line]:=0;
+ chessboard_table[k][6][_tmp_line]:=_pm*_intWRook;
+ chessboard_table[k][7][_tmp_line]:=_pm*_intWKing;
+ fi
+ fi
+ if(_piecetype=1000): % long castling
+ if(_pm=1):
+ _tmp_line:=1;
+ else:
+ _tmp_line:=8;
+ fi
+ if((chessboard_table[k][5][_tmp_line]=_pm*_intWKing) and
+ (chessboard_table[k][1][_tmp_line]=_pm*_intWRook)): % if king and
+ % in the right places
+ chessboard_table[k][5][_tmp_line]:=0;
+ chessboard_table[k][1][_tmp_line]:=0;
+ chessboard_table[k][4][_tmp_line]:=_pm*_intWRook;
+ chessboard_table[k][3][_tmp_line]:=_pm*_intWKing;
+ fi
+ fi
for i:=1 upto _chessSize:
for j:=1 upto _chessSize:
if(chessboard_table[k][i][j]=_piecetype):
- if(_chess_candidate(_piecetype, i, j, _iend, _jend,_wb,_capture)=true):
+ if(_chess_candidate(_piecetype, i, j, _iend, _jend,_wb,_capture,_ambiguity)=true):
if(_capture<>0):
if(_pm=1):
_chess_white_captures[k][_chess_wcaptures_nbr[k-1]]:=chessboard_table[k][i][j];
@@ -466,7 +520,7 @@ def _draw_main_lines(expr _k)(expr wb)(text slist)=
for i:=1 upto _chessSize:
for j:=1 upto _chessSize:
if(chessboard_table[_k][i][j]=_piecetype):
- if(_chess_candidate(_piecetype, i, j, _iend, _jend,wb,_capture)=true):
+ if(_chess_candidate(_piecetype, i, j, _iend, _jend,wb,_capture,_ambiguity)=true):
draw_arrows(_chess_main_lines_color)(_int_to_letter_w(i)&_int_to_str_w(j)&"--"&_int_to_letter_w(_iend)&_int_to_str_w(_jend));
fi
fi
@@ -740,9 +794,6 @@ def show_possible_moves_step(expr k)(expr s)=
for _ii:=-1 upto 1:
for _jj:=-1 upto 1:
if((_fl+_ii>0) and (_fl+_ii<9) and (_fn+_jj>0) and (_fn+_jj<9)):
- show "king";
- show _ii;
- show _jj;
if((_piecetype*chessboard_table[k][_fl+_ii][_fn+_jj])<=0):
_circle_move(_fl+_ii,_fn+_jj);
fi
diff --git a/graphics/metapost/contrib/macros/mpchess/metapost/mpchess-pgn.mp b/graphics/metapost/contrib/macros/mpchess/metapost/mpchess-pgn.mp
index 155aaad262..0796018e93 100644
--- a/graphics/metapost/contrib/macros/mpchess/metapost/mpchess-pgn.mp
+++ b/graphics/metapost/contrib/macros/mpchess/metapost/mpchess-pgn.mp
@@ -246,11 +246,11 @@ vardef _extract_single_move(expr s,wb)=
numeric output[];
_str := s;
_length:= length(_str);
- if(str="O-O"):
+ if(_str="O-O"):
_piecetype:=100;
_letter:=100;
_nbr:=100;
- elseif(str="O-O-O"):
+ elseif(_str="O-O-O"):
_piecetype:=1000;
_letter:=1000;
_nbr:=1000;
diff --git a/graphics/metapost/contrib/macros/mpchess/metapost/mpchess.mp b/graphics/metapost/contrib/macros/mpchess/metapost/mpchess.mp
index 0fc53bdf59..d16c821493 100644
--- a/graphics/metapost/contrib/macros/mpchess/metapost/mpchess.mp
+++ b/graphics/metapost/contrib/macros/mpchess/metapost/mpchess.mp
@@ -2,7 +2,7 @@
%% mpchess.mp %%
%% draw chessboards with metapost %%
%% chupin@ceremade.dauphine.fr %%
-%% Version 0.5 (avril 2023) %%
+%% Version 0.6 (avril 2023) %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% This work may be distributed and/or modified under the conditions of
@@ -12,6 +12,7 @@
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
%input format;
input hatching;
input mpchess-pieces; % piece of mpchess package
@@ -36,7 +37,7 @@ string _coords_font;
_coords_font:=defaultfont;
% chose the font to write coordinates on board
-def set_coords_font(expr f)=
+def set_coordinates_font(expr f)=
_coords_font:=f ;
enddef;
@@ -76,21 +77,24 @@ enddef;
boolean _chess_print_coords,_chess_coords_inout;
_chess_print_coords:=true;
_chess_coords_inout:=true; %true for inside
-def set_no_coords=
+def hide_coordinates=
_chess_print_coords:=false;
enddef;
-def set_coords=
+def show_coordinates=
_chess_print_coords:=true;
enddef;
-def set_coords_inside=
- _chess_coords_inout:=true;
+def set_coordinates_position(expr s)=
+ if(s="inside"):
+ _chess_coords_inout:=true;
+ elseif(s="outside"):
+ _chess_coords_inout:=false;
+ fi
enddef;
-def set_coords_outside=
- _chess_coords_inout:=false;
-enddef;
+
+
% boolean for white or black to move
boolean _white_to_move;
@@ -105,15 +109,15 @@ def set_white_to_move=
enddef;
% boolean to show a mark to indicate whos to move
-boolean show_whos_to_move;
-show_whos_to_move:=true;
+boolean _show_whos_to_move;
+_show_whos_to_move:=true;
-def set_whos_to_move=
- show_whos_to_move:=true;
+def show_whos_to_move=
+ _show_whos_to_move:=true;
enddef;
-def unset_whos_to_move=
- show_whos_to_move:=false;
+def hide_whos_to_move=
+ _show_whos_to_move:=false;
enddef;
@@ -230,11 +234,11 @@ def set_color_theme(expr t)=
fi
enddef;
-def set_white_color(expr c)=
+def set_white_squares_color(expr c)=
_whiteColorSquare:=c;
enddef;
-def set_black_color(expr c)=
+def set_black_squares_color(expr c)=
_blackColorSquare:=c;
enddef;
@@ -683,7 +687,7 @@ vardef _chess_build_chessboard_pic(expr k)=
fi
endfor;
endfor;
- if(show_whos_to_move):
+ if(_show_whos_to_move):
if(_chess_view_wb): %white side
if(not _white_to_move):
fill _triangle(0.3) rotated 180 shifted (_chessSquareU*(_chessSize+0.35),_chessSquareU*(_chessSize)+0.3*_chessSquareU)