#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "static.h"
#include "move.h"
int if_end_of_game(piece_entry *board[128]) {
return 0;
}
int get_row(int position)
{
return ((position>>4) & 0x07);
}
int get_col(int position)
{
return (position & 0x07);
}
int pawn_get_row_eval(int row)
{
int result;
switch(row)
{
case 0: result = 0; break;
case 1: result = 0; break;
case 2: result = -1; break;
case 3: result = 0; break;
case 4: result = 2; break;
case 5: result = 14; break;
case 6: result = 30; break;
case 7: result = 0; break;
}
return result;
}int pawn_get_row_eval_b(int row)
{
int result;
switch(row)
{
case 0: result = 0; break;
case 1: result = 30; break;
case 2: result = 14; break;
case 3: result = 2; break;
case 4: result = 0; break;
case 5: result = -1; break;
case 6: result = 0; break;
case 7: result = 0; break;
}
return result;
}
int pawn_get_col_eval(int col)
{
int result;
switch(col)
{
case 0: result = -2; break;
case 1: result = 0; break;
case 2: result = 3; break;
case 3: result = 4; break;
case 4: result = 5; break;
case 5: result = 1; break;
case 6: result = -2; break;
case 7: result = -2; break;
}
return result;
}
int knight_eval(int row, int col)
{
int result=0;
switch(row)
{
case 0: result += -3; break;
case 1: result += -2; break;
case 2: result += 0; break;
case 3: result += 1; break;
case 4: result += 1; break;
case 5: result += 0; break;
case 6: result += -2; break;
case 7: result += -3; break;
}
switch(col)
{
case 0: result += -2; break;
case 1: result += -1; break;
case 2: result += 0; break;
case 3: result += 2; break;
case 4: result += 2; break;
case 5: result += 0; break;
case 6: result += -1; break;
case 7: result += -2; break;
}
return result;
}
int static_evaluation(piece_entry *board[128], piece_entry *pieces_w[16], piece_entry *pieces_b[16], int side) {
/* 0 white
1 black */
int i=0;
int points=0;
int type=0;
if(side==1)
{
for(i=0;i<16;i++)
{
if(pieces_w[i]->captured==1) continue;
type = pieces_w[i]->type;
switch(type)
{
case 1:
points += 100 + pawn_get_row_eval(get_row(pieces_w[i]->position)) +
pawn_get_col_eval(get_col(pieces_w[i]->position)) * (get_row(pieces_w[i]->position)+1)/2;
/*
printf("pos %d,col %d, row %d, ce %d, re %d, pts %d, \n",pieces_w[i]->position,get_col(pieces_w[i]->position),get_row(pieces_w[i]->position),
pawn_get_col_eval(get_col(pieces_w[i]->position)),pawn_get_row_eval(get_row(pieces_w[i]->position)),
100 + pawn_get_row_eval(get_row(pieces_w[i]->position)) +
pawn_get_col_eval(get_col(pieces_b[i]->position)) * get_row(pieces_b[i]->position)/2);
*/
break;
case 2:
/* rook */
points += 500 + 1.5 * possible_moves_rook(board,pieces_w,pieces_b,side);
break;
case 3:
/*knight*/
points += 300 + 3*(knight_eval(get_row(pieces_w[i]->position),get_col(pieces_w[i]->position)));
//printf("pos %d value %d\n",pieces_w[i]->position,300 + 3*(4-knight_eval(get_row(pieces_w[i]->position),get_col(pieces_w[i]->position))));
break;
case 4:
/* bishop */
points += 300 + possible_moves_bishop(board,pieces_w,pieces_b,side);
break;
case 5:
/* king */
points += 10000;
/*10000-100 * number of moves to checkmate */
break;
case 6:
/*queen*/
points += 900 + possible_moves_queen(board,pieces_w,pieces_b,side);
if(move_num<6) points-=30;
break;
}
}
} else
{
for(i=0;i<16;i++)
{
if(pieces_b[i]->captured==1) continue;
type = pieces_b[i]->type;
switch(type)
{
case 7:
points += 100 + pawn_get_row_eval_b(get_row(pieces_b[i]->position)) +
pawn_get_col_eval(get_col(pieces_b[i]->position)) * abs(6-get_row(pieces_b[i]->position))/2;
/*
printf("pos %d,col %d, row %d, ce %d, re %d, pts %d, \n",pieces_b[i]->position,get_col(pieces_b[i]->position),get_row(pieces_b[i]->position),
pawn_get_col_eval(get_col(pieces_b[i]->position)),pawn_get_row_eval_b(get_row(pieces_b[i]->position)),
100 + pawn_get_row_eval_b(get_row(pieces_b[i]->position)) +
pawn_get_col_eval(get_col(pieces_b[i]->position)) * get_row(pieces_b[i]->position)/2);
*/
break;
case 8:
/* rook */
points += 500 + 1.5 * possible_moves_rook(board,pieces_w,pieces_b,side);
break;
case 9:
/*knight*/
points += 300 + 3*(1+knight_eval(get_row(pieces_b[i]->position),get_col(pieces_b[i]->position)));
break;
case 10:
/* bishop */
points += 300 + 2 * possible_moves_bishop(board,pieces_w,pieces_b,side);
break;
case 11:
/* king */
points += 10000;
/*10000-100 * number of moves to checkmate */
break;
case 12:
/*queen*/
points += 900 + possible_moves_queen(board,pieces_w,pieces_b,side);
if(move_num<6) points-=30;
//printf("q pos %d\n",possible_moves_queen(board,pieces_w,pieces_b,side));
break;
}
}
}
return points;
}