Playing around with it some more to see how a move would work.
This commit is contained in:
parent
98baa13264
commit
98993481b0
1 changed files with 69 additions and 33 deletions
|
@ -1,6 +1,9 @@
|
|||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <fmt/core.h>
|
||||
|
||||
using namespace fmt;
|
||||
|
||||
struct Point {
|
||||
int x, y;
|
||||
|
@ -29,6 +32,10 @@ public:
|
|||
table[obj->position].push_back(obj);
|
||||
}
|
||||
|
||||
void remove(Object* obj) {
|
||||
table.erase(obj->position);
|
||||
}
|
||||
|
||||
std::vector<Object*> getNearbyObjects(Point position) {
|
||||
std::vector<Object*> result;
|
||||
Point cell = position;
|
||||
|
@ -62,8 +69,37 @@ int main() {
|
|||
hashTable.insert(&bomb);
|
||||
|
||||
std::vector<Object*> nearby = hashTable.getNearbyObjects({24, 24});
|
||||
|
||||
for (Object* obj : nearby) {
|
||||
std::cout << obj->position.x << ", " << obj->position.y << std::endl;
|
||||
println("{},{}", obj->position.x, obj->position.y);
|
||||
}
|
||||
|
||||
println("AFTER MOVE");
|
||||
|
||||
// now attempt a move
|
||||
hashTable.remove(&bomb);
|
||||
bomb.position.x += 1;
|
||||
bomb.position.y += 1;
|
||||
hashTable.insert(&bomb);
|
||||
|
||||
nearby = hashTable.getNearbyObjects({24, 24});
|
||||
|
||||
for (Object* obj : nearby) {
|
||||
println("{},{}", obj->position.x, obj->position.y);
|
||||
}
|
||||
|
||||
println("AFTER MOVE BACK");
|
||||
|
||||
// now attempt a move
|
||||
hashTable.remove(&bomb);
|
||||
bomb.position.x -= 3;
|
||||
bomb.position.y -= 2;
|
||||
hashTable.insert(&bomb);
|
||||
|
||||
nearby = hashTable.getNearbyObjects({24, 24});
|
||||
|
||||
for (Object* obj : nearby) {
|
||||
println("{},{}", obj->position.x, obj->position.y);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue