Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/454.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中使用mod运算符_Javascript_Reactjs_Modulo_Poker - Fatal编程技术网

在JavaScript中使用mod运算符

在JavaScript中使用mod运算符,javascript,reactjs,modulo,poker,Javascript,Reactjs,Modulo,Poker,我正在使用ReactJS构建一个Texas Hold'em Poker web应用程序。为了跟踪经销商按钮,我使用以下公式 let currentPlayers = [ {name: "Foo", position: 1}, {name: "Bar", position: 2}, {name: "Baz", position: 3} ] let dealerButtonPos = 1 dealerButtonPos = ((dealerButtonPos + cur

我正在使用ReactJS构建一个Texas Hold'em Poker web应用程序。为了跟踪经销商按钮,我使用以下公式

let currentPlayers = [
    {name: "Foo", position: 1}, 
    {name: "Bar", position: 2},
    {name: "Baz", position: 3} 
]
let dealerButtonPos = 1

dealerButtonPos = ((dealerButtonPos + currentPlayers.length ) % currentPlayers.length + 1 )
我在这里要做的是确保经销商按钮从位置1开始,并且在每轮开始时始终处于正确位置。在这种情况下,经销商按钮应始终落在位置1、2、3、1上

在每一轮结束时,将调用带有公式的函数。这样最多可为8名玩家正确旋转经销商按钮。 我会一直处于正确的球员位置吗?我是否正确地实现了这一点?我很难概念化,也很难达到这一点。有人能解释一下mod运算符吗?

请解释清楚

让CurrentPlayer=[
{姓名:“Foo”,职位:1},
{名称:“酒吧”,位置:2},
{姓名:“Baz”,职位:3}
]
函数*CurrentPlayerInterator(播放器){
设指数=0;
while(true)
如果(索引<玩家长度){
让玩家[index++]
}否则{
索引=0
让玩家[index++]
}
}
设i=CurrentPlayerInterator(CurrentPlayer)
console.log(i.next().value)
console.log(i.next().value)
console.log(i.next().value)
console.log(i.next().value)

log(i.next().value)
我会这样做

let currentPlayers = [
    {name: "Foo", position: 1}, 
    {name: "Bar", position: 2},
    {name: "Baz", position: 3} 
]
let dealerButtonPos = 1
var index = dealerButtonPos % currentPlayers.length
dealerButtonPos = (index == 0) ? index + currentPlayers.length : index

(a+b)%b
a%b
+currentPlayers.length
<代码>+1!您可以使用
dealerButtonPos=(dealerButtonPos+1)%currentPlayers.length轻松地将其保持在数组的范围内。然而,要小心玩家站立或被淘汰的情况,留下一个“死”点,但仍然要发牌。“庄家”按钮比不考虑其他条件而简单地旋转稍微复杂一些。是的,如果你有虚拟的“座位”,玩家可以随时进出(以及通过冲出),那么你必须执行完整的按钮和游戏规则,包括抬头特例。@jered说得好。到目前为止,我已经考虑了活跃球员和非活跃球员。