diff --git a/src/botinterface.cpp b/src/botinterface.cpp index f72d7f3..fd8da85 100755 --- a/src/botinterface.cpp +++ b/src/botinterface.cpp @@ -17,10 +17,8 @@ AISnake::AISnake() { PlayerDirection AISnake::GetInput(const sf::Vector2f* source) { sf::Vector2f directionDelta; - if (!source) { - std::cout << "[ERROR - AI] Source was borked, bailing" << std::endl; + if (!source) return kUp; - } while (*source == path.top() && !path.empty()) { path.pop(); } if (path.empty()) { path.push(GetAnyOpenPath(*source)); } directionDelta = *source - path.top(); @@ -51,7 +49,6 @@ void AISnake::AdjustProbability(double amount) probabilityBFS += amount; if (probabilityBFS > 1.0) { probabilityBFS = 1.0; } if (probabilityBFS < 0.0) { probabilityBFS = 0.0; } - std::cout << "[Info - AI] New BFS probability: " << probabilityBFS << std::endl; return; } @@ -64,8 +61,8 @@ void AISnake::AddIteration(const int size) if (average > size) { AdjustProbability(adjustmentAmount); } else { AdjustProbability(-adjustmentAmount); } } - std::cout << "[Info - AI] Current average: " << average << std::endl; - std::cout << "[Info - AI] Previous iteration size: " << size << std::endl; + std::cout << "[LOG - AI] Current average: " << average << std::endl; + std::cout << "[LOG - AI] Previous iteration size: " << size << std::endl; } void AISnake::ResetPath(void) { @@ -94,7 +91,6 @@ void AISnake::GetNewPath(const sf::Vector2f& source) } void AISnake::BFS(const sf::Vector2f& source) { - std::cout << "[Info - AI] Rolled BFS" << std::endl; std::queue search; search.push(source); while (!search.empty()) { @@ -114,15 +110,10 @@ void AISnake::BFS(const sf::Vector2f& source) { GameSpace* space = &g_pEngine->gameBoard.at(nearby.y).at(nearby.x); if (space->m_bFood) { botPathUnsanitized.push(nearby); - std::cout << "[TRACE - BFS] Path successfully found food" << std::endl; return; } - if (nearby.x < 1 || nearby.y < 1 - || nearby.x > g_pEngine->GetGameBoundaries().x - 1 - || nearby.y > g_pEngine->GetGameBoundaries().y - 1) { - continue; - - } + if (nearby.x < 1 || nearby.y < 1) + continue; if (space->m_bVisited) continue; if (space->m_bSnake) @@ -134,12 +125,10 @@ void AISnake::BFS(const sf::Vector2f& source) { } g_pEngine->gameBoard.at(currentLocation.y).at(currentLocation.x).m_bVisited = true; } - std::cout << "[ERROR - BFS] Failed to get a path to food" << std::endl; pathFailed = true; } void AISnake::DFS(const sf::Vector2f& source) { - std::cout << "[Info - AI] Rolled DFS" << std::endl; std::stack search; search.push(source); while (!search.empty()) { @@ -159,15 +148,10 @@ void AISnake::DFS(const sf::Vector2f& source) { GameSpace* space = &g_pEngine->gameBoard.at(nearby.y).at(nearby.x); if (space->m_bFood) { botPathUnsanitized.push(nearby); - std::cout << "[TRACE - DFS] Path successfully found food" << std::endl; return; } - if (nearby.x < 1 || nearby.y < 1 - || nearby.x > g_pEngine->GetGameBoundaries().x - 1 - || nearby.y > g_pEngine->GetGameBoundaries().y - 1) { - continue; - - } + if (nearby.x < 1 || nearby.x > g_pEngine->GetGameBoundaries().x - 2) + continue; if (space->m_bVisited) continue; if (space->m_bSnake) @@ -179,7 +163,6 @@ void AISnake::DFS(const sf::Vector2f& source) { } g_pEngine->gameBoard.at(currentLocation.y).at(currentLocation.x).m_bVisited = true; } - std::cout << "[ERROR - DFS] Failed to get a path to food" << std::endl; pathFailed = true; } @@ -194,10 +177,9 @@ sf::Vector2f AISnake::GetAnyOpenPath(const sf::Vector2f& source) { for (auto path : paths) { try { - if (g_pEngine->gameBoard.at(path.y).at(path.x).m_bSnake) { - bail = path; + bail = path; + if (g_pEngine->gameBoard.at(path.y).at(path.x).m_bSnake) continue; - } return path; } catch (const std::out_of_range& error) { continue; // Out of bounds @@ -211,7 +193,6 @@ void AISnake::UnvisitBoard(void) { for (std::vector& i : g_pEngine->gameBoard) for (GameSpace& j : i) j.m_bVisited = false; - std::cout << "[TRACE - AI] Unvisited board" << std::endl; } void AISnake::UpdateAverage(const int size) { @@ -235,7 +216,6 @@ void AISnake::TrimPath(void) { } botPathUnsanitized.pop(); } - std::cout << "[TRACE - AI] Trimmed path" << std::endl; } void AISnake::EmptyPath(void) { diff --git a/src/gamestate.cpp b/src/gamestate.cpp index 8454225..8e49b5b 100755 --- a/src/gamestate.cpp +++ b/src/gamestate.cpp @@ -25,6 +25,8 @@ void GameEngine::Reset() { if (!state.m_bIsBotControlled) graphics.CheckContinue(); + else + bot.AddIteration(player.body.size()); player.Reset(); PrepareGameBoard(); state.m_bIsGameOver = false; @@ -34,7 +36,6 @@ void GameEngine::Reset() if (state.m_bNoDisplay) graphics.SetShowGame(false); graphics.SetShowGame((bot.amountPlayed + 1) % 50 == 0); - bot.AddIteration(player.body.size()); } } diff --git a/src/snake.hpp b/src/snake.hpp index c6f145e..ef6a5c4 100755 --- a/src/snake.hpp +++ b/src/snake.hpp @@ -20,7 +20,6 @@ struct Food { public: sf::Vector2f location; - char* food; void GenerateNewFood(sf::Vector2f boundaries); };