{"id":660346,"student_id":10,"content":"// 黑子(電腦)先下\ngrid[7][7] = 'b';\n\nforever(update);\n\n// 印出評估函式計算的分數在每個格子上\nfunction update () {\n for (var y = 0; y \u003c 15; y++) {\n for (var x = 0; x \u003c 15; x++) {\n if (grid[y][x] == '') {\n // drawText(score, 115 + x*30, 35 + y*30, 'black', 10);\n }\n }\n }\n}\n\n// 當玩家下完會觸發 AI 函式換電腦下棋\nfunction AI() {\n var bestScore = 0;\n var bestY;\n var bestX;\n for (var y = 0; y \u003c 15; y++) {\n for (var x = 0; x \u003c 15; x++) {\n if (grid[y][x] == '') {\n \n }\n }\n }\n \n}\n\n// 評估函式,組合八個方向的分數\n// north(北)、south(南)、west(西)、east(東)\n// northwest(西北)、southeast(東南)、northeast(東北)、southwest(西南)\nfunction evaluation (x, y) {\n \n}\n\n// 傳入五個格子內容,計算連成幾個\nfunction getScore (a, b, c, d, e) {\n \n}","created_at":"2023-12-12T11:19:28.573+08:00","updated_at":"2023-12-12T15:30:51.817+08:00","name":"五子棋 AI 大師(預設版)","language":"javascript","screenshot":{"url":"https://cdn1.koding.school/uploads/project/screenshot/660346/020f6b81ced1b77587336a7a98bfbb12.jpg"},"parent_id":2,"plugin":"setBackdrop('bg.png');\n\nconst BLACK = 'b';\nconst WHITE = 'w';\nconst ZZ = [0, 0, 0, 0, 0, 0, 0, 0, 0];\nconst V1 = [4, 3, 2, 1, 0, -1, -2, -3, -4];\nconst V2 = [-4, -3, -2, -1, 0, 1, 2, 3, 4];\n\n\nvar game = (function () {\n\n let grid = {};\n for (let y = -14; y \u003c= 29; y++) {\n grid[y] = {};\n for (let x = -14; x \u003c= 29; x++) {\n grid[y][x] = '';\n }\n }\n\n function isWin (x, y, vx, vy) {\n var re = grid[y + vy*0][x + vx*0] +\n grid[y + vy*1][x + vx*1] +\n grid[y + vy*2][x + vx*2] +\n grid[y + vy*3][x + vx*3] +\n grid[y + vy*4][x + vx*4];\n\n if (re == 'bbbbb') {\n drawText('黑方獲勝');\n stop();\n }\n if (re == 'wwwww') {\n drawText('白方獲勝');\n stop();\n }\n }\n \n //當玩家點擊格子時\n function onclick () {\n var x = Math.floor((cursor.x - 97)/30);\n var y = Math.floor((cursor.y - 17)/30);\n\n if (x \u003c 0 || x \u003e= 15 || y \u003c 0 || y \u003e= 15) return;\n \n place(x, y) \u0026\u0026 AI();\n }\n\n //繪製棋子\n function render () {\n for (var y = 0; y \u003c 15; y++) {\n for (var x = 0; x \u003c 15; x++) {\n pen.size = 0;\n if (grid[y][x] == '') continue;\n if (grid[y][x] == BLACK) pen.fillColor = 'black';\n if (grid[y][x] == WHITE) pen.fillColor = 'white';\n pen.drawCircle(x*30 + 110, y*30 + 30, 14);\n }\n }\n for (var x = 0; x \u003c 15; x++) {\n for (var y = 0; y \u003c 15; y++) {\n isWin(x, y, 1, 0);\n isWin(x, y, -1, 0);\n isWin(x, y, 0, 1);\n isWin(x, y, 0, -1);\n isWin(x, y, 1, 1);\n isWin(x, y, -1, 1);\n isWin(x, y, 1, -1);\n isWin(x, y, -1, -1);\n }\n }\n }\n\n function place (x, y) {\n\n if (grid[y][x] !== '') return false;\n\n var count = 0;\n for (var yy = 0; yy \u003c 15; yy++) {\n for (var xx = 0; xx \u003c 15; xx++) {\n if (grid[yy][xx] !== '') count++;\n }\n }\n grid[y][x] = count%2 === 0 ? BLACK: WHITE;\n \n return true;\n }\n\n function check(color, x, y) {\n\n if (color == 'white' || color == BLACK) color = WHITE;\n if (color == 'black' || color == WHITE) color = BLACK;\n\n var temp = grid[y][x];\n grid[y][x] = color;\n var result = [0, 1, 0, 0, 0, 0];\n var a, b, c;\n var start, len;\n for (len = 5; len \u003e= 2; len--) {\n for (start = 5 - len; start \u003c= 4; start++) {\n z = ZZ.slice(start, start + len);\n d = V1.slice(start, start + len);\n i = V2.slice(start, start + len);\n if (checkLine(grid, x, y, d, z, color)) result[len]++;\n if (checkLine(grid, x, y, z, d, color)) result[len]++;\n if (checkLine(grid, x, y, d, d, color)) result[len]++;\n if (checkLine(grid, x, y, d, i, color)) result[len]++;\n }\n }\n\n grid[x][y] = temp;\n\n return result;\n }\n\n function checkLine(grid, x, y, vx, vy, who) {\n for (var i = 0; i \u003c vx.length; i++) {\n var xx = x + vx[i];\n var yy = y + vy[i];\n if (grid[yy][xx] != who) return false;\n }\n return true;\n }\n\n when('click', onclick);\n forever(render);\n\n return {\n place: place,\n current: BLACK,\n grid: grid,\n };\n})();\n\ngrid = game.grid;","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":70,"hashid":"yeysg2y2v","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":14815023,"file_name":"bg.png","project_id":660346,"asset_id":705536,"created_at":"2023-12-12T15:30:51.816+08:00","updated_at":"2023-12-12T15:30:51.816+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦