Only generate legal moves in movegen
The main changes here are by @rhirsch123. I have added some speedups and identified some more code that can be removed if we only ever deal with legal moves.
The only(?) important implementation detail of legal move generation is that we now keep a bitboard of squares threatened by `~sideToMove` in `Position`, to help with king move generation. For speed and conciseness, we include x-ray threats through the `sideToMove`-colored king (this only matters when `sideToMove` is in check). As a bonus, these bitboards get re-used in quiet move scoring.
Things that can be simplified once we have legal movegen:
- We can merge the `legal()` and `pseudo_legal()` methods
- Since we have threat bitboards, we no longer need `attackers_to_exist()` in `legal()`, so we can remove that method
- We don't need a separate `generate<LEGAL>` method that performs legality checks
- This also means the `NON_EVASIONS` movegen target becomes redundant
The change to `ray_pass_bb()` is outdated but should still be beneficial for performance.
passed gainer STC: https://tests.stockfishchess.org/tests/view/6ac2e35d5349156614d93a31
LLR: 2.93 (-2.94,2.94) <0.00,2.00>
Total: 207232 W: 52791 L: 52245 D: 102196
Ptnml(0-2): 279, 23887, 54714, 24481, 255
passed non-reg LTC: https://tests.stockfishchess.org/tests/view/6ac2e3785349156614d93a33
LLR: 2.94 (-2.94,2.94) <-1.75,0.25>
Total: 163212 W: 42028 L: 41955 D: 79229
Ptnml(0-2): 39, 17157, 47137, 17238, 35
`speedtest 1 256 60` by @Torom:
```
sf_base = 2282060 +/- 6930 (95%)
sf_test = 2332255 +/- 5742 (95%)
diff = 50195 +/- 10399 (95%)
speedup = 2.19956% +/- 0.456% (95%)
Probability candidate is faster than baseline by at least
0.00%: 100.00%
0.25%: 100.00%
0.50%: 100.00%
1.00%: 100.00%
```
A previous benchmark with shorter speedtests IIUC obtained `0.91296% +/- 0.108%`.
The number of saved LOC is very modest, but the extra code is mostly helper functions, so I would call this a big conceptual simplification.
closes https://github.com/official-stockfish/Stockfish/pull/7214
Bench: 1648623
Co-authored-by: Ryan Hirsch <hirsch28@purdue.edu>