[go: up one dir, main page]

Menu

[r57]: / trunk / utils / RlMiscUtil.h  Maximize  Restore  History

Download this file

124 lines (100 with data), 3.3 kB

  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
//----------------------------------------------------------------------------
/** @file RlMiscUtil.h
Miscellaneous utility functions used by the RLGO module
*/
//----------------------------------------------------------------------------
#ifndef RLMISCUTIL_H
#define RLMISCUTIL_H
#include "GoBoard.h"
#include "SgMove.h"
#include "SgStatistics.h"
//----------------------------------------------------------------------------
typedef double RlFloat;
typedef SgStatistics<RlFloat, int> RlStat;
//----------------------------------------------------------------------------
// Number of players in the game
#define RL_NUM_COLOURS 2
// Maximum number of moves on any board size
#define RL_MAX_MOVES SG_PASS+1
// Maximum time-step in any game before an automatic draw is declared
#define RL_MAX_TIME 1002
const RlFloat RlInfinity = 1e8;
//----------------------------------------------------------------------------
#define ssize(X) (static_cast<signed>(X.size()))
template <class T>
inline bool Contains(const std::vector<T>& vec, const T& element)
{
return find(vec.begin(), vec.end(), element) != vec.end();
}
//----------------------------------------------------------------------------
/** Sanity checking */
// By default sanity checking only occurs in debug.
#ifdef _DEBUG
#define SANITY_CHECKING
#endif
#define IS_NAN(x) ((x) != (x))
#ifdef SANITY_CHECKING
#define SANITY_CHECK(x,from,to) \
if (IS_NAN((x)) || (x) < from || (x) > to) \
{ \
cerr << "Insane number " \
<< __FILE__ << ':' << __LINE__ << ": " << x << '\n'; \
abort(); \
}
#else
#define SANITY_CHECK(x,from,to) (static_cast<void>(0))
#endif
//----------------------------------------------------------------------------
/** Iterate through board, marking final move
*/
class RlBoardIterator
{
public:
RlBoardIterator(const GoBoard& board)
: m_point(board.BoardConst().BoardIterAddress()),
m_nextPoint(board.BoardConst().BoardIterAddress() + 1)
{
}
bool Final() const
{
return *m_nextPoint == SG_ENDPOINT;
}
/** Advance the state of the iteration to the next element. */
void operator++()
{
++m_point;
++m_nextPoint;
}
/** Return the value of the current element. */
SgPoint operator*() const
{
return *m_point;
}
/** Return true if iteration is valid, otherwise false. */
operator bool() const
{
return *m_point != SG_ENDPOINT;
}
private:
const SgPoint* m_point;
const SgPoint* m_nextPoint;
};
//----------------------------------------------------------------------------
/** Split string function */
inline void SplitString(const std::string &text, const std::string &seps,
std::list<std::string>& words)
{
int n = text.length();
int start, stop;
start = text.find_first_not_of(seps);
while ((start >= 0) && (start < n))
{
stop = text.find_first_of(seps, start);
if ((stop < 0) || (stop > n))
stop = n;
words.push_back(text.substr(start, stop - start));
start = text.find_first_not_of(seps, stop + 1);
}
}
//----------------------------------------------------------------------------
#endif // RLMISCUTIL_H