evalTraits.h
Go to the documentation of this file.
/* evalTraits.h
*/
#ifndef _EVAL_TRAITS_H
#define _EVAL_TRAITS_H
#include "osl/basic_type.h"
#include <algorithm>
namespace osl
{
namespace eval
{
template<Player P>
struct EvalTraits;
template<>
struct EvalTraits<BLACK>
{
static const int delta=1;
static const int MAX_VALUE = 250000000;
// infty become specific to Evaluation class
static int max(int v1,int v2){ return std::max(v1,v2); }
static int min(int v1,int v2){ return std::min(v1,v2); }
static bool betterThan(int v1,int v2)
{
return v1 > v2;
}
static bool notLessThan(int v1,int v2) {
return v1 >= v2;
}
static int convert(int value)
{
assert(value >= 0);
return value;
}
};
template<>
struct EvalTraits<WHITE>
{
static const int delta= -EvalTraits<BLACK>::delta;
static const int MAX_VALUE= -EvalTraits<BLACK>::MAX_VALUE;
static int max(int v1,int v2){ return std::min(v1,v2); }
static int min(int v1,int v2){ return std::max(v1,v2); }
static bool betterThan(int v1,int v2)
{
return v1 < v2;
}
static bool notLessThan(int v1,int v2)
{
return v1 <= v2;
}
static int convert(int value)
{
assert(value >= 0);
return -value;
}
};
inline bool betterThan(Player p, int v1,int v2)
{
assert(isValid(p));
if (p == BLACK)
return EvalTraits<BLACK>::betterThan(v1,v2);
else
return EvalTraits<WHITE>::betterThan(v1,v2);
}
inline bool notLessThan(Player p, int v1,int v2)
{
assert(isValid(p));
if (p == BLACK)
return EvalTraits<BLACK>::notLessThan(v1,v2);
else
return EvalTraits<WHITE>::notLessThan(v1,v2);
}
inline int max(Player p, int v1, int v2)
{
assert(isValid(p));
if (p == BLACK)
return EvalTraits<BLACK>::max(v1,v2);
else
return EvalTraits<WHITE>::max(v1,v2);
}
inline int min(Player p, int v1, int v2)
{
assert(isValid(p));
if (p == BLACK)
return EvalTraits<BLACK>::min(v1,v2);
else
return EvalTraits<WHITE>::min(v1,v2);
}
inline int delta(Player p)
{
assert(isValid(p));
if (p == BLACK)
return EvalTraits<BLACK>::delta;
else
return EvalTraits<WHITE>::delta;
}
inline int convert(Player P, int value)
{
assert(value >= 0);
return value*delta(P);
}
template <class Eval>
inline bool isConsistentValueForNormalState(int value)
{
const int infty = Eval::infty();
return ((value % 2) == 0)
&& EvalTraits<BLACK>::betterThan(value, EvalTraits<WHITE>::convert(infty))
&& EvalTraits<WHITE>::betterThan(value, infty);
}
inline bool isConsistentValue(int value)
{
return (value % 2) == 0
&& (EvalTraits<BLACK>::MAX_VALUE >= value)
&& (EvalTraits<WHITE>::MAX_VALUE <= value);
}
} // namespace eval
using eval::EvalTraits;
} // namespace osl
#endif /* _EVAL_TRAITS_H */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
basic_type.h
osl::eval
Definition eval_pieceStand.cc:468
osl::eval::notLessThan
bool notLessThan(Player p, int v1, int v2)
Definition evalTraits.h:75
osl::eval::isConsistentValueForNormalState
bool isConsistentValueForNormalState(int value)
詰がからんでいない局面での通常の評価値
Definition evalTraits.h:126
osl::eval::max
int max(Player p, int v1, int v2)
Definition evalTraits.h:84
osl::eval::min
int min(Player p, int v1, int v2)
Definition evalTraits.h:92
osl::eval::betterThan
bool betterThan(Player p, int v1, int v2)
Definition evalTraits.h:67
osl::eval::delta
int delta(Player p)
playerにとってちょっと高い値
Definition evalTraits.h:104
osl::eval::convert
int convert(Player P, int value)
Definition evalTraits.h:116
osl::eval::isConsistentValue
bool isConsistentValue(int value)
Definition evalTraits.h:133
osl
Definition additionalEffect.h:6
osl::isValid
bool isValid(Player player)
cast等で作られたplayerが正しいかどうかを返す
Definition basic_type.cc:9
osl::Player
Player
Definition basic_type.h:8
osl::WHITE
@ WHITE
Definition basic_type.h:10
osl::BLACK
@ BLACK
Definition basic_type.h:9
osl::eval::EvalTraits< BLACK >::max
static int max(int v1, int v2)
Definition evalTraits.h:21
osl::eval::EvalTraits< BLACK >::delta
static const int delta
Definition evalTraits.h:18
osl::eval::EvalTraits< BLACK >::MAX_VALUE
static const int MAX_VALUE
Definition evalTraits.h:19
osl::eval::EvalTraits< BLACK >::convert
static int convert(int value)
Definition evalTraits.h:34
osl::eval::EvalTraits< BLACK >::min
static int min(int v1, int v2)
Definition evalTraits.h:22
osl::eval::EvalTraits< BLACK >::betterThan
static bool betterThan(int v1, int v2)
Definition evalTraits.h:24
osl::eval::EvalTraits< BLACK >::notLessThan
static bool notLessThan(int v1, int v2)
Definition evalTraits.h:28
osl::eval::EvalTraits< WHITE >::betterThan
static bool betterThan(int v1, int v2)
Definition evalTraits.h:49
osl::eval::EvalTraits< WHITE >::min
static int min(int v1, int v2)
Definition evalTraits.h:47
osl::eval::EvalTraits< WHITE >::MAX_VALUE
static const int MAX_VALUE
Definition evalTraits.h:45
osl::eval::EvalTraits< WHITE >::notLessThan
static bool notLessThan(int v1, int v2)
Definition evalTraits.h:53
osl::eval::EvalTraits< WHITE >::delta
static const int delta
Definition evalTraits.h:44
osl::eval::EvalTraits< WHITE >::convert
static int convert(int value)
Definition evalTraits.h:60
osl::eval::EvalTraits< WHITE >::max
static int max(int v1, int v2)
Definition evalTraits.h:46
osl::eval::EvalTraits
Definition evalTraits.h:13