50 if (npieces > 6) {
return UNKNOWN; }
58 if (material[
WB] == 1 || material[
BB] == 1) {
return DRAW; }
59 if (material[
WN] == 1 || material[
BN] == 1) {
return DRAW; }
60 if (material[
WP] == 1 || material[
BP] == 1) {
return KPK(pos); }
65 if (material[
WR] == 1 && material[
WP] == 1 && material[
BR] == 1) {
68 if (material[
BR] == 1 && material[
BP] == 1 && material[
WR] == 1) {
72 if (material[
WB] == 1 && material[
WP] == 2) {
return KBPK(pos); }
73 if (material[
BB] == 1 && material[
BP] == 2) {
return KBPK(pos); }
78 if (material[
WB] == 1 && material[
WP] == 3) {
return KBPK(pos); }
79 if (material[
BB] == 1 && material[
BP] == 3) {
return KBPK(pos); }
82 if (npieces <= 2) {
return DRAW; }
88 if (material[
WP] == 1) {
89 if (material[
BQ] == 1) {
return KQKP(pos); }
90 if (material[
BR] == 1) {
return KRKP(pos); }
91 if (material[
BB] == 1 || material[
BN] == 1) {
return KMKP(pos); }
92 if (material[
WB] == 1) {
return KBPK(pos); }
95 if (material[
BP] == 1) {
96 if (material[
WQ] == 1) {
return KQKP(pos); }
97 if (material[
WR] == 1) {
return KRKP(pos); }
98 if (material[
WB] == 1 || material[
WN] == 1) {
return KMKP(pos); }
99 if (material[
BB] == 1) {
return KBPK(pos); }
103 if (material[
WB] == 2 || material[
BB] == 2) {
return KBBK(pos); }
104 if (material[
WB] == 1 && material[
WN] == 1) {
return KBNK(pos); }
105 if (material[
BB] == 1 && material[
BN] == 1) {
return KBNK(pos); }
106 if (material[
WR] == 1 && material[
BB] == 1) {
return KRKB(pos); }
107 if (material[
BR] == 1 && material[
WB] == 1) {
return KRKB(pos); }
108 if (material[
WR] == 1 && material[
BN] == 1) {
return KRKN(pos); }
109 if (material[
BR] == 1 && material[
WN] == 1) {
return KRKN(pos); }
113 if (material[
WN] == 2 || material[
BN] == 2
114 || (material[
WB] == 1 && material[
BB] == 1)
115 || (material[
WB] == 1 && material[
BN] == 1)
116 || (material[
WN] == 1 && material[
BB] == 1)
117 || (material[
WN] == 1 && material[
BN] == 1)) {
140 if (material[
WP] == 1) {
160 int winScore = 500 + 5 * wpRank;
165 if (bkRank <= wpRank) {
166 if ((stm ==
WHITE && wpRank > bkRank)
167 || (stm ==
BLACK && wpRank > bkRank + 1)) {
169 return (stm ==
WHITE) ? winValue : lossValue;
178 if (stm ==
WHITE) { bdist++; }
179 if (bdist + 1 < wdist && bdist + wpRank <=
RANK_8 + 1) {
return DRAW; }
182 if ((wpFyle ==
A_FYLE || wpFyle ==
H_FYLE) && wpFyle == bkFyle) {
186 if (wpRank <
RANK_6 && wpFyle == bkFyle
187 && (wpRank + 1 == bkRank || wpRank + 2 == bkRank)) {
191 if (wpRank ==
RANK_6 && wpFyle == bkFyle && wpRank + 1 == bkRank) {
197 if (wpRank + 2 == wkRank && wpFyle !=
A_FYLE && wpFyle !=
H_FYLE && wdist < bdist) {
198 int fileDiff = (int)wpFyle - (
int)wkFyle;
199 if (fileDiff >= -1 && fileDiff <= 1) {
200 return (stm ==
WHITE) ? winValue : lossValue;
206 if (wpFyle == wkFyle && wpFyle == bkFyle
207 && wpRank+1 == wkRank && wpRank+3 == bkRank) {
211 return (stm ==
WHITE) ? winValue : lossValue;
229 if (material[
WB] == 2) {
264 int score = 900 + (25 * bkCorner) - (10 * kingDist);
267 return (stm ==
WHITE) ? winValue : lossValue;
282 if (material[
WB] == 1) {
288 if (board[wb] !=
WB) {
squareT temp = wb; wb = wn; wn = temp; }
290 ASSERT (material[
BB] == 1 && material[
BN] == 1);
296 if (board[wb] !=
BB) {
squareT temp = wb; wb = wn; wn = temp; }
331 if (cornerDist2 < cornerDist) { cornerDist = cornerDist2; }
335 int winScore = 700 - 25 * cornerDist - 10 * kingDist;
338 return (stm ==
WHITE) ? winValue : lossValue;
353 if (material[
WB] == 1) {
357 if (pos->
FyleCount(
WP, wrongFile) != material[
WP]) {
return UNKNOWN; }
363 if (pos->
FyleCount(
BP, wrongFile) != material[
BP]) {
return UNKNOWN; }
393 if (material[
WB] == 1) {
408 if (bk ==
A2 || bk ==
A3 || bk ==
A4 || bk ==
B3 || bk ==
B4 || bk ==
C4) {
419 && (bk ==
C2 || bk ==
C3 || bk ==
D3 || bk ==
D4)) {
426 && bk !=
A1 && bk !=
B1) {
459 if (material[
WN] == 1) {
474 if (bk ==
A2 || bk ==
A3 || bk ==
A4 || bk ==
B3 || bk ==
B4 || bk ==
C4) {
494 if (bk !=
A1 && bk !=
B1 && kingsDist > 2
509 if (bk !=
A1 && bk !=
B1 && bk !=
C1 && bk !=
B2 536 if (material[
WP] == 1) {
572 if (material[
WQ] != 1) {
595 static const squareT drawSquares_BPa2_BKb1 [] = {
596 G1,
H1,
F2,
G2,
H2,
G3,
H3,
F4,
G4,
H4,
E5,
F5,
G5,
H5,
597 A6,
C6,
D6,
E6,
F6,
G6,
H6,
A7,
B7,
C7,
D7,
E7,
F7,
G7,
H7,
600 static const squareT drawSquares_BPa2_BKb2 [] = {
601 F1,
G1,
H1,
G2,
H2,
F3,
G3,
H3,
F4,
G4,
H4,
F5,
G5,
H5,
602 A6,
C6,
D6,
E6,
F6,
G6,
H6,
A7,
B7,
C7,
D7,
E7,
F7,
G7,
H7,
605 static const squareT drawSquares_BPc2_BKc1 [] = {
609 static const squareT drawSquares_BPc2_BKd1 [] = {
610 F6,
G6,
H6,
A7,
B7,
C7,
D7,
E7,
F7,
G7,
H7,
613 static const squareT drawSquares_BPc2_BKd2 [] = {
614 F6,
G6,
H6,
A7,
B7,
C7,
D7,
E7,
F7,
G7,
H7,
618 const squareT * drawSquares = drawSquares_None;
620 if (bk ==
B1) { drawSquares = drawSquares_BPa2_BKb1; }
621 if (bk ==
B2) { drawSquares = drawSquares_BPa2_BKb2; }
622 }
else if (bp ==
C2) {
623 if (bk ==
C1) { drawSquares = drawSquares_BPc2_BKc1; }
624 if (bk ==
D1) { drawSquares = drawSquares_BPc2_BKd1; }
625 if (bk ==
D2) { drawSquares = drawSquares_BPc2_BKd2; }
629 while (*drawSquares != NULL_SQUARE) {
630 if (wk == *drawSquares) {
return DRAW; }
655 if (material[
WR] != 1) {
677 static const squareT drawSquares_BPa2_BKb2 [] = {
680 static const squareT drawSquares_BPa2_BKb3 [] = {
681 E1,
F1,
G1,
H1,
D4,
E4,
F4,
G4,
H4,
A5,
B5,
C5,
D5,
E5,
F5,
G5,
H5,
A6,
B6,
C6,
684 static const squareT drawSquares_BPa3_BKb2 [] = {
685 E1,
F1,
G1,
H1,
E2,
F2,
G2,
H2,
D3,
E3,
F3,
G3,
H3,
D4,
E4,
F4,
G4,
H4,
D5,
E5,
686 F5,
G5,
H5,
A6,
B6,
C6,
D6,
E6,
F6,
G6,
H6,
A7,
B7,
C7,
D7,
E7,
F7,
G7,
H7,
A8,
689 static const squareT drawSquares_BPa3_BKb3 [] = {
690 F1,
G1,
H1,
F2,
G2,
H2,
F3,
G3,
H3,
D4,
E4,
F4,
G4,
H4,
D5,
E5,
F5,
G5,
H5,
A6,
691 B6,
C6,
D6,
E6,
F6,
G6,
H6,
A7,
B7,
C7,
D7,
E7,
F7,
G7,
H7,
A8,
B8,
C8,
D8,
E8,
694 static const squareT drawSquares_BPa3_BKb4 [] = {
695 G1,
H1,
G2,
H2,
G3,
H3,
G4,
H4,
D5,
E5,
F5,
G5,
H5,
A6,
B6,
C6,
D6,
E6,
F6,
G6,
696 H6,
A7,
B7,
C7,
D7,
E7,
F7,
G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8, NULL_SQUARE
698 static const squareT drawSquares_BPa4_BKa3 [] = {
701 static const squareT drawSquares_BPa4_BKa5 [] = {
704 static const squareT drawSquares_BPa4_BKb3 [] = {
705 G1,
H1,
G2,
H2,
G3,
H3,
G4,
H4,
E5,
F5,
G5,
H5,
E6,
F6,
G6,
H6,
A7,
B7,
C7,
D7,
706 E7,
F7,
G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8, NULL_SQUARE
708 static const squareT drawSquares_BPa4_BKb4 [] = {
709 H1,
H2,
H3,
H4,
H5,
D6,
E6,
F6,
G6,
H6,
A7,
B7,
C7,
D7,
E7,
F7,
G7,
H7,
A8,
B8,
712 static const squareT drawSquares_BPa4_BKb5 [] = {
713 A7,
B7,
C7,
D7,
E7,
F7,
G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8, NULL_SQUARE
715 static const squareT drawSquares_BPa5_BKb4 [] = {
716 E7,
F7,
G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8, NULL_SQUARE
718 static const squareT drawSquares_BPa5_BKb5 [] = {
721 static const squareT drawSquares_BPb2_BKa2 [] = {
722 E1,
F1,
G1,
H1,
E2,
F2,
G2,
H2,
E3,
F3,
G3,
H3,
D4,
E4,
F4,
G4,
H4,
B5,
C5,
D5,
723 E5,
F5,
G5,
H5,
A6,
B6,
C6,
D6,
E6,
F6,
G6,
H6,
A7,
B7,
C7,
D7,
E7,
F7,
G7,
H7,
726 static const squareT drawSquares_BPb2_BKa3 [] = {
727 F2,
G2,
H2,
F3,
G3,
H3,
F4,
G4,
H4,
A5,
E5,
G5,
H5,
A6,
B6,
C6,
D6,
E6,
F6,
H6,
728 A7,
B7,
C7,
D7,
E7,
F7,
G7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8, NULL_SQUARE
730 static const squareT drawSquares_BPb2_BKb3 [] = {
731 F2,
G2,
H2,
F3,
G3,
H3,
F4,
G4,
H4,
A5,
B5,
C5,
D5,
E5,
G5,
H5,
A6,
B6,
C6,
D6,
732 E6,
F6,
H6,
A7,
B7,
C7,
D7,
E7,
F7,
G7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8, NULL_SQUARE
734 static const squareT drawSquares_BPb2_BKc1 [] = {
735 F1,
G1,
H1,
F2,
G2,
H2,
E3,
F3,
G3,
H3,
A4,
D4,
E4,
F4,
G4,
H4,
A5,
C5,
D5,
E5,
736 F5,
G5,
H5,
A6,
C6,
D6,
E6,
F6,
G6,
H6,
A7,
C7,
D7,
E7,
F7,
G7,
H7,
A8,
C8,
D8,
739 static const squareT drawSquares_BPb2_BKc2 [] = {
742 static const squareT drawSquares_BPb2_BKc3 [] = {
743 E3,
A5,
B5,
C5,
D5,
E5,
A6,
B6,
C6,
D6,
A7,
B7,
C7,
A8,
B8,
C8, NULL_SQUARE
745 static const squareT drawSquares_BPb3_BKa2 [] = {
746 F1,
G1,
H1,
F2,
G2,
H2,
F3,
G3,
H3,
F4,
G4,
H4,
E5,
F5,
G5,
H5,
B6,
C6,
D6,
E6,
747 F6,
G6,
H6,
A7,
B7,
C7,
D7,
E7,
F7,
G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8, NULL_SQUARE
749 static const squareT drawSquares_BPb3_BKa3 [] = {
750 G1,
H1,
G2,
H2,
G3,
H3,
G4,
H4,
G5,
H5,
F6,
G6,
H6,
A7,
B7,
C7,
D7,
E7,
F7,
G7,
753 static const squareT drawSquares_BPb3_BKa4 [] = {
754 H1,
H2,
H3,
H4,
H5,
H6,
G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8, NULL_SQUARE
756 static const squareT drawSquares_BPb3_BKb2 [] = {
757 G1,
H1,
G2,
H2,
G3,
H3,
G4,
H4,
F5,
G5,
H5,
F6,
G6,
H6,
A7,
B7,
C7,
D7,
E7,
F7,
758 G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8, NULL_SQUARE
760 static const squareT drawSquares_BPb3_BKb4 [] = {
761 G1,
H1,
G2,
H2,
G3,
H3,
G4,
H4,
F5,
G5,
H5,
A6,
B6,
C6,
D6,
E6,
F6,
G6,
H6,
A7,
762 B7,
C7,
D7,
E7,
F7,
G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8, NULL_SQUARE
764 static const squareT drawSquares_BPb3_BKc2 [] = {
765 F1,
G1,
H1,
G2,
H2,
E3,
F3,
G3,
H3,
E4,
F4,
G4,
H4,
A5,
B5,
D5,
E5,
F5,
G5,
H5,
766 A6,
B6,
C6,
D6,
E6,
F6,
G6,
H6,
A7,
B7,
C7,
D7,
E7,
F7,
G7,
H7,
A8,
B8,
C8,
D8,
769 static const squareT drawSquares_BPb3_BKc3 [] = {
770 G1,
H1,
G2,
H2,
G3,
H3,
E4,
F4,
G4,
H4,
C5,
D5,
E5,
F5,
G5,
H5,
A6,
B6,
C6,
D6,
771 E6,
F6,
G6,
H6,
A7,
B7,
C7,
D7,
E7,
F7,
G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8,
774 static const squareT drawSquares_BPb3_BKc4 [] = {
775 H1,
H2,
H3,
H4,
E5,
F5,
G5,
H5,
C6,
D6,
E6,
F6,
G6,
H6,
A7,
B7,
C7,
D7,
E7,
F7,
776 G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8, NULL_SQUARE
778 static const squareT drawSquares_BPb4_BKa3 [] = {
779 H1,
H2,
H3,
H4,
H5,
H6,
G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8, NULL_SQUARE
781 static const squareT drawSquares_BPb4_BKa4 [] = {
784 static const squareT drawSquares_BPb4_BKa5 [] = {
787 static const squareT drawSquares_BPb4_BKb3 [] = {
788 H6,
G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8, NULL_SQUARE
790 static const squareT drawSquares_BPb4_BKc3 [] = {
791 H1,
H2,
H3,
H4,
E5,
F5,
G5,
H5,
D6,
E6,
F6,
G6,
H6,
A7,
B7,
C7,
D7,
E7,
F7,
G7,
794 static const squareT drawSquares_BPb4_BKc4 [] = {
795 D6,
E6,
F6,
G6,
H6,
D7,
E7,
F7,
G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8, NULL_SQUARE
797 static const squareT drawSquares_BPb4_BKc5 [] = {
800 static const squareT drawSquares_BPb5_BKc4 [] = {
803 static const squareT drawSquares_BPb5_BKc5 [] = {
806 static const squareT drawSquares_BPc2_BKb2 [] = {
809 static const squareT drawSquares_BPc2_BKb3 [] = {
810 A5,
B5,
C5,
D5,
A6,
B6,
C6,
D6,
B7,
C7,
D7,
E7,
B8,
C8,
D8,
E8, NULL_SQUARE
812 static const squareT drawSquares_BPc2_BKd1 [] = {
813 G1,
H1,
G2,
H2,
F3,
G3,
H3,
A4,
B4,
E4,
F4,
G4,
H4,
A5,
B5,
D5,
E5,
F5,
G5,
H5,
814 A6,
B6,
D6,
E6,
F6,
G6,
H6,
A7,
B7,
D7,
E7,
F7,
G7,
H7,
A8,
B8,
D8,
E8,
F8,
G8,
817 static const squareT drawSquares_BPc2_BKd3 [] = {
818 F3,
B5,
C5,
D5,
E5,
F5,
A6,
B6,
C6,
D6,
E6,
A7,
B7,
C7,
D7,
A8,
B8,
C8,
D8, NULL_SQUARE
820 static const squareT drawSquares_BPc3_BKb2 [] = {
821 G1,
H1,
G2,
H2,
G3,
H3,
G4,
H4,
A5,
C5,
D5,
E5,
F5,
G5,
H5,
A6,
B6,
C6,
D6,
E6,
822 F6,
G6,
H6,
A7,
B7,
C7,
D7,
E7,
F7,
G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8, NULL_SQUARE
824 static const squareT drawSquares_BPc3_BKb3 [] = {
825 H1,
H2,
H3,
H4,
A5,
B5,
H5,
A6,
B6,
C6,
D6,
E6,
F6,
G6,
H6,
A7,
B7,
C7,
D7,
E7,
826 F7,
G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8, NULL_SQUARE
828 static const squareT drawSquares_BPc3_BKb4 [] = {
829 A6,
B6,
A7,
B7,
C7,
D7,
E7,
F7,
G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8, NULL_SQUARE
831 static const squareT drawSquares_BPc3_BKc2 [] = {
832 H1,
H2,
H3,
H4,
G5,
H5,
A6,
B6,
C6,
D6,
E6,
F6,
G6,
H6,
A7,
B7,
C7,
D7,
E7,
F7,
833 G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8, NULL_SQUARE
835 static const squareT drawSquares_BPc3_BKc4 [] = {
836 H1,
H2,
H3,
H4,
G5,
H5,
A6,
B6,
C6,
D6,
E6,
F6,
G6,
H6,
A7,
B7,
C7,
D7,
E7,
F7,
837 G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8, NULL_SQUARE
839 static const squareT drawSquares_BPc3_BKd2 [] = {
840 G1,
H1,
H2,
F3,
G3,
H3,
F4,
G4,
H4,
A5,
B5,
C5,
E5,
F5,
G5,
H5,
A6,
B6,
C6,
D6,
841 E6,
F6,
G6,
H6,
A7,
B7,
C7,
D7,
E7,
F7,
G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8,
844 static const squareT drawSquares_BPc3_BKd3 [] = {
845 H1,
H2,
H3,
F4,
G4,
H4,
D5,
E5,
F5,
G5,
H5,
A6,
B6,
C6,
D6,
E6,
F6,
G6,
H6,
A7,
846 B7,
C7,
D7,
E7,
F7,
G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8, NULL_SQUARE
848 static const squareT drawSquares_BPc3_BKd4 [] = {
849 F5,
G5,
H5,
D6,
E6,
F6,
G6,
H6,
A7,
B7,
C7,
D7,
E7,
F7,
G7,
H7,
A8,
B8,
C8,
D8,
852 static const squareT drawSquares_BPc4_BKb3 [] = {
853 A6,
A7,
B7,
C7,
D7,
E7,
F7,
G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8, NULL_SQUARE
855 static const squareT drawSquares_BPc4_BKb4 [] = {
856 A6,
A7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8, NULL_SQUARE
858 static const squareT drawSquares_BPc4_BKc3 [] = {
859 F7,
G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8, NULL_SQUARE
861 static const squareT drawSquares_BPc4_BKd3 [] = {
862 F5,
G5,
H5,
E6,
F6,
G6,
H6,
A7,
B7,
C7,
D7,
E7,
F7,
G7,
H7,
A8,
B8,
C8,
D8,
E8,
865 static const squareT drawSquares_BPc4_BKd4 [] = {
866 E6,
F6,
G6,
H6,
E7,
F7,
G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8, NULL_SQUARE
868 static const squareT drawSquares_BPc4_BKd5 [] = {
871 static const squareT drawSquares_BPd2_BKc1 [] = {
872 G1,
H1,
G2,
H2,
A3,
G3,
H3,
A4,
B4,
E4,
F4,
G4,
H4,
A5,
B5,
E5,
F5,
G5,
H5,
A6,
873 B6,
E6,
F6,
G6,
H6,
A7,
B7,
E7,
F7,
G7,
H7,
A8,
B8,
E8,
F8,
G8,
H8, NULL_SQUARE
875 static const squareT drawSquares_BPd2_BKc3 [] = {
876 A3,
A5,
B5,
C5,
D5,
E5,
B6,
C6,
D6,
E6,
C7,
D7,
E7,
F7,
C8,
D8,
E8,
F8, NULL_SQUARE
878 static const squareT drawSquares_BPd2_BKd1 [] = {
879 H1,
H2,
H3,
A4,
G4,
H4,
A5,
B5,
C5,
D5,
E5,
F5,
G5,
H5,
A6,
B6,
C6,
D6,
E6,
F6,
880 G6,
H6,
A7,
B7,
C7,
D7,
E7,
F7,
G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8, NULL_SQUARE
882 static const squareT drawSquares_BPd2_BKd3 [] = {
883 H2,
H3,
H4,
A5,
B5,
C5,
D5,
E5,
F5,
G5,
A6,
B6,
C6,
D6,
E6,
F6,
G6,
H6,
A7,
B7,
884 C7,
D7,
E7,
F7,
G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8, NULL_SQUARE
886 static const squareT drawSquares_BPd2_BKe1 [] = {
887 A1,
H1,
A2,
H2,
A3,
G3,
H3,
A4,
B4,
C4,
F4,
G4,
H4,
A5,
B5,
C5,
E5,
F5,
G5,
H5,
888 A6,
B6,
C6,
E6,
F6,
G6,
H6,
A7,
B7,
C7,
E7,
F7,
G7,
H7,
A8,
B8,
C8,
E8,
F8,
G8,
891 static const squareT drawSquares_BPd2_BKe3 [] = {
892 G3,
C5,
D5,
E5,
F5,
G5,
C6,
D6,
E6,
F6,
B7,
C7,
D7,
E7,
B8,
C8,
D8,
E8, NULL_SQUARE
894 static const squareT drawSquares_BPd3_BKc2 [] = {
895 H1,
H2,
A3,
H3,
A4,
H4,
A5,
B5,
D5,
E5,
F5,
G5,
H5,
A6,
B6,
C6,
D6,
E6,
F6,
G6,
896 H6,
A7,
B7,
C7,
D7,
E7,
F7,
G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8, NULL_SQUARE
898 static const squareT drawSquares_BPd3_BKc3 [] = {
899 A4,
A5,
B5,
C5,
A6,
B6,
C6,
D6,
E6,
F6,
G6,
H6,
A7,
B7,
C7,
D7,
E7,
F7,
G7,
H7,
902 static const squareT drawSquares_BPd3_BKc4 [] = {
903 A5,
A6,
B6,
C6,
A7,
B7,
C7,
D7,
E7,
F7,
G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8,
906 static const squareT drawSquares_BPd3_BKd2 [] = {
907 H5,
A6,
B6,
C6,
D6,
E6,
F6,
G6,
H6,
A7,
B7,
C7,
D7,
E7,
F7,
G7,
H7,
A8,
B8,
C8,
910 static const squareT drawSquares_BPd3_BKd4 [] = {
911 H5,
A6,
B6,
C6,
D6,
E6,
F6,
G6,
H6,
A7,
B7,
C7,
D7,
E7,
F7,
G7,
H7,
A8,
B8,
C8,
914 static const squareT drawSquares_BPd3_BKe2 [] = {
915 H1,
H2,
G3,
H3,
G4,
H4,
A5,
B5,
C5,
D5,
F5,
G5,
H5,
A6,
B6,
C6,
D6,
E6,
F6,
G6,
916 H6,
A7,
B7,
C7,
D7,
E7,
F7,
G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8, NULL_SQUARE
918 static const squareT drawSquares_BPd3_BKe3 [] = {
919 G4,
H4,
E5,
F5,
G5,
H5,
A6,
B6,
C6,
D6,
E6,
F6,
G6,
H6,
A7,
B7,
C7,
D7,
E7,
F7,
920 G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8, NULL_SQUARE
922 static const squareT drawSquares_BPd3_BKe4 [] = {
923 G5,
H5,
E6,
F6,
G6,
H6,
A7,
B7,
C7,
D7,
E7,
F7,
G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
926 static const squareT drawSquares_BPd4_BKc3 [] = {
927 A5,
A6,
B6,
A7,
B7,
C7,
D7,
E7,
F7,
G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8, NULL_SQUARE
929 static const squareT drawSquares_BPd4_BKc4 [] = {
930 A6,
B6,
A7,
B7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8, NULL_SQUARE
932 static const squareT drawSquares_BPd4_BKc5 [] = {
935 static const squareT drawSquares_BPd4_BKd3 [] = {
936 A7,
G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8, NULL_SQUARE
938 static const squareT drawSquares_BPd4_BKd5 [] = {
941 static const squareT drawSquares_BPd4_BKe3 [] = {
942 G5,
H5,
F6,
G6,
H6,
A7,
B7,
C7,
D7,
E7,
F7,
G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
945 static const squareT drawSquares_BPd4_BKe4 [] = {
946 F6,
G6,
H6,
F7,
G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8, NULL_SQUARE
948 static const squareT drawSquares_BPd4_BKe5 [] = {
952 const squareT * drawSquares = drawSquares_None;
954 if (bk ==
B2) { drawSquares = drawSquares_BPa2_BKb2; }
955 else if (bk ==
B3) { drawSquares = drawSquares_BPa2_BKb3; }
956 }
else if (bp ==
A3) {
957 if (bk ==
B2) { drawSquares = drawSquares_BPa3_BKb2; }
958 else if (bk ==
B3) { drawSquares = drawSquares_BPa3_BKb3; }
959 else if (bk ==
B4) { drawSquares = drawSquares_BPa3_BKb4; }
960 }
else if (bp ==
A4) {
961 if (bk ==
A3) { drawSquares = drawSquares_BPa4_BKa3; }
962 else if (bk ==
A5) { drawSquares = drawSquares_BPa4_BKa5; }
963 else if (bk ==
B3) { drawSquares = drawSquares_BPa4_BKb3; }
964 else if (bk ==
B4) { drawSquares = drawSquares_BPa4_BKb4; }
965 else if (bk ==
B5) { drawSquares = drawSquares_BPa4_BKb5; }
966 }
else if (bp ==
A5) {
967 if (bk ==
B4) { drawSquares = drawSquares_BPa5_BKb4; }
968 else if (bk ==
B5) { drawSquares = drawSquares_BPa5_BKb5; }
969 }
else if (bp ==
B2) {
970 if (bk ==
A2) { drawSquares = drawSquares_BPb2_BKa2; }
971 else if (bk ==
A3) { drawSquares = drawSquares_BPb2_BKa3; }
972 else if (bk ==
B3) { drawSquares = drawSquares_BPb2_BKb3; }
973 else if (bk ==
C1) { drawSquares = drawSquares_BPb2_BKc1; }
974 else if (bk ==
C2) { drawSquares = drawSquares_BPb2_BKc2; }
975 else if (bk ==
C3) { drawSquares = drawSquares_BPb2_BKc3; }
976 }
else if (bp ==
B3) {
977 if (bk ==
A2) { drawSquares = drawSquares_BPb3_BKa2; }
978 else if (bk ==
A3) { drawSquares = drawSquares_BPb3_BKa3; }
979 else if (bk ==
A4) { drawSquares = drawSquares_BPb3_BKa4; }
980 else if (bk ==
B2) { drawSquares = drawSquares_BPb3_BKb2; }
981 else if (bk ==
B4) { drawSquares = drawSquares_BPb3_BKb4; }
982 else if (bk ==
C2) { drawSquares = drawSquares_BPb3_BKc2; }
983 else if (bk ==
C3) { drawSquares = drawSquares_BPb3_BKc3; }
984 else if (bk ==
C4) { drawSquares = drawSquares_BPb3_BKc4; }
985 }
else if (bp ==
B4) {
986 if (bk ==
A3) { drawSquares = drawSquares_BPb4_BKa3; }
987 else if (bk ==
A4) { drawSquares = drawSquares_BPb4_BKa4; }
988 else if (bk ==
A5) { drawSquares = drawSquares_BPb4_BKa5; }
989 else if (bk ==
B3) { drawSquares = drawSquares_BPb4_BKb3; }
990 else if (bk ==
C3) { drawSquares = drawSquares_BPb4_BKc3; }
991 else if (bk ==
C4) { drawSquares = drawSquares_BPb4_BKc4; }
992 else if (bk ==
C5) { drawSquares = drawSquares_BPb4_BKc5; }
993 }
else if (bp ==
B5) {
994 if (bk ==
C4) { drawSquares = drawSquares_BPb5_BKc4; }
995 else if (bk ==
C5) { drawSquares = drawSquares_BPb5_BKc5; }
996 }
else if (bp ==
C2) {
997 if (bk ==
B2) { drawSquares = drawSquares_BPc2_BKb2; }
998 else if (bk ==
B3) { drawSquares = drawSquares_BPc2_BKb3; }
999 else if (bk ==
D1) { drawSquares = drawSquares_BPc2_BKd1; }
1000 else if (bk ==
D3) { drawSquares = drawSquares_BPc2_BKd3; }
1001 }
else if (bp ==
C3) {
1002 if (bk ==
B2) { drawSquares = drawSquares_BPc3_BKb2; }
1003 else if (bk ==
B3) { drawSquares = drawSquares_BPc3_BKb3; }
1004 else if (bk ==
B4) { drawSquares = drawSquares_BPc3_BKb4; }
1005 else if (bk ==
C2) { drawSquares = drawSquares_BPc3_BKc2; }
1006 else if (bk ==
C4) { drawSquares = drawSquares_BPc3_BKc4; }
1007 else if (bk ==
D2) { drawSquares = drawSquares_BPc3_BKd2; }
1008 else if (bk ==
D3) { drawSquares = drawSquares_BPc3_BKd3; }
1009 else if (bk ==
D4) { drawSquares = drawSquares_BPc3_BKd4; }
1010 }
else if (bp ==
C4) {
1011 if (bk ==
B3) { drawSquares = drawSquares_BPc4_BKb3; }
1012 else if (bk ==
B4) { drawSquares = drawSquares_BPc4_BKb4; }
1013 else if (bk ==
C3) { drawSquares = drawSquares_BPc4_BKc3; }
1014 else if (bk ==
D3) { drawSquares = drawSquares_BPc4_BKd3; }
1015 else if (bk ==
D4) { drawSquares = drawSquares_BPc4_BKd4; }
1016 else if (bk ==
D5) { drawSquares = drawSquares_BPc4_BKd5; }
1017 }
else if (bp ==
D2) {
1018 if (bk ==
C1) { drawSquares = drawSquares_BPd2_BKc1; }
1019 else if (bk ==
C3) { drawSquares = drawSquares_BPd2_BKc3; }
1020 else if (bk ==
D1) { drawSquares = drawSquares_BPd2_BKd1; }
1021 else if (bk ==
D3) { drawSquares = drawSquares_BPd2_BKd3; }
1022 else if (bk ==
E1) { drawSquares = drawSquares_BPd2_BKe1; }
1023 else if (bk ==
E3) { drawSquares = drawSquares_BPd2_BKe3; }
1024 }
else if (bp ==
D3) {
1025 if (bk ==
C2) { drawSquares = drawSquares_BPd3_BKc2; }
1026 else if (bk ==
C3) { drawSquares = drawSquares_BPd3_BKc3; }
1027 else if (bk ==
C4) { drawSquares = drawSquares_BPd3_BKc4; }
1028 else if (bk ==
D2) { drawSquares = drawSquares_BPd3_BKd2; }
1029 else if (bk ==
D4) { drawSquares = drawSquares_BPd3_BKd4; }
1030 else if (bk ==
E2) { drawSquares = drawSquares_BPd3_BKe2; }
1031 else if (bk ==
E3) { drawSquares = drawSquares_BPd3_BKe3; }
1032 else if (bk ==
E4) { drawSquares = drawSquares_BPd3_BKe4; }
1033 }
else if (bp ==
D4) {
1034 if (bk ==
C3) { drawSquares = drawSquares_BPd4_BKc3; }
1035 else if (bk ==
C4) { drawSquares = drawSquares_BPd4_BKc4; }
1036 else if (bk ==
C5) { drawSquares = drawSquares_BPd4_BKc5; }
1037 else if (bk ==
D3) { drawSquares = drawSquares_BPd4_BKd3; }
1038 else if (bk ==
D5) { drawSquares = drawSquares_BPd4_BKd5; }
1039 else if (bk ==
E3) { drawSquares = drawSquares_BPd4_BKe3; }
1040 else if (bk ==
E4) { drawSquares = drawSquares_BPd4_BKe4; }
1041 else if (bk ==
E5) { drawSquares = drawSquares_BPd4_BKe5; }
1045 while (*drawSquares != NULL_SQUARE) {
1046 if (wk == *drawSquares) {
return DRAW; }
1069 if (material[
WP] == 1) {
1075 if (board[wr] !=
WR) {
squareT temp = wr; wr = wp; wp = temp; }
1084 if (board[wr] !=
BR) {
squareT temp = wr; wr = wp; wp = temp; }
1107 if (bkRank < wpRank) {
return UNKNOWN; }
1110 if (wrRank == brRank || wrFyle == brFyle) {
return UNKNOWN; }
1119 ekRank = bkRank; ekFyle = bkFyle; erRank = brRank; erFyle = brFyle;
1123 ekRank = wkRank; ekFyle = wkFyle; erRank = wrRank; erFyle = wrFyle;
1129 if (ekRank == erRank || ekFyle == erFyle) {
return UNKNOWN; }
1137 int rankDiff = (int)ekRank - (
int)erRank;
1138 if (rankDiff >= -1 && rankDiff <= 1) {
return UNKNOWN; }
1139 int fyleDiff = (int)ekFyle - (
int)erFyle;
1140 if (fyleDiff >= -1 && fyleDiff <= 1) {
return UNKNOWN; }
1158 && brRank <= RANK_6 && brRank > wpRank && brRank > wkRank
1159 && bkRank > brRank && bkRank >
RANK_4) {
1162 if (wk ==
A1 && wp ==
B2 && wr ==
B1) {
return UNKNOWN; }
1165 if (bkFyle == wpFyle && (brRank ==
RANK_6 || wrFyle != bkFyle)) {
1170 if ((bkFyle == wpFyle + 1 || bkFyle == wpFyle - 1)
1171 && brFyle != wpFyle && wrFyle != bkFyle) {
1180 if (wpRank ==
RANK_6 && bkFyle == wpFyle && bkRank >=
RANK_7 1181 && brRank ==
RANK_1 && wkRank <=
RANK_6 && wrRank != bkRank) {
1183 if (stm ==
BLACK) {
return DRAW; }
1186 if (wkRank != brRank && wkFyle != brFyle
squareT square_FlipRank(squareT sq)
uint square_Distance(squareT from, squareT to)
int Recognize(Position *pos)
colorT square_Color(squareT sq)
const squareT NULL_SQUARE
uint FyleCount(pieceT p, fyleT f) const
constexpr squareT square_Move(squareT sq, directionT dir)
squareT square_FlipDiag(squareT sq)
squareT GetKingSquare(colorT c)
const scoreFlagT SCORE_LOWER
rankT square_Rank(squareT sq)
const squareT * GetList(colorT c) const
bool square_IsCornerSquare(squareT sq)
colorT color_Flip(colorT c)
squareT square_Make(fyleT f, rankT r)
const directionT UP_RIGHT
const pieceT * GetBoard() const
squareT square_FlipFyle(squareT sq)
squareT square_NearestCorner(squareT sq)
bool square_IsEdgeSquare(squareT sq)
const scoreFlagT SCORE_NONE
const scoreFlagT SCORE_EXACT
uint SquareColorCount(pieceT p, colorT sqColor)
const scoreFlagT SCORE_UPPER
const byte * GetMaterial() const
bool square_Adjacent(squareT from, squareT to)
int recogValue(scoreFlagT flag, int score)
fyleT square_Fyle(squareT sq)