/// <summary> /// Look for Move patterns, where patterns can be of 2 to 5 elements. /// Returns the move to play against opponent according to the most probable move played. /// </summary> /// <returns>one of the two winning moves</returns> public override Move Play() { if (moveCount == 0) // when no moves has been played yet { return(RandomMove()); } WinningScenario mostLikely = null; if (moveCount >= 10 && (mostLikely = FindPattern()) != null) // if there is a pattern, we return the move to play winning scenario according to that pattern { return(MoveToPlay(mostLikely)); } else if (moveCount >= 20 && (mostLikely = FindPattern()) != null) { return(MoveToPlay(mostLikely)); } else if (moveCount >= 30 && (mostLikely = FindPattern()) != null) { return(MoveToPlay(mostLikely)); } else if (moveCount >= MOVEBUFFERSIZE && (mostLikely = FindPattern()) != null) { return(MoveToPlay(mostLikely)); } foreach (WinningScenario scenario in winningScenarios) { if (mostLikely == null || mostLikely.Probability < scenario.Probability) // if there is no pattern, return the counter of the most frequent move the opponent will play next { mostLikely = scenario; } } return(MoveToPlay(mostLikely)); }
/// <summary> /// Find the opponent's favourite move based off the weighted average and probability of moves played /// </summary> private void FindFavourite(Move opponentMove) { WinningScenario favouriteMove = null; if (moveCount >= 10) // need to observe at least 10 moves and use the accumulated probabilities of the moves played { foreach (WinningScenario scenario in winningScenarios) { if (favouriteMove == null || this.winningScenarios[(int)opponentMove].Probability < scenario.Probability) { favouriteMove = scenario; scenario.Weight = 0.15f; } } favouriteMove.Weight = 0.4f; } }
/// <summary> /// Look for Move patterns, where patterns can be of 2 to 5 elements /// Returns the move to play against opponent according to the most probable move played /// </summary> /// <returns>one of the two winning moves</returns> public override Move Play() { if (moveCount == 0) // no moves played yet { return(RandomMove()); } WinningScenario mostLikely = null; if (moveCount >= 10 && (mostLikely = FindPattern()) != null) // if there is a pattern, we return the move to play winning scenario according to that pattern { return(Game.SeededRandom.Next() % 2 == 0 ? mostLikely.FirstMoveToPlay : mostLikely.SecondMoveToPlay); } foreach (WinningScenario scenario in winningScenarios) { if (mostLikely == null || mostLikely.Probability < scenario.Probability) // if there is no pattern, return the counter of the most frequent move the opponent will play next { mostLikely = scenario; } } return(Game.SeededRandom.Next() % 2 == 0 ? mostLikely.FirstMoveToPlay : mostLikely.SecondMoveToPlay); // pick one of the two moves to counter (should make it into a function) }
/// <summary> /// Picks between the two possible counter moves to play against the opponent /// </summary> /// <param name="counterMove"></param> /// <returns></returns> private Move MoveToPlay(WinningScenario counterMove) { return(Game.SeededRandom.Next() % 2 == 0 ? counterMove.FirstMoveToPlay : counterMove.SecondMoveToPlay); }