Use 'pcg64_fast' for RNG
All checks were successful
ci/woodpecker/push/check Pipeline was successful
All checks were successful
ci/woodpecker/push/check Pipeline was successful
This is a higher quality source of randomness than a XOR-shift generator, while still being fast and easy to write.
This commit is contained in:
parent
7dd0da6628
commit
93d255623b
|
@ -60,138 +60,138 @@ impl MagicMoves {
|
|||
// region:sourcegen
|
||||
/// A set of magic numbers for bishop move generation.
|
||||
pub(crate) const BISHOP_SEED: [u64; Square::NUM_VARIANTS] = [
|
||||
4908958787341189172,
|
||||
1157496606860279808,
|
||||
289395876198088778,
|
||||
649648646467355137,
|
||||
19162426089930848,
|
||||
564067194896448,
|
||||
18586170375029026,
|
||||
9185354800693760,
|
||||
72172012436987968,
|
||||
317226351607872,
|
||||
2597178509285688384,
|
||||
1162205282238464,
|
||||
144154788211329152,
|
||||
172197832046936160,
|
||||
4625762105940000802,
|
||||
1477217245166903296,
|
||||
2251937789583872,
|
||||
289373902621379585,
|
||||
4616200855845409024,
|
||||
2251909637357568,
|
||||
3532510975437640064,
|
||||
563517968228352,
|
||||
562953309660434,
|
||||
1196005458310201856,
|
||||
2350914225914520576,
|
||||
2287018679861376,
|
||||
13836188353273790593,
|
||||
11267795163676832,
|
||||
297519119119499264,
|
||||
18588344158519552,
|
||||
10453428171813953792,
|
||||
72128237668534272,
|
||||
1298164929055953920,
|
||||
865575144395900952,
|
||||
9293076573325312,
|
||||
108104018148197376,
|
||||
578503662094123152,
|
||||
4665870505495102224,
|
||||
6066493872259301520,
|
||||
285877477613857,
|
||||
2328941618281318466,
|
||||
721165292771739652,
|
||||
4899973577790523400,
|
||||
75050392749184,
|
||||
2305878200632215680,
|
||||
11530099074925593616,
|
||||
290561512873919880,
|
||||
18652187227888000,
|
||||
3379933716168704,
|
||||
9223409493537718272,
|
||||
22273835729926,
|
||||
1152921524003672064,
|
||||
4647812741240848385,
|
||||
1244225087719112712,
|
||||
7367907171013001728,
|
||||
9263922034316951570,
|
||||
300758214358598160,
|
||||
4611686331973636096,
|
||||
2377900605806479360,
|
||||
6958097192913601024,
|
||||
864691130877743617,
|
||||
703824948904066,
|
||||
612700674899317536,
|
||||
180742128018784384,
|
||||
4634226011293351952,
|
||||
6918109887683821586,
|
||||
76562328660738184,
|
||||
7242919606867744800,
|
||||
13871652069997347969,
|
||||
1171657252671901696,
|
||||
147001475087730752,
|
||||
1752045392763101248,
|
||||
288406435526639744,
|
||||
4612213818402029888,
|
||||
9808848818951710728,
|
||||
9223394181731320840,
|
||||
54047645651435648,
|
||||
9224780030482579712,
|
||||
9049059098626048,
|
||||
1442330840700035221,
|
||||
1126037887157508,
|
||||
1153488887004529665,
|
||||
290485130928332936,
|
||||
9226749771011592258,
|
||||
148636405693678112,
|
||||
2260596997758984,
|
||||
73470481646424336,
|
||||
2341907012146823680,
|
||||
2314955761652335121,
|
||||
2265544246165632,
|
||||
13598764778463296,
|
||||
563087425962496,
|
||||
563087425962048,
|
||||
2163991853573081088,
|
||||
567353402270020,
|
||||
6488844433713538048,
|
||||
288810987011448834,
|
||||
11830884701569344,
|
||||
2747549955031826688,
|
||||
35734665298432,
|
||||
18025943920672800,
|
||||
292892945404789012,
|
||||
1153520472160470528,
|
||||
2260949167801860,
|
||||
155446765112299521,
|
||||
379008324189818944,
|
||||
4616480181217005576,
|
||||
576461027453960704,
|
||||
2450556349601564416,
|
||||
1160556519943569536,
|
||||
4612900059821375552,
|
||||
5477089643453251617,
|
||||
9223532084785594632,
|
||||
2810391870219355200,
|
||||
36594222015453185,
|
||||
4612011546951352320,
|
||||
2392883590201344,
|
||||
1152956706186200064,
|
||||
9009415592510464,
|
||||
81077999302148128,
|
||||
576746627483043968,
|
||||
301267327789056,
|
||||
39586720976896,
|
||||
720878306081243648,
|
||||
9223512777841312257,
|
||||
5764609859566698625,
|
||||
8088544233436348496,
|
||||
4612856276794474560,
|
||||
];
|
||||
|
||||
/// A set of magic numbers for rook move generation.
|
||||
pub(crate) const ROOK_SEED: [u64; Square::NUM_VARIANTS] = [
|
||||
2341871943948451840,
|
||||
18015635528220736,
|
||||
72066665545773824,
|
||||
1188959097794342912,
|
||||
12141713393631625314,
|
||||
720649693658353672,
|
||||
36029896538981888,
|
||||
36033359356363520,
|
||||
140746619355268,
|
||||
1158339898446446661,
|
||||
36591886560003650,
|
||||
578853633228023808,
|
||||
2392554490300416,
|
||||
140814806160384,
|
||||
180706952366596608,
|
||||
10696087878779396,
|
||||
1153260703948210820,
|
||||
310748649170673678,
|
||||
36311372044308544,
|
||||
9223444604757615104,
|
||||
1267187285230592,
|
||||
282574622818306,
|
||||
18722484274726152,
|
||||
2271591090110593,
|
||||
1153063519847989248,
|
||||
10168327557107712,
|
||||
4507998211276833,
|
||||
1153203035420233728,
|
||||
4631961017139660032,
|
||||
2454499182462107776,
|
||||
289367288355753288,
|
||||
18015815850820609,
|
||||
9268726066908758912,
|
||||
11547264697673728000,
|
||||
2314929519368081536,
|
||||
140943655192577,
|
||||
20266215511427202,
|
||||
180706969441535248,
|
||||
1302683805944911874,
|
||||
11534000122299940994,
|
||||
22676602724843520,
|
||||
4639271120198041668,
|
||||
1302104069046927376,
|
||||
9184220895313928,
|
||||
4612249105954373649,
|
||||
562984581726212,
|
||||
2312678200579457040,
|
||||
4647736876550193157,
|
||||
3170604524138139776,
|
||||
4684447574787096704,
|
||||
20283792725901696,
|
||||
1152992019380963840,
|
||||
117383863558471808,
|
||||
1153488854922068096,
|
||||
17596884583424,
|
||||
90074759127192064,
|
||||
4900502436426416706,
|
||||
4573968656793901,
|
||||
1161084564408385,
|
||||
1657887889314811910,
|
||||
4614501455660058690,
|
||||
4612530729109422081,
|
||||
642458506527236,
|
||||
1116704154754,
|
||||
180144122814791812,
|
||||
10448386594766422036,
|
||||
9403533616331358856,
|
||||
108095189301858304,
|
||||
72076290316044288,
|
||||
36066182562054145,
|
||||
4647717564258980096,
|
||||
13979173385364603396,
|
||||
4620833992751489152,
|
||||
297800804633419904,
|
||||
578009002156298240,
|
||||
2450099003505838082,
|
||||
1175721046778052864,
|
||||
20406952999780864,
|
||||
1175861788231598592,
|
||||
36169538802827392,
|
||||
288371663414771712,
|
||||
423313050501155,
|
||||
604731668136450,
|
||||
580261214513399808,
|
||||
297661437206136832,
|
||||
1750211954976489600,
|
||||
9020393411186696,
|
||||
9259543770406356001,
|
||||
44532368556032,
|
||||
10376381507760693256,
|
||||
52778707714176,
|
||||
4612829512676149248,
|
||||
1882513444629184528,
|
||||
2369460754144428160,
|
||||
9223380850137104901,
|
||||
2666413562481640036,
|
||||
141012643087392,
|
||||
16735517094631719424,
|
||||
17594358702087,
|
||||
2344264412262574084,
|
||||
422813768878080,
|
||||
1126450811896320,
|
||||
54466576291772936,
|
||||
42784758060548372,
|
||||
292874851780165648,
|
||||
18015364885839937,
|
||||
282644818493504,
|
||||
1184447393488764944,
|
||||
4649966632473477184,
|
||||
563499910594566,
|
||||
17632049496086,
|
||||
18502729728001,
|
||||
140742121013504,
|
||||
9711024139665536,
|
||||
246293205270784,
|
||||
290772515771392256,
|
||||
9230131836490350720,
|
||||
73326432604127360,
|
||||
453174886517643776,
|
||||
2396271245728563712,
|
||||
324259242966026501,
|
||||
288953994406543363,
|
||||
1153557061259362338,
|
||||
40533496293515441,
|
||||
1407392197644307,
|
||||
1729945211427624002,
|
||||
587808330812164100,
|
||||
9511606812128903298,
|
||||
];
|
||||
// endregion:sourcegen
|
||||
|
||||
|
|
|
@ -3,21 +3,25 @@ pub trait RandGen {
|
|||
fn gen(&mut self) -> u64;
|
||||
}
|
||||
|
||||
// A simple XOR-shift RNG implementation, for code-generation.
|
||||
// A simple pcg64_fast RNG implementation, for code-generation.
|
||||
#[cfg(test)]
|
||||
pub struct SimpleRng(u64);
|
||||
pub struct SimpleRng(u128);
|
||||
|
||||
#[cfg(test)]
|
||||
impl SimpleRng {
|
||||
pub fn new() -> Self {
|
||||
Self(4) // https://xkcd.com/221/
|
||||
Self(0xcafef00dd15ea5e5 | 1) // https://xkcd.com/221/
|
||||
}
|
||||
|
||||
pub fn gen(&mut self) -> u64 {
|
||||
self.0 ^= self.0 >> 12;
|
||||
self.0 ^= self.0 << 25;
|
||||
self.0 ^= self.0 >> 27;
|
||||
self.0
|
||||
const MULTIPLIER: u128 = 0x2360_ED05_1FC6_5DA4_4385_DF64_9FCC_F645;
|
||||
const XSHIFT: u32 = 64; // (128 - 64 + 64) / 2
|
||||
const ROTATE: u32 = 122; // 128 - 6
|
||||
|
||||
self.0 = self.0.wrapping_mul(MULTIPLIER);
|
||||
let rot = (self.0 >> ROTATE) as u32;
|
||||
let xsl = (self.0 >> XSHIFT) as u64 ^ (self.0 as u64);
|
||||
xsl.rotate_right(rot)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,10 +40,10 @@ mod test {
|
|||
fn rng() {
|
||||
let mut rng = SimpleRng::new();
|
||||
|
||||
assert_eq!(rng.gen(), 134217733);
|
||||
assert_eq!(rng.gen(), 4504699139039237);
|
||||
assert_eq!(rng.gen(), 13512173405898766);
|
||||
assert_eq!(rng.gen(), 9225626310854853124);
|
||||
assert_eq!(rng.gen(), 29836777971867270);
|
||||
assert_eq!(rng.gen(), 64934999470316615);
|
||||
assert_eq!(rng.gen(), 15459456780870779090);
|
||||
assert_eq!(rng.gen(), 13715484424881807779);
|
||||
assert_eq!(rng.gen(), 17718572936700675021);
|
||||
assert_eq!(rng.gen(), 14587996314750246637);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue