{"id":28279,"student_id":10,"content":"// 洗牌演算法\nfor (var i=0; i\u003c100; i++) {\n var rand1 = Math.floor(Math.random()*cards.length);\n var rand2 = Math.floor(Math.random()*cards.length);\n var temp = cards[rand1];\n cards[rand1] = cards[rand2];\n cards[rand2] = temp;\n}\n\n\nvar myCard = [];\nfor (var i=0; i\u003c52; i++) {\n if (i \u003c 5) {\n myCard.push(cards[i]);\n }else {\n cards[i].hidden = true;\n }\n}\n\n// 同花順\nfunction straightFlush (cards) {\n return straight(cards) \u0026\u0026 flush(cards);\n}\n\n// 鐵支\nfunction fourOfAKind (cards) {\n var record = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];\n for (var i=0; i\u003c5; i++) {\n record[cards[i].num] += 1;\n }\n for (var i=0; i\u003c13; i++) {\n if (record[i] == 4) {\n return true;\n }\n }\n return false;\n}\n\n// 葫蘆\nfunction fullHouse (cards) {\n return threeOfAkind(cards) \u0026\u0026 twoPair(cards);\n}\n\n// 同花\nfunction flush (cards) {\n return cards[0].color == cards[1].color \u0026\u0026\n cards[1].color == cards[2].color \u0026\u0026\n cards[2].color == cards[3].color \u0026\u0026\n cards[3].color == cards[4];\n}\n\n//順子\nfunction straight (cards) {\n cards.sort(function (a, b) { return a.num - b.num });\n var arr = cards.concat(cards).concat(cards);\n for (var i=0; i\u003carr.length - 5; i++) {\n if (arr[i + 4].num - arr[i + 3].num == 1 \u0026\u0026\n arr[i + 3].num - arr[i + 2].num == 1 \u0026\u0026\n arr[i + 2].num - arr[i + 1].num == 1 \u0026\u0026\n arr[i + 1].num - arr[i + 0].num == 1) {\n return true;\n }\n }\n return false;\n}\n\n// 三條\nfunction threeOfAkind (cards) {\n var record = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];\n for (var i=0; i\u003c5; i++) {\n record[cards[i].num] += 1;\n }\n for (var i=0; i\u003c13; i++) {\n if (record[i] == 3) {\n return true;\n }\n }\n return false;\n}\n\n// 兩對\nfunction twoPair (cards) {\n var count = 0;\n var record = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];\n for (var i=0; i\u003c5; i++) {\n record[cards[i].num] += 1;\n }\n for (var i=0; i\u003c13; i++) {\n if (record[i] == 2) {\n count++;\n }\n }\n return count == 2;\n}\n\n// 一對\nfunction pair (cards) {\n for (var a=0; a\u003c4; a++) {\n for (var b=a+1; b\u003c5; b++) {\n if (cards[a].num == cards[b].num) {\n return cards[a].num;\n }\n } \n }\n return false;\n}\n\nvar result = [\n straightFlush(myCard),\n fourOfAKind(myCard),\n fullHouse(myCard),\n flush(myCard),\n straight(myCard),\n threeOfAkind(myCard),\n twoPair(myCard),\n pair(myCard),\n]\n\nforever(function(){\n print(result, 100, 100, 'black', 20);\n});","created_at":"2018-05-08T12:19:54.297+08:00","updated_at":"2019-11-12T00:40:54.293+08:00","name":"洗牌演算法","language":"javascript","screenshot":{"url":"https://cdn7.koding.school/uploads/project/screenshot/28279/89edcce60b8890776f43b51e69f48ea4.jpg"},"parent_id":2,"plugin":"var cards = [];\n\nfor (var i=1; i\u003c=52; i++) {\n let s = createSprite(i + '.png');\n s.color = (i - 1)%4;\n s.num = (i - 1 - s.color)/4;\n s.color += 1;\n s.num += 1;\n s.scale = 0.5;\n cards.push(s);\n s.on('click', () =\u003e console.log(s.color, s.num));\n}\n\nforever(function(){\n for (var i=0; i\u003ccards.length; i++) {\n var x = i%10;\n var y = (i - x)/10;\n cards[i].x = x*60 + 50;\n cards[i].y = y*75 + 50;\n }\n})","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":327,"hashid":"6rpsq92j","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":521263,"file_name":"1.png","project_id":28279,"asset_id":63579,"created_at":"2018-05-08T13:08:28.773+08:00","updated_at":"2018-05-08T13:08:28.773+08:00"},{"id":521264,"file_name":"2.png","project_id":28279,"asset_id":63580,"created_at":"2018-05-08T13:08:28.776+08:00","updated_at":"2018-05-08T13:08:28.776+08:00"},{"id":521265,"file_name":"3.png","project_id":28279,"asset_id":63581,"created_at":"2018-05-08T13:08:30.436+08:00","updated_at":"2018-05-08T13:08:30.436+08:00"},{"id":521266,"file_name":"4.png","project_id":28279,"asset_id":63582,"created_at":"2018-05-08T13:08:30.440+08:00","updated_at":"2018-05-08T13:08:30.440+08:00"},{"id":521267,"file_name":"5.png","project_id":28279,"asset_id":63627,"created_at":"2018-05-08T13:08:48.041+08:00","updated_at":"2018-05-08T13:08:48.041+08:00"},{"id":521268,"file_name":"8.png","project_id":28279,"asset_id":63628,"created_at":"2018-05-08T13:08:48.044+08:00","updated_at":"2018-05-08T13:08:48.044+08:00"},{"id":521269,"file_name":"7.png","project_id":28279,"asset_id":63629,"created_at":"2018-05-08T13:08:48.626+08:00","updated_at":"2018-05-08T13:08:48.626+08:00"},{"id":521270,"file_name":"6.png","project_id":28279,"asset_id":63630,"created_at":"2018-05-08T13:08:48.628+08:00","updated_at":"2018-05-08T13:08:48.628+08:00"},{"id":521271,"file_name":"9.png","project_id":28279,"asset_id":63623,"created_at":"2018-05-08T13:09:29.820+08:00","updated_at":"2018-05-08T13:09:29.820+08:00"},{"id":521272,"file_name":"12.png","project_id":28279,"asset_id":63624,"created_at":"2018-05-08T13:09:29.823+08:00","updated_at":"2018-05-08T13:09:29.823+08:00"},{"id":521273,"file_name":"11.png","project_id":28279,"asset_id":63625,"created_at":"2018-05-08T13:09:30.660+08:00","updated_at":"2018-05-08T13:09:30.660+08:00"},{"id":521274,"file_name":"10.png","project_id":28279,"asset_id":63626,"created_at":"2018-05-08T13:09:30.662+08:00","updated_at":"2018-05-08T13:09:30.662+08:00"},{"id":521275,"file_name":"13.png","project_id":28279,"asset_id":63619,"created_at":"2018-05-08T13:10:12.768+08:00","updated_at":"2018-05-08T13:10:12.768+08:00"},{"id":521276,"file_name":"16.png","project_id":28279,"asset_id":63620,"created_at":"2018-05-08T13:10:12.771+08:00","updated_at":"2018-05-08T13:10:12.771+08:00"},{"id":521277,"file_name":"15.png","project_id":28279,"asset_id":63621,"created_at":"2018-05-08T13:10:13.524+08:00","updated_at":"2018-05-08T13:10:13.524+08:00"},{"id":521278,"file_name":"14.png","project_id":28279,"asset_id":63622,"created_at":"2018-05-08T13:10:13.526+08:00","updated_at":"2018-05-08T13:10:13.526+08:00"},{"id":521279,"file_name":"17.png","project_id":28279,"asset_id":63615,"created_at":"2018-05-08T13:10:39.684+08:00","updated_at":"2018-05-08T13:10:39.684+08:00"},{"id":521280,"file_name":"20.png","project_id":28279,"asset_id":63616,"created_at":"2018-05-08T13:10:39.687+08:00","updated_at":"2018-05-08T13:10:39.687+08:00"},{"id":521281,"file_name":"19.png","project_id":28279,"asset_id":63617,"created_at":"2018-05-08T13:10:40.104+08:00","updated_at":"2018-05-08T13:10:40.104+08:00"},{"id":521282,"file_name":"18.png","project_id":28279,"asset_id":63618,"created_at":"2018-05-08T13:10:40.106+08:00","updated_at":"2018-05-08T13:10:40.106+08:00"},{"id":521283,"file_name":"21.png","project_id":28279,"asset_id":63611,"created_at":"2018-05-08T13:11:01.903+08:00","updated_at":"2018-05-08T13:11:01.903+08:00"},{"id":521284,"file_name":"24.png","project_id":28279,"asset_id":63612,"created_at":"2018-05-08T13:11:01.905+08:00","updated_at":"2018-05-08T13:11:01.905+08:00"},{"id":521285,"file_name":"23.png","project_id":28279,"asset_id":63613,"created_at":"2018-05-08T13:11:02.321+08:00","updated_at":"2018-05-08T13:11:02.321+08:00"},{"id":521286,"file_name":"22.png","project_id":28279,"asset_id":63614,"created_at":"2018-05-08T13:11:02.324+08:00","updated_at":"2018-05-08T13:11:02.324+08:00"},{"id":521287,"file_name":"25.png","project_id":28279,"asset_id":63607,"created_at":"2018-05-08T13:11:39.029+08:00","updated_at":"2018-05-08T13:11:39.029+08:00"},{"id":521288,"file_name":"28.png","project_id":28279,"asset_id":63608,"created_at":"2018-05-08T13:11:39.032+08:00","updated_at":"2018-05-08T13:11:39.032+08:00"},{"id":521289,"file_name":"27.png","project_id":28279,"asset_id":63609,"created_at":"2018-05-08T13:11:39.496+08:00","updated_at":"2018-05-08T13:11:39.496+08:00"},{"id":521290,"file_name":"26.png","project_id":28279,"asset_id":63610,"created_at":"2018-05-08T13:11:39.499+08:00","updated_at":"2018-05-08T13:11:39.499+08:00"},{"id":521291,"file_name":"29.png","project_id":28279,"asset_id":63603,"created_at":"2018-05-08T13:11:59.940+08:00","updated_at":"2018-05-08T13:11:59.940+08:00"},{"id":521292,"file_name":"32.png","project_id":28279,"asset_id":63604,"created_at":"2018-05-08T13:11:59.942+08:00","updated_at":"2018-05-08T13:11:59.942+08:00"},{"id":521293,"file_name":"31.png","project_id":28279,"asset_id":63605,"created_at":"2018-05-08T13:12:00.527+08:00","updated_at":"2018-05-08T13:12:00.527+08:00"},{"id":521294,"file_name":"30.png","project_id":28279,"asset_id":63606,"created_at":"2018-05-08T13:12:00.529+08:00","updated_at":"2018-05-08T13:12:00.529+08:00"},{"id":521295,"file_name":"33.png","project_id":28279,"asset_id":63599,"created_at":"2018-05-08T13:12:36.174+08:00","updated_at":"2018-05-08T13:12:36.174+08:00"},{"id":521296,"file_name":"36.png","project_id":28279,"asset_id":63600,"created_at":"2018-05-08T13:12:36.176+08:00","updated_at":"2018-05-08T13:12:36.176+08:00"},{"id":521297,"file_name":"35.png","project_id":28279,"asset_id":63601,"created_at":"2018-05-08T13:12:36.948+08:00","updated_at":"2018-05-08T13:12:36.948+08:00"},{"id":521298,"file_name":"34.png","project_id":28279,"asset_id":63602,"created_at":"2018-05-08T13:12:36.950+08:00","updated_at":"2018-05-08T13:12:36.950+08:00"},{"id":521299,"file_name":"37.png","project_id":28279,"asset_id":63595,"created_at":"2018-05-08T13:13:07.151+08:00","updated_at":"2018-05-08T13:13:07.151+08:00"},{"id":521300,"file_name":"40.png","project_id":28279,"asset_id":63596,"created_at":"2018-05-08T13:13:07.154+08:00","updated_at":"2018-05-08T13:13:07.154+08:00"},{"id":521301,"file_name":"39.png","project_id":28279,"asset_id":63597,"created_at":"2018-05-08T13:13:08.121+08:00","updated_at":"2018-05-08T13:13:08.121+08:00"},{"id":521302,"file_name":"38.png","project_id":28279,"asset_id":63598,"created_at":"2018-05-08T13:13:08.123+08:00","updated_at":"2018-05-08T13:13:08.123+08:00"},{"id":521303,"file_name":"41.png","project_id":28279,"asset_id":63591,"created_at":"2018-05-08T13:13:30.510+08:00","updated_at":"2018-05-08T13:13:30.510+08:00"},{"id":521304,"file_name":"44.png","project_id":28279,"asset_id":63592,"created_at":"2018-05-08T13:13:30.513+08:00","updated_at":"2018-05-08T13:13:30.513+08:00"},{"id":521305,"file_name":"43.png","project_id":28279,"asset_id":63593,"created_at":"2018-05-08T13:13:31.228+08:00","updated_at":"2018-05-08T13:13:31.228+08:00"},{"id":521306,"file_name":"42.png","project_id":28279,"asset_id":63594,"created_at":"2018-05-08T13:13:31.230+08:00","updated_at":"2018-05-08T13:13:31.230+08:00"},{"id":521307,"file_name":"45.png","project_id":28279,"asset_id":63587,"created_at":"2018-05-08T13:13:53.480+08:00","updated_at":"2018-05-08T13:13:53.480+08:00"},{"id":521308,"file_name":"48.png","project_id":28279,"asset_id":63588,"created_at":"2018-05-08T13:13:53.482+08:00","updated_at":"2018-05-08T13:13:53.482+08:00"},{"id":521309,"file_name":"47.png","project_id":28279,"asset_id":63589,"created_at":"2018-05-08T13:13:54.246+08:00","updated_at":"2018-05-08T13:13:54.246+08:00"},{"id":521310,"file_name":"46.png","project_id":28279,"asset_id":63590,"created_at":"2018-05-08T13:13:54.249+08:00","updated_at":"2018-05-08T13:13:54.249+08:00"},{"id":521311,"file_name":"49.png","project_id":28279,"asset_id":63583,"created_at":"2018-05-08T13:14:16.461+08:00","updated_at":"2018-05-08T13:14:16.461+08:00"},{"id":521312,"file_name":"52.png","project_id":28279,"asset_id":63584,"created_at":"2018-05-08T13:14:16.463+08:00","updated_at":"2018-05-08T13:14:16.463+08:00"},{"id":521313,"file_name":"51.png","project_id":28279,"asset_id":63585,"created_at":"2018-05-08T13:14:17.303+08:00","updated_at":"2018-05-08T13:14:17.303+08:00"},{"id":521314,"file_name":"50.png","project_id":28279,"asset_id":63586,"created_at":"2018-05-08T13:14:17.306+08:00","updated_at":"2018-05-08T13:14:17.306+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦