klren0312 / daliy_knowledge

知识积累,正确使用方式是watch
21 stars 4 forks source link

斗地主算法相关 #201

Open klren0312 opened 4 years ago

klren0312 commented 4 years ago

发牌算法

//用1——54的数组代表54张牌
function myCreateArray(n){
    var arr = [];
    for(var i = 0; i < n; i++){
        arr[i] = i + 1;
    }
    return arr;
}

var cards = myCreateArray(54);
console.log('Get A Deck of Cards is: ' + cards);

//洗牌即是打乱数组顺序
function myShuffle(arr) {
    var len = arr.length;
    for (var i = 0; i < len - 1; i++) {
        var index = parseInt(Math.random() * (len - i));
        var temp = arr[index];
        arr[index] = arr[len - i - 1];
        arr[len - i - 1] = temp;
    }
}

myShuffle(cards);
console.log('Get A Disordered Cards is: ' + cards);

//玩家A,B,C各拿17张牌
var playerA = cards.slice(0,17);
console.log('playerA Has Cards: ' + playerA);

var playerB = cards.slice(17,34);
console.log('playerB Has Cards: ' + playerB);

var playerC = cards.slice(34,51);
console.log('playerC Has Cards: ' + playerC);

//留下3张底牌
var bottomCards = cards.slice(51,54);
console.log('Bottom Cards: ' + bottomCards);
klren0312 commented 4 years ago

https://github.com/linzhipeng/doudizhu

klren0312 commented 4 years ago

https://github.com/IMGameDesigner/PokerGame

klren0312 commented 4 years ago

https://github.com/duanwenqi127/ddz-picker