miskson 3 年之前
父節點
當前提交
636e88d144
共有 1 個文件被更改,包括 24 次插入11 次删除
  1. 24 11
      hw4/script.js

+ 24 - 11
hw4/script.js

@@ -253,16 +253,29 @@ for(let i = 6, step = 1; i > 0; i--) {
 }
 console.log(trigon)
 
-// //blacke belt 
-// let history = [1, 1, 1, 1]
-// let predictArray[1][1][1][1] = 0
+//black belt 
+let history = [1, 1, 1, 1]
+let predictArray = [
+    [
+        [[-1],[-1]],[[-1],[-1]]
+    ],
+    [
+        [[-1],[-1]],[[-1],[-1]]
+    ]
+]
 
-// while(true) {
-//     let variant = +prompt('input 1 or 0') || alert('wrong input!')
+while(true) {
+    console.log('my prediction is:',
+    predictArray[history[0]][history[1]][history[2]][history[3]] >= 0? predictArray[history[0]][history[1]][history[2]][history[3]]:
+    Math.random() > 0.5? 1 : 0
+    )
+    let variant = prompt('input 1 or 0')
 
-//     if(+variant === 1 || +variant === 0) {
-        
-//         history.shift()
-//         history.push(variant)
-//     }
-// }
+    if(variant === null) {
+        break;
+    } else if(+variant === 1 || +variant === 0) {
+        predictArray[history[0]][history[1]][history[2]][history[3]] = +variant
+        history.shift()
+        history.push(+variant)
+    }
+}