随便做的猜数字(电脑猜)游戏
望大佬指点程序代码:
<!doctype html> <html> <head> <title>人工智能猜数字V1.0.0</title> <meta charset="UTF-8"> </head> <body> <script> var n = 50000; var m = 50000; var yeah = false; var step = 1; var max = 100000; var min = 0; alert("请随便想一个1~100000之间的数字,我们的程序能在20次以内猜出您想的数字是什么"); var a = setInterval(function() { if (max - min == 2) { alert("是" + (max - 1)); window.location.reload(); } else { if (confirm(step + ". 大于" + n + "?"+max+" "+min)) { m /= 2; n += m; n = Math.round(n); min = n - m; min = Math.round(min); step++; } else { m /= 2; n -= m; n = Math.round(n); max = n + m + 1; max = Math.round(max); step++; } } }, 20) </script> </body> </html>