/// <summary> /// Picks a random place for the Baron that /// 1. doesn't impact the current player /// 2. does impact another player /// 3. twice as likely to Block a City vs. Block a settlement /// </summary> private async void OnPickRandomBaron(object sender, RoutedEventArgs e) { if (GameState != GameState.WaitingForRoll && GameState != GameState.WaitingForNext && GameState != GameState.MustMoveBaron) { return; } PlayerGameModel playerGameData = CurrentPlayer.GameData; if (playerGameData.MovedBaronAfterRollingSeven != false && playerGameData.PlayedKnightThisTurn) // not eligible to move baron { return; } List <Target> targetList = PickBaronVictim(true); if (targetList.Count == 0) { MessageDialog dlg = new MessageDialog("I can't seem to be able to find a good candidate.\nFigure it out yourself."); await dlg.ShowAsync(); return; } Random rand = new Random((int)DateTime.Now.Ticks); int index = rand.Next(targetList.Count); Target target = targetList[index]; CatanAction action = CatanAction.PlayedKnight; TargetWeapon weapon = TargetWeapon.Baron; if (GameState == GameState.MustMoveBaron) { action = CatanAction.AssignedBaron; } await AssignBaronOrKnight(target.Player, target.Tile, weapon, action, LogType.Normal); }
/// <summary> /// tries to be smart about where to place the baron /// 1. if Dodgy is playing (since he's always Red...) be sure and put it on him /// 2. pick the one with the most resource generating potential /// 3. if the highscore less than 5, try to block brick /// 5. if the highscore >=5, try to block Ore /// </summary> private async void OnPickOptimalBaron(object sender, RoutedEventArgs e) { if (GameState != GameState.WaitingForRoll && GameState != GameState.WaitingForNext && GameState != GameState.MustMoveBaron) { return; } PlayerGameModel playerGameData = CurrentPlayer.GameData; if (playerGameData.MovedBaronAfterRollingSeven != false && playerGameData.PlayedKnightThisTurn) // not eligible to move baron { return; } List <Target> targetList = PickBaronVictim(true); if (targetList.Count == 0) { MessageDialog dlg = new MessageDialog("I can't seem to be able to find a good candidate.\nFigure it out yourself."); await dlg.ShowAsync(); return; } // // Get the high score // we assume that if the high score is < 6 then we are in the expansion phase of the game int highScore = 0; foreach (var p in SavedAppState.Players) { if (p.GameData.Score > highScore) { highScore = p.GameData.Score; } } targetList.Sort((s1, s2) => s2.ResourcePotential - s1.ResourcePotential); Target target = null; int most = targetList[0].ResourcePotential; ResourceType[] orderedListOfResources = null; if (highScore < 6) { orderedListOfResources = new ResourceType[] { ResourceType.Brick, ResourceType.Wood, ResourceType.Wheat, ResourceType.Sheep, ResourceType.Ore }; } else { orderedListOfResources = new ResourceType[] { ResourceType.Ore, ResourceType.Wheat, ResourceType.Sheep, ResourceType.Brick, ResourceType.Wood }; } // // if somebody has 9 points, remove all options with player score < 9 if (highScore == 9) { for (int i = targetList.Count - 1; i >= 0; i--) { if (targetList[i].Player.GameData.Score < 9) { targetList.RemoveAt(i); } } } if (targetList.Count == 0) { MessageDialog dlg = new MessageDialog("I can't seem to be able to find a good candidate.\nFigure it out yourself."); await dlg.ShowAsync(); return; } List <Target> topList = new List <Target>(); int mostPotential = targetList[0].ResourcePotential; foreach (var t in targetList) { if (t.ResourcePotential > mostPotential - .1) { topList.Add(t); } else { break; // it is an ordered list } } Random rand = new Random((int)DateTime.Now.Ticks); target = topList[rand.Next(topList.Count)]; CatanAction action = CatanAction.PlayedKnight; TargetWeapon weapon = TargetWeapon.Baron; if (GameState == GameState.MustMoveBaron) { action = CatanAction.AssignedBaron; } await AssignBaronOrKnight(target.Player, target.Tile, weapon, action, LogType.Normal); }