adjust
This commit is contained in:
@ -13,7 +13,115 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "dataload.h"
|
#include <unordered_map>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
|
#include "data.h"
|
||||||
|
#include "zb64.h"
|
||||||
|
namespace DataLoad {
|
||||||
|
typedef long long LL;
|
||||||
|
const int buf_size = 4412555 * 4;
|
||||||
|
unsigned char buf[buf_size], data[buf_size];
|
||||||
|
bool already_have[14348907];
|
||||||
|
// std::unordered_map<LL,unsigned char> visible_to_probability;
|
||||||
|
int rid[15] = {0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2};
|
||||||
|
int cid[15] = {0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4};
|
||||||
|
class HashTable {
|
||||||
|
struct Node {
|
||||||
|
LL key;
|
||||||
|
unsigned char value;
|
||||||
|
Node *next;
|
||||||
|
Node(LL k, unsigned char v) : key(k), value(v), next(nullptr) {}
|
||||||
|
};
|
||||||
|
Node *table[14348907];
|
||||||
|
|
||||||
|
public:
|
||||||
|
HashTable() {
|
||||||
|
for (int i = 0; i < 14348907; i++) table[i] = nullptr;
|
||||||
|
}
|
||||||
|
~HashTable() {
|
||||||
|
for (int i = 0; i < 14348907; i++) {
|
||||||
|
Node *p = table[i];
|
||||||
|
while (p) {
|
||||||
|
Node *q = p->next;
|
||||||
|
delete p;
|
||||||
|
p = q;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unsigned char &operator[](LL key) {
|
||||||
|
int index = key % 14348907;
|
||||||
|
Node *p = table[index];
|
||||||
|
while (p) {
|
||||||
|
if (p->key == key) return p->value;
|
||||||
|
p = p->next;
|
||||||
|
}
|
||||||
|
p = new Node(key, 0);
|
||||||
|
p->next = table[index];
|
||||||
|
table[index] = p;
|
||||||
|
return p->value;
|
||||||
|
}
|
||||||
|
bool have(LL key) {
|
||||||
|
int index = key % 14348907;
|
||||||
|
Node *p = table[index];
|
||||||
|
while (p) {
|
||||||
|
if (p->key == key) return true;
|
||||||
|
p = p->next;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} visible_to_probability;
|
||||||
|
} // namespace DataLoad
|
||||||
|
void LoadData() {
|
||||||
|
using namespace DataLoad;
|
||||||
|
size_t raw_length = base64_decode(pre_calc_prob, buf, buf_size);
|
||||||
|
size_t data_length = decompressData(buf, raw_length, data, buf_size);
|
||||||
|
// std::cout<<"decompress finished.\n"<<std::endl;
|
||||||
|
// already_have.rehash(4412555);
|
||||||
|
// visible_to_probability.rehash(4412555);
|
||||||
|
const LL raw_line_base = 243;
|
||||||
|
const LL vis_line_base = 100000;
|
||||||
|
int cnt = 0;
|
||||||
|
for (int status = 0; status < 14348907; status++) {
|
||||||
|
LL inverse_status =
|
||||||
|
(status % raw_line_base) * raw_line_base * raw_line_base +
|
||||||
|
((status / raw_line_base) % raw_line_base) * raw_line_base +
|
||||||
|
(status / (raw_line_base * raw_line_base));
|
||||||
|
if (already_have[inverse_status]) continue;
|
||||||
|
// assert(already_have.find(status) == already_have.end());
|
||||||
|
already_have[status] = true;
|
||||||
|
int inner_mp[3][5] = {0}, visible_map[3][5];
|
||||||
|
LL status_tmp = status;
|
||||||
|
for (int i = 0; i < 15; i++) {
|
||||||
|
int row = rid[i], col = cid[i];
|
||||||
|
inner_mp[row][col] = (status_tmp % 3); // uncode the inner_status
|
||||||
|
status_tmp /= 3;
|
||||||
|
}
|
||||||
|
for (int row = 0; row < 3; row++)
|
||||||
|
for (int col = 0; col < 5; col++) {
|
||||||
|
if (inner_mp[row][col] == 0 || inner_mp[row][col] == 1) {
|
||||||
|
visible_map[row][col] = 9; // 9 means unshown to player
|
||||||
|
} else {
|
||||||
|
int mcnt = 0;
|
||||||
|
const int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1},
|
||||||
|
dy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
int nr = row + dx[i], nc = col + dy[i];
|
||||||
|
if (nr < 0 || nr >= 3 || nc < 0 || nc >= 5) continue;
|
||||||
|
mcnt += (inner_mp[nr][nc] == 0 ? 1 : 0);
|
||||||
|
}
|
||||||
|
visible_map[row][col] = mcnt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LL visible_status = 0;
|
||||||
|
for (int i = 0; i < 15; i++) {
|
||||||
|
int row = rid[i], col = cid[i];
|
||||||
|
visible_status = visible_status * 10 + visible_map[row][col];
|
||||||
|
}
|
||||||
|
visible_to_probability[visible_status] = data[cnt++];
|
||||||
|
}
|
||||||
|
// std::cout<<"Load data finished.\n"<<std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
extern int rows; // The count of rows of the game map
|
extern int rows; // The count of rows of the game map
|
||||||
extern int columns; // The count of columns of the game map
|
extern int columns; // The count of columns of the game map
|
||||||
|
@ -11,74 +11,62 @@ bool already_have[14348907];
|
|||||||
// std::unordered_map<LL,unsigned char> visible_to_probability;
|
// std::unordered_map<LL,unsigned char> visible_to_probability;
|
||||||
int rid[15] = {0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2};
|
int rid[15] = {0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2};
|
||||||
int cid[15] = {0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4};
|
int cid[15] = {0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4};
|
||||||
class HashTable
|
class HashTable {
|
||||||
{
|
struct Node {
|
||||||
struct Node
|
LL key;
|
||||||
{
|
unsigned char value;
|
||||||
LL key;
|
Node *next;
|
||||||
unsigned char value;
|
Node(LL k, unsigned char v) : key(k), value(v), next(nullptr) {}
|
||||||
Node* next;
|
};
|
||||||
Node(LL k,unsigned char v):key(k),value(v),next(nullptr){}
|
Node *table[14348907];
|
||||||
};
|
|
||||||
Node* table[14348907];
|
public:
|
||||||
public:
|
HashTable() {
|
||||||
HashTable()
|
for (int i = 0; i < 14348907; i++) table[i] = nullptr;
|
||||||
{
|
}
|
||||||
for(int i=0;i<14348907;i++)
|
~HashTable() {
|
||||||
table[i]=nullptr;
|
for (int i = 0; i < 14348907; i++) {
|
||||||
}
|
Node *p = table[i];
|
||||||
~HashTable()
|
while (p) {
|
||||||
{
|
Node *q = p->next;
|
||||||
for(int i=0;i<14348907;i++)
|
delete p;
|
||||||
{
|
p = q;
|
||||||
Node* p=table[i];
|
}
|
||||||
while(p)
|
}
|
||||||
{
|
}
|
||||||
Node* q=p->next;
|
unsigned char &operator[](LL key) {
|
||||||
delete p;
|
int index = key % 14348907;
|
||||||
p=q;
|
Node *p = table[index];
|
||||||
}
|
while (p) {
|
||||||
}
|
if (p->key == key) return p->value;
|
||||||
}
|
p = p->next;
|
||||||
unsigned char& operator[](LL key)
|
}
|
||||||
{
|
p = new Node(key, 0);
|
||||||
int index=key%14348907;
|
p->next = table[index];
|
||||||
Node* p=table[index];
|
table[index] = p;
|
||||||
while(p)
|
return p->value;
|
||||||
{
|
}
|
||||||
if(p->key==key)
|
bool have(LL key) {
|
||||||
return p->value;
|
int index = key % 14348907;
|
||||||
p=p->next;
|
Node *p = table[index];
|
||||||
}
|
while (p) {
|
||||||
p=new Node(key,0);
|
if (p->key == key) return true;
|
||||||
p->next=table[index];
|
p = p->next;
|
||||||
table[index]=p;
|
}
|
||||||
return p->value;
|
return false;
|
||||||
}
|
}
|
||||||
bool have(LL key)
|
} visible_to_probability;
|
||||||
{
|
|
||||||
int index=key%14348907;
|
|
||||||
Node* p=table[index];
|
|
||||||
while(p)
|
|
||||||
{
|
|
||||||
if(p->key==key)
|
|
||||||
return true;
|
|
||||||
p=p->next;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}visible_to_probability;
|
|
||||||
} // namespace DataLoad
|
} // namespace DataLoad
|
||||||
void LoadData() {
|
void LoadData() {
|
||||||
using namespace DataLoad;
|
using namespace DataLoad;
|
||||||
size_t raw_length = base64_decode(pre_calc_prob, buf, buf_size);
|
size_t raw_length = base64_decode(pre_calc_prob, buf, buf_size);
|
||||||
size_t data_length = decompressData(buf, raw_length, data, buf_size);
|
size_t data_length = decompressData(buf, raw_length, data, buf_size);
|
||||||
// std::cout<<"decompress finished.\n"<<std::endl;
|
// std::cout<<"decompress finished.\n"<<std::endl;
|
||||||
// already_have.rehash(4412555);
|
// already_have.rehash(4412555);
|
||||||
// visible_to_probability.rehash(4412555);
|
// visible_to_probability.rehash(4412555);
|
||||||
const LL raw_line_base = 243;
|
const LL raw_line_base = 243;
|
||||||
const LL vis_line_base = 100000;
|
const LL vis_line_base = 100000;
|
||||||
int cnt=0;
|
int cnt = 0;
|
||||||
for (int status = 0; status < 14348907; status++) {
|
for (int status = 0; status < 14348907; status++) {
|
||||||
LL inverse_status =
|
LL inverse_status =
|
||||||
(status % raw_line_base) * raw_line_base * raw_line_base +
|
(status % raw_line_base) * raw_line_base * raw_line_base +
|
||||||
@ -86,7 +74,7 @@ void LoadData() {
|
|||||||
(status / (raw_line_base * raw_line_base));
|
(status / (raw_line_base * raw_line_base));
|
||||||
if (already_have[inverse_status]) continue;
|
if (already_have[inverse_status]) continue;
|
||||||
// assert(already_have.find(status) == already_have.end());
|
// assert(already_have.find(status) == already_have.end());
|
||||||
already_have[status]=true;
|
already_have[status] = true;
|
||||||
int inner_mp[3][5] = {0}, visible_map[3][5];
|
int inner_mp[3][5] = {0}, visible_map[3][5];
|
||||||
LL status_tmp = status;
|
LL status_tmp = status;
|
||||||
for (int i = 0; i < 15; i++) {
|
for (int i = 0; i < 15; i++) {
|
||||||
@ -115,7 +103,7 @@ void LoadData() {
|
|||||||
int row = rid[i], col = cid[i];
|
int row = rid[i], col = cid[i];
|
||||||
visible_status = visible_status * 10 + visible_map[row][col];
|
visible_status = visible_status * 10 + visible_map[row][col];
|
||||||
}
|
}
|
||||||
visible_to_probability[visible_status] = data[cnt++];
|
visible_to_probability[visible_status] = data[cnt++];
|
||||||
}
|
}
|
||||||
// std::cout<<"Load data finished.\n"<<std::endl;
|
// std::cout<<"Load data finished.\n"<<std::endl;
|
||||||
}
|
}
|
Reference in New Issue
Block a user