public void LogOpponentMove(Move prediction, Move actual) { _totalPredictions++; if (prediction == actual) _successfullPredictions++; }
protected virtual void LogOpponentsPreviousMove(Move opponentsPreviousMove) { if (HasPredictionBeenMade) { Fitness.LogOpponentMove(CurrentPrediction, opponentsPreviousMove); } }
public Rule(List<Move> antecedents, Move consequent) { Antecedents = antecedents; Consequent = consequent; IsMatched = false; Weight = 0; }
public Move MakeMove(IPlayer you, IPlayer opponent, GameRules rules) { if (you.NumberOfDecisions == 0) { int pointsToWin = rules.PointsToWin; you.Log.AppendLine("v10"); _endGamePoints = pointsToWin - _endGameOffset; double calc; foreach (var odd in _tieStreakOddsOrig) { calc = odd.Value > 2 ? (odd.Value * .001 * pointsToWin) / (0.01 * rules.StartingDynamite) : odd.Value; _tieStreakOdds.Add(odd.Key, (int)Math.Round(calc, MidpointRounding.AwayFromZero)); you.Log.AppendLine(string.Format("{0}:{1}",odd.Key, _tieStreakOdds[odd.Key])); } } _hasDynamite = you.DynamiteRemaining > _dynamiteRemainingOffset; _opponentLastMove = opponent.LastMove; Move tieStreakMove = ProcessTieStreakLogic(you, opponent); Move moveStreakMove = ProcessMoveStreakLogic(you); Move endGameMove = ProcessEndGameLogic(opponent, rules); return endGameMove ?? tieStreakMove ?? moveStreakMove ?? GetMyMove(); }
public void AddHistory(Move myMove, Move opponentsMove) { if (myMove == null) throw new ArgumentNullException("myMove"); if (myMove == null) throw new ArgumentNullException("opponentsMove"); _myHistory.Insert(0, myMove); _opponentHistory.Insert(0, opponentsMove); }
public bool CanBeat(Move move) { if (!ValidMoves.Contains(GetType().Name)) return false; if (!ValidMoves.Contains(move.GetType().Name)) return true; return CanBeatLegalMove(move); }
/// <summary> /// Get the move that beats a specific move. /// </summary> /// <param name="theirMove"></param> /// <returns></returns> public static Move GetWinningMove(Move theirMove) { if (theirMove == Moves.Scissors) return Moves.Rock; if (theirMove == Moves.Rock) return Moves.Paper; if (theirMove == Moves.Paper) return Moves.Scissors; if (theirMove == Moves.WaterBalloon) return Moves.GetRandomMove(); return Moves.Dynamite; }
/* [TestMethod] public void PlayMatch(IRockPaperScissorsBot bot1, IRockPaperScissorsBot bot2) { //arrange int bot1Score = 0; int bot2Score = 0; while (bot1Score < 1000 && bot2Score < 1000) { break; //if (GetWinner(bot1.MakeMove(null, null, RockPaperScissorsPro.GameRules), bot2.MakeMove(null, null, GameRules)) bot1Score += 1; //else bot2Score += 1; } } */ /// <summary> /// true if move1, false if move2 /// </summary> /// <param name="move1"></param> /// <param name="move2"></param> /// <returns></returns> private bool GetWinner(Move move1, Move move2) { if ((move1 == Moves.Rock && (move2 == Moves.Scissors || move2 == Moves.WaterBalloon)) || (move1 == Moves.Paper && (move2 == Moves.Rock || move2 == Moves.WaterBalloon)) || (move1 == Moves.Scissors && (move2 == Moves.Paper || move2 == Moves.WaterBalloon)) || (move1 == Moves.Dynamite && (move2 == Moves.Rock || move2 == Moves.Paper || move2 == Moves.WaterBalloon)) || (move1 == Moves.WaterBalloon && move2 == Moves.Dynamite)) { return true; } else return false; }
private Move DetermineWinningMove(Move move1, Move move2) { if (move1 == move2) return null; if ( (move1 == Moves.Rock && (move2 == Moves.Scissors || move2 == Moves.WaterBalloon)) || (move1 == Moves.Paper && (move2 == Moves.Rock || move2 == Moves.WaterBalloon)) || (move1 == Moves.Scissors && (move2 == Moves.Paper || move2 == Moves.WaterBalloon)) || (move1 == Moves.Dynamite && move2 != Moves.WaterBalloon) || (move1 == Moves.WaterBalloon && move2 == Moves.Dynamite) ) return move1; return move2; }
private void AdjustRuleWeight(Move opponentsPreviousMove) { if (opponentsPreviousMove == null) return; var prediction = this.GetMatchedWithHightesWeight(); if (opponentsPreviousMove == prediction.Consequent) { prediction.IncrementWeight(); } else { prediction.DecrementWeight(); var shouldHaveFired = Table.GetMatchedConsequent(opponentsPreviousMove); shouldHaveFired.IncrementWeight(); } }
public void AddPercentToWeight(Move theMove, double Percent) { if (theMove == Moves.Rock) RockWeight += (RockWeight * Percent); else if (theMove == Moves.Paper) PaperWeight += (PaperWeight * Percent); else if (theMove == Moves.Scissors) ScissorsWeight += (ScissorsWeight * Percent); else if (theMove == Moves.Dynamite) DynamiteWeight *= (1 + Percent); else if (theMove == Moves.WaterBalloon) WaterWeight *= (1 + Percent); }
protected abstract bool CanBeatLegalMove(Move move);
protected override void LogOpponentsPreviousMove(Move opponentsPreviousMove) { base.LogOpponentsPreviousMove(opponentsPreviousMove); AdjustRuleWeight(opponentsPreviousMove); }
private Move ProcessEndGameLogic(IPlayer opponent, GameRules rules) { if (opponent.Points > _endGamePoints && _hasDynamite) { if(Moves.GetRandomNumber(2) == 0 && _lastEndGameThrow != Moves.Dynamite) { _lastEndGameThrow = Moves.Dynamite; return ThrowDynamite(); } else { _lastEndGameThrow = null; } } return null; }
public Rule GetMatchedConsequent(Move consequent) { return GetMatched().Where(r => r.Consequent == consequent).FirstOrDefault(); }
public void AddOneToWeight(Move theMove) { if (theMove == Moves.Rock) RockWeight += 1; else if (theMove == Moves.Paper) PaperWeight += 1; else if (theMove == Moves.Scissors) ScissorsWeight += 1; else if (theMove == Moves.Dynamite) ScissorsWeight += 1; else if (theMove == Moves.WaterBalloon) WaterWeight += 1; }
private static Rule RuleFrom(Move antecedent1, Move antecedent2, Move consequent) { return new Rule(new List<Move> { antecedent1, antecedent2 }, consequent); }
private void UpdatePlayerLastMove(TestPlayer player, Move move) { player.LastMove = move; }