public override PlayerTask GetMove(SabberStoneCoreAi.POGame.POGame poGame) { List <PlayerTask> simulatedactions = new List <PlayerTask>(); simulatedactions.AddRange(poGame.CurrentPlayer.Options()); Dictionary <PlayerTask, SabberStoneCoreAi.POGame.POGame> sim = poGame.Simulate(simulatedactions); Dictionary <PlayerTask, SabberStoneCoreAi.POGame.POGame> .KeyCollection keyColl = sim.Keys; Dictionary <int, PlayerTask> scoresKeyPair = new Dictionary <int, PlayerTask>(); scoresKeyPair.Clear(); try { int maxScore = Int32.MinValue; int _score = 0; foreach (PlayerTask key in keyColl) { //Console.WriteLine(key); //Console.WriteLine("Player num -->>>>"+poGame.CurrentPlayer.PlayerId); //Console.WriteLine("SIM -->>>>"+sim[key]); if (sim[key] == null) { continue; } if (key.PlayerTaskType == PlayerTaskType.END_TURN) { _score = Int32.MinValue + 1; } else { _score = Score(sim[key], poGame.CurrentPlayer.PlayerId); } //Console.WriteLine(_score); if (!scoresKeyPair.ContainsKey(_score)) { scoresKeyPair.Add(_score, key); } if (_score > maxScore) { maxScore = _score; } } //Console.WriteLine("Played ==>> "+scoresKeyPair[maxScore]); return(scoresKeyPair[maxScore]); } catch { return(poGame.CurrentPlayer.Options()[Rnd.Next(poGame.CurrentPlayer.Options().Count)]); } }
public override PlayerTask GetMove(SabberStoneCoreAi.POGame.POGame poGame) { CurrentPoGame = poGame; ChangeStrategy(); List <PlayerTask> actions = poGame.CurrentPlayer.Options(); Dictionary <PlayerTask, POGame.POGame> resultedictionary = poGame.Simulate(actions); List <int> rewards = GetActionsRewards(actions, resultedictionary); return(actions[pickAction(rewards)]); }
public POGame.POGame Simulate(SabberStoneCoreAi.POGame.POGame game, PlayerTask option) { LinkedList <PlayerTask> options = new LinkedList <PlayerTask>(); options.AddLast(option); Dictionary <PlayerTask, SabberStoneCoreAi.POGame.POGame> dict = game.Simulate(options.ToList <PlayerTask>()); SabberStoneCoreAi.POGame.POGame simulatedPOGame = null; dict.TryGetValue(option, out simulatedPOGame); return(simulatedPOGame); }
public override PlayerTask GetMove(SabberStoneCoreAi.POGame.POGame poGame) { List <PlayerTask> simulatedactions = new List <PlayerTask>(); simulatedactions.AddRange(poGame.CurrentPlayer.Options()); Dictionary <PlayerTask, SabberStoneCoreAi.POGame.POGame> sim = poGame.Simulate(simulatedactions); Dictionary <PlayerTask, SabberStoneCoreAi.POGame.POGame> .KeyCollection keyColl = sim.Keys; foreach (PlayerTask key in keyColl) { //do something with simulated actions //in case an EndTurn was simulated you need to set your own cards //see POGame.prepareOpponent() for an example } return(poGame.CurrentPlayer.Options()[0]); }
public PlayerTask getBestTask(SabberStoneCoreAi.POGame.POGame poGame) { double bestScore = Double.MinValue; PlayerTask bestTask = SabberStoneCore.Tasks.PlayerTasks.EndTurnTask.Any(poGame.CurrentPlayer); List <PlayerTask> tasksToSimulate = poGame.CurrentPlayer.Options(); Dictionary <PlayerTask, SabberStoneCoreAi.POGame.POGame> simulation = poGame.Simulate(tasksToSimulate); foreach (PlayerTask task in tasksToSimulate) { double score = scoreTask(poGame, simulation[task]); if (task.PlayerTaskType == PlayerTaskType.END_TURN) { score = 0; } if (score > bestScore) { bestScore = score; bestTask = task; } } return(bestTask); }
public override PlayerTask GetMove(SabberStoneCoreAi.POGame.POGame poGame) { List <PlayerTask> simulatedactions = new List <PlayerTask>(); simulatedactions.AddRange(poGame.CurrentPlayer.Options()); try { Dictionary <PlayerTask, SabberStoneCoreAi.POGame.POGame> sim = poGame.Simulate(simulatedactions); Dictionary <PlayerTask, SabberStoneCoreAi.POGame.POGame> .KeyCollection keyColl = sim.Keys; //required for score keeping .. creates acnd cleares a dictionary Dictionary <int, PlayerTask> scoresKeyPair = new Dictionary <int, PlayerTask>(); scoresKeyPair.Clear(); //Console.WriteLine(poGame.PartialPrint()); foreach (PlayerTask p in simulatedactions) { //Console.WriteLine(p); } //Console.WriteLine("*********** after simulation ***********"); int maxScore = Int32.MinValue; int _score = 0; foreach (PlayerTask key in keyColl) { //Console.WriteLine(key); //Console.WriteLine("Player num -->>>>"+poGame.CurrentPlayer.PlayerId); //Console.WriteLine("SIM -->>>>"+sim[key]); if (sim[key] == null) { continue; } _score = Score(sim[key], poGame.CurrentPlayer.PlayerId); //Console.WriteLine(_score); if (!scoresKeyPair.ContainsKey(_score)) { scoresKeyPair.Add(_score, key); } if (_score > maxScore) { maxScore = _score; } } //Console.WriteLine(maxScore); return(scoresKeyPair[maxScore]); /** * foreach (PlayerTask key in keyColl) * { * * if (key.PlayerTaskType == PlayerTaskType.MINION_ATTACK) * { * //Console.WriteLine("minion!!"); * return key; * } * //do something with simulated actions * //in case an EndTurn was simulated you need to set your own cards * //see POGame.prepareOpponent() for an example * } * * foreach (PlayerTask key in keyColl) * { * if (key.PlayerTaskType == PlayerTaskType.PLAY_CARD) * { * //Console.WriteLine("Play!!"); * return key; * } * //do something with simulated actions * //in case an EndTurn was simulated you need to set your own cards * //see POGame.prepareOpponent() for an example * } * * */ foreach (PlayerTask key in keyColl) { } } catch { return(poGame.CurrentPlayer.Options()[Rnd.Next(poGame.CurrentPlayer.Options().Count)]); } }
public override PlayerTask GetMove(SabberStoneCoreAi.POGame.POGame poGame) { PlayerTask option; List <PlayerTask> options = poGame.CurrentPlayer.Options(); //當下所有可執行動作的List List <PlayerTask> sim = new List <PlayerTask>(); //建立要模擬動作的List int num1 = rnd.Next(options.Count); sim.Add(options[num1]); Console.WriteLine("-----------^-----------"); Console.WriteLine("-----------" + options[num1] + "----------"); poGame.Simulate(sim); //Socre_control(options[0]); //Console.WriteLine("得" + result + "分"); Console.WriteLine("-----------ˇ------------"); Console.WriteLine(); Console.WriteLine("共" + options.Count + "種選擇"); Console.WriteLine("選第" + num1 + "個"); result = 0; //初始化result sim.Clear(); /* * * POGame.POGame gameClone = poGame.getCopy(); * * List<PlayerTask> options2 = gameClone.CurrentPlayer.Options(); * * int num_2 = rnd.Next(options2.Count); * PlayerTask action = options[num_2]; * try * { * // Process fails as soon as opponent plays a card, so use simulate here * Dictionary<PlayerTask, POGame.POGame> dic = gameClone.Simulate(new List<PlayerTask> { action }); * gameClone = dic[action]; * * } * catch (Exception e) * { * //Debug.WriteLine("Exception during single game simulation"); * //Debug.WriteLine(e.StackTrace); * } * * * PlayerTask option_2; * * * * sim.Add(options2[num_2]); * sim.Add(options2[1]); * * * Console.WriteLine("-----------^-----------"); * Console.WriteLine("-----------" + options2[num_2] + "----------"); * gameClone.Simulate(sim); * //Socre_control(options_2[0]); * //Console.WriteLine("得" + result + "分"); * * * Console.WriteLine("-----------ˇ------------"); * Console.WriteLine(); * * Console.WriteLine("共" + options_2.Count + "種選擇"); * Console.WriteLine("選第" + num_2 + "個"); * * result = 0; //初始化result * sim.Clear(); * */ option = options[num1]; return(option); }
public override PlayerTask GetMove(SabberStoneCoreAi.POGame.POGame poGame) { //Rnd = new Random(); PlayerTask option; List <PlayerTask> options = poGame.CurrentPlayer.Options(); /* * POGame.POGame gameClone = poGame.getCopy();// * List<PlayerTask> new_options = gameClone.CurrentPlayer.Options();// * int num = new_options.Count-1; //第幾種 //sim.Add(); * PlayerTask action = new_options[num];// * * * Console.WriteLine("----------一開始有------------"); * foreach (PlayerTask a in new_options) * { * Console.WriteLine(a); * } * Console.WriteLine("----------一開始有------------"); * Console.WriteLine("共" + new_options.Count + "種選擇"); * Console.WriteLine(); * * * Console.WriteLine("-----------執行第" + num + "項後-----------"); * Dictionary<PlayerTask, POGame.POGame> dic = gameClone.Simulate(new List<PlayerTask> { action }); * Console.WriteLine("-----------執行第" + num + "項後-----------"); * Console.WriteLine(); * * gameClone = dic[action];//更新遊戲狀態 * * List<PlayerTask> newnew_options = gameClone.CurrentPlayer.Options(); * * * Console.WriteLine("----------最後有------------"); * foreach (PlayerTask a in newnew_options) * { * Console.WriteLine(a); * } * Console.WriteLine("----------最後有------------"); * Console.WriteLine("共" + newnew_options.Count + "種選擇"); * Console.WriteLine(); * * * option = options[0]; */ //Program.game_percentage(); Score.Score s = null; s = myScore; int r = Rnd.Next(options.Count); option = options[r]; // List<PlayerTask> sim = new List<PlayerTask>(); // sim.Add(option); //poGame.Simulate(sim); //result = my_Score(option); Dictionary <PlayerTask, POGame.POGame> dic = poGame.Simulate(new List <PlayerTask> { option }); s.Controller = dic[option].CurrentPlayer; int initialPlayer = poGame.CurrentPlayer.PlayerId; if (s.Controller.Opponent.Hero.Health < 1) { won_num++; } Console.WriteLine("目前贏" + won_num + "場"); // Console.WriteLine(s.Rate()); /* * for (int i = 0; i < options.Count; i++) * { * * * * Console.WriteLine("-----------^-----------"); * Console.WriteLine("-----------" + options[i] + "----------"); //列出該回合所有可能的行動 * * // result = my_Score(options[i]); * //is_change.Add(result); * Console.WriteLine("得" + s.Rate() + "分"); * Console.WriteLine("-----------ˇ------------"); * Console.WriteLine(); * * }*/ /* * foreach(int change in is_change) * { * Console.WriteLine(change); * } */ foreach (PlayerTask option1 in options) { Console.WriteLine(option1); } Console.WriteLine("共" + options.Count + "種選擇"); Console.WriteLine("選第" + r + "個"); return(option); }
public override PlayerTask GetMove(SabberStoneCoreAi.POGame.POGame poGame) { /* * List<PlayerTask> turnList = new List<PlayerTask>(); * PlayerTask option; * do * { * List<PlayerTask> options = poGame.CurrentPlayer.Options(); * option = options[Rnd.Next(options.Count)]; * poGame.Process(option); * turnList.Add(option); * } while (option.PlayerTaskType != PlayerTaskType.END_TURN); * * return turnList; */ List <PlayerTask> sim = new List <PlayerTask>(); PlayerTask option; PlayerTask BestMove; int BestScore = -10000000; int num = 0; //第幾種 List <PlayerTask> options = poGame.CurrentPlayer.Options(); //int r = Rnd.Next(options.Count); //option = options[r]; //sim.Add(option); BestMove = options[0]; //initialize /* * foreach (PlayerTask option1 in options) * { * Console.WriteLine(option1); * } */ for (int i = 0; i < options.Count; i++) { sim.Add(options[i]); Console.WriteLine("-----------^-----------"); Console.WriteLine("-----------" + options[i] + "----------"); //列出該回合所有可能的行動 poGame.Simulate(sim); Socre_control(options[i]); Console.WriteLine("得" + result + "分"); Console.WriteLine("-----------ˇ------------"); Console.WriteLine(); if (options[i].PlayerTaskType != PlayerTaskType.END_TURN && result > BestScore) { BestMove = options[i]; BestScore = result; num = i; } result = 0; //初始化result sim.Clear(); } Console.WriteLine("共" + options.Count + "種選擇"); option = BestMove; Console.WriteLine("選第" + num + "個"); BestScore = -10000000; //初始化BestScore BestMove = options[0]; //初始化BestMove return(option); }