Complicating code in C#

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

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

Re: Complicating code in C#

Post by Henk »

O no I defined another dirty enum

Code: Select all

 
     enum SlidingType { Straight, Diagonal };
Henk
Posts: 7218
Joined: Mon May 27, 2013 10:31 am

Re: Complicating code in C#

Post by Henk »

To make ICoordset : IEnumerable<ICoord> I had to implement GetEnumerator for CoordSet64. But looks like it is a main computational bottleneck.

Don't know what to do about it. Make representation a List<ICoord> perhaps instead of a bitboard (uint64) . Doubt if that would make it faster.
For you have intersection and union operation. So maybe a sortedlist<ICoord> I don't know yet.

Code: Select all

      public IEnumerator<ICoord> GetEnumerator()
        {
            var bbIter = new BitboardIterator(bb);
            foreach (var bit in bbIter)
            {
                yield return new BitBoardCoord(bit);  // far too slow
            }
        }
  
Henk
Posts: 7218
Joined: Mon May 27, 2013 10:31 am

Re: Complicating code in C#

Post by Henk »

O wait maybe it is the Log operation.

Code: Select all

        public BitBoardCoord(ulong bit)
        {
            Index = (int)Math.Log(bit, 2);
        }
   
Henk
Posts: 7218
Joined: Mon May 27, 2013 10:31 am

Re: Complicating code in C#

Post by Henk »

Another terrible slow operation.

Code: Select all

      public static ulong ConvertToBitBoard(ICoordSet coordSet)
        {
            ulong result = 0;
            foreach (var coord in coordSet)
            {
                var bb = ConvertToBitBoard(coord);
                result |= bb;
            }
            return result;
        }
 
To fix this I have to repair at least 120 compile errors.
Coding horror movie never stops.

By the way argument should have been CoordSet64 and not ICoordSet.
So that will be another gazillion type casting errors.
Henk
Posts: 7218
Joined: Mon May 27, 2013 10:31 am

Re: Complicating code in C#

Post by Henk »

If ICoordSet: IEnumerable<ICoord> I can use Intersect and Union operation from LinQ.
Problem is that it returns an IEnumerable<ICoord> and not an ICoordSet or a CoordSet64.

So I can expect even more compile errors.

When will it compile? Maybe next week. After that remove run time errors and then find out that movegeneration is another two times lower.
Henk
Posts: 7218
Joined: Mon May 27, 2013 10:31 am

Re: Complicating code in C#

Post by Henk »

Too optimistic. Appears to be 4 times slower. But quick fixed tedious compile errors.
Maybe not a good idea to use system.Linq for enumerable operations on what was previously bitsets.

O wait I already found it. Can't use linq operations when computing hashkey for an occupancy during movegeneration. So you really have to use | & there instead of union and intersect. So can't use CoordSets there only bitboards (ulong). Or you have to make a fast implementation of union, intersect.
Henk
Posts: 7218
Joined: Mon May 27, 2013 10:31 am

Re: Complicating code in C#

Post by Henk »

Skipper able to play a game now. Last game was 9/2020. Performance not so great.

[pgn]
[Event "Computer Chess Game"]
[Site "LAPTOP-1FK7MTIP"]
[Date "2021.02.27"]
[Round "-"]
[White "Skipper_6"]
[Black "Stockfish 13"]
[Result "0-1"]
[TimeControl "120"]
[Annotator "1. +0.37 1... -0.33"]

1. e4 {+0.37/5} e5 {-0.33/24 5} 2. a4 {+0.46/5 2.8} Nf6 {+0.13/20 0.9} 3.
f3 {-0.04/5 2.8} Nxe4 {+2.32/19 1.0} 4. fxe4 {+1.22/6 2.7} Qh4+
{+3.76/25 1.2} 5. Ke2 {+0.74/6 2.7} Qxe4+ {+4.20/27 0.1} 6. Kf2
{+1.29/6 2.6} Bc5+ {+4.34/26 0.1} 7. d4 {+0.00/4 2.6} Bxd4+ {+4.40/26 0.1}
8. Kg3 {+1.13/4 2.5} Qg6+ {+3.93/27 1.9} 9. Kf3 {+0.20/4 2.5} Qf5+
{+99.95/245 0.8} 10. Ke2 {-327.62/7 2.4} Qe4+ {+99.97/245 0.1} 11. Kd2
{-327.64/7 2.4} Qe3# {+99.99/245 0.1}
{Xboard adjudication: Checkmate} 0-1
[/pgn]
Henk
Posts: 7218
Joined: Mon May 27, 2013 10:31 am

Re: Complicating code in C#

Post by Henk »

A file including System.Linq is a warning that implementation might be too slow.
Henk
Posts: 7218
Joined: Mon May 27, 2013 10:31 am

Re: Complicating code in C#

Post by Henk »

No time to waste
[pgn]
[Event "Computer Chess Game"]
[Site "LAPTOP-1FK7MTIP"]
[Date "2021.02.27"]
[Round "-"]
[White "Skipper_6"]
[Black "Fairy-Max 4.8V"]
[Result "1/2-1/2"]
[TimeControl "120"]
[Annotator "1. +0.20 2... +0.25"]

1. d4 {+0.20/6} Nf6 2. a3 {+0.73/5 2.8} c6 {+0.25/7 2.0} 3. a4
{+0.71/5 2.7} Qb6 {+0.17/7 2.7} 4. Bg5 {+0.56/4 2.7} Qxb2 {+0.84/8 1.9} 5.
Ra3 {+0.47/6 2.6} d5 {+0.86/8 3} 6. Rb3 {+0.19/5 2.6} Qa1 {+0.74/10 2.9} 7.
Ra3 {+0.55/5 2.5} Qb2 {+0.01/12 3} 8. Rb3 {+0.76/5 2.5} Qa1 {+0.00/12 2.0}
9. Ra3 {+0.85/5 2.4} Qb2 {+0.00/13 2.0}
{XBoard adjudication: repetition draw} 1/2-1/2
[/pgn]
Henk
Posts: 7218
Joined: Mon May 27, 2013 10:31 am

Re: Complicating code in C#

Post by Henk »

I get hardly 30kn/s in search when lucky but I don't count futile moves.
I remember speed used to be 3 times better half year ago.

So maybe time to make some ugly optimizations.

Garbage collection already takes 30% of the time.