• This looks great! It'd be good to see this in the app loader!

    Do you think you could come up with a small self-contained example bit of code that you could post up here that runs really slow like you mentioned? It might be we can find a way to make it faster.

    What do you mean by "Moves Left" - does it actually try and run through each move each time to see how many would be needed to finish?

    Just a thought but even without using compiled code, if you could split the code up such that it could run as a function that gets called multiple times, you could update the screen immediately, and then run the calculation in the background. If the user interacted with the Bangle to make another move you could just cancel, redraw with the new state and start again.

  • This looks great! It'd be good to see this in the app loader!

    Yes that's my aim, but i'm still working on it, i need to still add some options to make the input rects visible and make theming optional.

    Do you think you could come up with a small self-contained example bit of code that you could post up here that runs really slow like you mentioned? It might be we can find a way to make it faster.

    I'll have to check but it may not be easy to do this as i used classes and such that are intertwined with the checks

    What do you mean by "Moves Left" - does it actually try and run through each move each time to see how many would be needed to finish?

    Yes, after each "move" you have done, the game loops through all still available pegs using a double for loop (i have a two dimensional array to represent the playfield). And i have a Peg class which contains a canMoveToPostion function that will check if a certain Peg can move to a postion and return true or false. For each peg it then calls this functions with all possible move location per peg, these are 4 or 8 calls (moves) to that function depending on the difficulty (if diagonals are allowed). It has todo this for each peg on the board and then it will display value, but it also uses that value to determine if the game is over (moves left = 0, like no peg can move anywhere anymore)

    this is the current code:

    function movesLeft() {
      "compiled";
      let result = 0;
      pegsLeft = 0;
      let BoardPart;
      let Y, X;
      for (Y = 0; Y < NROFROWS; Y++) {
        for (X = 0; X < NROFCOLS; X++) {
          BoardPart = BoardParts.Items[Y][X];
          //print (BoardParts.Items[Y][X]);
          // if there is a boardpart on that X,Y Coordinate
          // check all direction if we can move to that if so increases the movesleft
          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);
            }
          }
        }
      }
      return result;
    }
    

    Just a thought but even without using compiled code, if you could split the code up such that it could run as a function that gets called multiple times, you could update the screen immediately, and then run the calculation in the background. If the user interacted with the Bangle to make another move you could just cancel, redraw with the new state and start again.

    thats not a bad idea, but i'm not sure how easily i can adapt to this, you see i do a single frame game loop and everything gets done during that single frame as soon as thats over the game is idling, i don't have a loop that keeps getting called. If nothing needs drawing it doesn't do anything at all but i could give it a try by recalling the game loop if the calculation had not finished but i'll need to check how i can actually do this. When you say run the calculation in the background do you refer to something like threads or so ? Is that some special functionality in javascript / bangle ?

About