Skip to content

Javascript starter bot - 2 bugs #8

Description

@jan-vodila

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;
    }
  1. 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);	
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions