有点意思~

var cc = 0
var my = 20, you = 2000;
for (var i = 0; ; i++) {
    if (cc != 'mywin') {
        cc = this.jisuan(my, you)
    } else {
        console.log(i)
        if (i < (you / my)) {
            console.log('my win')
        } else {
            console.log('my last')
        }
        break
    }
}
function jisuan(my, you) {
    for (var i = 0; ; i++) {
        var jieguo = Math.floor(Math.random() * (10 - 1 + 1)) + 1
        var check = Math.floor(Math.random() * (2))
        if (check) {
            my += jieguo;
            you -= jieguo;
        } else {
            you += jieguo;
            my -= jieguo;
        }
        if (my <= 0) {
            return 'youwin'
        }
        if (you <= 0) {
            return 'mywin'
        }
    }
}

 

posted @ 2023-03-27 21:41  悬剑丶  阅读(30)  评论(0编辑  收藏  举报