From bc244c3b8cb14bc5d00ffcd3db380528e64914a0 Mon Sep 17 00:00:00 2001 From: Florian Aucomte Date: Wed, 28 Feb 2024 11:38:20 +0000 Subject: [PATCH] fix: Make algorithm score setting consistent with presence of model solutions (#1585) * fix: Set Python scores to 10 * Lockfile * Make algo scores consistent with model solutions * Remove prints * Feedback again * Small fixes * Iterator --- Pipfile.lock | 339 +++++++++--------- game/admin.py | 34 +- game/end_to_end_tests/test_play_through.py | 26 +- .../0090_add_missing_model_solutions.py | 122 +++++++ ...disable_algo_score_if_no_model_solution.py | 40 +++ game/static/game/js/game.js | 20 +- game/static/game/js/pathFinder.js | 134 +++---- 7 files changed, 452 insertions(+), 263 deletions(-) create mode 100644 game/migrations/0090_add_missing_model_solutions.py create mode 100644 game/migrations/0091_disable_algo_score_if_no_model_solution.py diff --git a/Pipfile.lock b/Pipfile.lock index 41a32afc4..3ca55f39c 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -40,18 +40,18 @@ }, "certifi": { "hashes": [ - "sha256:9b469f3a900bf28dc19b8cfbf8019bf47f7fdd1a65a1d4ffb98fc14166beb4d1", - "sha256:e036ab49d5b79556f99cfc2d9320b34cfbe5be05c5871b51de9329f0603b0474" + "sha256:0569859f95fc761b18b45ef421b1290a0f65f147e92a1e5eb3e635f9a5e4e66f", + "sha256:dc383c07b76109f368f6106eee2b593b04a011ea4d55f652c6ca24a754d1cdd1" ], "markers": "python_version >= '3.6'", - "version": "==2023.11.17" + "version": "==2024.2.2" }, "cfl-common": { "hashes": [ - "sha256:e11d1431329e91a1aeaec15c6df654a9fb8bf9c44a929ef394278515f9ff5936", - "sha256:f4ef1456a2a9507b0e93751596c05e8333a2feb3267d3b8cd8f88fceb88cc982" + "sha256:267a006a1cc1d32ea1d9bd10af301060ed7bef89b7112f5b9911f5d87f54b3a3", + "sha256:49adb00f19c93d68f6562f7e5a26d9a417d94264610646f6eab03c7dcb0bb6a9" ], - "version": "==6.39.7" + "version": "==6.41.1" }, "charset-normalizer": { "hashes": [ @@ -175,11 +175,11 @@ }, "django": { "hashes": [ - "sha256:82968f3640e29ef4a773af2c28448f5f7a08d001c6ac05b32d02aeee6509508b", - "sha256:d48608d5f62f2c1e260986835db089fa3b79d6f58510881d316b8d88345ae6e1" + "sha256:5dd5b787c3ba39637610fe700f54bf158e33560ea0dba600c19921e7ff926ec5", + "sha256:aaee9fb0fb4ebd4311520887ad2e33313d368846607f82a9a0ed461cd4c35b18" ], "markers": "python_version >= '3.6'", - "version": "==3.2.23" + "version": "==3.2.24" }, "django-countries": { "hashes": [ @@ -197,19 +197,20 @@ }, "django-formtools": { "hashes": [ - "sha256:21f8d5dac737f1e636fa8a0a10969c1c32f525a6dfa27c29592827ba70d9643a", - "sha256:49ea8a64ddef4728a558bf5f8f622c0f4053b979edcf193bf00dd80432ab2f12" + "sha256:47cb34552c6efca088863d693284d04fc36eaaf350eb21e1a1d935e0df523c93", + "sha256:bce9b64eda52cc1eef6961cc649cf75aacd1a707c2fff08d6c3efcbc8e7e761a" ], - "markers": "python_version >= '3.7'", - "version": "==2.4.1" + "markers": "python_version >= '3.8'", + "version": "==2.5.1" }, "django-import-export": { "hashes": [ - "sha256:2c1b16e1cf2ea5f62a165d8867e7c6dcff25673ab7201fd18aaf67c9ee90367e", - "sha256:78973202e93897326ab0411d64eaf89b72779fcb21ee9e5f64f3fb96571a5978" + "sha256:39a4216c26a2dba6429b64c68b3fe282a6279bb71afb4015c13df0696bdbb4cd", + "sha256:dffedd53bed33cfcceb3b2f13d4fd93a21826f9a2ae37b9926a1e1f4be24bcb9" ], "index": "pypi", - "version": "==3.3.3" + "markers": "python_version >= '3.8'", + "version": "==3.3.7" }, "django-js-reverse": { "hashes": [ @@ -274,11 +275,11 @@ }, "idna": { "hashes": [ - "sha256:814f528e8dead7d329833b91c5faa87d60bf71824cd12a7530b5526063d02cb4", - "sha256:90b77e79eaa3eba6de819a0c442c0b4ceefc341a7a2ab77d7562bf49f425c5c2" + "sha256:9ecdbbd083b06798ae1e86adcbfe8ab1479cf864e4ee30fe4e46a003d12491ca", + "sha256:c05567e9c24a6b9faaa835c4821bad0590fbb9d5779e7caa6e1cc4978e7eb24f" ], "markers": "python_version >= '3.5'", - "version": "==3.4" + "version": "==3.6" }, "ipython": { "hashes": [ @@ -286,6 +287,7 @@ "sha256:b0340d46a933d27c657b211a329d0be23793c36595acf9e6ef4164bc01a1804c" ], "index": "pypi", + "markers": "python_version >= '3.8'", "version": "==8.12.3" }, "jedi": { @@ -300,6 +302,7 @@ "hashes": [ "sha256:081e256ab3c5f3f09c7b8dea3bf3bf5e64a97c6995fd9eea880639b3f93a9f9a", "sha256:3ab5ad18e47db560f4f0c09e3d28cf3bb1a44711257488ac2adad69f4f7f8425", + "sha256:5fb2297a4754a6c8e25cfe5c015a3b51a2b6b9021b333f989bb8ce9d60eb5828", "sha256:65455a2728b696b62100eb5932604aa13a29f4ac9a305d95773c14aaa7200aaf", "sha256:89c5ce497fcf3aba1dd1b19aae93b99f68257e5f2026b731b00a872f13324c7f", "sha256:f1efc1b612299c88aec9e39d6ca0c266d360daa5b19d9430bdeaffffa86993f9" @@ -418,11 +421,11 @@ }, "pexpect": { "hashes": [ - "sha256:0b48a55dcb3c05f3329815901ea4fc1537514d6ba867a152b581d69ae3710937", - "sha256:fc65a43959d153d0114afe13997d439c22823a27cefceb5ff35c2178c6784c0c" + "sha256:7236d1e080e4936be2dc3e326cec0af72acf9212a7e1d060210e70a47e253523", + "sha256:ee7d41123f3c9911050ea2c2dac107568dc43b2d3b0c7557a33212c398ead30f" ], "markers": "sys_platform != 'win32'", - "version": "==4.8.0" + "version": "==4.9.0" }, "pgeocode": { "hashes": [ @@ -441,11 +444,11 @@ }, "prompt-toolkit": { "hashes": [ - "sha256:941367d97fc815548822aa26c2a269fdc4eb21e9ec05fc5d447cf09bad5d75f0", - "sha256:f36fe301fafb7470e86aaf90f036eef600a3210be4decf461a5b1ca8403d3cb2" + "sha256:3527b7af26106cbc65a040bcc84839a3566ec1b051bb0bfe953631e704b0ff7d", + "sha256:a11a29cb3bf0a28a387fe5122cdb649816a957cd9261dcedf8c9f1fef33eacf6" ], "markers": "python_full_version >= '3.7.0'", - "version": "==3.0.41" + "version": "==3.0.43" }, "ptyprocess": { "hashes": [ @@ -463,11 +466,11 @@ }, "pygments": { "hashes": [ - "sha256:1b37f1b1e1bff2af52ecaf28cc601e2ef7077000b227a0675da25aef85784bc4", - "sha256:e45a0e74bf9c530f564ca81b8952343be986a29f6afe7f5ad95c5f06b7bdf5e8" + "sha256:b27c2826c47d0f3219f29554824c30c5e8945175d888647acd804ddd04af846c", + "sha256:da46cec9fd2de5be3a8a784f434e4c4ab670b4ff54d605c4c2717e9d49c4c367" ], "markers": "python_version >= '3.7'", - "version": "==2.17.1" + "version": "==2.17.2" }, "pyhamcrest": { "hashes": [ @@ -502,10 +505,10 @@ }, "pytz": { "hashes": [ - "sha256:7b4fddbeb94a1eba4b557da24f19fdf9db575192544270a9101d8509f9f43d7b", - "sha256:ce42d816b81b68506614c11e8937d3aa9e41007ceb50bfdcb0749b921bf646c7" + "sha256:2a29735ea9c18baf14b448846bde5a48030ed267578472d8955cd0e7443a9812", + "sha256:328171f4e3623139da4983451950b28e95ac706e13f3f2630a879749e7a8b319" ], - "version": "==2023.3.post1" + "version": "==2024.1" }, "pyyaml": { "hashes": [ @@ -538,6 +541,7 @@ "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4", "sha256:9046c58c4395dff28dd494285c82ba00b546adfc7ef001486fbf0324bc174fba", "sha256:9eb6caa9a297fc2c2fb8862bc5370d0303ddba53ba97e71f08023b6cd73d16a8", + "sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef", "sha256:a0cd17c15d3bb3fa06978b4e8958dcdc6e0174ccea823003a106c7d4d7899ac5", "sha256:afd7e57eddb1a54f0f1a974bc4391af8bcce0b444685d936840f125cf046d5bd", "sha256:b1275ad35a5d18c62a7220633c913e1b42d44b46ee12554e5fd39c70a243d6a3", @@ -622,42 +626,42 @@ }, "traitlets": { "hashes": [ - "sha256:9b232b9430c8f57288c1024b34a8f0251ddcc47268927367a0dd3eeaca40deb5", - "sha256:baf991e61542da48fe8aef8b779a9ea0aa38d8a54166ee250d5af5ecf4486619" + "sha256:2e5a030e6eff91737c643231bfcf04a65b0132078dad75e4936700b213652e74", + "sha256:8585105b371a04b8316a43d5ce29c098575c2e477850b62b848b964f1444527e" ], "markers": "python_version >= '3.8'", - "version": "==5.13.0" + "version": "==5.14.1" }, "typing-extensions": { "hashes": [ - "sha256:8f92fc8806f9a6b641eaa5318da32b44d401efaac0f6678c9bc448ba3605faa0", - "sha256:df8e4339e9cb77357558cbdbceca33c303714cf861d1eef15e1070055ae8b7ef" + "sha256:23478f88c37f27d76ac8aee6c905017a143b0b1b886c3c9f66bc2fd94f9f5783", + "sha256:af72aea155e91adfc61c3ae9e0e342dbc0cba726d6cba4b6c72c1f34e47291cd" ], - "markers": "python_version >= '3.8'", - "version": "==4.8.0" + "markers": "python_version < '3.10'", + "version": "==4.9.0" }, "tzdata": { "hashes": [ - "sha256:11ef1e08e54acb0d4f95bdb1be05da659673de4acbd21bf9c69e94cc5e907a3a", - "sha256:7e65763eef3120314099b6939b5546db7adce1e7d6f2e179e3df563c70511eda" + "sha256:2674120f8d891909751c38abcdfd386ac0a5a1127954fbc332af6b5ceae07efd", + "sha256:9068bc196136463f5245e51efda838afa15aaeca9903f49050dfa2679db4d252" ], "markers": "python_version >= '2'", - "version": "==2023.3" + "version": "==2024.1" }, "urllib3": { "hashes": [ - "sha256:55901e917a5896a349ff771be919f8bd99aff50b79fe58fec595eb37bbc56bb3", - "sha256:df7aa8afb0148fa78488e7899b2c59b5f4ffcfa82e6c54ccb9dd37c1d7b52d54" + "sha256:450b20ec296a467077128bff42b73080516e71b56ff59a60a02bef2232c4fa9d", + "sha256:d0570876c61ab9e520d776c38acbbb5b05a776d3f9ff98a5c8fd5162a444cf19" ], "markers": "python_version >= '3.8'", - "version": "==2.1.0" + "version": "==2.2.1" }, "wcwidth": { "hashes": [ - "sha256:25eb3ecbec328cdb945f56f2a7cfe784bdf7a73a8197398c7a7c65e7fe93e9ae", - "sha256:c4b153acf29f1f0d7fb1b00d097cce82b73de7a2016321c8d7ca71bd76dd848b" + "sha256:3da69048e4540d84af32131829ff948f1e022c1c6bdb8d6102117aac784f6859", + "sha256:72ea0c06399eb286d978fdedb6923a9eb47e1c486ce63e9b4e64fc18303972b5" ], - "version": "==0.2.11" + "version": "==0.2.13" }, "xlrd": { "hashes": [ @@ -677,10 +681,10 @@ "develop": { "aimmo": { "hashes": [ - "sha256:1c4e9ea558c083b8f59b365d1f1dfd6d94e8aee863ea96dcaeec488fd72541f8", - "sha256:4c8d20c738e4a4443ca98e03621b96c5c79309f4f817faf3aaf731380c621d8a" + "sha256:104c52376867cd86e319b5b706012a8235c55bdb262ab17feebc39961c024cbd", + "sha256:749368fc0ff7358208459ec0fa129c2d44e972ac1b99452fa8b93ea8a233f1c5" ], - "version": "==2.10.12" + "version": "==2.11.1" }, "asgiref": { "hashes": [ @@ -692,11 +696,11 @@ }, "attrs": { "hashes": [ - "sha256:1f28b4522cdc2fb4256ac1a020c78acf9cba2c6b461ccd2c126f3aa8e8335d04", - "sha256:6279836d581513a26f1bf235f9acd333bc9115683f14f7e8fae46c98fc50e015" + "sha256:935dc3b529c262f6cf76e50877d35a4bd3c1de194fd41f47a2b7ae8f19971f30", + "sha256:99b87a485a5820b23b879f04c2305b44b951b502fd64be915879d77a7e8fc6f1" ], "markers": "python_version >= '3.7'", - "version": "==23.1.0" + "version": "==23.2.0" }, "cachetools": { "hashes": [ @@ -708,18 +712,18 @@ }, "certifi": { "hashes": [ - "sha256:9b469f3a900bf28dc19b8cfbf8019bf47f7fdd1a65a1d4ffb98fc14166beb4d1", - "sha256:e036ab49d5b79556f99cfc2d9320b34cfbe5be05c5871b51de9329f0603b0474" + "sha256:0569859f95fc761b18b45ef421b1290a0f65f147e92a1e5eb3e635f9a5e4e66f", + "sha256:dc383c07b76109f368f6106eee2b593b04a011ea4d55f652c6ca24a754d1cdd1" ], "markers": "python_version >= '3.6'", - "version": "==2023.11.17" + "version": "==2024.2.2" }, "cfl-common": { "hashes": [ - "sha256:e11d1431329e91a1aeaec15c6df654a9fb8bf9c44a929ef394278515f9ff5936", - "sha256:f4ef1456a2a9507b0e93751596c05e8333a2feb3267d3b8cd8f88fceb88cc982" + "sha256:267a006a1cc1d32ea1d9bd10af301060ed7bef89b7112f5b9911f5d87f54b3a3", + "sha256:49adb00f19c93d68f6562f7e5a26d9a417d94264610646f6eab03c7dcb0bb6a9" ], - "version": "==6.39.7" + "version": "==6.41.1" }, "charset-normalizer": { "hashes": [ @@ -819,11 +823,11 @@ }, "codeforlife-portal": { "hashes": [ - "sha256:5f7b96a80ef71353011a72e0e98a6a01e36e0efd1441d096faa9a545917e38b1", - "sha256:df7b8c297d694c7b414b4d65616f7f402032db621f43f6e5a5b217209bfd17c6" + "sha256:642c9269aafbc0cd9807dc0291a7f2b1f90503d9874d4a1295f189f85ea47fcf", + "sha256:fc8cf94f0eec3c099284599056b5c5ec684682f407faa4531b3aa4147d872588" ], "index": "pypi", - "version": "==6.39.7" + "version": "==6.41.1" }, "defusedxml": { "hashes": [ @@ -843,11 +847,11 @@ }, "django": { "hashes": [ - "sha256:82968f3640e29ef4a773af2c28448f5f7a08d001c6ac05b32d02aeee6509508b", - "sha256:d48608d5f62f2c1e260986835db089fa3b79d6f58510881d316b8d88345ae6e1" + "sha256:5dd5b787c3ba39637610fe700f54bf158e33560ea0dba600c19921e7ff926ec5", + "sha256:aaee9fb0fb4ebd4311520887ad2e33313d368846607f82a9a0ed461cd4c35b18" ], "markers": "python_version >= '3.6'", - "version": "==3.2.23" + "version": "==3.2.24" }, "django-classy-tags": { "hashes": [ @@ -872,19 +876,20 @@ }, "django-formtools": { "hashes": [ - "sha256:21f8d5dac737f1e636fa8a0a10969c1c32f525a6dfa27c29592827ba70d9643a", - "sha256:49ea8a64ddef4728a558bf5f8f622c0f4053b979edcf193bf00dd80432ab2f12" + "sha256:47cb34552c6efca088863d693284d04fc36eaaf350eb21e1a1d935e0df523c93", + "sha256:bce9b64eda52cc1eef6961cc649cf75aacd1a707c2fff08d6c3efcbc8e7e761a" ], - "markers": "python_version >= '3.7'", - "version": "==2.4.1" + "markers": "python_version >= '3.8'", + "version": "==2.5.1" }, "django-import-export": { "hashes": [ - "sha256:2c1b16e1cf2ea5f62a165d8867e7c6dcff25673ab7201fd18aaf67c9ee90367e", - "sha256:78973202e93897326ab0411d64eaf89b72779fcb21ee9e5f64f3fb96571a5978" + "sha256:39a4216c26a2dba6429b64c68b3fe282a6279bb71afb4015c13df0696bdbb4cd", + "sha256:dffedd53bed33cfcceb3b2f13d4fd93a21826f9a2ae37b9926a1e1f4be24bcb9" ], "index": "pypi", - "version": "==3.3.3" + "markers": "python_version >= '3.8'", + "version": "==3.3.7" }, "django-js-reverse": { "hashes": [ @@ -957,6 +962,7 @@ "sha256:9e8b9b4364fef70dde10a5f85c5a75d447ca2189ec648325610fab1268daec97" ], "index": "pypi", + "markers": "python_version >= '3.6' and python_version < '4.0'", "version": "==1.2.0" }, "django-treebeard": { @@ -1021,74 +1027,75 @@ }, "google-auth": { "hashes": [ - "sha256:79905d6b1652187def79d491d6e23d0cbb3a21d3c7ba0dbaa9c8a01906b13ff3", - "sha256:d4bbc92fe4b8bfd2f3e8d88e5ba7085935da208ee38a134fc280e7ce682a05f2" + "sha256:25141e2d7a14bfcba945f5e9827f98092716e99482562f15306e5b026e21aa72", + "sha256:34fc3046c257cedcf1622fc4b31fc2be7923d9b4d44973d481125ecc50d83885" ], "markers": "python_version >= '3.7'", - "version": "==2.23.4" + "version": "==2.28.1" }, "greenlet": { "hashes": [ - "sha256:0a02d259510b3630f330c86557331a3b0e0c79dac3d166e449a39363beaae174", - "sha256:0b6f9f8ca7093fd4433472fd99b5650f8a26dcd8ba410e14094c1e44cd3ceddd", - "sha256:100f78a29707ca1525ea47388cec8a049405147719f47ebf3895e7509c6446aa", - "sha256:1757936efea16e3f03db20efd0cd50a1c86b06734f9f7338a90c4ba85ec2ad5a", - "sha256:19075157a10055759066854a973b3d1325d964d498a805bb68a1f9af4aaef8ec", - "sha256:19bbdf1cce0346ef7341705d71e2ecf6f41a35c311137f29b8a2dc2341374565", - "sha256:20107edf7c2c3644c67c12205dc60b1bb11d26b2610b276f97d666110d1b511d", - "sha256:22f79120a24aeeae2b4471c711dcf4f8c736a2bb2fabad2a67ac9a55ea72523c", - "sha256:2847e5d7beedb8d614186962c3d774d40d3374d580d2cbdab7f184580a39d234", - "sha256:28e89e232c7593d33cac35425b58950789962011cc274aa43ef8865f2e11f46d", - "sha256:329c5a2e5a0ee942f2992c5e3ff40be03e75f745f48847f118a3cfece7a28546", - "sha256:337322096d92808f76ad26061a8f5fccb22b0809bea39212cd6c406f6a7060d2", - "sha256:3fcc780ae8edbb1d050d920ab44790201f027d59fdbd21362340a85c79066a74", - "sha256:41bdeeb552d814bcd7fb52172b304898a35818107cc8778b5101423c9017b3de", - "sha256:4eddd98afc726f8aee1948858aed9e6feeb1758889dfd869072d4465973f6bfd", - "sha256:52e93b28db27ae7d208748f45d2db8a7b6a380e0d703f099c949d0f0d80b70e9", - "sha256:55d62807f1c5a1682075c62436702aaba941daa316e9161e4b6ccebbbf38bda3", - "sha256:5805e71e5b570d490938d55552f5a9e10f477c19400c38bf1d5190d760691846", - "sha256:599daf06ea59bfedbec564b1692b0166a0045f32b6f0933b0dd4df59a854caf2", - "sha256:60d5772e8195f4e9ebf74046a9121bbb90090f6550f81d8956a05387ba139353", - "sha256:696d8e7d82398e810f2b3622b24e87906763b6ebfd90e361e88eb85b0e554dc8", - "sha256:6e6061bf1e9565c29002e3c601cf68569c450be7fc3f7336671af7ddb4657166", - "sha256:80ac992f25d10aaebe1ee15df45ca0d7571d0f70b645c08ec68733fb7a020206", - "sha256:816bd9488a94cba78d93e1abb58000e8266fa9cc2aa9ccdd6eb0696acb24005b", - "sha256:85d2b77e7c9382f004b41d9c72c85537fac834fb141b0296942d52bf03fe4a3d", - "sha256:87c8ceb0cf8a5a51b8008b643844b7f4a8264a2c13fcbcd8a8316161725383fe", - "sha256:89ee2e967bd7ff85d84a2de09df10e021c9b38c7d91dead95b406ed6350c6997", - "sha256:8bef097455dea90ffe855286926ae02d8faa335ed8e4067326257cb571fc1445", - "sha256:8d11ebbd679e927593978aa44c10fc2092bc454b7d13fdc958d3e9d508aba7d0", - "sha256:91e6c7db42638dc45cf2e13c73be16bf83179f7859b07cfc139518941320be96", - "sha256:97e7ac860d64e2dcba5c5944cfc8fa9ea185cd84061c623536154d5a89237884", - "sha256:990066bff27c4fcf3b69382b86f4c99b3652bab2a7e685d968cd4d0cfc6f67c6", - "sha256:9fbc5b8f3dfe24784cee8ce0be3da2d8a79e46a276593db6868382d9c50d97b1", - "sha256:ac4a39d1abae48184d420aa8e5e63efd1b75c8444dd95daa3e03f6c6310e9619", - "sha256:b2c02d2ad98116e914d4f3155ffc905fd0c025d901ead3f6ed07385e19122c94", - "sha256:b2d3337dcfaa99698aa2377c81c9ca72fcd89c07e7eb62ece3f23a3fe89b2ce4", - "sha256:b489c36d1327868d207002391f662a1d163bdc8daf10ab2e5f6e41b9b96de3b1", - "sha256:b641161c302efbb860ae6b081f406839a8b7d5573f20a455539823802c655f63", - "sha256:b8ba29306c5de7717b5761b9ea74f9c72b9e2b834e24aa984da99cbfc70157fd", - "sha256:b9934adbd0f6e476f0ecff3c94626529f344f57b38c9a541f87098710b18af0a", - "sha256:ce85c43ae54845272f6f9cd8320d034d7a946e9773c693b27d620edec825e376", - "sha256:cf868e08690cb89360eebc73ba4be7fb461cfbc6168dd88e2fbbe6f31812cd57", - "sha256:d2905ce1df400360463c772b55d8e2518d0e488a87cdea13dd2c71dcb2a1fa16", - "sha256:d57e20ba591727da0c230ab2c3f200ac9d6d333860d85348816e1dca4cc4792e", - "sha256:d6a8c9d4f8692917a3dc7eb25a6fb337bff86909febe2f793ec1928cd97bedfc", - "sha256:d923ff276f1c1f9680d32832f8d6c040fe9306cbfb5d161b0911e9634be9ef0a", - "sha256:daa7197b43c707462f06d2c693ffdbb5991cbb8b80b5b984007de431493a319c", - "sha256:dbd4c177afb8a8d9ba348d925b0b67246147af806f0b104af4d24f144d461cd5", - "sha256:dc4d815b794fd8868c4d67602692c21bf5293a75e4b607bb92a11e821e2b859a", - "sha256:e9d21aaa84557d64209af04ff48e0ad5e28c5cca67ce43444e939579d085da72", - "sha256:ea6b8aa9e08eea388c5f7a276fabb1d4b6b9d6e4ceb12cc477c3d352001768a9", - "sha256:eabe7090db68c981fca689299c2d116400b553f4b713266b130cfc9e2aa9c5a9", - "sha256:f2f6d303f3dee132b322a14cd8765287b8f86cdc10d2cb6a6fae234ea488888e", - "sha256:f33f3258aae89da191c6ebaa3bc517c6c4cbc9b9f689e5d8452f7aedbb913fa8", - "sha256:f7bfb769f7efa0eefcd039dd19d843a4fbfbac52f1878b1da2ed5793ec9b1a65", - "sha256:f89e21afe925fcfa655965ca8ea10f24773a1791400989ff32f467badfe4a064", - "sha256:fa24255ae3c0ab67e613556375a4341af04a084bd58764731972bcbc8baeba36" + "sha256:01bc7ea167cf943b4c802068e178bbf70ae2e8c080467070d01bfa02f337ee67", + "sha256:0448abc479fab28b00cb472d278828b3ccca164531daab4e970a0458786055d6", + "sha256:086152f8fbc5955df88382e8a75984e2bb1c892ad2e3c80a2508954e52295257", + "sha256:098d86f528c855ead3479afe84b49242e174ed262456c342d70fc7f972bc13c4", + "sha256:149e94a2dd82d19838fe4b2259f1b6b9957d5ba1b25640d2380bea9c5df37676", + "sha256:1551a8195c0d4a68fac7a4325efac0d541b48def35feb49d803674ac32582f61", + "sha256:15d79dd26056573940fcb8c7413d84118086f2ec1a8acdfa854631084393efcc", + "sha256:1996cb9306c8595335bb157d133daf5cf9f693ef413e7673cb07e3e5871379ca", + "sha256:1a7191e42732df52cb5f39d3527217e7ab73cae2cb3694d241e18f53d84ea9a7", + "sha256:1ea188d4f49089fc6fb283845ab18a2518d279c7cd9da1065d7a84e991748728", + "sha256:1f672519db1796ca0d8753f9e78ec02355e862d0998193038c7073045899f305", + "sha256:2516a9957eed41dd8f1ec0c604f1cdc86758b587d964668b5b196a9db5bfcde6", + "sha256:2797aa5aedac23af156bbb5a6aa2cd3427ada2972c828244eb7d1b9255846379", + "sha256:2dd6e660effd852586b6a8478a1d244b8dc90ab5b1321751d2ea15deb49ed414", + "sha256:3ddc0f794e6ad661e321caa8d2f0a55ce01213c74722587256fb6566049a8b04", + "sha256:3ed7fb269f15dc662787f4119ec300ad0702fa1b19d2135a37c2c4de6fadfd4a", + "sha256:419b386f84949bf0e7c73e6032e3457b82a787c1ab4a0e43732898a761cc9dbf", + "sha256:43374442353259554ce33599da8b692d5aa96f8976d567d4badf263371fbe491", + "sha256:52f59dd9c96ad2fc0d5724107444f76eb20aaccb675bf825df6435acb7703559", + "sha256:57e8974f23e47dac22b83436bdcf23080ade568ce77df33159e019d161ce1d1e", + "sha256:5b51e85cb5ceda94e79d019ed36b35386e8c37d22f07d6a751cb659b180d5274", + "sha256:649dde7de1a5eceb258f9cb00bdf50e978c9db1b996964cd80703614c86495eb", + "sha256:64d7675ad83578e3fc149b617a444fab8efdafc9385471f868eb5ff83e446b8b", + "sha256:68834da854554926fbedd38c76e60c4a2e3198c6fbed520b106a8986445caaf9", + "sha256:6b66c9c1e7ccabad3a7d037b2bcb740122a7b17a53734b7d72a344ce39882a1b", + "sha256:70fb482fdf2c707765ab5f0b6655e9cfcf3780d8d87355a063547b41177599be", + "sha256:7170375bcc99f1a2fbd9c306f5be8764eaf3ac6b5cb968862cad4c7057756506", + "sha256:73a411ef564e0e097dbe7e866bb2dda0f027e072b04da387282b02c308807405", + "sha256:77457465d89b8263bca14759d7c1684df840b6811b2499838cc5b040a8b5b113", + "sha256:7f362975f2d179f9e26928c5b517524e89dd48530a0202570d55ad6ca5d8a56f", + "sha256:81bb9c6d52e8321f09c3d165b2a78c680506d9af285bfccbad9fb7ad5a5da3e5", + "sha256:881b7db1ebff4ba09aaaeae6aa491daeb226c8150fc20e836ad00041bcb11230", + "sha256:894393ce10ceac937e56ec00bb71c4c2f8209ad516e96033e4b3b1de270e200d", + "sha256:99bf650dc5d69546e076f413a87481ee1d2d09aaaaaca058c9251b6d8c14783f", + "sha256:9da2bd29ed9e4f15955dd1595ad7bc9320308a3b766ef7f837e23ad4b4aac31a", + "sha256:afaff6cf5200befd5cec055b07d1c0a5a06c040fe5ad148abcd11ba6ab9b114e", + "sha256:b1b5667cced97081bf57b8fa1d6bfca67814b0afd38208d52538316e9422fc61", + "sha256:b37eef18ea55f2ffd8f00ff8fe7c8d3818abd3e25fb73fae2ca3b672e333a7a6", + "sha256:b542be2440edc2d48547b5923c408cbe0fc94afb9f18741faa6ae970dbcb9b6d", + "sha256:b7dcbe92cc99f08c8dd11f930de4d99ef756c3591a5377d1d9cd7dd5e896da71", + "sha256:b7f009caad047246ed379e1c4dbcb8b020f0a390667ea74d2387be2998f58a22", + "sha256:bba5387a6975598857d86de9eac14210a49d554a77eb8261cc68b7d082f78ce2", + "sha256:c5e1536de2aad7bf62e27baf79225d0d64360d4168cf2e6becb91baf1ed074f3", + "sha256:c5ee858cfe08f34712f548c3c363e807e7186f03ad7a5039ebadb29e8c6be067", + "sha256:c9db1c18f0eaad2f804728c67d6c610778456e3e1cc4ab4bbd5eeb8e6053c6fc", + "sha256:d353cadd6083fdb056bb46ed07e4340b0869c305c8ca54ef9da3421acbdf6881", + "sha256:d46677c85c5ba00a9cb6f7a00b2bfa6f812192d2c9f7d9c4f6a55b60216712f3", + "sha256:d4d1ac74f5c0c0524e4a24335350edad7e5f03b9532da7ea4d3c54d527784f2e", + "sha256:d73a9fe764d77f87f8ec26a0c85144d6a951a6c438dfe50487df5595c6373eac", + "sha256:da70d4d51c8b306bb7a031d5cff6cc25ad253affe89b70352af5f1cb68e74b53", + "sha256:daf3cb43b7cf2ba96d614252ce1684c1bccee6b2183a01328c98d36fcd7d5cb0", + "sha256:dca1e2f3ca00b84a396bc1bce13dd21f680f035314d2379c4160c98153b2059b", + "sha256:dd4f49ae60e10adbc94b45c0b5e6a179acc1736cf7a90160b404076ee283cf83", + "sha256:e1f145462f1fa6e4a4ae3c0f782e580ce44d57c8f2c7aae1b6fa88c0b2efdb41", + "sha256:e3391d1e16e2a5a1507d83e4a8b100f4ee626e8eca43cf2cadb543de69827c4c", + "sha256:fcd2469d6a2cf298f198f0487e0a5b1a47a42ca0fa4dfd1b6862c999f018ebbf", + "sha256:fd096eb7ffef17c456cfa587523c5f92321ae02427ff955bebe9e3c63bc9f0da", + "sha256:fe754d231288e1e64323cfad462fcee8f0288654c10bdf4f603a39ed923bef33" ], "markers": "python_version >= '3.7'", - "version": "==3.0.1" + "version": "==3.0.3" }, "h11": { "hashes": [ @@ -1108,11 +1115,11 @@ }, "idna": { "hashes": [ - "sha256:814f528e8dead7d329833b91c5faa87d60bf71824cd12a7530b5526063d02cb4", - "sha256:90b77e79eaa3eba6de819a0c442c0b4ceefc341a7a2ab77d7562bf49f425c5c2" + "sha256:9ecdbbd083b06798ae1e86adcbfe8ab1479cf864e4ee30fe4e46a003d12491ca", + "sha256:c05567e9c24a6b9faaa835c4821bad0590fbb9d5779e7caa6e1cc4978e7eb24f" ], "markers": "python_version >= '3.5'", - "version": "==3.4" + "version": "==3.6" }, "importlib-metadata": { "hashes": [ @@ -1120,6 +1127,7 @@ "sha256:dd0173e8f150d6815e098fd354f6414b0f079af4644ddfe90c71e2fc6174346d" ], "index": "pypi", + "markers": "python_version >= '3.7'", "version": "==4.13.0" }, "iniconfig": { @@ -1142,6 +1150,7 @@ "hashes": [ "sha256:081e256ab3c5f3f09c7b8dea3bf3bf5e64a97c6995fd9eea880639b3f93a9f9a", "sha256:3ab5ad18e47db560f4f0c09e3d28cf3bb1a44711257488ac2adad69f4f7f8425", + "sha256:5fb2297a4754a6c8e25cfe5c015a3b51a2b6b9021b333f989bb8ce9d60eb5828", "sha256:65455a2728b696b62100eb5932604aa13a29f4ac9a305d95773c14aaa7200aaf", "sha256:89c5ce497fcf3aba1dd1b19aae93b99f68257e5f2026b731b00a872f13324c7f", "sha256:f1efc1b612299c88aec9e39d6ca0c266d360daa5b19d9430bdeaffffa86993f9" @@ -1352,17 +1361,16 @@ "sha256:f379abd2f1e3dddb2b61bc67977a6b5a0a3f7485538bcc6f39ec76163891ee48", "sha256:fe4c15f6c9285dc54ce6553a3ce908ed37c8f3825b5a51a15c91442bb955b868" ], - "index": "pypi", "markers": "python_version >= '3.8'", "version": "==10.2.0" }, "pluggy": { "hashes": [ - "sha256:cf61ae8f126ac6f7c451172cf30e3e43d3ca77615509771b3a984a0730651e12", - "sha256:d89c696a773f8bd377d18e5ecda92b7a3793cbe66c87060a6fb58c7b6e1061f7" + "sha256:7db9f7b503d67d1c5b95f59773ebb58a8c1c288129a88665838012cfb07b8981", + "sha256:8c85c2876142a764e5b7548e7d9a0e0ddb46f5185161049a79b7e974454223be" ], "markers": "python_version >= '3.8'", - "version": "==1.3.0" + "version": "==1.4.0" }, "pyasn1": { "hashes": [ @@ -1413,11 +1421,12 @@ }, "pytest": { "hashes": [ - "sha256:0d009c083ea859a71b76adf7c1d502e4bc170b80a8ef002da5806527b9591fac", - "sha256:d989d136982de4e3b29dabcc838ad581c64e8ed52c11fbe86ddebd9da0818cd5" + "sha256:2cf0005922c6ace4a3e2ec8b4080eb0d9753fdc93107415332f50ce9e7994280", + "sha256:b090cdf5ed60bf4c45261be03239c2c1c22df034fbffe691abe93cd80cea01d8" ], "index": "pypi", - "version": "==7.4.3" + "markers": "python_version >= '3.7'", + "version": "==7.4.4" }, "pytest-django": { "hashes": [ @@ -1425,6 +1434,7 @@ "sha256:d9076f759bb7c36939dbdd5ae6633c18edfc2902d1a69fdbefd2426b970ce6c2" ], "index": "pypi", + "markers": "python_version >= '3.5'", "version": "==4.5.2" }, "pytest-order": { @@ -1433,6 +1443,7 @@ "sha256:9d65c3b6dc6d6ee984d6ae2c6c4aa4f1331e5b915116219075c888c8bcbb93b8" ], "index": "pypi", + "markers": "python_version >= '3.6'", "version": "==1.2.0" }, "pytest-xdist": { @@ -1441,6 +1452,7 @@ "sha256:d075629c7e00b611df89f490a5063944bee7a4362a5ff11c7cc7824a03dfce24" ], "index": "pypi", + "markers": "python_version >= '3.7'", "version": "==3.5.0" }, "python-dateutil": { @@ -1453,10 +1465,10 @@ }, "pytz": { "hashes": [ - "sha256:7b4fddbeb94a1eba4b557da24f19fdf9db575192544270a9101d8509f9f43d7b", - "sha256:ce42d816b81b68506614c11e8937d3aa9e41007ceb50bfdcb0749b921bf646c7" + "sha256:2a29735ea9c18baf14b448846bde5a48030ed267578472d8955cd0e7443a9812", + "sha256:328171f4e3623139da4983451950b28e95ac706e13f3f2630a879749e7a8b319" ], - "version": "==2023.3.post1" + "version": "==2024.1" }, "pyyaml": { "hashes": [ @@ -1489,6 +1501,7 @@ "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4", "sha256:9046c58c4395dff28dd494285c82ba00b546adfc7ef001486fbf0324bc174fba", "sha256:9eb6caa9a297fc2c2fb8862bc5370d0303ddba53ba97e71f08023b6cd73d16a8", + "sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef", "sha256:a0cd17c15d3bb3fa06978b4e8958dcdc6e0174ccea823003a106c7d4d7899ac5", "sha256:afd7e57eddb1a54f0f1a974bc4391af8bcce0b444685d936840f125cf046d5bd", "sha256:b1275ad35a5d18c62a7220633c913e1b42d44b46ee12554e5fd39c70a243d6a3", @@ -1606,6 +1619,7 @@ "sha256:4c19e6aac202719373108d53a5a8e9336ba8d2b25822ca32ae6ff37acbabbdbe" ], "index": "pypi", + "markers": "python_version >= '3.7'", "version": "==4.9.0" }, "setuptools": { @@ -1613,7 +1627,6 @@ "sha256:d0b9a8433464d5800cbe05094acf5c6d52a91bfac9b52bcfc4d41382be5d5d31", "sha256:e197a19aa8ec9722928f2206f8de752def0e4c9fc6953527360d1c36d94ddb2f" ], - "index": "pypi", "markers": "python_version >= '3.7'", "version": "==65.5.1" }, @@ -1673,11 +1686,11 @@ }, "trio": { "hashes": [ - "sha256:16f89f7dcc8f7b9dcdec1fcd863e0c039af6d0f9a22f8dfd56f75d75ec73fd48", - "sha256:bb4abb3f4af23f96679e7c8cdabb8b234520f2498550d2cf63ebfd95f2ce27fe" + "sha256:c3bd3a4e3e3025cd9a2241eae75637c43fe0b9e88b4c97b9161a55b9e54cd72c", + "sha256:ffa09a74a6bf81b84f8613909fb0beaee84757450183a7a2e0b47b455c0cac5d" ], "markers": "python_version >= '3.8'", - "version": "==0.23.1" + "version": "==0.24.0" }, "trio-websocket": { "hashes": [ @@ -1689,35 +1702,35 @@ }, "typing-extensions": { "hashes": [ - "sha256:8f92fc8806f9a6b641eaa5318da32b44d401efaac0f6678c9bc448ba3605faa0", - "sha256:df8e4339e9cb77357558cbdbceca33c303714cf861d1eef15e1070055ae8b7ef" + "sha256:23478f88c37f27d76ac8aee6c905017a143b0b1b886c3c9f66bc2fd94f9f5783", + "sha256:af72aea155e91adfc61c3ae9e0e342dbc0cba726d6cba4b6c72c1f34e47291cd" ], - "markers": "python_version >= '3.8'", - "version": "==4.8.0" + "markers": "python_version < '3.10'", + "version": "==4.9.0" }, "tzdata": { "hashes": [ - "sha256:11ef1e08e54acb0d4f95bdb1be05da659673de4acbd21bf9c69e94cc5e907a3a", - "sha256:7e65763eef3120314099b6939b5546db7adce1e7d6f2e179e3df563c70511eda" + "sha256:2674120f8d891909751c38abcdfd386ac0a5a1127954fbc332af6b5ceae07efd", + "sha256:9068bc196136463f5245e51efda838afa15aaeca9903f49050dfa2679db4d252" ], "markers": "python_version >= '2'", - "version": "==2023.3" + "version": "==2024.1" }, "urllib3": { "hashes": [ - "sha256:55901e917a5896a349ff771be919f8bd99aff50b79fe58fec595eb37bbc56bb3", - "sha256:df7aa8afb0148fa78488e7899b2c59b5f4ffcfa82e6c54ccb9dd37c1d7b52d54" + "sha256:450b20ec296a467077128bff42b73080516e71b56ff59a60a02bef2232c4fa9d", + "sha256:d0570876c61ab9e520d776c38acbbb5b05a776d3f9ff98a5c8fd5162a444cf19" ], "markers": "python_version >= '3.8'", - "version": "==2.1.0" + "version": "==2.2.1" }, "websocket-client": { "hashes": [ - "sha256:084072e0a7f5f347ef2ac3d8698a5e0b4ffbfcab607628cadabc650fc9a83a24", - "sha256:b3324019b3c28572086c4a319f91d1dcd44e6e11cd340232978c684a7650d0df" + "sha256:10e511ea3a8c744631d3bd77e61eb17ed09304c413ad42cf6ddfa4c7787e8fe6", + "sha256:f4c3d22fec12a2461427a29957ff07d35098ee2d976d3ba244e688b8b4057588" ], "markers": "python_version >= '3.8'", - "version": "==1.6.4" + "version": "==1.7.0" }, "wsproto": { "hashes": [ diff --git a/game/admin.py b/game/admin.py index 0d46a5253..480487605 100644 --- a/game/admin.py +++ b/game/admin.py @@ -1,26 +1,54 @@ from django.contrib import admin -from game.models import Level, Block, Episode, Workspace, LevelDecor +from game.models import Level, Block, Episode, Workspace, LevelDecor, Attempt class LevelAdmin(admin.ModelAdmin): - search_fields = ["name", "id", "owner__user__username", "owner__user__first_name"] + search_fields = [ + "name", + "id", + "owner__user__username", + "owner__user__first_name", + ] raw_id_fields = ["next_level", "locked_for_class"] readonly_fields = ["owner"] list_display = ["name", "id", "episode", "owner"] +class EpisodeAdmin(admin.ModelAdmin): + list_display = ["id", "name"] + + class WorkspaceAdmin(admin.ModelAdmin): raw_id_fields = ["owner"] +class AttemptAdmin(admin.ModelAdmin): + search_fields = [ + "level", + "student", + "start_time", + "finish_time", + "is_best_attempt", + ] + raw_id_fields = ["student"] + list_display = [ + "level", + "student", + "start_time", + "finish_time", + "is_best_attempt", + ] + + class LevelDecorAdmin(admin.ModelAdmin): search_fields = ["level__name"] list_display = ["id", "level", "x", "y", "decorName"] admin.site.register(Level, LevelAdmin) +admin.site.register(Episode, EpisodeAdmin) admin.site.register(Workspace, WorkspaceAdmin) -admin.site.register(Episode) admin.site.register(Block) +admin.site.register(Attempt, AttemptAdmin) admin.site.register(LevelDecor, LevelDecorAdmin) diff --git a/game/end_to_end_tests/test_play_through.py b/game/end_to_end_tests/test_play_through.py index 326dbecbb..d9448b627 100644 --- a/game/end_to_end_tests/test_play_through.py +++ b/game/end_to_end_tests/test_play_through.py @@ -278,43 +278,43 @@ def test_level_079(self): self._complete_level(79) def test_episode_10(self): - self._complete_episode(10, 80, check_algorithm_score=False) + self._complete_episode(10, 80) def test_level_080(self): - self._complete_level(80, check_algorithm_score=False) + self._complete_level(80) def test_level_081(self): - self._complete_level(81, check_algorithm_score=False) + self._complete_level(81) def test_level_082(self): - self._complete_level(82, check_algorithm_score=False) + self._complete_level(82) def test_level_083(self): - self._complete_level(83, check_algorithm_score=False) + self._complete_level(83) def test_level_084(self): - self._complete_level(84, check_algorithm_score=False) + self._complete_level(84) def test_level_085(self): - self._complete_level(85, check_algorithm_score=False) + self._complete_level(85) def test_level_086(self): - self._complete_level(86, check_algorithm_score=False) + self._complete_level(86) def test_level_087(self): - self._complete_level(87, check_algorithm_score=False) + self._complete_level(87) def test_level_088(self): - self._complete_level(88, check_algorithm_score=False) + self._complete_level(88) def test_level_089(self): - self._complete_level(89, check_algorithm_score=False) + self._complete_level(89) def test_level_090(self): - self._complete_level(90, check_algorithm_score=False) + self._complete_level(90) def test_level_091(self): - self._complete_level(91, check_algorithm_score=False) + self._complete_level(91) def test_episode_11(self): self._complete_episode(11, 92, check_algorithm_score=False) diff --git a/game/migrations/0090_add_missing_model_solutions.py b/game/migrations/0090_add_missing_model_solutions.py new file mode 100644 index 000000000..37b7de1ff --- /dev/null +++ b/game/migrations/0090_add_missing_model_solutions.py @@ -0,0 +1,122 @@ +import re + +from django.apps.registry import Apps +from django.db import migrations + + +def add_missing_model_solutions(apps: Apps, *args): + Level = apps.get_model("game", "Level") + + model_solutions = { + "80": "[5]", + "81": "[10]", + "82": "[11]", + "83": "[5]", + "84": "[5]", + "85": "[3]", + "86": "[8]", + "87": "[8]", + "88": "[11]", + "89": "[11]", + "90": "[15]", + "91": "[15]", + } + + for level_name, model_solution in model_solutions.items(): + count = Level.objects.filter(name=level_name).update( + model_solution=model_solution, disable_algorithm_score=False + ) + assert count == 1 + + Attempt = apps.get_model("game", "Attempt") + + attempts = Attempt.objects.filter( + level__name__in=[ + "80", + "81", + "82", + "83", + "84", + "85", + "86", + "87", + "88", + "89", + "90", + "91", + ], + score=10, + ).prefetch_related("level") + + for attempt in attempts.iterator(chunk_size=500): + workspace = attempt.workspace + + # Get number of blocks from solution - 1 to discount Start block + number_of_blocks = len(re.findall(" 0; -} - - ocargo.PathFinder.prototype.getScore = function() { - var routeCoins = {}; - var instrCoins = {}; - var performance= ""; + let routeCoins = {}; + let instrCoins = {}; + let performance= ""; - var pathLengthScore = 0; - if(!this.pathScoreDisabled){ + let pathLengthScore = 0; + if (!this.pathScoreDisabled) { pathLengthScore = Math.max(0, this.getTravelledPathScore()); routeCoins = this.getNumCoins(pathLengthScore, this.maxScoreForPathLength); } - var totalScore = pathLengthScore; + let totalScore = pathLengthScore; - if (this.isBlocklyLevelNotPython()) { + if (!this.algorithmScoreDisabled) { var initInstrScore = this.getScoreForNumberOfInstructions(); var instrScore = Math.max(0, initInstrScore); @@ -67,7 +61,6 @@ ocargo.PathFinder.prototype.getScore = function() { instrCoins = this.getNumCoins(instrScore, this.maxScoreForNumberOfInstructions); } - if (pathLengthScore < this.maxScoreForPathLength) { performance = "pathLonger"; } @@ -77,11 +70,11 @@ ocargo.PathFinder.prototype.getScore = function() { else if (initInstrScore < this.maxScoreForNumberOfInstructions) { performance = "algorithmLonger"; } - else if (totalScore === this.maxScore) { + else if (totalScore === this.maxScore) { performance = "scorePerfect"; } - var endLevelMsg = function(performance) { + const endLevelMsg = function(performance) { switch (performance){ case 'pathLonger': return gettext('Try finding a shorter route to the destination.'); @@ -116,18 +109,17 @@ ocargo.PathFinder.prototype.getNumCoins = function(score, maxScore) { }; ocargo.PathFinder.prototype.getTravelledPathScore = function() { - var travelled = this.van.getDistanceTravelled(); + const travelled = this.van.getDistanceTravelled(); const START_AND_END_BLOCKS = 2; return this.maxScoreForPathLength - (travelled + START_AND_END_BLOCKS - this.optimalPath.length); }; ocargo.PathFinder.prototype.getScoreForNumberOfInstructions = function() { - - var blocksUsed = ocargo.utils.isIOSMode() ? ocargo.game.mobileBlocks : ocargo.blocklyControl.activeBlocksCount(); - var algorithmScore = 0; - var difference = this.maxScoreForNumberOfInstructions; - for (var i = 0; i < this.modelSolution.length; i++) { - var currDifference = blocksUsed - this.modelSolution[i]; + const blocksUsed = ocargo.utils.isIOSMode() ? ocargo.game.mobileBlocks : ocargo.blocklyControl.activeBlocksCount(); + let algorithmScore = 0; + let difference = this.maxScoreForNumberOfInstructions; + for (let i = 0; i < this.modelSolution.length; i++) { + let currDifference = blocksUsed - this.modelSolution[i]; if (Math.abs(currDifference) < difference) { difference = Math.abs(currDifference); algorithmScore = this.maxScoreForNumberOfInstructions - currDifference; @@ -137,13 +129,11 @@ ocargo.PathFinder.prototype.getScoreForNumberOfInstructions = function() { }; ocargo.PathFinder.prototype.getLength = function(stack) { - - var total = 0; - var i; + let total = 0; if (!stack) { return total; } - for (i = 0; i < stack.length; i++) { + for (let i = 0; i < stack.length; i++) { if (stack[i].command === "While") { total += this.getLength(stack[i].block); } @@ -156,16 +146,14 @@ ocargo.PathFinder.prototype.getLength = function(stack) { return total; }; - - function getOptimalPath(nodes, destinations) { // Brute force Travelling Salesman implementation, using A* to determine the connection lengths // If the map size increases or lots of destinations are required, it may need to be rethought - var hash = {}; + let hash = {}; function getPathBetweenNodes(node1, node2) { - var key = '(' + node1.coordinate.x + ',' + node1.coordinate.y + '),(' + node2.coordinate.x + + const key = '(' + node1.coordinate.x + ',' + node1.coordinate.y + '),(' + node2.coordinate.x + ',' + node2.coordinate.y + ')'; - var solution; + let solution; if (key in hash) { solution = hash[key]; } @@ -177,13 +165,13 @@ function getOptimalPath(nodes, destinations) { } function getPermutationPath(start, permutation) { - var fragPath = [getPathBetweenNodes(start, permutation[0], nodes)]; - for (var i = 1; i < permutation.length; i++) { + let fragPath = [getPathBetweenNodes(start, permutation[0], nodes)]; + for (let i = 1; i < permutation.length; i++) { fragPath.push(getPathBetweenNodes(permutation[i-1], permutation[i], nodes)); } - var fullPath = [start]; - for (var i = 0; i < fragPath.length; i++) { + let fullPath = [start]; + for (let i = 0; i < fragPath.length; i++) { if (!fragPath[i]) { return null; } @@ -194,12 +182,12 @@ function getOptimalPath(nodes, destinations) { return fullPath; } - var permutations = []; + let permutations = []; function permute(array, data) { - var current; - var currentPermutation = data || []; + let current; + let currentPermutation = data || []; - for (var i = 0; i < array.length; i++) { + for (let i = 0; i < array.length; i++) { // Take node out current = array.splice(i, 1)[0]; // Then the current permutation is complete so add it @@ -213,26 +201,25 @@ function getOptimalPath(nodes, destinations) { } } - var start = nodes[0]; - var bestScore = Number.POSITIVE_INFINITY; - var bestPermutationPath = null; - var destinationNodes = []; + let start = nodes[0]; + let bestScore = Number.POSITIVE_INFINITY; + let bestPermutationPath = null; + let destinationNodes = []; - for (var i = 0; i < destinations.length; i++) { + for (let i = 0; i < destinations.length; i++) { destinationNodes.push(destinations[i].node); } permute(destinationNodes); - for (var i = 0; i < permutations.length; i++) { - var permutation = permutations[i]; - var permutationPath = getPermutationPath(start, permutation, nodes); + for (let i = 0; i < permutations.length; i++) { + let permutation = permutations[i]; + const permutationPath = getPermutationPath(start, permutation, nodes); if (permutationPath && permutationPath.length < bestScore) { bestScore = permutationPath.length; bestPermutationPath = permutationPath; } } - return bestPermutationPath; } @@ -243,21 +230,19 @@ function QueueLink(node, score) { } function PriorityQueue() { - var head = null; - this.push = function(node, score) { if (this.head == null) { this.head = new QueueLink(node, score); } else if (this.head.score > score) { - var tmp = this.head; + let tmp = this.head; this.head = new QueueLink(node, score); this.head.next = tmp; } else { - var i = this.head; - var found = false; + let i = this.head; + let found = false; while (i.next != null && !found) { if (i.next.score > score) { - var tmp = i.next; + let tmp = i.next; i.next = new QueueLink(node, score); i.next.next = tmp; found = true; @@ -274,7 +259,7 @@ function PriorityQueue() { if (this.head == null) { return null; } else { - var result = this.head.node; + const result = this.head.node; this.head = this.head.next; return result; } @@ -286,12 +271,11 @@ function PriorityQueue() { } function aStar(origin, destination, nodes) { - - var end = destination; // Nodes already visited. - var current; - var start = origin; - var closedSet = {}; // The neighbours yet to be evaluated. - var openSet = new PriorityQueue(); + const end = destination; // Nodes already visited. + let current; + const start = origin; + let closedSet = {}; // The neighbours yet to be evaluated. + let openSet = new PriorityQueue(); openSet.push(start, 0); initialiseParents(nodes); @@ -304,14 +288,14 @@ function aStar(origin, destination, nodes) { if (current === end) { return getNodeList(current); } - for (var i = 0; i < current.connectedNodes.length; i++) { - var neighbour = current.connectedNodes[i]; + for (let i = 0; i < current.connectedNodes.length; i++) { + let neighbour = current.connectedNodes[i]; if (Object.prototype.hasOwnProperty.call(closedSet, neighbour.id)) { continue; } closedSet[neighbour.id] = true; neighbour.parent = current; - var score = distanceFromStart(neighbour) + heuristic(destination, neighbour); + const score = distanceFromStart(neighbour) + heuristic(destination, neighbour); openSet.push(neighbour, score); } } @@ -319,21 +303,21 @@ function aStar(origin, destination, nodes) { return null; function heuristic(node1, node2) { - var d1 = Math.abs(node2.coordinate.x - node1.coordinate.x); - var d2 = Math.abs(node2.coordinate.y - node1.coordinate.y); + const d1 = Math.abs(node2.coordinate.x - node1.coordinate.x); + const d2 = Math.abs(node2.coordinate.y - node1.coordinate.y); return d1 + d2; } function initialiseParents(nodes) { - for (var i = 0; i < nodes.length; i++) { + for (let i = 0; i < nodes.length; i++) { nodes[i].parent = null; nodes[i].id = i; } } function distanceFromStart(current) { - var count = 0; - var i = current; + let count = 0; + let i = current; while (i.parent != null) { count = count + 1; i = i.parent; @@ -342,8 +326,8 @@ function aStar(origin, destination, nodes) { } function getNodeList(current) { - var curr = current; - var ret = []; + let curr = current; + let ret = []; while (curr !== start && curr !== null) { ret.push(curr); curr = curr.parent; @@ -355,7 +339,7 @@ function aStar(origin, destination, nodes) { } function areDestinationsReachable(start, destinations, nodes) { - for (var i = 0; i < destinations.length; i++) { + for (let i = 0; i < destinations.length; i++) { if (aStar(start, destinations[i], nodes) == null) { return false; }