repetitionCounter.h
Go to the documentation of this file.
/* repetitionCounter.h
*/
#ifndef OSL_REPETITIONCOUNTER_H
#define OSL_REPETITIONCOUNTER_H
#include "osl/numEffectState.h"
#include "osl/hash/hashKeyStack.h"
#include "osl/sennichite.h"
#include <list>
#include <vector>
#include <cassert>
#include <iosfwd>
namespace osl
{
class RepetitionCounter
{
struct Table;
std::unique_ptr<Table> table;
CArray<std::vector<int>, 2> continuous_check;
HashKeyStack hash_history;
int order() const { return hash_history.size(); }
public:
typedef std::list<int> list_t;
RepetitionCounter();
RepetitionCounter(const RepetitionCounter& c);
explicit RepetitionCounter(const NumEffectState& initial);
~RepetitionCounter();
private:
void push(const HashKey& new_key, bool is_check);
public:
void push(const NumEffectState& state, Move move);
void push(const NumEffectState& state);
void push(const HashKey& key, const NumEffectState& state);
void pop();
void clear();
const Sennichite isSennichite(const NumEffectState& state, Move move) const;
private:
const Sennichite isAlmostSennichiteUnsafe(int first_move) const
{
assert(first_move >= 0);
const int duration = (order() - first_move) / 2;
if (continuous_check[BLACK].back() >= duration)
return Sennichite::BLACK_LOSE();
if (continuous_check[WHITE].back() >= duration)
return Sennichite::WHITE_LOSE();
return Sennichite::DRAW();
}
public:
const Sennichite isAlmostSennichite(const HashKey& key) const
{
const int first_move = getFirstMove(key);
if (first_move < 0)
return Sennichite::NORMAL();
return isAlmostSennichiteUnsafe(first_move);
}
const std::pair<Sennichite,int> distanceToSennichite(const HashKey& key) const;
unsigned int countRepetition(const HashKey&) const;
const list_t getRepetitions(const HashKey&) const;
void printMatches(const HashKey& key) const;
int getLastMove(const HashKey& key) const;
int getFirstMove(const HashKey& key) const;
int checkCount(Player attack) const {
assert(! continuous_check[attack].empty());
return continuous_check[attack].back();
}
const HashKeyStack& history() const { return hash_history; }
bool isConsistent() const;
static bool maybeEqual(const RepetitionCounter& l, const RepetitionCounter& r);
};
}
#endif /* OSL_REPETITIONCOUNTER_H */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
osl::CArray
Definition container.h:20
osl::Move
圧縮していない moveの表現 .
Definition basic_type.h:1052
osl::NumEffectState
利きを持つ局面
Definition numEffectState.h:34
osl::RepetitionCounter
千日手の検出.
Definition repetitionCounter.h:21
osl::RepetitionCounter::isSennichite
const Sennichite isSennichite(const NumEffectState &state, Move move) const
Definition repetitionCounter.cc:167
osl::RepetitionCounter::clear
void clear()
Definition repetitionCounter.cc:20
osl::RepetitionCounter::table
std::unique_ptr< Table > table
Definition repetitionCounter.h:23
osl::RepetitionCounter::getLastMove
int getLastMove(const HashKey &key) const
key の手を最後に登録した指手番号.
Definition repetitionCounter.cc:145
osl::RepetitionCounter::distanceToSennichite
const std::pair< Sennichite, int > distanceToSennichite(const HashKey &key) const
Definition repetitionCounter.cc:182
osl::RepetitionCounter::checkCount
int checkCount(Player attack) const
Definition repetitionCounter.h:91
osl::RepetitionCounter::~RepetitionCounter
~RepetitionCounter()
Definition repetitionCounter.cc:61
osl::RepetitionCounter::push
void push(const HashKey &new_key, bool is_check)
Definition repetitionCounter.cc:66
osl::RepetitionCounter::RepetitionCounter
RepetitionCounter()
Definition repetitionCounter.cc:35
osl::RepetitionCounter::list_t
std::list< int > list_t
Definition repetitionCounter.h:28
osl::RepetitionCounter::getRepetitions
const list_t getRepetitions(const HashKey &) const
Definition repetitionCounter.cc:200
osl::RepetitionCounter::countRepetition
unsigned int countRepetition(const HashKey &) const
Definition repetitionCounter.cc:191
osl::RepetitionCounter::continuous_check
CArray< std::vector< int >, 2 > continuous_check
Definition repetitionCounter.h:24
osl::RepetitionCounter::isAlmostSennichite
const Sennichite isAlmostSennichite(const HashKey &key) const
このまま同形を繰り返したらどの結果になるかを返す
Definition repetitionCounter.h:69
osl::RepetitionCounter::printMatches
void printMatches(const HashKey &key) const
Definition repetitionCounter.cc:210
osl::RepetitionCounter::hash_history
HashKeyStack hash_history
Definition repetitionCounter.h:25
osl::RepetitionCounter::order
int order() const
Definition repetitionCounter.h:26
osl::RepetitionCounter::isConsistent
bool isConsistent() const
Definition repetitionCounter.cc:222
osl::RepetitionCounter::getFirstMove
int getFirstMove(const HashKey &key) const
key の手を最初に登録した指手番号.
Definition repetitionCounter.cc:153
osl::RepetitionCounter::maybeEqual
static bool maybeEqual(const RepetitionCounter &l, const RepetitionCounter &r)
Definition repetitionCounter.cc:256
osl::RepetitionCounter::history
const HashKeyStack & history() const
Definition repetitionCounter.h:95
osl::RepetitionCounter::pop
void pop()
Definition repetitionCounter.cc:120
osl::RepetitionCounter::isAlmostSennichiteUnsafe
const Sennichite isAlmostSennichiteUnsafe(int first_move) const
Definition repetitionCounter.h:55
osl::Sennichite
Definition sennichite.h:12
osl::Sennichite::DRAW
static Sennichite DRAW()
Definition sennichite.h:22
osl::Sennichite::BLACK_LOSE
static Sennichite BLACK_LOSE()
Definition sennichite.h:23
osl::Sennichite::WHITE_LOSE
static Sennichite WHITE_LOSE()
Definition sennichite.h:24
osl::Sennichite::NORMAL
static Sennichite NORMAL()
Definition sennichite.h:21
osl::hash::HashKeyStack
Definition hashKeyStack.h:12
osl::hash::HashKey
Definition hashKey.h:153
hashKeyStack.h
osl
Definition additionalEffect.h:6
osl::Player
Player
Definition basic_type.h:8
osl::WHITE
@ WHITE
Definition basic_type.h:10
osl::BLACK
@ BLACK
Definition basic_type.h:9
numEffectState.h
list_t
osl::RepetitionCounter::list_t list_t
Definition repetitionCounter.cc:10
sennichite.h
osl::RepetitionCounter::Table
Definition repetitionCounter.cc:14