From aba9a9cc35f528c8760d5d3bd16aaaccf5118b9e Mon Sep 17 00:00:00 2001 From: Trianta <56975502+Trimutex@users.noreply.github.com> Date: Wed, 14 Aug 2024 04:01:14 -0500 Subject: [PATCH] ai: remove food greed and adjust probability weights manually a bit for testing --- src/botinterface.cpp | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/src/botinterface.cpp b/src/botinterface.cpp index 5b4dd25..2c05d07 100755 --- a/src/botinterface.cpp +++ b/src/botinterface.cpp @@ -285,27 +285,22 @@ void AISnake::CheckLocalFreedom(void) { continue; // Out of bounds } double openSpaces = 0; - bool foodNearby = false; for (int j = -1; j < 2; ++j) { for (int k = -1; k < 2; ++k) { try { if (!g_pEngine->gameBoard.at(choices[i].y + j).at(choices[i].x + k).m_bSnake) ++openSpaces; - if (g_pEngine->gameBoard.at(choices[i].y + j).at(choices[i].x + k).m_bFood) - foodNearby = true; } catch (const std::out_of_range& error) { continue; // Out of bounds } } } chances[i] = openSpaces * 0.11111111111; - if (foodNearby) - chances[i] = 1; // Ignore chance, be greedy because food } - probabilityDown *= chances[0]; - probabilityRight *= chances[1]; - probabilityUp *= chances[2]; - probabilityLeft *= chances[3]; + probabilityDown *= chances[0] * 4; + probabilityRight *= chances[1] * 4; + probabilityUp *= chances[2] * 4; + probabilityLeft *= chances[3] * 4; } // Improves probability that direction of food is best option @@ -313,19 +308,13 @@ void AISnake::CheckLocalFreedom(void) { void AISnake::CheckFoodDirection(void) { sf::Vector2f delta = g_pEngine->GetHeadLocation() - g_pEngine->GetFoodLocation(); if (delta.x > 0) - probabilityLeft *= 2; + probabilityLeft *= 1.5; if (delta.x < 0) - probabilityRight *= 2; + probabilityRight *= 1.5; if (delta.y > 0) - probabilityUp *= 2; + probabilityUp *= 1.5; if (delta.y < 0) - probabilityDown *= 2; - std::array choices; - choices.fill(g_pEngine->GetHeadLocation()); - choices[0].y += 1; - choices[1].x += 1; - choices[2].y -= 1; - choices[3].x -= 1; + probabilityDown *= 1.5; } void AISnake::RemoveImpossibleChoice(void) {