Skip to content

Commit

Permalink
Remove dependencies on SgRandom::Global
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.code.sf.net/p/fuego/code/trunk@2009 2e953b5c-c64d-0410-be54-f773e93e544c
  • Loading branch information
mmueller65 committed Aug 16, 2015
1 parent 6143090 commit 36500a6
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions smartgame/SgHash.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ class SgHash
Caution: after Clear() hash code matches code of empty board. */
void Clear();

/** Set to random value. */
void Invalidate();

bool operator<(const SgHash& code) const;

bool operator==(const SgHash& code) const;
Expand All @@ -69,7 +66,7 @@ class SgHash

/** Return a random hash code.
@return A random hash code, which is not zero. */
static SgHash Random();
static SgHash Random(SgRandom& random);

/** Roll bits n places to the left */
void RollLeft(int n);
Expand Down Expand Up @@ -189,12 +186,6 @@ unsigned int SgHash<N>::Hash(int max) const
return GetWord() % max;
}

template<int N>
void SgHash<N>::Invalidate()
{
*this = Random();
}

template<int N>
bool SgHash<N>::IsZero() const
{
Expand All @@ -214,14 +205,14 @@ unsigned int SgHash<N>::Mix32(int key) const
}

template<int N>
SgHash<N> SgHash<N>::Random()
SgHash<N> SgHash<N>::Random(SgRandom& random)
{
SgHash hashcode;
hashcode.m_code = SgRandom::Global().Int();
hashcode.m_code = random.Int();
for (int i = 1; i < (N / 32); ++i)
{
hashcode.m_code <<= 32;
hashcode.m_code |= SgRandom::Global().Int();
hashcode.m_code |= random.Int();
}

return hashcode;
Expand Down Expand Up @@ -296,9 +287,10 @@ class SgHashZobrist
2 * SG_MAXPOINT, plus capture hash */
static const int MAX_HASH_INDEX = 1500;

SgHashZobrist();
/** Initialize table using random generator */
SgHashZobrist(SgRandom& random);

const SgHash<N>& Get(int index) const
const SgHash<N>& Get(int index) const
{
return m_hash[index];
}
Expand All @@ -307,28 +299,33 @@ class SgHashZobrist
static const SgHashZobrist& GetTable();

private:
static SgHashZobrist m_globalTable;
static SgRandom s_random;
static SgHashZobrist s_globalTable;

SgArray<SgHash<N>, MAX_HASH_INDEX> m_hash;
};

/** For backwards compatibility */
typedef SgHashZobrist<64> SgHashZobristTable;

/** */
template<int N>
SgRandom SgHashZobrist<N>::s_random;

template<int N>
SgHashZobrist<N> SgHashZobrist<N>::m_globalTable;
SgHashZobrist<N> SgHashZobrist<N>::s_globalTable(s_random);

template<int N>
SgHashZobrist<N>::SgHashZobrist()
SgHashZobrist<N>::SgHashZobrist(SgRandom& random)
{
for (int i = 0; i < MAX_HASH_INDEX; ++i)
m_hash[i] = SgHash<N>::Random();
m_hash[i] = SgHash<N>::Random(random);
}

template<int N>
const SgHashZobrist<N>& SgHashZobrist<N>::GetTable()
{
return m_globalTable;
return s_globalTable;
}

//----------------------------------------------------------------------------
Expand Down

0 comments on commit 36500a6

Please sign in to comment.