generated from godotengine/godot-cpp-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.hpp
More file actions
102 lines (82 loc) · 2.55 KB
/
utils.hpp
File metadata and controls
102 lines (82 loc) · 2.55 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
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
#pragma once
#include <godot_cpp/variant/utility_functions.hpp>
#include <godot_cpp/variant/string.hpp>
#include <algorithm>
#include <chrono>
#include <string>
#include <vector>
using namespace std;
using namespace godot;
enum AlgoType {
BFS,
UCS,
ASTAR,
};
struct Coordinates {
int x;
int y;
bool operator<(const Coordinates& other) const {
if (x != other.x) {
return x < other.x;
}
return y < other.y;
}
bool operator==(const Coordinates& other) const {
return x == other.x && y == other.y;
}
bool operator!=(const Coordinates& other) const {
return !(*this == other);
}
};
struct Piece {
char id;
Coordinates coordinates;
int size;
bool is_vertical;
bool is_primary;
};
struct Board {
int rows;
int cols;
int other_pieces_count;
int pixel_size;
int pixel_padding;
Coordinates exit_coordinates;
vector<vector<char>> grid;
int piece_padding = 1;
};
struct PieceMove {
Coordinates old_coordinates;
Coordinates new_coordinates;
};
struct Solution {
vector<PieceMove> moves;
chrono::duration<double, milli> duration;
int node;
bool is_solved;
Solution() : node(0), is_solved(false) {}
};
struct SearchNode {
std::vector<Piece> pieces;
Board board;
std::vector<PieceMove> path;
int val; // nilai heuristik dari state ini
char piece_moved;
Coordinates original_pos_moved_piece;
SearchNode(const std::vector<Piece>& p, const Board& b, const std::vector<PieceMove>& path, int h, char pid = ' ', Coordinates opos = {-1,-1}) : pieces(p), board(b), path(path), val(h), piece_moved(pid), original_pos_moved_piece(opos) {}
bool operator>(const SearchNode& other) const {
return val > other.val;
}
};
class Utils {
public:
static void print_board(Board& board, std:: vector<Piece>& pieces);
static godot::String stringToGodotString(const std::string& stdString);
static std::string godotStringToString(const godot::String& godotString);
static int calculate(const Board& initial_board, const vector<Piece>& current_pieces);
static bool is_exit(const Board& initial_board, const std::vector<Piece>& current_pieces);
// helper function
static const Piece* get_primary_piece(const vector<Piece>& pieces_list);
static std::string state_to_string(const std::vector<Piece>& current_pieces);
static bool is_cell_clear(const Board& initial_board, int r_check, int c_check, const std::vector<Piece>& pieces_in_state, char moving_piece_id);
};