stellar

Stellar - Chess engine written in C
Log | Files | Refs

score.c (4331B)


      1 #include "score.h"
      2 
      3 // clang-format off
      4 struct Score_T {
      5   int value;
      6   int position[64];
      7   int capture[6];
      8 };
      9 
     10 const struct Score_T Scores[] = {
     11 [PAWN] = {
     12 .value = 100,
     13 .position = {
     14              0,   0,   0,   0,   0,   0,   0,   0,
     15              0,   0,   0, -10, -10,   0,   0,   0,
     16              0,   0,   0,   5,   5,   0,   0,   0,
     17              5,   5,  10,  20,  20,   5,   5,   5,
     18             10,  10,  10,  20,  20,  10,  10,  10,
     19             20,  20,  20,  30,  30,  30,  20,  20,
     20             30,  30,  30,  40,  40,  30,  30,  30,
     21             90,  90,  90,  90,  90,  90,  90,  90, },
     22 .capture = {   [PAWN] = 105, [KNIGHT] = 205,
     23              [BISHOP] = 305,   [ROOK] = 405,
     24               [QUEEN] = 505,   [KING] = 605} },
     25 [KNIGHT] = {
     26 .value = 300,
     27 .position = {
     28             -5,  -10 , 0,   0,   0,   0, -10,  -5,
     29             -5,   0,   0,   0,   0,   0,   0,  -5,
     30             -5,   5,  20,  10,  10,  20,   5,  -5,
     31             -5,  10,  20,  30,  30,  20,  10,  -5,
     32             -5,  10,  20,  30,  30,  20,  10,  -5,
     33             -5,   5,  20,  20,  20,  20,   5,  -5,
     34             -5,   0,   0,  10,  10,   0,   0,  -5,
     35             -5,   0,   0,   0,   0,   0,   0,  -5, },
     36 .capture = {   [PAWN] = 104, [KNIGHT] = 204,
     37              [BISHOP] = 304,   [ROOK] = 404,
     38               [QUEEN] = 504,   [KING] = 604} },
     39 [BISHOP] = {
     40 .value = 350,
     41 .position = {
     42              0,   0, -10,   0,   0, -10,   0,   0,
     43              0,  30,   0,   0,   0,   0,  30,   0,
     44              0,  10,   0,   0,   0,   0,  10,   0,
     45              0,   0,  10,  20,  20,  10,   0,   0,
     46              0,   0,  10,  20,  20,  10,   0,   0,
     47              0,   0,   0,  10,  10,   0,   0,   0,
     48              0,   0,   0,   0,   0,   0,   0,   0,
     49              0,   0,   0,   0,   0,   0,   0,   0, },
     50 .capture = {   [PAWN] = 103, [KNIGHT] = 203,
     51              [BISHOP] = 303,   [ROOK] = 403,
     52               [QUEEN] = 503,   [KING] = 603} },
     53 [ROOK] = {
     54 .value = 500,
     55 .position = {
     56              0,   0,   0,  20,  20,   0,   0,   0,
     57              0,   0,  10,  20,  20,  10,   0,   0,
     58              0,   0,  10,  20,  20,  10,   0,   0,
     59              0,   0,  10,  20,  20,  10,   0,   0,
     60              0,   0,  10,  20,  20,  10,   0,   0,
     61              0,   0,  10,  20,  20,  10,   0,   0,
     62             50,  50,  50,  50,  50,  50,  50,  50,
     63             50,  50,  50,  50,  50,  50,  50,  50, },
     64 .capture = {   [PAWN] = 102, [KNIGHT] = 202,
     65              [BISHOP] = 302,   [ROOK] = 402,
     66               [QUEEN] = 502,   [KING] = 602} },
     67 [QUEEN] = {
     68 .value = 1000,
     69 .position = {
     70              0,   0,   0,   0,   0,   0,   0,   0,
     71              0,   0,   0,   0,   0,   0,   0,   0,
     72              0,   0,   0,   0,   0,   0,   0,   0,
     73              0,   0,   0,   0,   0,   0,   0,   0,
     74              0,   0,   0,   0,   0,   0,   0,   0,
     75              0,   0,   0,   0,   0,   0,   0,   0,
     76              0,   0,   0,   0,   0,   0,   0,   0,
     77              0,   0,   0,   0,   0,   0,   0,   0, },
     78 .capture = {   [PAWN] = 101, [KNIGHT] = 201,
     79              [BISHOP] = 301,   [ROOK] = 401,
     80               [QUEEN] = 501,   [KING] = 601} },
     81 [KING] = {
     82 .value = 10000,
     83 .position = {
     84              0,   0,   5,   0, -15,   0,  10,   0,
     85              0,   5,   5,  -5,  -5,   0,   5,   0,
     86              0,   0,   5,  10,  10,   5,   0,   0,
     87              0,   5,  10,  20,  20,  10,   5,   0,
     88              0,   5,  10,  20,  20,  10,   5,   0,
     89              0,   5,   5,  10,  10,   5,   5,   0,
     90              0,   0,   5,   5,   5,   5,   0,   0,
     91              0,   0,   0,   0,   0,   0,   0,   0, },
     92 .capture = {   [PAWN] = 100, [KNIGHT] = 200,
     93              [BISHOP] = 300,   [ROOK] = 400,
     94               [QUEEN] = 500,   [KING] = 600} },
     95 };
     96 
     97 const int mirror_score[128] =
     98 {
     99 	a8, b8, c8, d8, e8, f8, g8, h8,
    100 	a7, b7, c7, d7, e7, f7, g7, h7,
    101 	a6, b6, c6, d6, e6, f6, g6, h6,
    102 	a5, b5, c5, d5, e5, f5, g5, h5,
    103 	a4, b4, c4, d4, e4, f4, g4, h4,
    104 	a3, b3, c3, d3, e3, f3, g3, h3,
    105 	a2, b2, c2, d2, e2, f2, g2, h2,
    106 	a1, b1, c1, d1, e1, f1, g1, h1, no_sq,
    107 };
    108 // clang-format on
    109 
    110 int Score_value(ePiece piece) { return Scores[piece].value; }
    111 
    112 int Score_position(ePiece piece, eColor color, Square square) {
    113     if (color == BLACK) square = mirror_score[square];
    114     return Scores[piece].position[square];
    115 }
    116 
    117 int Score_capture(ePiece src, ePiece tgt) {
    118     return Scores[src].capture[tgt] + 10000;
    119 }