-
Notifications
You must be signed in to change notification settings - Fork 0
/
9tile.c
112 lines (94 loc) · 2.35 KB
/
9tile.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <stdio.h>
#include <pthread.h>
#include <stdint.h>
//#include <stdlib.h>
#define THREADS 16
uint64_t mcStepSeed(const uint64_t s, const uint64_t salt)
{
return s * (s * 6364136223846793005ULL + 1442695040888963407ULL) + salt;
}
int mcFirstIsZero(const uint64_t s)
{
//mod = 16;
return (int)(((long)s >> 24) % 13) == 0;
}
uint64_t getChunkSeed(uint64_t ss, int x, int z)
{
ss += x;
ss = mcStepSeed(ss, z);
ss = mcStepSeed(ss, x);
ss = mcStepSeed(ss, z);
return ss;
}
uint64_t getStartSalt(uint64_t ws)
{
ws = mcStepSeed(ws, 7590731853067264053ULL);
ws = mcStepSeed(ws, 7590731853067264053ULL);
ws = mcStepSeed(ws, 7590731853067264053ULL);
return ws;
}
uint64_t getStartSeed(uint64_t ws)
{
return mcStepSeed(getStartSalt(ws), 0);
}
int mapSpecial(uint64_t ws)
{
const uint64_t st = getStartSalt(ws);
const uint64_t ss = getStartSeed(ws);
int i, j;
for (j = 0; j < 3; j++)
{
for (i = 0; i < 3; i++)
{
if (!mcFirstIsZero(getChunkSeed(ss, i-1, j-1)))
{
return 0;
}
}
}
return 1;
}
void * mapSpecialRange(uint64_t offset)
{
uint64_t min = offset;
uint64_t max = offset + (1LL << 32) - 1;
for(uint64_t seed = min; seed <= max; seed++)
{
if(mapSpecial(seed))
{
printf("%lld\n", seed);
}
}
}
void spawnThreads(uint64_t offoffset)
{
uint64_t offset = offoffset;
pthread_t thread_id[THREADS];
int err;
int i;
for(i = 0; i < THREADS; i++)
{
pthread_create(&thread_id[i], NULL, mapSpecialRange, offset);
offset += (1ULL << 32);
}
for(i = 0; i < THREADS; i++)
{
pthread_join(thread_id[i], NULL);
}
}
int main()
{
printf("this configuration will do %lld seeds per block\n\n", THREADS * (1ULL << 32));
int startblock, endblock;
printf("block to start at: ");
scanf("%d", &startblock);
printf("block to end at: ");
scanf("%d", &endblock);
for(int i = startblock; i <= endblock; i++)
{
uint64_t chunkstart = THREADS * (uint64_t)i << 32;
//printf("Started block #%d with offset %ld\n", i, chunkstart);
spawnThreads(chunkstart);
}
return 0;
}