theaigames / next

1 stars 0 forks source link

Javascript starter bot - 2 bugs #8

Open jan-vodila opened 7 years ago

jan-vodila commented 7 years ago

Hi,

I find two bugs in your starter bot for javascript language. They are both in the logic.js file.

  1. It is in function isInBounds. You are checking the coordinates as follows:

    if (0 >= coordinate.x || coordinate.x >= settings.field_width) {
        return false;
    }
    
    if (0 >= coordinate.y || coordinate.y >= settings.field_height) {
        return false;
    }

    So it means that all 0 coordinates for X & Y axes are returned as false. The corrected version should be:

    if (0 > coordinate.x || coordinate.x >= settings.field_width) {
        return false;
    }
    
    if (0 > coordinate.y || coordinate.y >= settings.field_height) {
        return false;
    }
  2. It is in function getCoordinateFor. You are checking if some cell of the field is equal to botId, but it has a problem when both players are staying on the same cell. Because then the cell is equal to '01' so your code returns index === -1

Your version:

function getCoordinateFor(settings, field, botId) {
    const index = field.findIndex(f => f === botId);
    return indexToCoordinate(settings, index);  
}

Should be corrected to something like:

function getCoordinateFor(settings, field, botId) {
    const index = field.findIndex(f => f.includes(botId));
    return indexToCoordinate(settings, index);  
}