CoolFace
Apppublic

AnGrapicStudio/brain-x-stage2-simulation

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
nuclear_kernel.cpp75 linesDownload Raw Back to root
1#include <cstdint>
2#include <cstring>
3#include <ctime>
4
5#ifdef _WIN32
6#define EXPORT __declspec(dllexport)
7#else
8#define EXPORT
9#endif
10
11extern "C" {
12
13struct State {
14  int64_t pat10;
15  int64_t patWin;
16  int64_t buf10;
17  int64_t bufWin;
18};
19
20// Simple but fast 64-bit RNG (SplitMix64)
21static inline uint64_t splitmix64(uint64_t *state) {
22  uint64_t z = (*state += 0x9e3779b97f4a7c15);
23  z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9;
24  z = (z ^ (z >> 27)) * 0x94d049bb133111eb;
25  return z ^ (z >> 31);
26}
27
28static inline int draw_card(uint64_t *rng_state) {
29  uint64_t val = splitmix64(rng_state) % 13;
30  return (val >= 9) ? 0 : (int)val + 1;
31}
32
33EXPORT void simulate_batch_scalar(uint64_t seed, int32_t iterations,
34                                  int64_t *out_counts) {
35  uint64_t rng_state = seed;
36  int64_t b_wins = 0, p_wins = 0, ties = 0;
37
38  for (int i = 0; i < iterations; i++) {
39    int p1 = draw_card(&rng_state);
40    int p2 = draw_card(&rng_state);
41    int b1 = draw_card(&rng_state);
42    int b2 = draw_card(&rng_state);
43
44    int p_score = (p1 + p2) % 10;
45    int b_score = (b1 + b2) % 10;
46
47    // Simplified Baccarat (Level 2 Nuclear Logic)
48    if (p_score <= 5) {
49      p_score = (p_score + draw_card(&rng_state)) % 10;
50    }
51    if (b_score <= 5) {
52      b_score = (b_score + draw_card(&rng_state)) % 10;
53    }
54
55    if (b_score > p_score)
56      b_wins++;
57    else if (p_score > b_score)
58      p_wins++;
59    else
60      ties++;
61  }
62
63  out_counts[0] = b_wins;
64  out_counts[1] = p_wins;
65  out_counts[2] = ties;
66}
67
68EXPORT void run_simulation_cpp(int64_t total_rounds, uint64_t seed,
69                               int32_t window, int64_t *counts10, void *keysWin,
70                               void *countsWin, uint64_t size_mask,
71                               State *state) {
72  simulate_batch_scalar(seed, (int32_t)total_rounds, counts10);
73}
74}
75