コード例 #1
0
ファイル: WeightsTest.cs プロジェクト: ErikDonato/MyBot
        public void TestAddPercentToWeight()
        {
            //arrange
            var weights = new Weights()
            {
                RockWeight = 1,
                PaperWeight = 2,
                ScissorsWeight = 1,
                DynamiteWeight = 2,
                WaterWeight = 4
            };

            //act
            weights.AddPercentToWeight(Moves.Rock, .5);
            weights.AddPercentToWeight(Moves.Paper, .5);
            weights.AddPercentToWeight(Moves.Scissors, .1);
            weights.AddPercentToWeight(Moves.Dynamite, 1);
            weights.AddPercentToWeight(Moves.WaterBalloon, 2);

            //assert
            Assert.IsTrue(weights.RockWeight == 1.5);
            Assert.IsTrue(weights.PaperWeight == 3);
            Assert.IsTrue(weights.ScissorsWeight == 1.1);
            Assert.IsTrue(weights.DynamiteWeight == 4);
            Assert.IsTrue(weights.WaterWeight == 12);
        }
コード例 #2
0
ファイル: Helpers.cs プロジェクト: ErikDonato/MyBot
        public static Weights FindOptimallyRandomWeights(int ThrowValue, Weights TheirWeights)
        {
            Weights weights = new Weights();

            var something = (TheirWeights.DynamitePercent * .6) + (TheirWeights.RPSPercent * .4) + (TheirWeights.WaterWeight * .2);

            return weights;
        }
コード例 #3
0
ファイル: Strats.cs プロジェクト: ErikDonato/MyBot
 public static Move RandomWeighted(Random rand, Weights weights)
 {
     var pick = rand.NextDouble();
     double prevWeight = 0;
     if (pick <= (prevWeight += weights.RockPercent)) return Moves.Rock;
     if (pick <= (prevWeight += weights.PaperPercent)) return Moves.Paper;
     if (pick <= (prevWeight += weights.ScissorsPercent)) return Moves.Scissors;
     if (pick <= (prevWeight += weights.DynamitePercent)) return Moves.Dynamite;
     if (pick <= (prevWeight += weights.WaterPercent)) return Moves.WaterBalloon;
     throw new Exception("Something's wrong with RandomWeighted Yo.  pick=" + pick + ", but the WeightTotal=" + weights.WeightTotal);
 }
コード例 #4
0
ファイル: Helpers.cs プロジェクト: ErikDonato/MyBot
 public static Weights GetActualWeights(List<Move> moves)
 {
     var Weights = new Weights()
     {
         RockWeight = moves.FindAll(m => m.Equals(Moves.Rock)).Count,
         PaperWeight = moves.FindAll(m => m.Equals(Moves.Paper)).Count,
         ScissorsWeight = moves.FindAll(m => m.Equals(Moves.Scissors)).Count,
         DynamiteWeight = moves.FindAll(m => m.Equals(Moves.Dynamite)).Count,
         WaterWeight = moves.FindAll(m => m.Equals(Moves.WaterBalloon)).Count,
     };
     return Weights;
 }
コード例 #5
0
ファイル: MyBot.cs プロジェクト: ErikDonato/MyBot
        public MyBot()
        {
            _MyMoves = new List<Move>();
            _TheirMoves = new List<Move>();
            _ThrowValues = new List<int>();
            MyDynamiteUsed = 0;
            TheirDynamiteUsed = 0;

            MyActualWeights = new Weights();
            TheirActualWeights = new Weights();
            MyWeightsBySet = new List<List<Weights>>();
            TheirWeightsBySet = new List<List<Weights>>();
            MyPerceivedWeightsbyThrowValue = new List<Weights>();
            TheirPerceivedWeightsByThrowValue = new List<Weights>();
        }
コード例 #6
0
ファイル: WeightsTest.cs プロジェクト: ErikDonato/MyBot
        public void TestCalculatedPercents()
        {
            //arrange
            var weights = new Weights()
            {
                RockWeight = 1,
                PaperWeight = 2,
                ScissorsWeight = 1,
                DynamiteWeight = 2,
                WaterWeight = 4
            };

            //act

            //assert
            Assert.IsTrue(weights.RockPercent == .1);
            Assert.IsTrue(weights.PaperPercent == .2);
            Assert.IsTrue(weights.ScissorsPercent == .1);
            Assert.IsTrue(weights.DynamitePercent == .2);
            Assert.IsTrue(weights.WaterPercent == .4);
            Assert.IsTrue(weights.RPSPercent == .4);
        }
コード例 #7
0
ファイル: MyBot.cs プロジェクト: ErikDonato/MyBot
        public Weights SetWeights()
        {
            var Weights = new Weights();

            //TODO: this could get complicated
            //Figure base weights from TheirPerceivedWeights
            Weights.RockWeight = TheirPerceivedWeightsByThrowValue[ThisThrowValue - 1].ScissorsWeight + TheirPerceivedWeightsByThrowValue[ThisThrowValue - 1].WaterWeight;
            Weights.PaperWeight = TheirPerceivedWeightsByThrowValue[ThisThrowValue - 1].RockWeight + TheirPerceivedWeightsByThrowValue[ThisThrowValue - 1].WaterWeight;
            Weights.ScissorsWeight = TheirPerceivedWeightsByThrowValue[ThisThrowValue - 1].PaperWeight + TheirPerceivedWeightsByThrowValue[ThisThrowValue - 1].WaterWeight;
            Weights.DynamiteWeight = TheirPerceivedWeightsByThrowValue[ThisThrowValue - 1].RPSWeight;
            Weights.WaterWeight = TheirPerceivedWeightsByThrowValue[ThisThrowValue - 1].DynamiteWeight;

            //conserve dynamite
            if (ThisThrowValue == 1) Weights.DynamiteWeight = 0;    //don't throw dynamite if only worth 1 point.
            if (MyDynamiteUsed > 98) Weights.DynamiteWeight = 0;    //don't throw dynamite I don't have
            //don't throw dumb water
            if (TheirDynamiteUsed > 98) Weights.WaterWeight = 0;    //don't throw water if they don't have dynamite

            return Weights;
        }
コード例 #8
0
ファイル: MyBot.cs プロジェクト: ErikDonato/MyBot
        public Move MakeMove(IPlayer you, IPlayer opponent, GameRules rules)
        {
            _ThrowValues.Add(ThisThrowValue);
            if (you.NumberOfDecisions == 0)
            {
                //start of game, let's set it up yo!
                return Strats.RandomWeighted(new Random(), new Weights() { DynamiteWeight = 0, WaterWeight = 0, PaperWeight = 1, RockWeight = 1, ScissorsWeight = 1 });
            }

            Weights WeightsForThisThrow = new Weights();

            _MyMoves.Add(you.LastMove);
            _TheirMoves.Add(opponent.LastMove);

            if (you.LastMove == Moves.Dynamite) MyDynamiteUsed += 1;
            if (opponent.LastMove == Moves.Dynamite) TheirDynamiteUsed += 1;

            MyActualWeights = Helpers.GetActualWeights(_MyMoves);
            TheirActualWeights = Helpers.GetActualWeights(_TheirMoves);

            HarvestPerceivedWeightsByThrowValue();
            //not sure I care about this.
            /*for (int i = 5; i <= 100; i++)
                HarvestSets(you, opponent, i);
            */

            return Strats.RandomWeighted(new Random(), SetWeights());
        }