Complicating code in C#

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Henk
Posts: 7216
Joined: Mon May 27, 2013 10:31 am

Re: Complicating code in C#

Post 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;
         }
}
Henk
Posts: 7216
Joined: Mon May 27, 2013 10:31 am

Re: Complicating code in C#

Post 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.
Henk
Posts: 7216
Joined: Mon May 27, 2013 10:31 am

Re: Complicating code in C#

Post 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.
Henk
Posts: 7216
Joined: Mon May 27, 2013 10:31 am

Re: Complicating code in C#

Post 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.
Henk
Posts: 7216
Joined: Mon May 27, 2013 10:31 am

Re: Complicating code in C#

Post 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 ??
Henk
Posts: 7216
Joined: Mon May 27, 2013 10:31 am

Re: Complicating code in C#

Post 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?
Henk
Posts: 7216
Joined: Mon May 27, 2013 10:31 am

Re: Complicating code in C#

Post 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.
Henk
Posts: 7216
Joined: Mon May 27, 2013 10:31 am

Re: Complicating code in C#

Post 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);
        }
Henk
Posts: 7216
Joined: Mon May 27, 2013 10:31 am

Re: Complicating code in C#

Post 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.
Henk
Posts: 7216
Joined: Mon May 27, 2013 10:31 am

Re: Complicating code in C#

Post 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