private static void RunRobotMatch(int matches = 100) { int matchId = 1; var ui = Chat.GetUI(); ui.Send("Inserisci il nome del primo robot"); var strategyHome = ui.Get(); ui.Send("Inserisci il nome del secondo robot"); var strategyVisitor = ui.Get(); List <Tuple <int, int> > scores = new List <Tuple <int, int> >(); for (int i = 0; i < matches; i++) { var g = new BriscolaGame(new ItalianDeckFactory(), new PlayerFactory()); var runner = new GameRunner(g, ui, _strategyFactory); runner.InitializeRoboMatch(strategyHome, strategyVisitor, 4); var result = runner.Play(); scores.Add(result); } foreach (var score in scores) { ui.Send("MATCH " + matchId + ": " + score.Item1 + " - " + score.Item2); matchId++; } var team1Score = scores.Count(x => x.Item1 > 60) * 2 + scores.Count(x => x.Item1 == 60); var team2Score = scores.Count(x => x.Item2 > 60) * 2 + scores.Count(x => x.Item2 == 60); ui.Send("Squadra 1: " + team1Score); ui.Send("Squadra 2: " + team2Score); }
/// <summary> /// Gioca una singola partita e restituisce il risultato /// </summary> /// <param name="ui"></param> /// <param name="turnNumber"></param> /// <param name="homeStrategy"></param> /// <param name="visitorStrategy"></param> /// <returns>Ritorna /// 0 = pareggio /// 1 = vince <see cref="homeStrategy"/> /// 2 = vince <see cref="visitorStrategy"/> /// </returns> private int DoSingleMatch(IUserInterface ui, int turnNumber, IStrategy homeStrategy, IStrategy visitorStrategy) { IStrategy s1, s2; bool switched = turnNumber % 2 == 1; if (switched) { s1 = homeStrategy; s2 = visitorStrategy; } else { s2 = homeStrategy; s1 = visitorStrategy; } var g = new BriscolaGame(new ItalianDeckFactory(), new PlayerFactory()); var runner = new GameRunner(g, ui, _strategyFactory); runner.InitializeRoboMatch(s1.Name, s2.Name, 4); var result = runner.Play(); if (switched) { return(GetOutcome(result.Item1, result.Item2)); } else { return(GetOutcome(result.Item2, result.Item1)); } }
private static void RunRobotMatch(int matches) { int matchId = 1; var ui = Chat.GetUI(); var allStrategies = _strategyFactory.GetAllRobots().Select(s => s.Name).ToArray(); ui.Send("Robot disponibili:"); for (int i = 0; i < allStrategies.Length; i++) { ui.Send($" {i + 1} | {allStrategies[i]}"); } ui.Send(""); ui.Send(" 0 | Annulla"); ui.Send(""); var s1Choiche = ui.GetInt("Scegli il primo robot", null); var s2Choiche = ui.GetInt("Scegli il secondo robot", null); var strategyHome = allStrategies[s1Choiche - 1]; var strategyVisitor = allStrategies[s2Choiche - 1]; var numPlayers = ui.GetInt("Scegli il numero di giocatori (default = 4)", 4); var scores = new List <Tuple <int, int> >(); for (int i = 0; i < matches; i++) { var g = new BriscolaGame(new ItalianDeckFactory(), new PlayerFactory()); var runner = new GameRunner(g, ui, _strategyFactory); runner.InitializeRoboMatch(strategyHome, strategyVisitor, numPlayers); var result = runner.Play(); scores.Add(result); } foreach (var score in scores) { ui.Send("MATCH " + matchId + ": " + score.Item1 + " - " + score.Item2); matchId++; } var team1Score = scores.Count(x => x.Item1 > 60) * 2 + scores.Count(x => x.Item1 == 60); var team2Score = scores.Count(x => x.Item2 > 60) * 2 + scores.Count(x => x.Item2 == 60); ui.Send("Squadra 1: " + team1Score); ui.Send("Squadra 2: " + team2Score); }