From 9bb4b8ebcac0d82c5940cb0c61b3eca3c47a8776 Mon Sep 17 00:00:00 2001 From: Trimutex Date: Mon, 16 Oct 2023 12:35:35 -0500 Subject: [PATCH] Increased survivability with DFS when no path --- src/botinterface.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/botinterface.cpp b/src/botinterface.cpp index 9843479..4ac0535 100755 --- a/src/botinterface.cpp +++ b/src/botinterface.cpp @@ -41,10 +41,11 @@ namespace snakeplusplus void AISnake::GetNewPath(const std::vector< std::vector >& gameBoard, const sf::Vector2f& source, const sf::Vector2f& boundaries, const int snakeSize) { // Search for food - if (snakeSize < 135) { - BFS(gameBoard, source, boundaries); - } else { + BFS(gameBoard, source, boundaries); + if (gameBoard[botPathUnsanitized.top().y][botPathUnsanitized.top().x] != 'X') { + while (!botPathUnsanitized.empty()) { botPathUnsanitized.pop(); } DFS(gameBoard, source, boundaries); + while (botPathUnsanitized.size() > 15) { botPathUnsanitized.pop(); } } // Create path for food path.push(botPathUnsanitized.top()); -- 2.45.2