File: eval_types.h

package info (click to toggle)
sjaakii 1.4.1-3.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,628 kB
  • sloc: ansic: 16,287; cpp: 4,543; makefile: 15
file content (148 lines) | stat: -rw-r--r-- 4,088 bytes parent folder | download | duplicates (5)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*  Sjaak, a program for playing chess
 *  Copyright (C) 2011, 2014  Evert Glebbeek
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef EVAL_TYPES_H
#define EVAL_TYPES_H

#include "compilerdef.h"

typedef int16_t eval_t;

struct eval_pair_t {
   eval_t mg, eg;

   eval_pair_t () { mg = eg = 0; }
   eval_pair_t (int v) { mg = eg = v; }
   eval_pair_t (int m, int e) { mg = m; eg = e; }


   inline eval_pair_t operator = (const eval_pair_t p) {
      mg = p.mg;
      eg = p.eg;
      return *this;
   }

   inline eval_pair_t operator = (const int v) {
      mg = v;
      eg = v;
      return *this;
   }

   inline eval_pair_t operator << (const int bits) const {
      return eval_pair_t(mg << bits, eg << bits);
   }
   inline eval_pair_t operator >> (const int bits) const {
      return eval_pair_t(mg >> bits, eg >> bits);
   }

   inline eval_pair_t operator +=(const eval_pair_t &rhs) {
      mg += rhs.mg;
      eg += rhs.eg;
      return *this;
   }
   inline eval_pair_t operator -=(const eval_pair_t &rhs) {
      mg -= rhs.mg;
      eg -= rhs.eg;
      return *this;
   }
   inline eval_pair_t operator *=(const eval_pair_t &rhs) {
      mg *= rhs.mg;
      eg *= rhs.eg;
      return *this;
   }
   inline eval_pair_t operator /=(const eval_pair_t &rhs) {
      mg /= rhs.mg;
      eg /= rhs.eg;
      return *this;
   }

   inline eval_pair_t operator +=(const int &rhs) {
      mg += rhs;
      eg += rhs;
      return *this;
   }
   inline eval_pair_t operator -=(const int &rhs) {
      mg -= rhs;
      eg -= rhs;
      return *this;
   }
   inline eval_pair_t operator *=(const int &rhs) {
      mg *= rhs;
      eg *= rhs;
      return *this;
   }
   inline eval_pair_t operator /=(const int &rhs) {
      mg /= rhs;
      eg /= rhs;
      return *this;
   }


   inline const eval_pair_t operator +(const eval_pair_t &rhs) const {
      return eval_pair_t(*this) += rhs;
   }
   inline const eval_pair_t operator -(const eval_pair_t &rhs) const {
      return eval_pair_t(*this) -= rhs;
   }
   inline const eval_pair_t operator *(const eval_pair_t &rhs) const {
      return eval_pair_t(*this) *= rhs;
   }
   inline const eval_pair_t operator /(const eval_pair_t &rhs) const {
      return eval_pair_t(*this) /= rhs;
   }

   inline const eval_pair_t operator +(const int &rhs) const {
      return eval_pair_t(*this) += eval_pair_t(rhs);
   }
   inline const eval_pair_t operator -(const int &rhs) const {
      return eval_pair_t(*this) -= eval_pair_t(rhs);
   }
   inline const eval_pair_t operator *(const int &rhs) const {
      return eval_pair_t(*this) *= eval_pair_t(rhs);
   }
   inline const eval_pair_t operator /(const int &rhs) const {
      return eval_pair_t(*this) /= eval_pair_t(rhs);
   }

   inline const eval_pair_t operator *(const float &rhs) const {
      return eval_pair_t(int(this->mg * rhs), int(this->eg * rhs));
   }

   inline eval_t interpolate(int x, int scale) const {
      //if (x < 0) x = 0;
      //if (x > scale) x = scale;
      if (expect(scale == 0, false)) return mg;
      return (scale * mg + (scale - x) * (eg-mg) ) / scale;
   }

   inline eval_pair_t operator -() const {
      return eval_pair_t(-mg, -eg);
   }
};

/* Pawn structure tables */
template <typename kind>
struct pawn_structure_t {
   bitboard_t<kind> open;
   bitboard_t<kind> passed;
   bitboard_t<kind> stop;
   bitboard_t<kind> weak;
   bitboard_t<kind> attacked[NUM_SIDES];
   eval_t shelter_score[NUM_SIDES][16];
};


#endif