eonarheim / AntAICompetition

Simple Ant Hill AI Competition Simulation Server
4 stars 1 forks source link

Hill Disappears #21

Closed randombits01 closed 9 years ago

randombits01 commented 9 years ago

Sometimes the game would not end when an enemy hill was attacked. Instead the hill would disappear, and the game would continue on. (Ants are still able to spawn at their normal location.)

eonarheim commented 9 years ago

@randombits01 Will investigate

randombits01 commented 9 years ago

Is there logic that might set the hill to "open space" on accident?

eonarheim commented 9 years ago

@randombits01 I think the reason that hills disappear is food spawns on them!

 if (rng.NextDouble() < _chanceToSpawnFood)
{
    var x1 = rng.Next(0, midWidth);
    var y1 = rng.Next(0, midHeight);
    var potentialCell = GetCell(x1, y1);
    if (potentialCell.Type != CellType.Wall) ////<-  AAAAAA!!!!!
    {
        GetCell(x1, y1).Type = CellType.Food;
    }
}

That would explain why the UI stops rendering and why the win condition could never fire.

// Check for win condition
var winningAnt = newAnts.FirstOrDefault(a => GetCell(a.X, a.Y).Type == CellType.Hill && Hills[a.Owner].X != a.X && Hills[a.Owner].Y != a.Y);
// update cells UI
game.Board.Cells.forEach(function(cell) {
    var $td = $("#board tr").eq(cell.Y).find("td").eq(cell.X);
    $td.prop("class", "");

    if (!cell.Ant) {
        switch (cell.Type) {
        case "Space":
            $td.addClass("space");
            break;
        case "Wall":
            $td.addClass("wall");
            break;
        case "Food":
            $td.addClass("food");
            break;
        case "Hill":
            $td.addClass("hill");
            break;
        }
    } else {
        $td.addClass("ant player-" + game.Players.indexOf(cell.Ant.Owner));
    }
});