• That looks great!

    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

About

Avatar for Gordon @Gordon started