ai: remove food greed and adjust probability weights manually a bit for testing
This commit is contained in:
		
							parent
							
								
									a5902171ec
								
							
						
					
					
						commit
						aba9a9cc35
					
				@ -285,27 +285,22 @@ void AISnake::CheckLocalFreedom(void) {
 | 
				
			|||||||
            continue; // Out of bounds
 | 
					            continue; // Out of bounds
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        double openSpaces = 0;
 | 
					        double openSpaces = 0;
 | 
				
			||||||
        bool foodNearby = false;
 | 
					 | 
				
			||||||
        for (int j = -1; j < 2; ++j) {
 | 
					        for (int j = -1; j < 2; ++j) {
 | 
				
			||||||
            for (int k = -1; k < 2; ++k) {
 | 
					            for (int k = -1; k < 2; ++k) {
 | 
				
			||||||
                try {
 | 
					                try {
 | 
				
			||||||
                    if (!g_pEngine->gameBoard.at(choices[i].y + j).at(choices[i].x + k).m_bSnake)
 | 
					                    if (!g_pEngine->gameBoard.at(choices[i].y + j).at(choices[i].x + k).m_bSnake)
 | 
				
			||||||
                        ++openSpaces;
 | 
					                        ++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) {
 | 
					                } catch (const std::out_of_range& error) {
 | 
				
			||||||
                    continue; // Out of bounds
 | 
					                    continue; // Out of bounds
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        chances[i] = openSpaces * 0.11111111111;
 | 
					        chances[i] = openSpaces * 0.11111111111;
 | 
				
			||||||
        if (foodNearby)
 | 
					 | 
				
			||||||
            chances[i] = 1; // Ignore chance, be greedy because food
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    probabilityDown *= chances[0];
 | 
					    probabilityDown *= chances[0] * 4;
 | 
				
			||||||
    probabilityRight *= chances[1];
 | 
					    probabilityRight *= chances[1] * 4;
 | 
				
			||||||
    probabilityUp *= chances[2];
 | 
					    probabilityUp *= chances[2] * 4;
 | 
				
			||||||
    probabilityLeft *= chances[3];
 | 
					    probabilityLeft *= chances[3] * 4;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Improves probability that direction of food is best option
 | 
					// Improves probability that direction of food is best option
 | 
				
			||||||
@ -313,19 +308,13 @@ void AISnake::CheckLocalFreedom(void) {
 | 
				
			|||||||
void AISnake::CheckFoodDirection(void) {
 | 
					void AISnake::CheckFoodDirection(void) {
 | 
				
			||||||
    sf::Vector2f delta = g_pEngine->GetHeadLocation() - g_pEngine->GetFoodLocation();
 | 
					    sf::Vector2f delta = g_pEngine->GetHeadLocation() - g_pEngine->GetFoodLocation();
 | 
				
			||||||
    if (delta.x > 0)
 | 
					    if (delta.x > 0)
 | 
				
			||||||
        probabilityLeft *= 2;
 | 
					        probabilityLeft *= 1.5;
 | 
				
			||||||
    if (delta.x < 0)
 | 
					    if (delta.x < 0)
 | 
				
			||||||
        probabilityRight *= 2;
 | 
					        probabilityRight *= 1.5;
 | 
				
			||||||
    if (delta.y > 0)
 | 
					    if (delta.y > 0)
 | 
				
			||||||
        probabilityUp *= 2;
 | 
					        probabilityUp *= 1.5;
 | 
				
			||||||
    if (delta.y < 0)
 | 
					    if (delta.y < 0)
 | 
				
			||||||
        probabilityDown *= 2;
 | 
					        probabilityDown *= 1.5;
 | 
				
			||||||
    std::array<sf::Vector2f, 4> choices;
 | 
					 | 
				
			||||||
    choices.fill(g_pEngine->GetHeadLocation());
 | 
					 | 
				
			||||||
    choices[0].y += 1;
 | 
					 | 
				
			||||||
    choices[1].x += 1;
 | 
					 | 
				
			||||||
    choices[2].y -= 1;
 | 
					 | 
				
			||||||
    choices[3].x -= 1;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void AISnake::RemoveImpossibleChoice(void) {
 | 
					void AISnake::RemoveImpossibleChoice(void) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user