Page 6 of 23

Re: Complicating code in C#

Posted: Mon Jan 11, 2021 2:48 pm
by Henk
Missing part. Otherwise you won't understand GenOccupancies method posted above.

Code: Select all

 public class BitSet64
 {
        // least significant bit
        public static UInt64 First(UInt64 bits) 
            => bits & (~bits + 1);

        public static UInt64 Rest(UInt64 bits) 
        {
            var res = bits & (bits - 1);
            Debug.Assert(res == bits - First(bits));
            return res;
         }
}

Re: Complicating code in C#

Posted: Mon Jan 11, 2021 4:20 pm
by Henk
Don't know. If you want to implement 3d Chess then you probably need some kind of a 3d scene viewer.
Can you use winboard for that? Otherwise you need to implement a viewer yourself.

Re: Complicating code in C#

Posted: Mon Jan 11, 2021 9:44 pm
by Henk
All needless complcated. I had better write.

Code: Select all

       public int ComputeHashKey(ulong occupancy, ulong magic, int nBits)
        {
            var ind = occupancy * magic;
            var hashKey = (int)(ind >> (64 - nBits));
            return hashKey;
        }

        public void FillDiagonalMovesHashTable()
        {
            var diagonalOccupancies = GenOccupancies(DiagonalOcc, 0);
            foreach (var occupancy in diagonalOccupancies)
            {
                int index = ComputeHashKey(occupancy, DiagonalMagicNr, NDiagonalBits);
                DiagonalMovesArr[index] = GenerateDiagonalMoves(occupancy);
            }
        }
 
Maybe even possible now to use an other hashfunction. Have not tried yet.

To be continued.

Re: Complicating code in C#

Posted: Tue Jan 12, 2021 1:36 pm
by Henk
O wait hashfunction for move generation must be perfect. That is collision free. So can't use standard hashalgorithms from C# I guess.
Random(seed) also does not generate unique numbers.
seed = diagonal or vertical occupancy(square, position)


Problem is I do have these magic numbers but lost the code that generated them.
So if these magic numbers get accidentally corrupted I can't generate different ones.

Re: Complicating code in C#

Posted: Wed Jan 13, 2021 12:06 pm
by Henk
Some people using Microsoft PowerApps or similar.
So trent is low code, configure and using some strange scription language to knit the pieces together?

If so then better copy (modules of) an existing chess engine.

Programming from scratch forbidden for it costs too much (development) time ??

Re: Complicating code in C#

Posted: Thu Jan 14, 2021 11:31 am
by Henk
In C# you can now also put static methods in an interface. Don't know yet what is the advantage.
Makes it more clear. No hidden static methods?

Re: Complicating code in C#

Posted: Sat Jan 16, 2021 11:49 am
by Henk
"using static". Just hides a dependency. The more dependencies the more problems.

I mean just reduce dependencies. Don't hide them. using static is ok. But then all code in same file might be dependent which might not be ok.

Re: Complicating code in C#

Posted: Wed Jan 20, 2021 9:53 am
by Henk
Can't think of a better solution. Black and White are methods.

Code: Select all

       public static IPieceColor PieceColor(ColorSign color)
        {
            return color == ColorSign.White ? PieceColorsInstance.pieceColors[1] :
                                              PieceColorsInstance.pieceColors[0];
        }
  
        public static IPieceColor White()
        {
           return PieceColor(ColorSign.White);
        }

        public static IPieceColor Black()
        {
           return PieceColor(ColorSign.Black);
        }

Re: Complicating code in C#

Posted: Wed Jan 20, 2021 11:54 am
by Henk
Blunder to put Value in interface. Same holds for IPieceKind etc.

Code: Select all

 
  public interface IPieceColor
    {
        //int Value { get; }
    }
 
Now I can repair another zillion compile errors.
Think twice before you put something in an interface that is heavily used.

Re: Complicating code in C#

Posted: Sat Jan 23, 2021 3:51 pm
by Henk
Still repairing compile errors. For days now. Something went wrong.

Maybe:
- never change code that worked
- never use constants or enums
- writing generic code impossible unless something small
- don't try to make code solid unless it is new code