-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEnhancedHashCalculator.cpp
More file actions
52 lines (43 loc) · 2.24 KB
/
EnhancedHashCalculator.cpp
File metadata and controls
52 lines (43 loc) · 2.24 KB
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
//
// Enhanced State Hash Calculator Implementation
//
#include "EnhancedHashCalculator.h"
uint64_t EnhancedHashCalculator::computeStateHash(const Genome &genome) {
uint64_t hash = 0;
// Hash action sequence (existing logic but improved)
for (int i = 0; i < 350; ++i) {
if (genome.actions[i] == -1 || genome.actions[i] == 0) {
break;
}
auto a = static_cast<uint64_t>(static_cast<uint32_t>(genome.actions[i]));
hash = mixHash(hash, a);
// Include position information to maintain sequence order
hash = mixHash(hash, static_cast<uint64_t>(i));
}
// Add critical game state information to prevent hash collisions
// Player HP and MP states
hash = mixHash(hash, static_cast<uint64_t>(genome.AllyPlayer.hp) << 32);
hash = mixHash(hash, static_cast<uint64_t>(genome.EnemyPlayer.hp) << 16);
hash = mixHash(hash, static_cast<uint64_t>(genome.AllyPlayer.mp) << 8);
// Turn and position information
hash = mixHash(hash, static_cast<uint64_t>(genome.turn));
hash = mixHash(hash, static_cast<uint64_t>(genome.position) << 4);
hash = mixHash(hash, genome.state);
// Important status effects that affect battle outcome
hash = mixHash(hash, (genome.AllyPlayer.paralysis ? 1ULL : 0ULL) << 48);
hash = mixHash(hash, (genome.AllyPlayer.sleeping ? 1ULL : 0ULL) << 47);
hash = mixHash(hash, (genome.AllyPlayer.PoisonEnable ? 1ULL : 0ULL) << 46);
// // Buff levels that significantly impact combat
// hash = mixHash(hash, static_cast<uint64_t>(genome.AllyPlayer.BuffLevel) << 44);
// hash = mixHash(hash, static_cast<uint64_t>(genome.AllyPlayer.AtkBuffLevel) << 40);
// hash = mixHash(hash, static_cast<uint64_t>(genome.AllyPlayer.TensionLevel) << 36);
//
// Special abilities and charges
hash = mixHash(hash, (genome.AllyPlayer.specialCharge ? 1ULL : 0ULL) << 35);
hash = mixHash(hash, (genome.AllyPlayer.acrobaticStar ? 1ULL : 0ULL) << 34);
hash = mixHash(hash, static_cast<uint64_t>(genome.AllyPlayer.specialChargeTurn) << 24);
return hash;
}
uint64_t EnhancedHashCalculator::mixHash(uint64_t hash, uint64_t value, uint64_t multiplier) {
return hash ^ (value + multiplier + (hash << 6) + (hash >> 2));
}