Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.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
Ios 从人工智能到多人游戏_Ios_Xcode_Multiplayer_Equals Operator - Fatal编程技术网

Ios 从人工智能到多人游戏

Ios 从人工智能到多人游戏,ios,xcode,multiplayer,equals-operator,Ios,Xcode,Multiplayer,Equals Operator,我目前有一个单人棋盘游戏,有一个人类玩家和三个AI玩家。我想把它改成四个人。如何从下面的代码中实现这一点?我可以简单地对第一行“currentplayer==3”使用and或语句,并将其改为“currentplayer==3 | 1”吗 if(currentPlayer==3&([currentTokens count])){ 对于(int count=0;count

我目前有一个单人棋盘游戏,有一个人类玩家和三个AI玩家。我想把它改成四个人。如何从下面的代码中实现这一点?我可以简单地对第一行“currentplayer==3”使用and或语句,并将其改为“currentplayer==3 | 1”吗

if(currentPlayer==3&([currentTokens count])){
对于(int count=0;count<[currentTokens count];count++){
令牌*令牌=(令牌*)[currentTokens对象索引:计数];
[令牌setUserInteractionEnabled:是];
}
}
else if([currentTokens count])//对于非人类玩家
{
//NSLog(“Break3.3”);
int arrLength=[currentTokens计数];
//NSLog(@“Break3.4和%i”,arrLength);
//////////////////出现六个骰子时非人类的AI////////////
令牌*非人类令牌;
int tokenathomecont=0;
if(firstDiceValue==6){
对于(int count=0;count<[currentTokens count];count++){
令牌*selectedToken=(令牌*)[currentTokens对象索引:计数];
如果(选择Token.isAtHome){
tokenAtHomeCount++;
非人类令牌=(令牌*)[currentTokens对象索引:计数];
打破
}
}
如果(!tokenAtHomeCount){
非人类令牌=(令牌*)[currentTokens对象索引:(arc4random()%arrLength)];
}
}
否则{
非人类令牌=(令牌*)[currentTokens对象索引:(arc4random()%arrLength)];
}
////////////////////////////////
[self-performSelector:@selector(CourseOperationWithDelay:)withObject:NonHumanTokenAfterDelay:1.5];
//[self-moveToken:non-humanToken直到:firstDiceValue];
如果([currentTokens count]){
[self-DisplayMessageForMovingTokens:currentPlayer];
}
}

理想情况下,如果你用人类玩家替换你的AI,你会完全抛弃AI代码。我会考虑为每个玩家复制人类代码

假设你有:

if(player==1) {
     player 1's turn stuff here
}
您可以从中展开并继续:

if(player==2) {
     player 2's turn stuff here
}

如果这是一个基于回合的游戏,不要跟踪玩家,而是跟踪回合。第一回合是玩家一,第二回合是玩家二,当你达到本回合的最大玩家数时,只需重置即可。

谢谢。似乎是目前最安全的选择。
if(player==2) {
     player 2's turn stuff here
}