public override int PlayGame(RolloutGame game, int alpha, int beta, int depthLimit, string command) { string playCommand = command; if (game.reachedDepthLimit(depthLimit) || game.isGameOver()) { return(game.evalGame()); } if (string.IsNullOrEmpty(command)) { Random rnd = new Random(Guid.NewGuid().GetHashCode()); List <string> possiblePlays; switch (game.getGameState()) { case GameStates.ACCUSE: possiblePlays = game.getPossibleAccuses(playerName); playCommand = possiblePlays[rnd.Next(possiblePlays.Count)]; break; case GameStates.KILL: if (character.canKill()) { possiblePlays = game.getPossibleAccuses(playerName); playCommand = possiblePlays[rnd.Next(possiblePlays.Count)]; } break; case GameStates.HEAL: if (character.canHeal()) { possiblePlays = game.getPossibleHeals(playerName); playCommand = possiblePlays[rnd.Next(possiblePlays.Count)]; } break; case GameStates.TALK: if (character.canHeal()) { possiblePlays = InfoSet.getPossibleTalks().Select(x => x.Key).ToList(); playCommand = possiblePlays[rnd.Next(possiblePlays.Count)]; } break; case GameStates.QUESTION: possiblePlays = game.getPossibleQuestions(playerName); playCommand = possiblePlays[rnd.Next(possiblePlays.Count)]; break; default: playCommand = "pass"; break; } } RolloutGame playGame = game.Copy(); playGame.applyMove(playCommand); int moveValue = playGame.getNextPlayer().PlayGame(playGame, alpha, beta, depthLimit); return(moveValue); }
public override int PlayGame(RolloutGame game, int alpha, int beta, int depthLimit, string command) { //int v = Int16.MinValue; List <string> possiblePlays = new List <string>() { "" }; int v = Int16.MinValue; if (game.reachedDepthLimit(depthLimit) || game.isGameOver()) { return(game.evalGame()); } if (string.IsNullOrEmpty(command)) { switch (game.getGameState()) { case GameStates.ACCUSE: possiblePlays = game.getPossibleAccuses(playerName); break; case GameStates.KILL: if (character.canKill()) { possiblePlays = game.getPossibleKills(playerName); } break; case GameStates.HEAL: if (character.canHeal()) { possiblePlays = game.getPossibleHeals(playerName); } break; case GameStates.QUESTION: if (character.canQuestion()) { possiblePlays = game.getPossibleQuestions(playerName); } break; case GameStates.TALK: possiblePlays = InfoSet.getPossibleTalks().Select(x => x.Key).ToList(); break; default: possiblePlays.Add("pass"); break; } } else { possiblePlays[0] = command; } foreach (string playCommand in possiblePlays) { RolloutGame playGame = game.Copy(); playGame.applyMove(playCommand); int moveValue = playGame.getNextPlayer().PlayGame(playGame, alpha, beta, depthLimit); if (moveValue > v) { v = moveValue; } if (v >= beta) { return(v); } if (v > alpha) { alpha = v; } } return(v); }