The piece-square-tables do encourage the king to retreat to the first row. You can see the PSTs by right-clicking on the piece, selecting Properties, and then look at the Midgame or Endgame PST tab.
We can eliminate that desire by zeroing the "forwardness" midgame PST component (which is negative for the king.) In your AddPieceTypes function:
King.PSTMidgameForwardness = 0;
See if that helps. There can be other factors as well, like the deveopment evaluation and king safety evaluation, although the development evaluation should be encouraging it to castle.
The piece-square-tables do encourage the king to retreat to the first row. You can see the PSTs by right-clicking on the piece, selecting Properties, and then look at the Midgame or Endgame PST tab.
We can eliminate that desire by zeroing the "forwardness" midgame PST component (which is negative for the king.) In your AddPieceTypes function:
King.PSTMidgameForwardness = 0;
See if that helps. There can be other factors as well, like the deveopment evaluation and king safety evaluation, although the development evaluation should be encouraging it to castle.