UINT8 mboard_state::read_board() { UINT8 i_18, i_AH; UINT8 data; data = 0xff; /* Example board scan: Starting postion and pawn on E2 is lifted mask: 7f 0111 1111 Line 8 data: 0 0000 0000 all fields occupied mask: bf 1011 1111 Line 7 data: 0 0000 0000 all fields occupied mask: df 1101 1111 Line 6 data: ff 1111 1111 all fields empty mask: ef 1110 1111 Line 5 data: ff 1111 1111 all fields empty mask: f7 1111 0111 Line 4 data: ff 1111 1111 all fields empty mask: fb 1111 1011 Line 3 data: ff 1111 1111 all fields empty mask: fd 1111 1101 Line 2 data: 10 0001 0000 E2 is empty rest is occupied mask: fe 1111 1110 Line 1 data: 0 0000 0000 all fields occupied */ /* looking for cleared bit in mask Line18_REED => current line */ if (data && Line18_REED) { i_18 = get_first_cleared_bit(Line18_REED); if (i_18 == NOT_VALID) printf("No cleared bit in mask Line18_REED!\n"); else { /* looking for a piece in this line and clear bit in data if found */ for (i_AH = 0; i_AH < 8; i_AH = i_AH + 1) if (IsPiece(64 - (i_18 * 8 + 8 - i_AH))) data &= ~(1 << i_AH); // clear bit read_board_flag = TRUE; } } return data; }
int Evaluation(int *Board, TPlayer Player){ int Score=0 ; int NWKings=0, NBKings=0, NWMen=0, NBMen=0; for( register int i=10 ; i<45 ; ++i ){ if(IsPiece(Board[i])){ int Piece= Board[i]; switch(Piece){ case WMAN: NWMen++; break; case BMAN: NBMen++; break; case WKING: NWKings++; break; case BKING: NBKings++; break; } } } if(Board[10]==WMAN&&Board[12]==WMAN&&NBMen>1) Score-=BACKRANK; if(Board[44]==BMAN&&Board[42]==BMAN&&NWMen>1) Score+=BACKRANK; int MaterialBlack= NBKings*KING+NBMen*CHECKER; int MaterialWhite= NWKings*KING+NWMen*CHECKER; //hints to exchange pieces if ahead in material Score+= ((MaterialBlack-MaterialWhite)*200) /(MaterialBlack+MaterialWhite); Score+=MaterialBlack-MaterialWhite; return Player==BLACK?Score:-Score; }