Subversion Repositories Games.Chess Giants

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
99 pmbaty 1
/*
2
    Texel - A UCI chess engine.
3
    Copyright (C) 2013-2014  Peter Ă–sterlund, peterosterlund2@gmail.com
4
 
5
    This program is free software: you can redistribute it and/or modify
6
    it under the terms of the GNU General Public License as published by
7
    the Free Software Foundation, either version 3 of the License, or
8
    (at your option) any later version.
9
 
10
    This program is distributed in the hope that it will be useful,
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
    GNU General Public License for more details.
14
 
15
    You should have received a copy of the GNU General Public License
16
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18
 
19
/*
20
 * material.hpp
21
 *
22
 *  Created on: May 1, 2013
23
 *      Author: petero
24
 */
25
 
26
#ifndef MATERIAL_HPP_
27
#define MATERIAL_HPP_
28
 
29
#include "piece.hpp"
30
 
31
/**
32
 * An incrementally updated material identifier.
33
 * For each legal piece configuration, a unique identifier is computed.
34
 */
35
class MatId {
36
public:
37
    static const int WP = 1;
38
    static const int WR = 9;
39
    static const int WN = 91;
40
    static const int WB = 767;
41
    static const int WQ = 5903;
42
 
43
    static const int BP = 1 << 16;
44
    static const int BR = 9 << 16;
45
    static const int BN = 91 << 16;
46
    static const int BB = 767 << 16;
47
    static const int BQ = 5903 << 16;
48
 
49
    MatId();
50
 
51
    /** Add a piece to the material configuration. */
52
    void addPiece(int pType);
53
 
54
    /** Remove a piece from the material configuration. */
55
    void removePiece(int pType);
56
 
57
    /** Add cnt pieces of tyep ptype to the material configuration. */
58
    void addPieceCnt(int pType, int cnt);
59
 
60
    /** Get the material configuration identifier. */
61
    int operator()() const;
62
 
63
    /** Get ID for black/white mirror position. */
64
    static int mirror(int id);
65
 
66
private:
67
    int hash;
68
    static const int materialId[Piece::nPieceTypes];
69
};
70
 
71
inline
72
MatId::MatId()
73
    : hash(0) {
74
}
75
 
76
inline void
77
MatId::addPiece(int pType) {
78
    hash += materialId[pType];
79
}
80
 
81
inline void
82
MatId::removePiece(int pType) {
83
    hash -= materialId[pType];
84
}
85
 
86
inline void
87
MatId::addPieceCnt(int pType, int cnt) {
88
    hash += materialId[pType] * cnt;
89
}
90
 
91
inline int
92
MatId::operator()() const {
93
    return hash;
94
}
95
 
96
inline int
97
MatId::mirror(int h) {
98
    unsigned int ret = h;
99
    return (ret >> 16) | ((ret & 0xffff) << 16);
100
}
101
 
102
#endif /* MATERIAL_HPP_ */