0

我目前有一个单人棋盘游戏,有一个人类玩家和三个 AI 玩家。我想将其更改为四个人类玩家。我怎样才能从下面的代码中实现这一点?我可以简单地对第一行“currentplayer ==3”使用和 OR 语句并将其读取为“currentplayer == 3 | 1”

   if (currentPlayer == 3 && ([currentTokens count])){
    for (int count = 0; count < [currentTokens count]; count++) {
        Token *token = (Token*)[currentTokens objectAtIndex:count];
        [token setUserInteractionEnabled:YES];
    }

}
else if ([currentTokens count])//For NonHuman Players
{
    //        NSLog(@"Break3.3");

    int arrLength = [currentTokens count];
    //        NSLog(@"Break3.4 and %i",arrLength);

    ////////////////// AI for NON HUMAN AT OCCURENCE OF SIX OF DICE////////////
    Token *nonHumanToken;
    int tokenAtHomeCount = 0;
    if (firstDiceValue == 6) {
        for (int count = 0; count < [currentTokens count]; count++) {
            Token *selectedToken = (Token*)[currentTokens objectAtIndex:count];
            if (selectedToken.isAtHome) {
                tokenAtHomeCount++;
                nonHumanToken = (Token*)[currentTokens objectAtIndex:count];
                break;
            }
        }

        if (!tokenAtHomeCount) {
            nonHumanToken = (Token*)[currentTokens objectAtIndex:(arc4random()%arrLength)];
        }

    }
    else{
        nonHumanToken = (Token*)[currentTokens objectAtIndex:(arc4random()%arrLength)];
    }
    ////////////////////////////////
    [self performSelector:@selector(courseOfActionWithDelay:) withObject:nonHumanToken afterDelay:1.5];

    //        [self moveToken:nonHumanToken Till:firstDiceValue];

    if ([currentTokens count]) {
        [self DisplayMessageForMovingTokens:currentPlayer];
    }

}
4

1 回答 1

0

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

假设你有:

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

你会扩展它并继续:

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

如果这是一个回合制游戏,而不是追踪玩家,追踪回合。第一回合是玩家一,第二回合是玩家二,然后一旦你达到该回合的最大玩家人数就重置。

于 2014-11-26T02:51:45.200 回答