Looking at the first bit of code you have there I see you do:
BoardPart = BoardParts.Items[Y][X];
But then you do:
if (BoardParts.Items[Y][X]) {
if (BoardParts.Items[Y][X].AnimPhase < 2) {
pegsLeft++;
result += CPeg_CanMoveTo(BoardParts.Items[Y][X], X + 2, Y, false);
result += CPeg_CanMoveTo(BoardParts.Items[Y][X], X - 2, Y, false);
result += CPeg_CanMoveTo(BoardParts.Items[Y][X], X, Y - 2, false);
result += CPeg_CanMoveTo(BoardParts.Items[Y][X], X, Y + 2, false);
result += CPeg_CanMoveTo(BoardParts.Items[Y][X], X + 2, Y - 2, false);
result += CPeg_CanMoveTo(BoardParts.Items[Y][X], X + 2, Y + 2, false);
result += CPeg_CanMoveTo(BoardParts.Items[Y][X], X - 2, Y + 2, false);
result += CPeg_CanMoveTo(BoardParts.Items[Y][X], X - 2, Y - 2, false);
}
}
So you reference BoardParts.Items[Y][X] a lot - each time Espruino is having to do a lot of lookups to find BoardParts, Items, then Y and X. What if you just replaced all occurrences or BoardParts.Items[Y][X] with BoardPart (which should be the same?).
That might make a reasonable difference to the speed as well
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
That looks great!
Looking at the first bit of code you have there I see you do:
But then you do:
So you reference
BoardParts.Items[Y][X]
a lot - each time Espruino is having to do a lot of lookups to find BoardParts, Items, then Y and X. What if you just replaced all occurrences orBoardParts.Items[Y][X]
withBoardPart
(which should be the same?).That might make a reasonable difference to the speed as well