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 »

Code: Select all

  var nextPrioQ = PrioQ.Pop();
  var nextMoveGenerator = this.Set(Name.PrioQ, nextPrioQ);
 
This code is probably far too slow. But what can you do.
Idea was to do object oriented programming but not allowing object to change state.

Maybe use (int, IMoveBase) NextMove(int i). No that will only work for priority queue.
Not for staged movegeneration.

Changed it. Ugly and still creating new generator objects.

Code: Select all

  var mv = PrioQ[i];
  var nextMoveGenerator = new MoveGenerator(rep,  i + 1);
 
Henk
Posts: 7216
Joined: Mon May 27, 2013 10:31 am

Re: Complicating code in C#

Post by Henk »

I now have this:

Code: Select all

public interface IMoveGenerator
{
 ...
    public (IMoveBase, IMoveGenerator, int) Next(int i);
}
Maybe better to pass a stage parameter as well. For now when a stage has ended a new generator is created.
Henk
Posts: 7216
Joined: Mon May 27, 2013 10:31 am

Re: Complicating code in C#

Post by Henk »

Bwlaaaaah. Saturday evening I played a game and found it was blundering.
After few hours debugging I found it was move generator.

Move generator skipped half of the moves for it returned index of next move while it called Next(i + 1) after each move.

So again few hours lost of my free time. Nice hobby (not).
Maybe better not change anything (complicated) on saturday to have a good weekend.
Henk
Posts: 7216
Joined: Mon May 27, 2013 10:31 am

Re: Complicating code in C#

Post by Henk »

Now I have this. Just to prevent updating movegenerator object
Speed by the way still only about 45kn/s. (not counting futile moves)

Code: Select all

 
public interface IMoveGenerator
{
 	 public (IMoveBase, IMovePrioQ, StageType, int) Next(IMovePrioQ prioQ, StageType stage, int i);
}
 
spirch
Posts: 95
Joined: Fri Nov 09, 2012 12:36 am

Re: Complicating code in C#

Post by spirch »

Henk wrote: Wed Mar 17, 2021 12:30 pm Now I have this. Just to prevent updating movegenerator object
Speed by the way still only about 45kn/s. (not counting futile moves)

Code: Select all

 
public interface IMoveGenerator
{
 	 public (IMoveBase, IMovePrioQ, StageType, int) Next(IMovePrioQ prioQ, StageType stage, int i);
}
 
if you are looking for speed, value tuple (structure) might not be it unless you use it by using reference when passing it around

on side note, did you ever profile your engine?
do it to see where it slow
do it to see the complexity of call being made
do it to see how much memory it's being used and how much GC slow it down
Henk
Posts: 7216
Joined: Mon May 27, 2013 10:31 am

Re: Complicating code in C#

Post by Henk »

Already found something: Calling SEE when computing priority of a move much too slow.
Now I get this. See below. (Reducing like hell)

Everything you do in eval makes it slow. So I try to reduce that. Best would be only to count piece square value.
But that gives problem with giving castling bonus.

Other bottlenecks: Collecting captures. Computing hash key, computing move priority, sorting move priority queue.
Immutable datastructures etc.

Because search is recursive performance call tree being misleading.

Code: Select all

   1      47           11              6    d2d4
   2       3           13            133    d2d4  d7d5
   3      40           17            559    d2d4  d7d5  g1f3
   4      -3           19           1087    d2d4  d7d5  g1f3  b8c6
   4      -1           21           1685    e2e4  g8f6  e4e5  f6e4
   5      34           37           8844    e2e4  b8c6  b1c3  e7e5  g1f3
   6       7           51          15939    e2e4  b8c6  d2d4  e7e5  d4e5  c6e5
   7      15           67          26477    e2e4  b8c6  d2d4  g8f6  b1c3  e7e5  g1f3  e5d4  f3d4  c6d4  d1d4
   8       7           93          46300    e2e4  b8c6  g1f3  e7e5  d2d4  f8d6  d4e5  c6e5
   9      28          274         190823    e2e4  b8c6  g1f3  e7e5  b1c3  g8f6  f1c4  f8c5  e1g1
  10      28          399         289175    e2e4  b8c6  d2d4  g8f6  d4d5  c6e5  b1c3  e7e6  g1f3  f8d6
  11       5          934         711399    e2e4  e7e5  d2d3  f8d6  g1f3  g8f6  c1e3  b8c6  b1c3  e8g8  f1e2
  11       9         1124         868871    d2d4  d7d5  b1c3  b8c6  c1f4
  12       6         1232         960202    d2d4  d7d5  b1c3  b8c6  c1f4  e7e6  e2e3  g8f6  f1d3  f8d6  g1f3  c8d7
  13       7         1400        1095184    d2d4  d7d5  b1c3  b8c6  c1f4  e7e6  e2e3  g8f6  f1d3  f8d6  g1f3  d6f4  e3f4
  14       8         1962        1545417    d2d4  d7d5  g1f3  g8f6  b1c3  c8f5  c1f4  b8c6  e2e3
  15       8         3256        2552820    d2d4  d7d5  g1f3  g8f6  b1c3  e7e6  c1g5  c7c5  e2e4  c5d4  f3d4  f8c5  f1b5  c8d7  b5d7  d8d7
  16       8         5458        4236664    d2d4  d7d5  g1f3  g8f6  b1c3  e7e6  c1g5  c7c5  e2e4  c5d4  f3d4  f8c5  f1b5  c8d7  b5d7  d8d7
  17      13         9542        7407134    d2d4  d7d5  g1f3  g8f6  e2e3  b8c6  c2c4  e7e6  b1c3  c8d7  c4d5  e6d5  f1d3  f8d6  e1g1
  18      10        15105       11680875    d2d4  d7d5  g1f3  g8f6  e2e3  e7e6  c2c4  c7c5  b1c3  b8c6  f1d3  d5c4  d3c4  f8d6  e1g1  c8d7  c1d2  e8g8
  19      12        27739       20624405    d2d4  d7d5  g1f3  g8f6  e2e3  e7e6  c2c4  c7c5  b1c3  b8c6  f1d3  f8d6  c3b5  d6e7  c1d2  c8d7  d2c3  a7a6  c4d5  e6d5
  
Henk
Posts: 7216
Joined: Mon May 27, 2013 10:31 am

Re: Complicating code in C#

Post by Henk »

Reached level 20. This is fun. Trying to break Skippers depth record. hi hi hi.

Code: Select all

 
  19      21        20737       17319457    d2d4  d7d5  c1f4  b8c6  g1f3  e7e6  b1c3  g8f6  c3b5  f8b4  c2c3  b4a5  e2e3  a7a6  b2b4  c6b4  b5c7  a5c7  f4c7  d8c7  c3b4
  20      20        32988       27019516    d2d4  d7d5  c1f4  b8c6  g1f3  e7e6  b1c3  g8f6  c3b5  f8b4  c2c3  b4a5  e2e3  a7a6  b5a3  e8g8  f1d3  c8d7  e1g1  a5b6
Henk
Posts: 7216
Joined: Mon May 27, 2013 10:31 am

Re: Complicating code in C#

Post by Henk »

Have to wait for ages.

Code: Select all

 
21       4        96937       71462998    e2e4  e7e5  d2d3  g8f6  f2f4  d7d6  b1c3  c7c5  f1e2  b8c6  g1f3  c8e6  e1g1  f8e7  f4f5  e6d7  c1e3  e8g8  a1b1  a8b8  f1f2
Henk
Posts: 7216
Joined: Mon May 27, 2013 10:31 am

Re: Complicating code in C#

Post by Henk »

How do you call this variation. Can't call it bongcloud. Maybe Skippercloud. Or what is bongcloud.

Code: Select all

 
12       7         5591        3493012    e2e4  f7f5  e4f5  d7d5  d1h5  e8d7  h5d1  b8c6  g1f3  e7e5  f5e6  d7e6
From wiki
"
The opening's name is thought to originate either from Chess.com user "Lenny Bongcloud" who used the opening to little success, or to more generally be a reference to a bong, a device used for consuming cannabis
"
Henk
Posts: 7216
Joined: Mon May 27, 2013 10:31 am

Re: Complicating code in C#

Post by Henk »

stupid hobby

Code: Select all

 
31       1       172596      134972483    d2d4  d7d5  g1f3  g8f6  c1f4  b8c6  e2e3  e7e6  c2c4  f8d6  f4d6  c7d6  f1d3  e8g8  c4d5  e6d5  b1c3  c8e6  e1g1  a8c8  e3e4  h7h5  e4d5  f6d5  a2a4  d5f6  a1a3  d6d5  a3b3  b7b6  h2h4