tt: TTEntry 成员变量名带上比特位数

This commit is contained in:
Calcitem 2020-09-01 23:49:12 +08:00
parent a87504b134
commit 6cf8d4c6fa
3 changed files with 54 additions and 25 deletions

View File

@ -47,7 +47,7 @@ Value TranspositionTable::probe(const Key &key,
#ifdef TRANSPOSITION_TABLE_FAKE_CLEAN_NOT_EXACT_ONLY
if (tte.type != BOUND_EXACT) {
#endif
if (tte.age != transpositionTableAge) {
if (tte.age8 != transpositionTableAge) {
return VALUE_UNKNOWN;
}
#ifdef TRANSPOSITION_TABLE_FAKE_CLEAN_NOT_EXACT_ONLY
@ -55,23 +55,23 @@ Value TranspositionTable::probe(const Key &key,
#endif
#endif // TRANSPOSITION_TABLE_FAKE_CLEAN
if (depth > tte.depth) {
if (depth > tte.depth()) {
goto out;
}
type = tte.type;
type = tte.bound();
switch (tte.type) {
switch (tte.bound()) {
case BOUND_EXACT:
return tte.value;
return tte.value();
break;
case BOUND_UPPER:
if (tte.value <= alpha) {
if (tte.value8 <= alpha) {
return alpha; // TODO: https://github.com/calcitem/NineChess/issues/25
}
break;
case BOUND_LOWER:
if (tte.value >= beta) {
if (tte.value() >= beta) {
return beta;
}
break;
@ -136,10 +136,10 @@ int TranspositionTable::save(const Value &value,
if (search(key, tte)) {
#ifdef TRANSPOSITION_TABLE_FAKE_CLEAN
if (tte.age == transpositionTableAge) {
if (tte.age8 == transpositionTableAge) {
#endif // TRANSPOSITION_TABLE_FAKE_CLEAN
if (tte.type != BOUND_NONE &&
tte.depth > depth) {
if (tte.genBound8 != BOUND_NONE &&
tte.depth() > depth) {
return -1;
}
#ifdef TRANSPOSITION_TABLE_FAKE_CLEAN
@ -147,16 +147,16 @@ int TranspositionTable::save(const Value &value,
#endif // TRANSPOSITION_TABLE_FAKE_CLEAN
}
tte.value = value;
tte.depth = depth;
tte.type = type;
tte.value8 = value;
tte.depth8 = depth;
tte.genBound8 = type;
#ifdef TT_MOVE_ENABLE
tte.ttMove = ttMove;
#endif // TT_MOVE_ENABLE
#ifdef TRANSPOSITION_TABLE_FAKE_CLEAN
tte.age = transpositionTableAge;
tte.age8 = transpositionTableAge;
#endif // TRANSPOSITION_TABLE_FAKE_CLEAN
TT.insert(key, tte);

View File

@ -17,32 +17,55 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TT_H
#define TT_H
#ifndef TT_H_INCLUDED
#define TT_H_INCLUDED
#include "config.h"
#include "types.h"
#include "position.h"
#include "search.h"
#include "hashmap.h"
#include "types.h"
using namespace CTSL;
#ifdef TRANSPOSITION_TABLE_ENABLE
/// TTEntry struct is the 4 bytes transposition table entry, defined as below:
///
/// value 8 bit
/// depth 8 bit
/// type 8 bit
/// age 8 bit
struct TTEntry
{
Value value;
Depth depth;
enum Bound type;
Value value() const
{
return (Value)value8;
}
Depth depth() const
{
return (Depth)depth8 + DEPTH_OFFSET;
}
Bound bound() const
{
return (Bound)(genBound8);
}
private:
friend class TranspositionTable;
int8_t value8;
int8_t depth8;
uint8_t genBound8;
#ifdef TRANSPOSITION_TABLE_FAKE_CLEAN
uint8_t age;
uint8_t age8;
#endif // TRANSPOSITION_TABLE_FAKE_CLEAN
#ifdef TT_MOVE_ENABLE
Move ttMove;
#endif // TT_MOVE_ENABLE
};
class TranspositionTable
{
public:
@ -82,4 +105,4 @@ extern uint8_t transpositionTableAge;
#endif // TRANSPOSITION_TABLE_ENABLE
#endif /* TT_H */
#endif // #ifndef TT_H_INCLUDED

View File

@ -272,6 +272,12 @@ enum Piece : uint8_t
using Depth = int8_t;
enum : int
{
DEPTH_NONE = 0, // TODO: -6,
DEPTH_OFFSET = DEPTH_NONE
};
enum Square : int32_t
{
SQ_0 = 0, SQ_1 = 1, SQ_2 = 2, SQ_3 = 3, SQ_4 = 4, SQ_5 = 5, SQ_6 = 6, SQ_7 = 7,