鬥地主相關邏輯演算法(JavaScript)

2021-08-21 15:01:27 字數 2898 閱讀 999

注:隨便寫的草稿,專案已丟失。

var _ = require('lodash')

var logic = {}

logic.canchupaijudge = function (cards, curcards) `)

var type2 = self.cardstypejudge(curcards)

console.log(`桌面上已有牌型:$`)

if (cards.length > 0 && curcards.length > 0)

}else

}if (cards.length != curcards.length)

else

}else if (type1 == '三帶一張牌' || type1 == '三帶一對牌')

var x = 0

var y = 0

for (var i = 0; i < cards.length; i++)

for (var i = 0; i < curcards.length; i++)

if (x <= y)

}else if (type1 == '四帶二')

var x = 0

var y = 0

for (var i = 0; i < cards.length; i++)

for (var i = 0; i < curcards.length; i++)

if (x <= y)

}else if (type1 == '飛機帶翅膀')

var max1 = 0

var max2 = 0

for (var i = 0; i < cards.length; i++)

}for (var i = 0; i < curcards.length; i++)

}if (max1 <= max2) }}

}}

return 0

}logic.cardstypejudge = function (cards)

}if (flag) }}

if (judge)

return '單順'

}else if (arr[0] == 2 && arr.length >= 3) }}

if (judge)

return '雙順'

}else if (arr[0] == 3 && arr.length >= 2) }}

if (judge)

return '三順'}}

else

else if (arr.length == 2)

else if (arr.length == 3)

else if (arr.length >= 4)

for (var i = arr.length / 2; i < arr.length; i++)

if (flag)

return '飛機帶翅膀'}}

}return null

}logic.systemplay = function (curcards, data)

var x = 0

var y = 0

for (var i = 0; i < curcards.length; i++)

}var type = this.cardstypejudge(curcards)

var len = curcards.length

if (len == 0)

if (type == '火箭')

return 1

if (type == '單牌') }}

else if (type == '對牌') }}

else if (type == '三張牌' || type == '三帶一張牌' || type == '三帶一對牌') }}

else if (type == '三帶一對牌') }}

for (var k = 0; k < data.length; k++) }}

}else if (type == '炸彈' || type == '四帶二')

else }}

}}

else if (len == 8)

else }}

}}

}for (var k = 0; k < data.length; k++) }}

}else if (type == '單順')

for (var i = 0; i < data.length; i++)

return 0}}

else if (data[i].value - mark > 1)

arr[i] = true}}

else }}

}else if (type == '雙順')

else

cur = null

cnt = 0

}else if (data[i].value - cur == 1)

}else }}

}for (var i = 0; i < data.length; i++)

}else if (type == '三順')

else

cur = null

cnt = 0

}else if (data[i].value - cur == 1)

}else }}

}for (var i = 0; i < data.length; i++)

}//沒有更大的匹配牌型時,如果有大小王,則打出火箭

if (data[data.length - 1].value >= 14 && data[data.length - 2].value >= 14)

return 1

},module.exports = logic

鬥地主出牌演算法

根據鬥地主出牌規則.對玩家出的牌進行檢驗.判斷是否符合出牌規則.關於鬥地主的出牌規則網上有很多 思路 將玩家的牌按公升序排序.然後將牌進行拆分,分存在4個陣列中.拆分規則如下 假設有牌 333 444 555 789 則拆分後陣列中的資料如下 arr 0 345789 arr 1 345 arr 2...

找朋友(鬥地主) 判斷邏輯

1.牌與數值的對映關係如下 數值 牌 3 3 4 4 10 10 11 j 12 q 13 k 14 a 15 2 16 小王 17 大王 18 花牌 可以變成任意牌 2.以下判斷方法傳入的引數必須是從 大到小排好序的陣列 3.可以帶任意張 花牌 牌 如果滿足條件並且有多種可能,最終返回的是最大值 ...

鬥地主中跟牌邏輯分析

qlistmethod playbeathand hand hand 壓雙排 else if hand.gethandtype hand pair 如果壓雙牌,盡量從雙牌中挑 player nextplayer m player getnextplayer 從手牌中查詢相同牌型 qlist beat...