{"id":150213,"student_id":10,"content":"{\"html\":\"\u003c!DOCTYPE html\u003e\\n\u003chtml lang=\\\"en\\\"\u003e\\n\\n\u003chead\u003e\\n \u003cmeta charset=\\\"UTF-8\\\"\u003e\\n \u003cmeta name=\\\"viewport\\\" content=\\\"width=device-width, initial-scale=1.0\\\"\u003e\\n \u003cmeta http-equiv=\\\"X-UA-Compatible\\\" content=\\\"ie=edge\\\"\u003e\\n \u003ctitle\u003eSudoku Solver\u003c/title\u003e\\n \u003clink rel=\\\"stylesheet\\\" href=\\\"index.css\\\"\u003e\\n \u003cscript src=\\\"https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.js\\\"\u003e\u003c/script\u003e\\n\u003c/head\u003e\\n\\n\u003cbody\u003e\\n \u003cdiv id=\\\"sudoku\\\"\u003e\\n \u003ch1\u003e數獨遊戲\u003c/h1\u003e\\n \u003cdiv class=\\\"game\\\"\u003e\\n \u003cdiv class=\\\"grid\\\"\u003e\\n \u003cdiv v-for=\\\"row, x in grid\\\" class=\\\"row\\\"\u003e\\n \u003cdiv v-for=\\\"col, y in row\\\" class=\\\"col\\\"\u003e\\n \u003cinput v-model.number=\\\"grid[x][y]\\\" :disabled=\\\"originGrid[x][y] != 0\\\" :style=\\\"textColor(grid[x][y])\\\"\u003e\\n \u003c/div\u003e\\n \u003c/div\u003e\\n \u003c/div\u003e\\n \u003cdiv class=\\\"vertical\\\"\u003e\\n \u003cdiv v-for=\\\"i in 9\\\"\u003e\\n \u003cdiv v-show=\\\"v_check(i - 1)\\\" class=\\\"active\\\"\u003e\u003c/div\u003e\\n \u003c/div\u003e\\n \u003c/div\u003e\\n \u003cdiv class=\\\"horizontal\\\"\u003e\\n \u003cdiv v-for=\\\"i in 9\\\"\u003e\\n \u003cdiv v-show=\\\"h_check(i - 1)\\\" class=\\\"active\\\"\u003e\u003c/div\u003e\\n \u003c/div\u003e\\n \u003c/div\u003e\\n \u003cdiv class=\\\"blocks\\\"\u003e\\n \u003cdiv v-for=\\\"i in 9\\\"\u003e\\n \u003cdiv v-show=\\\"b_check(i - 1)\\\" class=\\\"active\\\"\u003e\u003c/div\u003e\\n \u003c/div\u003e\\n \u003c/div\u003e\\n \u003c/div\u003e\\n \u003cbutton @click=\\\"newGame\\\"\u003e新遊戲\u003c/button\u003e\\n \u003cbutton @click=\\\"resolve\\\"\u003e破解\u003c/button\u003e\\n \u003c/div\u003e\\n\u003c/body\u003e\\n\u003c/html\u003e\",\"css\":\"body {\\n padding: 15px;\\n display: flex;\\n justify-content: center;\\n align-items: center;\\n background-color: lightyellow;\\n}\\n\\n#sudoku {\\n text-align: center;\\n}\\n\\nimg {\\n width: 100px;\\n}\\n\\nbutton {\\n margin: 10px 5px;\\n}\\n\\n.game {\\n width: 450px;\\n height: 450px;\\n border: 1px solid black;\\n position: relative;\\n}\\n\\n.row {\\n width: 100%;\\n height: calc(100%/9);\\n}\\n\\n.col {\\n position: relative;\\n display: inline-block;\\n width: calc(100%/9);\\n height: 100%;\\n margin: 0;\\n border: 1px solid #00000050;\\n box-sizing: border-box;\\n}\\n\\ninput {\\n position: absolute;\\n top: 0;\\n left: 0;\\n width: calc(100% - 2px);\\n height: calc(100% - 2px);\\n margin: 0;\\n text-align: center;\\n border-width: 0px;\\n box-sizing: border-box;\\n font-size: 1.2rem;\\n outline: none;\\n color: black;\\n background-color: rgba(0, 0, 0, 0);\\n}\\n\\ninput:disabled {\\n font-weight: 900;\\n font-size: 1.1rem;\\n /* background-color: lightyellow; */\\n background-color: rgba(0, 0, 0, 0);\\n cursor: not-allowed;\\n}\\n\\n.grid {\\n width: 100%;\\n height: 100%;\\n position: absolute;\\n top: 0;\\n left: 0;\\n}\\n\\n.vertical,\\n.horizontal,\\n.blocks {\\n position: absolute;\\n top: 0;\\n left: 0;\\n right: 0;\\n bottom: 0;\\n display: flex;\\n flex-wrap: wrap;\\n pointer-events: none;\\n}\\n\\n.vertical \u003e div {\\n width: calc(100%/9);\\n height: 100%;\\n position: relative;\\n}\\n\\n.horizontal \u003e div {\\n width: 100%;\\n height: calc(100%/9);\\n position: relative;\\n}\\n\\n.blocks \u003e div {\\n width: 150px;\\n height: 150px;\\n border: 1px solid black;\\n box-sizing: border-box;\\n position: relative;\\n}\\n\\n.vertical .active {\\n z-index: -1;\\n position: absolute;\\n top: -12px;\\n left: 12px;\\n right: 12px;\\n bottom: -12px;\\n background-color: #ff595960;\\n}\\n\\n.horizontal .active {\\n z-index: -1;\\n position: absolute;\\n top: 12px;\\n left: -12px;\\n right: -12px;\\n bottom: 12px;\\n background-color: #ffa40060;\\n}\\n\\n.blocks .active {\\n z-index: -1;\\n position: absolute;\\n top: 6px;\\n left: 6px;\\n right: 6px;\\n bottom: 6px;\\n background-color: #00c4b360;\\n}\\n\",\"js\":\"var count; \\n\\nfunction start () {\\n count = 0; //計算遞迴的次數\\n resolve();\\n console.log('遞迴嘗試了 ' + count + ' 次!');\\n}\\n\\n\\nfunction resolve () {\\n \\n //限制遞迴次數避免網頁癱瘓\\n if (count \u003e= 300000) return;\\n count++;\\n\\n for (var x = 0; x \u003c 9; x++) {\\n for (var y = 0; y \u003c 9; y++) {\\n if (grid[x][y] == 0) {\\n\\n var arr = [];\\n for (var i = 0; i \u003c 9; i++) {\\n arr.push(grid[x][i]);\\n }\\n\\n for (var i = 0; i \u003c 9; i++) {\\n arr.push(grid[i][y]);\\n }\\n\\n var offsetX = x - x % 3;\\n var offsetY = y - y % 3;\\n for (var xx = 0; xx \u003c 3; xx++) {\\n for (var yy = 0; yy \u003c 3; yy++) {\\n arr.push(grid[offsetX + xx][offsetY + yy]);\\n }\\n }\\n\\n for (var i = 1; i \u003c= 9; i++) {\\n if (arr.indexOf(i) == -1) {\\n grid[x][y] = i;\\n var b = resolve();\\n if (b) return true;\\n grid[x][y] = 0;\\n }\\n }\\n return false;\\n }\\n }\\n }\\n return true;\\n}\\n\"}","created_at":"2020-05-22T10:14:07.974+08:00","updated_at":"2020-06-11T17:29:53.235+08:00","name":"數獨9x9","language":"web","screenshot":{"url":"https://cdn5.koding.school/uploads/project/screenshot/150213/49bc425220c891559d86fe3209256d9a.jpg"},"parent_id":3,"plugin":"const HARD_MAZE = [\n [8, 0, 0, 0, 0, 0, 0, 0, 0],\n [0, 0, 3, 6, 0, 0, 0, 0, 0],\n [0, 7, 0, 0, 9, 0, 2, 0, 0],\n [0, 5, 0, 0, 0, 7, 0, 0, 0],\n [0, 0, 0, 0, 4, 5, 7, 0, 0],\n [0, 0, 0, 1, 0, 0, 0, 3, 0],\n [0, 0, 1, 0, 0, 0, 0, 6, 8],\n [0, 0, 8, 5, 0, 0, 0, 1, 0],\n [0, 9, 0, 0, 0, 0, 4, 0, 0],\n];\n\nconst EMPTY_MAZE = [\n [0, 0, 0, 0, 0, 0, 0, 0, 0],\n [0, 0, 0, 0, 0, 0, 0, 0, 0],\n [0, 0, 0, 0, 0, 0, 0, 0, 0],\n [0, 0, 0, 0, 0, 0, 0, 0, 0],\n [0, 0, 0, 0, 0, 0, 0, 0, 0],\n [0, 0, 0, 0, 0, 0, 0, 0, 0],\n [0, 0, 0, 0, 0, 0, 0, 0, 0],\n [0, 0, 0, 0, 0, 0, 0, 0, 0],\n [0, 0, 0, 0, 0, 0, 0, 0, 0],\n];\n\nfunction generator(grid) {\n for (let x = 0; x \u003c 9; x++) {\n for (let y = 0; y \u003c 9; y++) {\n if (grid[x][y] === 0) {\n let arr = [];\n for (let i = 0; i \u003c 9; i++) {\n arr.push(grid[x][i]);\n arr.push(grid[i][y]);\n }\n\n let offsetX = Math.floor(x / 3);\n let offsetY = Math.floor(y / 3);\n for (let xx = 0; xx \u003c 3; xx++) {\n for (let yy = 0; yy \u003c 3; yy++) {\n arr.push(grid[offsetX * 3 + xx][offsetY * 3 + yy]);\n }\n }\n\n let rand = shuffle();\n\n for (let i = 0; i \u003c 9; i++) {\n if (arr.indexOf(rand[i]) === -1) {\n grid[x][y] = rand[i];\n if (generator(grid)) return true;\n grid[x][y] = 0;\n }\n }\n return false;\n }\n }\n }\n randomHide(grid)\n return true;\n}\n\nfunction shuffle() {\n let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];\n for (let i = 0; i \u003c 100; i++) {\n let rand1 = Math.floor(Math.random() * 9);\n let rand2 = Math.floor(Math.random() * 9);\n let temp = arr[rand1];\n arr[rand1] = arr[rand2];\n arr[rand2] = temp;\n }\n return arr;\n}\n\nfunction randomHide(grid) {\n let count = 0;\n // provide at least 17 seeds number\n while (count \u003c 81 - 25) {\n let x = Math.floor(Math.random() * 9)\n let y = Math.floor(Math.random() * 9)\n if (grid[x][y] !== 0) {\n grid[x][y] = 0;\n count++;\n }\n }\n}\n\nfunction array2dToGrid(arr2d) {\n let grid = {};\n for (let x = 0; x \u003c 9; x++) {\n grid[x] = {};\n for (let y = 0; y \u003c 9; y++) {\n grid[x][y] = arr2d[x][y] !== 0 ? arr2d[x][y] : 0;\n }\n }\n return grid;\n}\n\nvar grid = array2dToGrid(HARD_MAZE);\n\n\nlet game = new Vue({\n el: '#sudoku',\n data: {\n grid: grid,\n originGrid: JSON.parse(JSON.stringify(grid)),\n },\n methods: {\n v_check(y) {\n let arr = [];\n for (let i = 0; i \u003c 9; i++) {\n arr.push(grid[i][y]);\n }\n return !this.isValid(arr);\n },\n\n h_check(x) {\n let arr = [];\n for (let i = 0; i \u003c 9; i++) {\n arr.push(grid[x][i]);\n }\n return !this.isValid(arr);\n },\n\n b_check(i) {\n let offsetX = i % 3;\n let offsetY = (i - offsetX) / 3;\n let arr = [];\n for (let x = 0; x \u003c 3; x++) {\n for (let y = 0; y \u003c 3; y++) {\n arr.push(grid[offsetY * 3 + y][offsetX * 3 + x]);\n }\n }\n return !this.isValid(arr);\n },\n\n isValid(arr) {\n for (let a = 0; a \u003c arr.length - 1; a++) {\n for (let b = a + 1; b \u003c arr.length; b++) {\n if (arr[a] === arr[b] \u0026\u0026 arr[b] !== 0) return false;\n }\n }\n return true;\n },\n \n textColor(num) {\n if (num == 0) {\n return { color: 'rgba(0, 0, 0, 0)' }\n } else {\n return { color: 'rgba(0, 0, 0, 1)' }\n }\n },\n\n resolve() {\n // window.resolve \u0026\u0026 resolve(grid);\n window.start \u0026\u0026 window.start();\n },\n\n newGame() {\n let newGrid = array2dToGrid(EMPTY_MAZE);\n generator(newGrid);\n\n for (let x = 0; x \u003c 9; x++) {\n for (let y = 0; y \u003c 9; y++) {\n this.grid[x][y] = newGrid[x][y];\n }\n }\n\n this.originGrid = JSON.parse(JSON.stringify(this.grid));\n }\n },\n});\n\n\n\n\n\n","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":314,"hashid":"882sgjwy","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":2653986,"file_name":"coding.png","project_id":150213,"asset_id":101987,"created_at":"2020-05-29T17:06:25.765+08:00","updated_at":"2020-05-29T17:06:30.247+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
前往網站頁面
1:1:1
1:1
full
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦