1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
#include <stdio.h>
#include <stdlib.h>
#include "chess.h"
#include "data.h"
/* last modified 10/18/99 */
/*
********************************************************************************
* *
* Phase() is use to determine the phase of the game: opening, middlegame or *
* endgame. the three phases are identified by the following criteria: *
* *
* (a) opening: if any minor pieces are still on their original squares, or *
* the king has not yet castled nor given up the right to castle, then *
* opening development rules still apply. *
* (b) middle-game: if the opening criteria are not met, and the end-game *
* criteria are not met, then all that's left is a middle-game. *
* (c) end-game: if both sides have less than 17 points of material, not *
* counting pawns, (Q=9, R=5, BN=3) then we are in an end-game. *
* *
********************************************************************************
*/
void Phase(void) {
int t_opening, t_middle_game, t_end_game;
TREE * const tree=local[0];
/*
----------------------------------------------------------
| |
| if both sides have not yet lost the right to |
| castle, then this is still an opening position. |
| |
----------------------------------------------------------
*/
t_opening=opening;
t_middle_game=middle_game;
t_end_game=end_game;
if (opening) {
do {
if (move_number < 26) {
if (WhiteCastle(1)>0) break;
if (BlackCastle(1)>0) break;
}
opening=0;
middle_game=1;
end_game=0;
} while (0);
}
/*
----------------------------------------------------------
| |
| if the piece point count drops below 17 (two rooks and |
| two minor pieces) then this is an end-game. |
| |
----------------------------------------------------------
*/
if (TotalWhitePieces < 15 && TotalBlackPieces < 15) {
opening=0;
middle_game=0;
end_game=1;
}
if (opening && opening != t_opening)
Print(128,"opening phase\n");
else if (middle_game && middle_game != t_middle_game)
Print(128,"middle-game phase\n");
else if (end_game != t_end_game)
Print(128,"end-game phase\n");
}
|