Does not give number of similar positions encountered.
Might be handy when testing transposition table.
Testing the key (IKey) used in search.
Code: Select all
ITranspositionTable<IKey, UlongValue> ttable;
Moderators: hgm, Rebel, chrisw
Code: Select all
ITranspositionTable<IKey, UlongValue> ttable;
Do you mean cases like 1.- d4, d5; 2.- Nf3 and 1.- Nf3, d5; 2.- d4 in a Perft(3) run? If so, JetChess perft counter suits your need. I have posted many 'unique positions' runs over the years, just search "unique positions" and my username in the advanced search engine of TalkChess (the gear button next to the magnifying glass button, top right of the page).Henk wrote: ↑Sat Dec 12, 2020 2:05 pm https://www.chessprogramming.org/Perft_Results
Does not give number of similar positions encountered.
Might be handy when testing transposition table.
Testing the key (IKey) used in search.
Code: Select all
ITranspositionTable<IKey, UlongValue> ttable;
Code: Select all
Positions( 1) = 20
Positions( 2) = 400
Positions( 3) = 5,362
Positions( 4) = 72,078
Positions( 5) = 822,518
Positions( 6) = 9,417,681
Positions( 7) = 96,400,068
Positions( 8) = 988,187,354
Positions( 9) = 9,183,421,888
Positions(10) = 85,375,278,064
Positions(11) = 726,155,461,002
Code: Select all
class ULongTTable<T> : TranspositionTable<IKey, UlongValue> where T: IEqualityComparer<IKey>, new()
{
public ULongTTable() : base(new T() )
{
}
}
public class PerftAlgoritm
{
IKeyFactory keyFactory;
ITranspositionTable<IKey, UlongValue> ttable;
public PerftAlgoritm()
{
keyFactory = new StringKeyFactory();
ttable = new ULongTTable<StringKeyEQComparer>();
}
public ulong PerftUnique(IChessPosition pos, int depth)
{
var key = keyFactory.BuildKey(pos);
var entry = ttable[key];
if (entry != null)
{
return 0;
}
ulong res;
if (depth == 0)
{
res = 1;
}
else
{
var legalMoves = LegalMoveGenerator.ListLegalMoves(pos);
res = (ulong)legalMoves.Sum(mv => (long)PerftUnique(pos.Move(mv), depth - 1));
}
if (ttable[key] == null)
{
ttable = ttable.Add(key, new UlongValue(res));
}
return res;
}
}
public class StringKeyFactory : IKeyFactory
{
public StringKeyFactory()
{
}
public IKey BuildKey(IChessPosition pos)
{
var key = new StringKey(pos);
return key;
}
public IEqualityComparer<IKey> BuildKeyComparer()
{
return new StringKeyEQComparer();
}
}
public class StringKey : IKey
{
public string Fen
{
get;
}
public StringKey(IChessPosition pos)
{
Fen = pos.ConvertToFen();
}
public override int GetHashCode()
{
return Fen.GetHashCode();
}
public bool Equals(IKey key)
{
return ((StringKey)key).Fen == Fen;
}
}
public class StringKeyEQComparer : IEqualityComparer<IKey>
{
public bool Equals(IKey x, IKey y)
{
return ((StringKey)x).Equals((StringKey)y);
}
public int GetHashCode(IKey key)
{
return ((StringKey)key).GetHashCode();
}
}
public class StringKeyFactory : IKeyFactory
{
public StringKeyFactory()
{
}
public IKey BuildKey(IChessPosition pos)
{
var key = new StringKey(pos);
return key;
}
public IEqualityComparer<IKey> BuildKeyComparer()
{
return new StringKeyEQComparer();
}
}
I really like SJE. He wrote our PGN standard, and he shared the things he learned freely.Ajedrecista wrote: ↑Mon Dec 14, 2020 7:21 pm Hello Henk:
Using advanced search, searching unique by username sje (the great Steven Edwards, who sadly passed away four years ago) at Programming and Technical Discussions subforum returns interesting results. Steven computed unique positions for different plies starting from the initial positions and uploaded the FEN strings. These links are dead now, but someone here might have downloaded them and can share these files if they keep them stored.
[Looks like telling lies all the time]
Code: Select all
public class Key : IKey
{
readonly byte[] rep;
public byte this[int i]
{
get
{
return rep[i];
}
}
public Key(IChessPosition pos, HashAlgorithm hashAlgorithm)
{
rep = pos.ComputeHashKey(hashAlgorithm);
}
public bool Equals(IKey key)
{
int k = 0;
foreach(var b in rep)
{
if (b != ((Key)key)[k]) return false;
k++;
}
return true;
}
public override int GetHashCode()
{
return BitConverter.ToInt32(rep);
}
}