Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 构建扑克概率计算器-如何收集不断被删除和重新创建的对象的数据?_Javascript_Aggregation_Poker - Fatal编程技术网

Javascript 构建扑克概率计算器-如何收集不断被删除和重新创建的对象的数据?

Javascript 构建扑克概率计算器-如何收集不断被删除和重新创建的对象的数据?,javascript,aggregation,poker,Javascript,Aggregation,Poker,我目前正在开发一个扑克概率计算器,它基本上可以根据用户的起始手预测用户赢得扑克游戏的几率。它“玩”了数百万个游戏,然后计算出每一个起始手牌导致其拥有者拥有最高级别手牌的频率 我已经编写了很多游戏代码,您可以在下面看到: function playPoker(tableSize) { //Create the players, the deck and the card table which stores the 5 cards the players have in common var p

我目前正在开发一个扑克概率计算器,它基本上可以根据用户的起始手预测用户赢得扑克游戏的几率。它“玩”了数百万个游戏,然后计算出每一个起始手牌导致其拥有者拥有最高级别手牌的频率

我已经编写了很多游戏代码,您可以在下面看到:

function playPoker(tableSize) {

//Create the players, the deck and the card table which stores the 5 cards the players have in common
var players = createPlayers(tableSize);
var deck = createDeck();
var cardTable = new CardTable();

//Deal each player two cards
for (i = 0; i < 2; i++) {
    for (j = 0; j < players.length; j++) {
        deal(deck, players[j]);
    }
}

//Put five cards down on the table
for (k = 0; k < 5; k++) {
    deal(deck, cardTable);
}

//Check for various winning hands here for each player
for (m = 0; m < players.length; m++) {

    //Merge the player's two cards with the five cards on the table
    var subjectCards = (players[m].cards).concat(cardTable.cards);

    //Make an array of the values of each of the seven cards, which will be used to determine 4 of a kind, 3 of a kind and pairs
    var valuesInOrder = getValuesInOrder(subjectCards);

    //Create a dummy array, so that valuesInOrder remains unchanged
    var straightValues = valuesInOrder.slice();

    //Remove any duplicate card, meaning that the array contains only unique values (i.e. 2, 4, 5, 7, K ... NOT 2, 2, 2, 8, K, K, A)
    var straightValues = straightenUp(straightValues);

    //Calculate how many pairs are in the hand
    var numPairs = howManyPairs(valuesInOrder);

    //Check whether the player has a royal flush, the highest ranking hand - then check the other hands by ranking
    checkRoyalFlush(subjectCards, straightValues);

    checkStraightFlush(subjectCards, straightValues);

    checkFourOAK(valuesInOrder);

    checkFullHouse(valuesInOrder)

    checkFlush(subjectCards);

    checkStraight(straightValues);

    checkThreeOAK(valuesInOrder);

    checkTwoPairs(numPairs);

    checkPair(numPairs);

}

}`
函数playPoker(表大小){
//创建玩家、牌组和存储玩家共有5张牌的牌表
var players=createPlayers(表大小);
var deck=createDeck();
var cardTable=新的cardTable();
//给每位玩家发两张牌
对于(i=0;i<2;i++){
对于(j=0;j
基本上,每张卡都是一个对象,具有一个suit属性(从1到4)和一个value属性(从2到14)。我已经具备了计算排名的所有逻辑,但我不知道如何整理每个卡片对象的数据(即K的频率)♥ K♠ 导致排名最高的手牌,5000万中有多少次?)


显然,我可以创建每次右起手获胜时递增的if语句,但我需要创建52^2条语句。有人有更优雅的解决方案吗?谢谢

你只需要一本有169个键的字典,所有的起始键都是独一无二的。他们的正装并不重要,只要他们合适,彩虹或一双。有了这样一个字典,你可以增加排名最高的手牌的相应值。

你只想追踪每一手牌的赢牌数?你有没有考虑过一本以手为键的字典?我只需要编辑一套,并将每笔交易作为字符串存储在一个对象键下,该对象键的数值每次计数都会递增。这样,您不需要手工编写任何代码和一个简单的对象。键(计数)循环可以在最后完成所有报告。那么169个键和值对?我需要写出每个潜在的起始手吗?你需要一个对起始手进行分类的函数。例如8h9d->98o,AhKh->AKs。如果这样做有效,您可以在密钥已经存在的情况下增加该值,或者添加该值。结果字典的长度也可以用来检查您是否首先生成了所有169个不同的对。。要生成百分比,您可能需要跟踪一只手丢失的次数,因为它们并不一致。只有4只可能的AA手和12只可能的AKo手。谢谢你的评论。这一点很好,因为起跑手之间也缺乏一致性。因此,使用分类函数,只需取两张卡的两个值,按大小顺序排列(即2,4;J,K;等等),确定它们是否属于同一套,然后将该信息保存为字符串(如您所说的KAs或89o)?谢谢,我实际上是如何从拥有代表一对卡的字符串开始的(KAO)记录这样一张卡的赢利/损失?@ Zetland,你可以使用另一本字典,使用<代码> {赢:0,丢失:0 } <代码>或添加你自己的数据结构。如果这个答案帮助你解决这个问题,请考虑接受它。