-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
Hi,
I find two bugs in your starter bot for javascript language.
They are both in the logic.js
file.
- 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;
}
- It is in
function getCoordinateFor
. You are checking if some cell of the field is equal tobotId
, 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 returnsindex === -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);
}