0

I have the following code and want to know which is the fastest way to copy the _zobrist and _hashEnPassant arrays?

internal void InitHash()
{
    Int32 i;
    for ( i = 0; i < 2; i++ )
        for ( Int32 j = 0; j < 6; j++ )
            for ( Int32 k = 0; k < 64; k++ )
                _zobrist[ i, j, k ] = HashRand();

    for ( i = 0; i < 64; ++i )
        _hashEnPassant[ i ] = HashRand();
}

The reason for is this that my chess engine creates multiple analysis boards and rather than recreating new boards from scratch I basically clone an existing board. The issue I am having is that calling the InitHash() method or just doing a simple copy is too slow.

I have looked at this and am not sure how to modify this to work with UInt64 types.

Community
  • 1
  • 1
Intrepid
  • 2,781
  • 2
  • 29
  • 54

1 Answers1

0

From here: http://msdn.microsoft.com/en-us/library/z50k9bft%28v=vs.110%29.aspx

If looks like you just need to copy the total number of elements in the Array using Array.com

Array.Copy( myObjArray, 0, myIntArray, 0, numElements );

numElements would be 2*6*64?

Just to show the API declaration from the website and the values you would use:

public static void Copy(
    Array sourceArray,
    int sourceIndex,
    Array destinationArray,
    int destinationIndex,
    int length
)

Values:

sourceIndex = 0
destinationIndex = 0
length = x*y*z (array dimension lengths)
Derek
  • 7,615
  • 5
  • 33
  • 58