/// <summary> /// Generate a play action for current scene. /// </summary> /// <param name="scene">The scene.</param> /// <returns>The cards to be played.</returns> public RockAction GetPlayAction(RockScene scene) { // You can just return an null or empty list, which means ends turn. //// return null; //// Put your codes in here. RockSceneContext context = new RockSceneContext(scene); double bestScore = 0d; List <int> bestAction = null; Random r = new Random(); foreach (List <int> action in scene.PlayOptions) { double score = PlayActionScore.ComputeScore(context, action); score += r.NextDouble(); if (score >= bestScore) { bestScore = score; bestAction = action; } } if (bestAction != null) { return(RockAction.Create(bestAction)); } return(this.DefaultGetPlayAction(scene)); }
/// <summary> /// Generate a play action for current scene. /// </summary> /// <param name="scene">The scene.</param> /// <returns>The cards to be played.</returns> public RockAction GetPlayAction(RockScene scene) { this.tracer.Verbose(RockJsonSerializer.Serialize(scene)); try { if (string.IsNullOrEmpty(this.configuration.BotEndpoint)) { var robot = new Bot.RockBot(); var action = robot.GetPlayAction(scene); this.tracer.Verbose(RockJsonSerializer.Serialize(action)); return(action); } else { var apiClient = new RockApiClient(); var action = apiClient.Post <RockAction>($"{this.configuration.BotEndpoint}{RockConstants.DefaultBotPlayRelativePath}", scene); this.tracer.Verbose(RockJsonSerializer.Serialize(action)); return(action); } } catch (Exception e) { this.tracer.Error($"Unexpected Exception from Bot: {e}"); return(RockAction.Create()); } }
/// <summary> /// The default implementation of GetPlayAction /// </summary> /// <param name="scene">the scene</param> /// <returns>the cards to be played</returns> private RockAction DefaultGetPlayAction(RockScene scene) { if (scene.PlayOptions.Count == 0) { return(RockAction.Create()); } else { // this smart bot will randomly choose an play action. return(RockAction.Create(scene.PlayOptions[new Random().Next(0, scene.PlayOptions.Count)])); } }
public void TestRockActionFactoryMethods() { var action = RockAction.Create(new List <int>()); Assert.AreEqual(action.Version, 1); Assert.AreEqual(action.Objects.Count, 0); Assert.AreEqual(action.Slot, -1); action = RockAction.Create(new List <int>(), 2); Assert.AreEqual(action.Version, 1); Assert.AreEqual(action.Objects.Count, 0); Assert.AreEqual(action.Slot, 2); }
/// <summary> /// The default implementation of GetMulliganAction /// </summary> /// <param name="scene">the scene</param> /// <returns>the cards to be mulligan-ed</returns> private RockAction DefaultGetMulliganAction(RockScene scene) { List <int> cards = new List <int>(); foreach (RockCard card in scene.Self.Cards) { if (card.Cost >= 4) { cards.Add(card.RockId); } } return(RockAction.Create(cards)); }