{
  "information": {
    "Title": "ejss_model_knight_moves_no_hint Knight Moves Hot Seat 2 Player Game for Strategy Thinking, Reach the star to win!",
    "Author": [
      "Shaun Quek",
      "Loo Kang Wee",
      "based on ideas by Theresa Heng",
      "Francisco Esquembre",
      "F\u00e9lix Jes\u00fas Garcia Clemente,"
    ],
    "AuthorLogo": [
      "",
      "",
      "",
      "",
      ""
    ],
    "Password": "",
    "Keywords": "",
    "Abstract": "",
    "Copyright": "",
    "Level": "",
    "Language": "",
    "Logo": [
      "./knight_moves/Screenshot 2021-05-03 at 4.22.37 PM (2).png"
    ],
    "RunAlways": "true",
    "ModelTab": "",
    "ModelTabTitle": "",
    "ModelName": "",
    "FixedNavigationBar": "false",
    "CSSFile": "",
    "DetectedFiles": [
      "./knight_moves/Screenshot 2021-05-03 at 4.22.37 PM (2).png"
    ],
    "AuxiliaryFiles": [
      "./knight_moves/"
    ],
    "HTMLHead": "<script async=\"true\" src=\"https://www.googletagmanager.com/gtag/js?id=UA-3326007-19\"></script>\n<script>\n  window.dataLayer = window.dataLayer || [];\n  function gtag(){dataLayer.push(arguments);}\n  gtag('js', new Date());\n  gtag('config', 'UA-3326007-19');\n</script>\n<script data-ad-client=\"ca-pub-0121577198857509\" async=\"true\" src=\"https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js\"></script>",
    "SaveInXMLFormat": "false",
    "IncludeSource": "true",
    "IncludeLibrary": "true",
    "UglifyJS": "false",
    "PreviewFullModel": "false",
    "UseInterpreter": "true",
    "UseDeltaForODE": "false"
  },
  "description": {
    "pages": []
  },
  "model": {
    "variables": {
      "pages": [
        {
          "Name": "Var Table",
          "Active": "true",
          "Internal": "false",
          "Type": "VARIABLE_EDITOR",
          "PageComment": "",
          "Variables": [
            {
              "Name": "board",
              "Value": "",
              "Type": "String",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "numOfRows",
              "Value": "10",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "numOfCols",
              "Value": "11",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "numOfSquares",
              "Value": "0",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "squareX",
              "Value": "",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "squareY",
              "Value": "",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "squareLength",
              "Value": "1",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "squareColor",
              "Value": "",
              "Type": "String",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "squareHighlighted",
              "Value": "",
              "Type": "String",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "posToIdx",
              "Value": "",
              "Type": "String",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "idxToPos",
              "Value": "",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "interact",
              "Value": "",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "font",
              "Value": "\"normal normal 2vw\"",
              "Type": "String",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "gameOver",
              "Value": "false",
              "Type": "boolean",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "",
              "Value": "",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "startX",
              "Value": "",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "startY",
              "Value": "",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "",
              "Value": "",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            }
          ]
        },
        {
          "Name": "lookang",
          "Active": "true",
          "Internal": "false",
          "Type": "VARIABLE_EDITOR",
          "PageComment": "",
          "Variables": [
            {
              "Name": "",
              "Value": "",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "textXunicodek",
              "Value": "2",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "textYunicodek",
              "Value": "0",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "",
              "Value": "",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            }
          ]
        },
        {
          "Name": "text",
          "Active": "true",
          "Internal": "false",
          "Type": "VARIABLE_EDITOR",
          "PageComment": "",
          "Variables": [
            {
              "Name": "textStr",
              "Value": "",
              "Type": "String",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "textX",
              "Value": "",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "textY",
              "Value": "",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "textXunicode",
              "Value": "",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "textYunicode",
              "Value": "",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "",
              "Value": "",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "",
              "Value": "",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            }
          ]
        },
        {
          "Name": "colors",
          "Active": "true",
          "Internal": "false",
          "Type": "VARIABLE_EDITOR",
          "PageComment": "",
          "Variables": [
            {
              "Name": "unfilledColor",
              "Value": "\"lightgrey\"",
              "Type": "String",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "highlightColor",
              "Value": "\"lightgrey\"",
              "Type": "String",
              "Dimension": "",
              "Comment": "\"#aed581\"",
              "Domain": "public"
            },
            {
              "Name": "p1Color",
              "Value": "\"#42a5f5\"",
              "Type": "String",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "p2Color",
              "Value": "\"#ef5350\"",
              "Type": "String",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "moveCounter",
              "Value": "1",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "",
              "Value": "",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            }
          ]
        },
        {
          "Name": "turn",
          "Active": "true",
          "Internal": "false",
          "Type": "VARIABLE_EDITOR",
          "PageComment": "",
          "Variables": [
            {
              "Name": "turn",
              "Value": "0",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "turnColor",
              "Value": "p1Color",
              "Type": "String",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "turnText",
              "Value": "\"It is Player's 1 turn!\"",
              "Type": "String",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            }
          ]
        }
      ]
    },
    "initialization": {
      "pages": [
        {
          "Name": "Init Page",
          "Active": "true",
          "Internal": "false",
          "Type": "CODE_EDITOR",
          "Comment": "",
          "Code": "// INITIALISING BOARD (* means star, S means start, O means a grid square, _ means blank space)\n// bottom to top row\n\nboard =\n[\n  \"*OS_OO__*O_\",\n  \"OOO_OOO__O_\",\n  \"_OO_OOOO_O_\",\n  \"OOO_OOOOOO_\",\n  \"OOOOOOO____\",\n  \"OOOOOOO_O__\",\n  \"_OOOOOOOOOO\",\n  \"OOOOOOOOOOO\",\n  \"_OOOOO_O_O_\",\n  \"__O*_O_____\"\n];\n\nnumOfRows = 10;\nnumOfCols = 11;\n\n// posToIdx is a 2D array which takes the x and y positions of a grid square, and gives the corresponding idx of that square\n// idxToPos is a 1D array which takes the idx of a grid square, and gives the corresponding x and y positions of that square\n// idx ==index\n\nsquareX = [], squareY = [], squareColor = [], squareHighlighted = [], idxToPos = [], posToIdx = [];\ntextX = [], textY = [], textStr = [];\n\n//var startX, startY;\n// move to become variables\n// INITIALISING GRID SQUARES \n\nfor(var i = 0; i < numOfRows; i++){ // y\n  posToIdx.push([]); // adding a new array to exsiting array\n  for(var j = 0; j < numOfCols; j++){ // x\n    if(board[i][j] == \"_\"){\n      posToIdx[i].push(-1);\n      continue;\n    }\n    squareX.push(j * squareLength); // \n    squareY.push(i * squareLength);\n    squareHighlighted.push(0);\n    squareColor.push(unfilledColor);\n          \n                posToIdx[i].push(numOfSquares); // counter\n    idxToPos.push([j, i]);\n    \n    numOfSquares++; //counter\n    \n    if(board[i][j] == \"S\" || board[i][j] == \"*\"){\n      textStr.push(board[i][j]);\n      textX.push(j * squareLength);\n      textY.push(i * squareLength);\n    }\n    if(board[i][j] == \"S\"){ // for the code below\n      startX = j;\n      startY = i;\n    }\n  }\n}\n\nfindPossibleMoves(startX, startY); // for the code above\n//console.log(posToIdx);"
        },
        {
          "Name": "manuallylaystarunicode",
          "Active": "true",
          "Internal": "false",
          "Type": "CODE_EDITOR",
          "Comment": "",
          "Code": "textXunicode = [], textYunicode = []\n\nfor(var i = 0; i < numOfRows; i++){\n  for(var j = 0; j < numOfCols; j++){\n  if (board[i][j]==\"*\"){\n    //board[i][j] = \"a\"\n    textXunicode.push(j * squareLength);\n    textYunicode.push(i * squareLength);\n    //alert(\"*\")\n    }\n    \n    \n    \n    \n}\n}"
        }
      ]
    },
    "evolution": {
      "information": {
        "FPS": "20",
        "SPD": "1",
        "RealTimeVariable": "",
        "Autoplay": "true"
      },
      "pages": []
    },
    "fixed_relations": {
      "pages": []
    },
    "custom": {
      "pages": [
        {
          "Name": "findPossibleMoves",
          "Active": "true",
          "Internal": "false",
          "Type": "LIBRARY_EDITOR",
          "Comment": "",
          "Code": "// given a particular grid coordinate, determine which squares are available from that square. It returns false if there is no possible moves, and true if there is.\nfunction findPossibleMoves(x, y) {\n  // the 8 directions a knight can move on a chess board\n  const dx = [-1, 1, 2, 2, -1, 1, -2, -2];\n  const dy = [2, 2, 1, -1, -2, -2, 1, -1];\n\n  var possible = false;\n  for(var i = 0; i < 8; i++) {\n    var curX = x + dx[i], curY = y + dy[i];\n    //console.log(curX, curY);\n    if(curX < 0 || curX >= numOfCols || curY < 0 || curY >= numOfRows || posToIdx[curY][curX] == -1){ // out of bound and illegal\n      continue;\n    }\n    possible = true;\n    var curIdx = posToIdx[curY][curX];\n    squareHighlighted[curIdx] = 1;\n  }\n  return possible;\n}"
        },
        {
          "Name": "onClickSquare",
          "Active": "true",
          "Internal": "false",
          "Type": "LIBRARY_EDITOR",
          "Comment": "",
          "Code": "// on clicking of a square\nfunction onClickSquare(x, y) {\n  if(gameOver)\n    return;\n    \n  var idx = posToIdx[y][x];\n  // idex == -1 blank space or landed on before\n  if(idx == -1 || !squareHighlighted[idx]){\n    _tools.showOkDialog(\"You cannot move to this square! Click a legal move.\");\n   \n   for(var i = 0; i < numOfSquares; i++){\n      if(squareHighlighted[i]) {\n        squareColor[i] = highlightColor;\n        }\n    }\n    \n    return;\n  }\n  // set the current grid square to no longer be available\n  posToIdx[y][x] = -1; // [y][x] is correct set to landed before -1\n  \n  for(var i = 0; i < numOfSquares; i++) { // refresh color\n    if(squareColor[i] == highlightColor) {\n      squareColor[i] = unfilledColor;\n    }\n    if(squareHighlighted[i])\n      squareHighlighted[i] = 0;\n  }\n\n  // player 1\n  if(turn == 0) {\n    squareColor[idx] = p1Color;\n  }\n  // player 2\n  else {\n    squareColor[idx] = p2Color;\n  }\n  textStr.push(moveCounter++);\n  textX.push(x * squareLength);\n  textY.push(y * squareLength);\n  \n  //lookang attempt to add unicode knight position\n  textXunicodek=(x * squareLength);\n  textYunicodek=(y * squareLength);\n  \n  \n  // if landed on a star\n  if(board[y][x] == '*') {\n    _tools.showOkDialog(\"Player \" + (turn + 1) + \" wins!\");\n    turnText = \"Player \" + (turn + 1) + \" wins!\";\n    gameOver = true;\n  } \n  // if no more moves\n  else if(!findPossibleMoves(x, y)) {\n    _tools.showOkDialog(\"Player \" + ((turn + 1) % 2 + 1) + \" has no moves, so Player \" + (turn + 1) + \" wins!\");\n    turnText = \"Player \" + (turn + 1) + \" wins!\";\n    gameOver = true;\n  } \n  else {\n    turn = (turn + 1) % 2;\n    turnText = \"It is Player \" + (turn + 1) + \"'s turn!\";\n    turnColor = turn == 0 ? p1Color : p2Color;\n  }\n}"
        }
      ]
    },
    "elements": {
      "list": []
    }
  },
  "view": {
    "Tree": [
      {
        "Name": "topPanel",
        "Type": "Panel",
        "Expanded": "true",
        "Properties": [
          {
            "name": "Display",
            "value": "\"inline-flex\""
          }
        ],
        "Children": [
          {
            "Name": "turn",
            "Type": "Label",
            "Properties": [
              {
                "name": "Background",
                "value": "turnColor"
              },
              {
                "name": "Text",
                "value": "turnText"
              },
              {
                "name": "Width",
                "value": "\"70vw\""
              },
              {
                "name": "Font",
                "value": "font"
              }
            ]
          },
          {
            "Name": "reset",
            "Type": "Button",
            "Properties": [
              {
                "name": "Text",
                "value": "\"\u21bbReset\""
              },
              {
                "name": "OnClick",
                "value": "_reset();"
              },
              {
                "name": "Width",
                "value": "\"20vw\""
              },
              {
                "name": "Font",
                "value": "font"
              }
            ]
          }
        ]
      },
      {
        "Name": "mainPanel",
        "Type": "Panel",
        "Expanded": "true",
        "Properties": [],
        "Children": [
          {
            "Name": "plottingPanel",
            "Type": "PlottingPanel",
            "Expanded": "true",
            "Properties": [
              {
                "name": "Gutters",
                "value": "[0,0,0,0]"
              },
              {
                "name": "YScalePrecision",
                "value": "0"
              },
              {
                "name": "XFixedTick",
                "value": "-0.5"
              },
              {
                "name": "Enabled",
                "value": "true"
              },
              {
                "name": "SquareAspect",
                "value": "true"
              },
              {
                "name": "YFixedTick",
                "value": "-0.5"
              },
              {
                "name": "YAutoTicks",
                "value": "false"
              },
              {
                "name": "XTickStep",
                "value": "11"
              },
              {
                "name": "YTickStep",
                "value": "12"
              },
              {
                "name": "AutoScaleY",
                "value": "true"
              },
              {
                "name": "AutoScaleX",
                "value": "true"
              },
              {
                "name": "CursorTypeForMove",
                "value": "\"pointer\""
              },
              {
                "name": "XAutoTicks",
                "value": "false"
              },
              {
                "name": "Height",
                "value": "\"90vh\""
              },
              {
                "name": "XScalePrecision",
                "value": "0"
              },
              {
                "name": "Width",
                "value": "\"100%\""
              }
            ],
            "Children": [
              {
                "Name": "shapeSet",
                "Type": "ShapeSet2D",
                "Properties": [
                  {
                    "name": "NumberOfElements",
                    "value": "numOfSquares"
                  },
                  {
                    "name": "FillColor",
                    "value": "squareColor"
                  },
                  {
                    "name": "Sensitivity",
                    "value": "0"
                  },
                  {
                    "name": "SizeX",
                    "value": "squareLength"
                  },
                  {
                    "name": "ShapeType",
                    "value": "\"RECTANGLE\""
                  },
                  {
                    "name": "X",
                    "value": "squareX"
                  },
                  {
                    "name": "Y",
                    "value": "squareY"
                  },
                  {
                    "name": "OnPress",
                    "value": "var x = idxToPos[interact][0], y = idxToPos[interact][1];\n//console.log(interact, x, y);\nonClickSquare(x, y);\n"
                  },
                  {
                    "name": "SizeY",
                    "value": "squareLength"
                  },
                  {
                    "name": "EnabledPosition",
                    "value": "\"ENABLED_NO_MOVE\""
                  },
                  {
                    "name": "ElementInteracted",
                    "value": "interact"
                  }
                ]
              },
              {
                "Name": "textStarthome",
                "Type": "Text2D",
                "Properties": [
                  {
                    "name": "X",
                    "value": "startX"
                  },
                  {
                    "name": "Y",
                    "value": "startY"
                  },
                  {
                    "name": "Text",
                    "value": "\"\ud83c\udfe0\""
                  },
                  {
                    "name": "Font",
                    "value": "\"normal normal 4vw \""
                  }
                ]
              },
              {
                "Name": "textSetuniocdeStar_End",
                "Type": "TextSet2D",
                "Properties": [
                  {
                    "name": "X",
                    "value": "textXunicode"
                  },
                  {
                    "name": "Y",
                    "value": "textYunicode"
                  },
                  {
                    "name": "Text",
                    "value": "\"\u2b50\""
                  },
                  {
                    "name": "FontWeight",
                    "value": "\"bold\""
                  },
                  {
                    "name": "Font",
                    "value": "\"normal normal 4vw \""
                  }
                ]
              },
              {
                "Name": "unicodeknight",
                "Type": "Text2D",
                "Properties": [
                  {
                    "name": "FillColor",
                    "value": "\"Green\""
                  },
                  {
                    "name": "X",
                    "value": "textXunicodek"
                  },
                  {
                    "name": "Y",
                    "value": "textYunicodek"
                  },
                  {
                    "name": "Text",
                    "value": "\"\u265e\""
                  },
                  {
                    "name": "Font",
                    "value": "\"normal normal 5vw \""
                  }
                ]
              },
              {
                "Name": "textSet",
                "Type": "TextSet2D",
                "Properties": [
                  {
                    "name": "X",
                    "value": "textX"
                  },
                  {
                    "name": "Y",
                    "value": "textY"
                  },
                  {
                    "name": "Text",
                    "value": "%textStr%"
                  },
                  {
                    "name": "FontWeight",
                    "value": "\"bold\""
                  },
                  {
                    "name": "Font",
                    "value": "font"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "Name": "html",
        "Type": "Panel",
        "Properties": [
          {
            "name": "Html",
            "value": "<h2>Rules</h2>\n<iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/ZwzDE3tXxeY?si=-oIO7ks0N_CLbyLk\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen></iframe>\n<p>Each player makes a knight's move to an empty square from the place the opponent landed on the preceding turn.</p>\n<p>Allowed knight's moves are shown in the light green color squares.</p>\n\n<h2>To win: reach a star or leave your opponent with nowhere to go.</h2>\n<p> Player lands on one of the three golden stars and wins the game.</p>\n<p> The player whose turn cannot make any knight's move to an emplty square and thus loses.</p>\n\n  <h2>For more resources</h2>\n  <ul>\n    <li>\n      <a href=\"https://sg.iwant2study.org/ospsg/index.php/interactive-resources/mathematics/1054-knight-intro\" target=\"_blank\" rel=\"noopener noreferrer\">\n        Knight \u2014 Intro\n      </a>\n    </li>\n    <li>\n      <a href=\"https://sg.iwant2study.org/ospsg/index.php/interactive-resources/mathematics/1101-knight-moves-no-hint\" target=\"_blank\" rel=\"noopener noreferrer\">\n        Knight Moves (No Hint)\n      </a>\n    </li>\n    <li>\n      <a href=\"https://sg.iwant2study.org/ospsg/index.php/interactive-resources/mathematics/1057-knight-moves\" target=\"_blank\" rel=\"noopener noreferrer\">\n        Knight Moves\n      </a>\n    </li>\n    <li>\n      <a href=\"https://sg.iwant2study.org/ospsg/index.php/interactive-resources/mathematics/1055-knight-star-to-star\" target=\"_blank\" rel=\"noopener noreferrer\">\n        Knight: Star to Star\n      </a>\n    </li>\n    <li>\n      <a href=\"https://sg.iwant2study.org/ospsg/index.php/interactive-resources/mathematics/1102-knight-star-to-star-no-hint\" target=\"_blank\" rel=\"noopener noreferrer\">\n        Knight: Star to Star (No Hint)\n      </a>\n    </li>\n    <li>\n      <a href=\"https://sg.iwant2study.org/ospsg/index.php/events/1106-20210830-digital-e2k-applications-knights-move\" target=\"_blank\" rel=\"noopener noreferrer\">\n        Digital E2K Applications: Knight\u2019s Move (Event)\n      </a>\n    </li>\n  </ul>"
          }
        ]
      }
    ],
    "RootProperties": []
  },
  "metadata": {
    "APP": "WebEJS",
    "CreatedWith": "WebEJS : The web version of Easy JavaScript Simulations",
    "MoreInfo": "WebEJS 1.1",
    "version": "https://www.um.es/fem/wikis/webejs/"
  }
}