Skip to content

Commit 4fb72e8

Browse files
committed
fix: depth limit in ids
1 parent f3ed582 commit 4fb72e8

File tree

6 files changed

+41
-33
lines changed

6 files changed

+41
-33
lines changed

src/main_scene/main_scene.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ void MainScene::_on_solve_button_pressed() {
160160
if (is_solved = solution.is_solved) {
161161
UtilityFunctions::print("IDS found a solution!");
162162
} else {
163-
UtilityFunctions::print("IDS could not find a solution.");
163+
UtilityFunctions::print("IDS could not find a solution with depth: ", String::num_int64(ids::MAX_DEPTH_LIMIT));
164164
}
165165
is_searching = false;
166166
break;
@@ -588,8 +588,8 @@ bool MainScene::load_input(String path, vector<Piece>& pieces, Board& board) {
588588
Ref<ConcavePolygonShape3D> collision_shape = collision_shape_node->get_shape();
589589
if (collision_shape.is_valid()) {
590590
PackedVector3Array vertices;
591-
float half_width = static_cast<float>(board.cols) / 2.0f;
592-
float half_depth = static_cast<float>(board.rows) / 2.0f;
591+
float half_width = static_cast<float>(board.cols - 0.1f) / 2.0f;
592+
float half_depth = static_cast<float>(board.rows - 0.1f) / 2.0f;
593593

594594
vertices.push_back(Vector3(half_width, 0.0f, half_depth));
595595
vertices.push_back(Vector3(-half_width, 0.0f, half_depth));

src/search/astar/astar.cpp

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ Solution astar::search_astar(const Board& initial_board, const vector<Piece>& in
7474
AStarSearchNode initial_astar_node(initial_pieces, initial_board, {}, initial_g_cost, initial_h_cost);
7575
pq.push(initial_astar_node);
7676

77-
godot::UtilityFunctions::print("ASTAR: Initial g_cost: " + godot::String::num_int64(initial_astar_node.actual_g_cost) +
78-
", h_cost: " + godot::String::num_int64(initial_astar_node.h_cost) +
79-
", f_cost: " + godot::String::num_int64(initial_astar_node.val)); // val dari base class adalah f_cost
77+
// godot::UtilityFunctions::print("ASTAR: Initial g_cost: " + godot::String::num_int64(initial_astar_node.actual_g_cost) +
78+
// ", h_cost: " + godot::String::num_int64(initial_astar_node.h_cost) +
79+
// ", f_cost: " + godot::String::num_int64(initial_astar_node.val)); // val dari base class adalah f_cost
8080

8181
while (!pq.empty()) {
8282
AStarSearchNode current_node = pq.top();
@@ -89,32 +89,32 @@ Solution astar::search_astar(const Board& initial_board, const vector<Piece>& in
8989
}
9090
visited_states.insert(current_state_str);
9191

92-
godot::UtilityFunctions::print("ASTAR: Exploring node. " +
93-
godot::String("f(n):") + godot::String::num_int64(current_node.val) + // f_cost dari base.val
94-
godot::String(", g(n):") + godot::String::num_int64(current_node.actual_g_cost) +
95-
godot::String(", h(n):") + godot::String::num_int64(current_node.h_cost) +
96-
". Path length: " + godot::String::num_int64(static_cast<int64_t>(current_node.path.size()))); // path dari base
92+
// godot::UtilityFunctions::print("ASTAR: Exploring node. " +
93+
// godot::String("f(n):") + godot::String::num_int64(current_node.val) + // f_cost dari base.val
94+
// godot::String(", g(n):") + godot::String::num_int64(current_node.actual_g_cost) +
95+
// godot::String(", h(n):") + godot::String::num_int64(current_node.h_cost) +
96+
// ". Path length: " + godot::String::num_int64(static_cast<int64_t>(current_node.path.size()))); // path dari base
9797

98-
if (current_node.piece_moved != ' ') { // piece_moved dari base
99-
Coordinates new_pos_for_log = {-1, -1};
100-
for(const auto& p_state : current_node.pieces) { // pieces dari base
101-
if (p_state.id == current_node.piece_moved) {
102-
new_pos_for_log = p_state.coordinates;
103-
break;
104-
}
105-
}
106-
godot::UtilityFunctions::print("Moved piece: ", godot::String::utf8(&current_node.piece_moved, 1),
107-
" from (", current_node.original_position.x, ",", current_node.original_position.y,
108-
") to (", new_pos_for_log.x, ",", new_pos_for_log.y, ")"); // original_position dari base
109-
}
98+
// if (current_node.piece_moved != ' ') { // piece_moved dari base
99+
// Coordinates new_pos_for_log = {-1, -1};
100+
// for(const auto& p_state : current_node.pieces) { // pieces dari base
101+
// if (p_state.id == current_node.piece_moved) {
102+
// new_pos_for_log = p_state.coordinates;
103+
// break;
104+
// }
105+
// }
106+
// godot::UtilityFunctions::print("Moved piece: ", godot::String::utf8(&current_node.piece_moved, 1),
107+
// " from (", current_node.original_position.x, ",", current_node.original_position.y,
108+
// ") to (", new_pos_for_log.x, ",", new_pos_for_log.y, ")"); // original_position dari base
109+
// }
110110

111111
if (Utils::is_exit(current_node.board, current_node.pieces)) { // board dan pieces dari base
112112
result.is_solved = true;
113113
result.moves = current_node.path; // path dari base
114-
godot::UtilityFunctions::print("ASTAR: Solution Found! Optimal steps (g_cost): " +
115-
godot::String::num_int64(current_node.actual_g_cost) + ". Total moves: " +
116-
godot::String::num_int64(result.moves.size()) + ". Nodes visited: " +
117-
godot::String::num_int64(static_cast<int64_t>(result.node)));
114+
// godot::UtilityFunctions::print("ASTAR: Solution Found! Optimal steps (g_cost): " +
115+
// godot::String::num_int64(current_node.actual_g_cost) + ". Total moves: " +
116+
// godot::String::num_int64(result.moves.size()) + ". Nodes visited: " +
117+
// godot::String::num_int64(static_cast<int64_t>(result.node)));
118118
break;
119119
}
120120

@@ -131,8 +131,8 @@ Solution astar::search_astar(const Board& initial_board, const vector<Piece>& in
131131
auto time_end = chrono::high_resolution_clock::now();
132132
result.duration = chrono::duration<double, milli>(time_end - time_start);
133133

134-
if (!result.is_solved) {
135-
godot::UtilityFunctions::print("ASTAR: No solution found. Nodes visited: " + godot::String::num_int64(static_cast<int64_t>(result.node)));
136-
}
134+
// if (!result.is_solved) {
135+
// godot::UtilityFunctions::print("ASTAR: No solution found. Nodes visited: " + godot::String::num_int64(static_cast<int64_t>(result.node)));
136+
// }
137137
return result;
138138
}

src/search/ids/ids.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ Solution ids::search_ids(const Board& initial_board, const vector<Piece>& initia
5454
Solution result;
5555
result.node = 0;
5656

57-
const int MAX_DEPTH_LIMIT = 100000;
58-
5957
for (int depth_limit = 0; depth_limit <= MAX_DEPTH_LIMIT; ++depth_limit) {
6058
SearchNode initial_node(initial_pieces, initial_board, {}, 0);
6159
set<string> visited_dls;

src/search/ids/ids.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
class ids {
88
public:
9+
static const int MAX_DEPTH_LIMIT = 100;
910
static Solution search_ids(const Board& initial_board, const std::vector<Piece>& initial_pieces);
1011
};
1112

test/4.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
5 5
2+
5
3+
EAAA.
4+
ED.PB
5+
.D.PB
6+
.D.CB
7+
...C.
8+
K

tukang-parkir-simulator/scenes/main.tscn

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ ground_horizon_color = Color(0.662243, 0.671743, 0.686743, 1)
1212
sky_material = SubResource("ProceduralSkyMaterial_kuqtn")
1313

1414
[sub_resource type="Environment" id="Environment_3lc0u"]
15-
background_mode = 2
15+
background_mode = 1
16+
background_color = Color(0.364706, 0, 0.0862745, 1)
1617
sky = SubResource("Sky_whr1e")
1718
tonemap_mode = 2
1819
glow_enabled = true

0 commit comments

Comments
 (0)