public override string ToString() { var averageStrategy = string.Join(";", calculateAverageStrategy()); var infoSet = InfoSet.ToString(); return(string.Format("{0} {1}", InfoSet, averageStrategy)); }
public override int PlayGame(PerfectInformationGame pig, int alpha, int beta, int depthLimit, int card = -1) { if (Sueca.UTILITY_FUNC == 2 && pig.IsAnyTeamWinning()) { return(pig.EvalGame2()); } if (pig.reachedDepthLimit(depthLimit) || pig.IsEndGame()) { return(pig.EvalGame1()); } int chosenCard; if (card != -1) { chosenCard = card; } else { chosenCard = InfoSet.RuleBasedDecision(); } Move move = new Move(Id, chosenCard); pig.ApplyMove(move); int value = pig.GetNextPlayer().PlayGame(pig, alpha, beta, depthLimit); pig.UndoMove(move); return(value); }
public void RawData_AllOpponentsCardsGiven_ReturnProperValue() { var commonPossibleCardsSet = new CardsSet(new[] { new Card(Rank.Jack, Color.Clubs), new Card(Rank.Queen, Color.Diamonds), }); CardsSet[] possibleCardsSets = { _playersCards, commonPossibleCardsSet, commonPossibleCardsSet.Clone(), }; CardsSet[] certainCardsSets = { new CardsSet(), new CardsSet(new[] { new Card(Rank.Ten,Color.Hearts) }), new CardsSet(new[] { new Card(Rank.Ace,Color.Hearts), new Card(Rank.Nine, Color.Hearts) }), }; var infoSet = new InfoSet( _playersCards, _playersCards, _opponentsIds, possibleCardsSets, certainCardsSets, _cardsLeft, 0, 0 ); var expected = ( _playersCards.Code, ( 0, (certainCardsSets[1] | new CardsSet(new[] { new Card(Rank.Queen, Color.Diamonds) })).Code, certainCardsSets[2].Code ) ); var result = infoSet.RawData; Assert.Equal(expected, result); }
public void RawData_NotEqualPossibleCardsSets_ReturnProperValue() { CardsSet[] possibleCardsSets = { _playersCards, new CardsSet(new[] { new Card(Rank.Ace,Color.Spades) }), new CardsSet(new[] { new Card(Rank.Ace,Color.Diamonds) }), }; CardsSet[] certainCardsSets = { new CardsSet(), new CardsSet(new[] { new Card(Rank.Ten,Color.Hearts) }), new CardsSet(new[] { new Card(Rank.Ace,Color.Hearts) }), }; var infoSet = new InfoSet( _playersCards, _playersCards, _opponentsIds, possibleCardsSets, certainCardsSets, _cardsLeft, 0, 0 ); var expected = ( _playersCards.Code, ( 0, (certainCardsSets[1] | new CardsSet(new[] { new Card(Rank.Ace, Color.Spades) })).Code, (certainCardsSets[2] | new CardsSet(new[] { new Card(Rank.Ace, Color.Diamonds) })).Code ) ); var result = infoSet.RawData; Assert.Equal(expected, result); }
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); }
/// <summary> /// 通过名称获取网站的信息 /// </summary> private InfoSet GetInfWithName(String name) { StreamReader reader = new StreamReader(App.RootPath + App.WebConfig, Encoding.UTF8); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(reader); reader.Close(); XmlElement root = xmlDocument.DocumentElement; XmlNodeList xnl = root.SelectNodes("/Configs/Web"); XmlNodeList cxnl = null; InfoSet loginInfSet = new InfoSet { name = name }; foreach (XmlNode i in xnl) { if (i.Attributes["name"].Value.Equals(name)) { cxnl = i.ChildNodes; loginInfSet.NeedLogin = i.Attributes["login"].Value.Equals("true"); loginInfSet.Compressed = i.Attributes["gzip"].Value.Equals("true"); loginInfSet.Verify = i.Attributes["needverifycode"].Value.Equals("true"); loginInfSet.CharSet = i.Attributes["charset"].Value; break; } } if (cxnl != null) { foreach (XmlNode i in cxnl) { switch (i.Attributes["type"].Value) { case "uri": loginInfSet.Uris.Add(i.Attributes["uri"].Value); break; case "action": loginInfSet.KeyValuePairs.Add(new KeyValuePair <string, string> (i.Attributes["name"].Value, i.Attributes["value"].Value)); break; case "verify": loginInfSet.VerifyCode = i.Attributes["value"].Value; break; case "idcode": loginInfSet.IdCodes = new KeyValuePair <string, string> (i.Attributes["name"].Value, i.Attributes["value"].Value); break; case "cookie": loginInfSet.Cookies.Add(new KeyValuePair <string, string> (i.Attributes["name"].Value, i.Attributes["value"].Value)); break; } } return(loginInfSet); } else { return(null); } }
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); }