{
  "information": {
    "Title": "Knight Strategy game to maximise moves landing on stars only",
    "Author": [
      "Shaun Quek",
      "Loo Kang Wee",
      "Francisco Esquembre",
      "F\u00e9lix Jes\u00fas Garcia Clemente",
      "based on idea by Theresa Heng"
    ],
    "AuthorLogo": [
      "",
      "",
      "",
      ""
    ],
    "Password": "",
    "Keywords": "",
    "Abstract": "",
    "Copyright": "",
    "Level": "",
    "Language": "",
    "Logo": [
      "./knight_star_to_star/Screenshot 2021-05-05 at 3.53.49 PM (2).png"
    ],
    "RunAlways": "true",
    "ModelTab": "",
    "ModelTabTitle": "",
    "ModelName": "",
    "FixedNavigationBar": "false",
    "CSSFile": "",
    "DetectedFiles": [
      "./knight_star_to_star/Screenshot 2021-05-05 at 3.53.49 PM (2).png"
    ],
    "AuxiliaryFiles": [
      "./knight_star_to_star/"
    ],
    "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": "numOfRows",
              "Value": "6",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "numOfCols",
              "Value": "6",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "numOfSquares",
              "Value": "0",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "numOfStars",
              "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": "squareColor",
              "Value": "",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "squareHighlighted",
              "Value": "",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "squareFilled",
              "Value": "",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "squareLength",
              "Value": "1",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "idxToPos",
              "Value": "",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "posToIdx",
              "Value": "",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "symbolStr",
              "Value": "",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "symbolX",
              "Value": "",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "symbolY",
              "Value": "",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "textStr",
              "Value": "",
              "Type": "double",
              "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": "moveCounter",
              "Value": "1",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "topScore",
              "Value": "",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "interact",
              "Value": "",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "gameOver",
              "Value": "false",
              "Type": "boolean",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "font",
              "Value": "\"normal normal 2vw\"",
              "Type": "String",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "fontSymbol",
              "Value": "\"normal normal 5vw\"",
              "Type": "String",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "",
              "Value": "",
              "Type": "String",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            }
          ]
        },
        {
          "Name": "colours",
          "Active": "true",
          "Internal": "false",
          "Type": "VARIABLE_EDITOR",
          "PageComment": "",
          "Variables": [
            {
              "Name": "filledColor",
              "Value": "\"rgba(0,255,0,0.5)\"",
              "Type": "String",
              "Dimension": "",
              "Comment": "\"#bdbdbd\"",
              "Domain": "public"
            },
            {
              "Name": "unfilledColor",
              "Value": "\"rgba(0,0,255,0.5)\"",
              "Type": "String",
              "Dimension": "",
              "Comment": "\"#e0e0e0\"",
              "Domain": "public"
            },
            {
              "Name": "highlightColor",
              "Value": "\"#aed581\"",
              "Type": "String",
              "Dimension": "",
              "Comment": "\"#aed581\"",
              "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": "textXunicode",
              "Value": "-1",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            },
            {
              "Name": "textYunicode",
              "Value": "0",
              "Type": "double",
              "Dimension": "",
              "Comment": "null",
              "Domain": "public"
            }
          ]
        }
      ]
    },
    "initialization": {
      "pages": [
        {
          "Name": "Init Page",
          "Active": "true",
          "Internal": "false",
          "Type": "CODE_EDITOR",
          "Comment": "",
          "Code": "var board = [\n  \"*OO**O\",\n  \"O***OO\",\n  \"******\",\n  \"****O*\",\n  \"*O***O\",\n  \"O****O\"\n];\n\n// INITIALISATION\nif(topScore == undefined)\n  topScore = 0;\n\ntextStr = [], textX = [], textY = [];\nsymbolStr = [], symbolX = [], symbolY = [];\n\nsquareX = [], squareY = [], squareColor = [], squareHighlighted = [], squareFilled = [];\nidxToPos = [], posToIdx = [];\nnumOfSquares = 0;\nfor(var i = 0; i < numOfRows; i++) {\n  posToIdx.push([]);\n  for(var j = 0; j < numOfCols; j++) {\n    if(board[i][j] == \"*\"){\n      squareFilled.push(0);\n      squareHighlighted.push(1);\n      // star emoji\n      symbolStr.push(\"\u2b50\");\n      symbolX.push(squareLength * j);\n      symbolY.push(squareLength * i);\n      \n      numOfStars++;\n    }\n    else{\n      squareFilled.push(1);\n      squareHighlighted.push(0);\n    }\n    \n    squareX.push(squareLength * j);\n    squareY.push(squareLength * i);\n\n    squareColor.push(unfilledColor);\n\n    idxToPos.push([j, i]);\n    posToIdx[i].push(numOfSquares++);\n  }\n}\n\n_tools.showOkDialog(\"Click on any star to begin!\");\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": "function 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    if(curX < 0 || curX >= numOfCols || curY < 0 || curY >= numOfRows) { // out of bound and illegal\n      continue;\n    } \n    var curIdx = posToIdx[curY][curX];\n    if(!squareFilled[curIdx]){\n      possible = true;\n      squareHighlighted[curIdx] = 1;\n    }\n  }\n  return possible;\n}"
        },
        {
          "Name": "onClickSquare",
          "Active": "true",
          "Internal": "false",
          "Type": "LIBRARY_EDITOR",
          "Comment": "",
          "Code": "// on clicking of a square\nfunction onClickSquare(idx) {\n  if(gameOver)\n    return;\n\n  var x = idxToPos[idx][0], y = idxToPos[idx][1];\n  \n  if(!squareHighlighted[idx]) {\n    _tools.showOkDialog(\"You cannot move to this square! Click a legal move using the green squares.\");\n    for(var i = 0; i < numOfSquares; i++) {\n      if(squareHighlighted[i])\n        squareColor[i] = highlightColor;\n    }\n    return;\n  }\n  // set the current grid square to be filled\n  squareFilled[idx] = 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  squareColor[idx] = filledColor;\n  textStr.push(moveCounter++);\n  textX.push(x * squareLength);\n  textY.push(y * squareLength);\n  \n  \n  //lookang attempt to add unicode knight position\n  textXunicode=(x * squareLength);\n  textYunicode=(y * squareLength);\n  \n  // updating topScore\n  topScore = Math.max(moveCounter - 1, topScore);\n\n  // if no more moves\n  if(moveCounter == numOfStars + 1) {\n    _tools.showOkDialog(\"The whole board has been filled, good job!\");\n    gameOver = true;\n  } else if(!findPossibleMoves(x, y)) {\n    _tools.showOkDialog(\"There are no more possible moves! Score: \" + (moveCounter - 1));\n    gameOver = true;\n  }\n\n}"
        }
      ]
    },
    "elements": {
      "list": []
    }
  },
  "view": {
    "Tree": [
      {
        "Name": "topPanel",
        "Type": "Panel",
        "Expanded": "true",
        "Properties": [
          {
            "name": "CSS",
            "value": "{\n  \"grid-template-columns\": \"1fr 1fr 1fr\"\n}\n"
          },
          {
            "name": "Display",
            "value": "\"grid\""
          }
        ],
        "Children": [
          {
            "Name": "topScore",
            "Type": "Label",
            "Properties": [
              {
                "name": "Text",
                "value": "\"Top Score: \" + topScore"
              },
              {
                "name": "Font",
                "value": "font"
              }
            ]
          },
          {
            "Name": "score",
            "Type": "Label",
            "Properties": [
              {
                "name": "Text",
                "value": "\"Current Score: \" + (moveCounter -1)"
              },
              {
                "name": "Font",
                "value": "font"
              }
            ]
          },
          {
            "Name": "reset",
            "Type": "Button",
            "Properties": [
              {
                "name": "Text",
                "value": "\"\u21bbReset\""
              },
              {
                "name": "OnPress",
                "value": "_reset()"
              },
              {
                "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": "numOfRows * squareLength"
              },
              {
                "name": "YTickStep",
                "value": "numOfCols * squareLength"
              },
              {
                "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": "onClickSquare(interact);"
                  },
                  {
                    "name": "SizeY",
                    "value": "squareLength"
                  },
                  {
                    "name": "EnabledPosition",
                    "value": "\"ENABLED_NO_MOVE\""
                  },
                  {
                    "name": "ElementInteracted",
                    "value": "interact"
                  }
                ]
              },
              {
                "Name": "symbolSet",
                "Type": "TextSet2D",
                "Properties": [
                  {
                    "name": "X",
                    "value": "symbolX"
                  },
                  {
                    "name": "Y",
                    "value": "symbolY"
                  },
                  {
                    "name": "Text",
                    "value": "%symbolStr%"
                  },
                  {
                    "name": "Font",
                    "value": "fontSymbol"
                  }
                ]
              },
              {
                "Name": "unicodeknight",
                "Type": "Text2D",
                "Properties": [
                  {
                    "name": "FillColor",
                    "value": "\"Magenta\""
                  },
                  {
                    "name": "X",
                    "value": "textXunicode"
                  },
                  {
                    "name": "Y",
                    "value": "textYunicode"
                  },
                  {
                    "name": "Text",
                    "value": "\"\u265e\""
                  },
                  {
                    "name": "Font",
                    "value": "\"normal normal 7vw \""
                  }
                ]
              },
              {
                "Name": "textSet",
                "Type": "TextSet2D",
                "Properties": [
                  {
                    "name": "X",
                    "value": "textX"
                  },
                  {
                    "name": "Y",
                    "value": "textY"
                  },
                  {
                    "name": "Text",
                    "value": "%textStr%"
                  },
                  {
                    "name": "Font",
                    "value": "font"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "Name": "html",
        "Type": "Panel",
        "Properties": [
          {
            "name": "Html",
            "value": "<h2>Knight's Move</h2>\n<p>The knight (\u2658, \u265e) is a piece in the game of chess and is represented by a horse's head and neck.</p>\n<p>The knight's movement is unique: it may move two squares vertically and one square horizontally, or two squares horizontally and one square vertically (with both forming the shape of an L). This way, a knight can have a maximum of 8 moves. While moving, the knight can jump over pieces to reach its destination.</p>\n<h2>Single Player Game</h2>\n<p>Try to discover the best strategy/pattern to maximise the number of moves by landing on legal squares/stars.</p>\n<p>Given the current map of stars, try to move the maximum possible number of knight's move possible.</p>\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.2",
    "version": "https://www.um.es/fem/wikis/webejs/"
  }
}