Complicating code in C#

Discussion of chess software programming and technical issues.

Moderators: hgm, Dann Corbit, Harvey Williamson

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
Post Reply
Henk
Posts: 6834
Joined: Mon May 27, 2013 8:31 am

Re: Complicating code in C#

Post by Henk » Mon Jan 11, 2021 1:48 pm

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: 6834
Joined: Mon May 27, 2013 8:31 am

Re: Complicating code in C#

Post by Henk » Mon Jan 11, 2021 3:20 pm

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: 6834
Joined: Mon May 27, 2013 8:31 am

Re: Complicating code in C#

Post by Henk » Mon Jan 11, 2021 8:44 pm

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: 6834
Joined: Mon May 27, 2013 8:31 am

Re: Complicating code in C#

Post by Henk » Tue Jan 12, 2021 12:36 pm

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: 6834
Joined: Mon May 27, 2013 8:31 am

Re: Complicating code in C#

Post by Henk » Wed Jan 13, 2021 11:06 am

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: 6834
Joined: Mon May 27, 2013 8:31 am

Re: Complicating code in C#

Post by Henk » Thu Jan 14, 2021 10:31 am

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: 6834
Joined: Mon May 27, 2013 8:31 am

Re: Complicating code in C#

Post by Henk » Sat Jan 16, 2021 10:49 am

"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: 6834
Joined: Mon May 27, 2013 8:31 am

Re: Complicating code in C#

Post by Henk » Wed Jan 20, 2021 8:53 am

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: 6834
Joined: Mon May 27, 2013 8:31 am

Re: Complicating code in C#

Post by Henk » Wed Jan 20, 2021 10:54 am

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: 6834
Joined: Mon May 27, 2013 8:31 am

Re: Complicating code in C#

Post by Henk » Sat Jan 23, 2021 2:51 pm

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

Post Reply