public override Move Play() { //Console.WriteLine(playCount); playCount++; /* * Move bestMove = Move.Rock; * if (!prev.HasValue) * { * return Move.Rock; * } * switch (bestMove) * { * case Move.Rock; * case Move.Scissors; * return Move.Spock; * case Move.Paper; * case Move.Lizard; * return Move.Scissors; * case Move.Spock; * return Move.Lizard; * default; * return Move.Lizard; * * * } */ if (upgradeAI == false) { //Console.WriteLine(playCount); //if(rockCount > paperCount ? rockCount : (rockCount > paperCount) ? rockCount : (paperCount > scissorsCount) ? rockCount : (rockCount > spockCount) ? rockCount : (rockCount > lizardCount) ? true : false) // { // newCount = rockCount; // } // total = (rockMax + paperMax + scissorMax + spockMax + lizardMax) / 2; //Console.WriteLine(newCount); if (circle == false) { Observe(enemy);//Get enemy, play normal AI } if (normal == false) //Will stop when normal Ai is true, { CircleCheck(enemy); //Check if circular AI, will overwrite previous enemy. After 5 battles it will determine it's a normal AI or not. } if (circle == false) //When it's not circular Ai, will check for spam.Wont play anything unless 5 in a row. { SpamCheck(enemy); } EnemyCounter(enemy); return(playMove); } if (upgradeAI == true)//My normal Ai but different move rates. { // Console.WriteLine("Upgrade ai being called......"); //Console.WriteLine("CURRENT ENEMY ROLLS " +); upgradeCount++; if (rockMax > paperMax && rockMax > scissorMax && rockMax > spockMax && rockMax > lizardMax && !upgradeRoll) { //Console.WriteLine("MOST ROCKS"); //scissorMax = 1; //lizardMax = 1; rockMax *= 10; //rockMax + 100;//Plays paper // spockMax *= 5;//Plays Scissors upgradeRoll = true; total = (rockMax + paperMax + scissorMax + spockMax + lizardMax); //Console.WriteLine("MAX ROCKS : " + rockMax + "MAX PAPER : " + (rockMax + paperMax) + "MAX SCISSORS : " + (rockMax + paperMax + scissorMax) + "MAX SPOCK : " + (rockMax + paperMax + scissorMax + spockMax) + "MAX LIZARD : " + (rockMax + paperMax + scissorMax + spockMax + lizardMax) + " TOTAL " + total); } else if (paperMax > rockMax && paperMax > scissorMax && paperMax > spockMax && paperMax > lizardMax && !upgradeRoll) { //Console.WriteLine("MOST PAPERS"); //rockMax = 1; //spockMax = 1; paperMax *= 10;// paperMax + 100;//Plays scissors // lizardMax *= 5; upgradeRoll = true; total = (rockMax + paperMax + scissorMax + spockMax + lizardMax); //Console.WriteLine("MAX ROCKS : " + rockMax + "MAX PAPER : " + (rockMax + paperMax) + "MAX SCISSORS : " + (rockMax + paperMax + scissorMax) + "MAX SPOCK : " + (rockMax + paperMax + scissorMax + spockMax) + "MAX LIZARD : " + (rockMax + paperMax + scissorMax + spockMax + lizardMax) + " TOTAL " + total); } else if (scissorMax > rockMax && scissorMax > paperMax && scissorMax > spockMax && scissorMax > lizardMax && !upgradeRoll) { //Console.WriteLine("MOST SCISSORS"); scissorMax *= 10;// scissorMax + 100;//Plays Spock // rockMax *= 5; // paperMax = 1; //lizardMax = 1; upgradeRoll = true; total = (rockMax + paperMax + scissorMax + spockMax + lizardMax); //Console.WriteLine("MAX ROCKS : " + rockMax + "MAX PAPER : " + (rockMax + paperMax) + "MAX SCISSORS : " + (rockMax + paperMax + scissorMax) + "MAX SPOCK : " + (rockMax + paperMax + scissorMax + spockMax) + "MAX LIZARD : " + (rockMax + paperMax + scissorMax + spockMax + lizardMax) + " TOTAL " + total); } else if (spockMax > rockMax && spockMax > paperMax && spockMax > scissorMax && spockMax > lizardMax && !upgradeRoll) { //Console.WriteLine("MOST SPOCKS"); spockMax *= 10;// spockMax + 100;//Plays Lizard // paperMax *= 5; // scissorMax = 1; //rockMax = 1; upgradeRoll = true; total = (rockMax + paperMax + scissorMax + spockMax + lizardMax); //Console.WriteLine("MAX ROCKS : " + rockMax + "MAX PAPER : " + (rockMax + paperMax) + "MAX SCISSORS : " + (rockMax + paperMax + scissorMax) + "MAX SPOCK : " + (rockMax + paperMax + scissorMax + spockMax) + "MAX LIZARD : " + (rockMax + paperMax + scissorMax + spockMax + lizardMax) + " TOTAL " + total); } else if (lizardMax > rockMax && lizardMax > paperMax && lizardMax > scissorMax && lizardMax > spockMax && !upgradeRoll) { //Console.WriteLine("MOST LIZARDS"); lizardMax *= 10;// lizardMax + 100;//Plays Rock //scissorMax *= 5; // spockMax = 1; // paperMax = 1; upgradeRoll = true; total = (rockMax + paperMax + scissorMax + spockMax + lizardMax); //Console.WriteLine("MAX ROCKS : " + rockMax + "MAX PAPER : " + (rockMax + paperMax) + "MAX SCISSORS : " + (rockMax + paperMax + scissorMax) + "MAX SPOCK : " + (rockMax + paperMax + scissorMax + spockMax) + "MAX LIZARD : " + (rockMax + paperMax + scissorMax + spockMax + lizardMax) + " TOTAL " + total); } //Console.WriteLine("We're at upgraded AI " + upgradeCount); // Console.WriteLine("The number of playcount reached. " + playCount); //Rock Higher than paper, if so, is Rock higher then scissors?, if so, rock higher then spock? if so is rock higher than lizard? then rock, else.... liz //int v = rockCount > paperCount ? (rockCount > scissorsCount ? (rockCount > spockCount ? ((rockCount > lizardCount ? rockCount : lizardCount) : spockCount//(rockCount > lizardCount ? rockCount : lizardCount) : scissorsCount) : paperCount; int roll = ran.Next((total + 1)); // Console.WriteLine("\n\nNUMBER ROLLED" + roll); if (roll >= 0 && roll <= (rockMax)) { // Console.WriteLine("Beating ROCK"); playMove = Move.Paper; // Console.WriteLine("Playing " + playMove); return(playMove); } else if (roll > (rockMax) && roll <= (rockMax + paperMax)) { // Console.WriteLine("Beating PAPER"); playMove = Move.Scissors; // Console.WriteLine("Playing " + playMove); return(playMove); } else if (roll > (rockMax + paperMax) && roll <= (rockMax + paperMax + scissorMax)) { // Console.WriteLine("Beating SCISSORS"); playMove = Move.Spock; // Console.WriteLine("Playing " + playMove); return(playMove); } else if (roll > (rockMax + paperMax + scissorMax) && roll <= (rockMax + paperMax + scissorMax + spockMax)) { // Console.WriteLine("Beating SPOCK"); playMove = Move.Lizard; // Console.WriteLine("Playing " + playMove); return(playMove); } else if (roll > (rockMax + paperMax + scissorMax + spockMax) && roll <= (rockMax + paperMax + scissorMax + spockMax + lizardMax)) { // Console.WriteLine("Beating LIZARD"); playMove = Move.Rock; // Console.WriteLine("Playing " + playMove); return(playMove); } else { Console.WriteLine("Random MOve sent"); return(RandomMove()); } //Console.WriteLine("Number rolled : " + roll); //if (upgradeCount == 66) //{ // upgradeAI = false; // upgradeCount = 0; // } } //Console.WriteLine("MOVE IM ABOUT TO PLAY IS OUT OF LOOP " + playMove); return(playMove);//RandomMove(); //Check if it's between 0 and 5. if true, then you add it inside the list. }
public override void Observe(Move oppo) { a = oppo; b.Add(oppo); }
private void CircleCheck(Move enemy) { // Stack<Move> myS = new Stack<Move>(); // myS.Push(enemy); // myS.Peek(); if (check == true && !upgradeAI)//Checking the circle. { if (enemy == Move.Scissors && lastEnemyMove == Move.Spock) { // Console.WriteLine("Calling SPOCK in CIRCULAR AI"); playMove = enemy; // Console.WriteLine("MY MOVE IS " + playMove); circleCount++; } else if (enemy == Move.Paper && lastEnemyMove == Move.Scissors) { // Console.WriteLine("Calling scissors in CIRCULAR AI"); playMove = enemy; // Console.WriteLine("MY MOVE IS " + playMove); circleCount++; } else if (enemy == Move.Rock && lastEnemyMove == Move.Paper) { //Console.WriteLine("Calling PAPER in CIRCULAR AI"); playMove = enemy; // Console.WriteLine("MY MOVE IS " + playMove); circleCount++; } else if (enemy == Move.Lizard && lastEnemyMove == Move.Rock) { //Console.WriteLine("Calling ROCK in CIRCULAR AI"); playMove = enemy; //playMove = Move.Rock; //Console.WriteLine("MY MOVE IS " + playMove); circleCount++; } else if (enemy == Move.Spock && lastEnemyMove == Move.Lizard) { //Console.WriteLine("Calling LIZARD in CIRCULAR AI"); playMove = enemy; //playMove = Move.Lizard; //Console.WriteLine("MY MOVE IS " + playMove); circleCount++; } else { // Console.WriteLine("Circle has been reset or not found."); circleCount = 0; normalCount--; circle = false; if (normalCount <= -5) { // Console.WriteLine("AI HAS BEEN CONFIRMED NORMAL"); normal = true; } playMove = lastEnemyMove; } } lastEnemyMove = enemy; //Store the last enemy move. if (check == false) //Play this when initialised. { playMove = Move.Spock; } check = true; //Checking for circular shall commence next battle. if (circleCount >= 5 && circle == false) //Will say if circle Ai has been found. { // Console.WriteLine("CIRCLE DETECTED"); circle = true; } }
private void SpamCheck(Move enemy) { if (!upgradeAI) { if (enemy == Move.Rock)//Checking variable value. { // rockCount++; constRock += 1; constPaper = 0; constScissors = 0; constLizard = 0; constSpock = 0; } else if (enemy == Move.Paper) { //paperCount++; constPaper += 1; constRock = 0; constScissors = 0; constLizard = 0; constSpock = 0; } else if (enemy == Move.Scissors) { //scissorsCount++; constScissors += 1; constRock = 0; constPaper = 0; constLizard = 0; constSpock = 0; } else if (enemy == Move.Spock) { //spockCount++; constSpock += 1; constRock = 0; constPaper = 0; constScissors = 0; constLizard = 0; } else if (enemy == Move.Lizard) { //lizardCount++; constLizard += 1; constRock = 0; constPaper = 0; constScissors = 0; constSpock = 0; } else { //Console.WriteLine("Weird move detected, Played random AI (TACS)"); playMove = RandomMove(); } //Check if spams only one move. if (constRock >= 7)//Checking variable value. When above 5 it should play this move. { //Console.WriteLine("SPAMMER DETECTED"); playMove = Move.Paper; spam = true; } if (constPaper >= 7)//Checking variable value. When above 5 it should play this move. { //Console.WriteLine("SPAMMER DETECTED"); playMove = Move.Scissors; spam = true; } if (constScissors >= 7)//Checking variable value. When above 5 it should play this move. { // Console.WriteLine("SPAMMER DETECTED"); playMove = Move.Spock; spam = true; } if (constSpock >= 7)//Checking variable value. When above 5 it should play this move. { //Console.WriteLine("SPAMMER DETECTED"); playMove = Move.Lizard; spam = true; } if (constLizard >= 7)//Checking variable value. When above 5 it should play this move. { // Console.WriteLine("SPAMMER DETECTED"); playMove = Move.Scissors; spam = true; } if (constRock < 7 && constPaper < 7 && constScissors < 7 && constSpock < 7 && constLizard < 7) { spam = false; } } }
Move RandomPair(Move move1, Move move2) { return(Game.SeededRandom.NextDouble() < 0.5 ? move1 : move2); }
public override void Observe(Move opponentMove) { //opponentLastMove[count++] = (int)opponentMove; oppMove = opponentMove; //Console.WriteLine($"opponent played {opponentLastMove}"); }
public void RecordShakespeare(Move playedMove) { ssOpSeq += (int)playedMove; }
private void SpamCheck(Move enemy) { if (enemy == Move.Rock) { b1++; c1 += 1; c2 = 0; c3 = 0; c4 = 0; c5 = 0; } else if (enemy == Move.Paper) { b2++; c2 += 1; c1 = 0; c3 = 0; c4 = 0; c5 = 0; } else if (enemy == Move.Scissors) { b3++; c3 += 1; c1 = 0; c2 = 0; c4 = 0; c5 = 0; } else if (enemy == Move.Spock) { b5++; c5 += 1; c1 = 0; c2 = 0; c3 = 0; c4 = 0; } else if (enemy == Move.Lizard) { b4++; c4 += 1; c1 = 0; c2 = 0; c3 = 0; c5 = 0; } else { Console.WriteLine("Weird move detected, Played random AI (TACS)"); g1 = RandomMove(); } if (c1 > 5) { g1 = Move.Paper; i = true; } if (c2 > 5) { g1 = Move.Scissors; i = true; } if (c3 > 5) { g1 = Move.Spock; i = true; } if (c5 > 5) { g1 = Move.Lizard; i = true; } if (c4 > 5) { g1 = Move.Scissors; i = true; } if (c1 < 5 && c2 < 5 && c3 < 5 && c5 < 5 && c4 < 5) { i = false; } }
public void RecordMarkov(Move prePrevious, Move previous, Move current) { markovData[(int)prePrevious, (int)previous, (int)current]++; }
public override void Observe(Move opponentMove) { RecordMarkov(opponentSecondLastplayedMove, opponentLastplayedMove, opponentMove); RecordShakespeare(opponentMove); opponentSequence += (int)opponentMove; playedGames++; if (opponentLastplayedMove == opponentMove) { opponentLastplayedMoveAgain++; } else { opponentLastplayedMoveAgain = 0; //inQueue = true; } opponentSecondLastplayedMove = opponentLastplayedMove; opponentLastplayedMove = opponentMove; #region PreviousProject //if (opponentMove < 0) //{ // Console.WriteLine(); //} #region QTYWINLOST if (WonLast(lastplayedMove, opponentMove)) { wonLast = true; qtyWon++; wonInRow++; lostInRow = 0; //Console.WriteLine($"W:{qtyWon} WIR:{wonInRow}"); } else { wonLast = false; qtyLost++; lostInRow++; wonInRow = 0; //Console.WriteLine($"L:{qtyLost} LIR:{lostInRow}"); } #endregion opponentMoves.Add(opponentMove); #region CALC_PERCENTAGE if (opponentMove >= 0) { moveQty[(int)opponentMove]++; playermoveQty[(int)lastplayedMove]++; SetPercentage(opponentMove); playerMoves.Add(lastplayedMove); SetPlayerPercentage(lastplayedMove); GetHighestPercentageMove(); } #endregion int minDist = MinDistance(); chosenMove = GetCounterMove(opponentMove - minDist); if (playedGames >= 19) { opponentSequence2 += (int)opponentMove; if (int.Parse(opponentSequence[sequenceIndex].ToString()) == (int)opponentMove) { inQueue = false; chosenMove = GetCounterMove((Move)int.Parse(opponentSequence[++sequenceIndex].ToString())); } else { inQueue = false; chosenMove = GetCounterFavMove(); sequenceIndex = 0; if (!wonLast) { int index = 0; int sequenceLenght = 15; if (opponentSequence2.Length > sequenceLenght) { string inRow5 = opponentSequence2.Remove(0, opponentSequence2.Length - sequenceLenght); if (opponentSequence.Contains(inRow5)) { index = opponentSequence.IndexOf(inRow5); if (index > sequenceLenght) { index = 0; } } } sequenceIndex = index + sequenceLenght; if (int.Parse(opponentSequence[sequenceIndex].ToString()) == (int)opponentMove) { inQueue = false; chosenMove = GetCounterMove((Move)int.Parse(opponentSequence[++sequenceIndex].ToString())); } } } } if (qtyLost > 20 && !wonLast || qtyLost < 40) { inQueue = false; chosenMove = GetCounterFavMove(); } if (IsItCircular()) { inQueue = false; chosenMove = opponentMove; } #endregion inQueue = false; if (playedGames <= 20) { ssIndex = FindSS(); chosenMove = GetCounterMove((Move)int.Parse(ssConverted[ssIndex++].ToString())); ssFound = true; if (ssIndex >= ssConverted.Length) { ssIndex = 0; } } else { chosenMove = GetCounterMove((Move)int.Parse(ssConverted[ssIndex].ToString())); ssIndex++; if (ssIndex >= ssConverted.Length) { ssIndex = 0; } } if (qtyLost > 30 && playedGames > 30) { chosenMove = GetCounterMove(HighestMarkov(opponentSecondLastplayedMove, opponentLastplayedMove)); } else { ssIndex = FindSS(); chosenMove = GetCounterMove((Move)int.Parse(ssConverted[ssIndex].ToString())); } }
public override void Observe(Move opponentMove) { a = opponentMove; b.Add(a); }
public WinningScenario(Move opponentMove, Move firstMoveToPlay, Move secondMoveToPlay) : this() { this.OpponentMove = opponentMove; this.FirstMoveToPlay = firstMoveToPlay; this.SecondMoveToPlay = secondMoveToPlay; }
/// <summary> /// Observe opponent's moves and increment the probability of that move played. /// Store the move in the circular array. /// </summary> /// <param name="opponentMove"></param> public override void Observe(Move opponentMove) { this.moveCount++; // for every opponent move played, increase its probability this.winningScenarios[(int)opponentMove].Probability++; recentMoves.AddElement(opponentMove); }
/// <summary> /// Observe the move of the opponent in the last round. Saves that move /// </summary> /// <param name="opponentMove"></param> public override void Observe(Move opponentMove) { OpponentMoves.Add((CurrentRound - 1), opponentMove); }
/// <summary> /// Actualize the counts of the moves /// </summary> private void RefreshCounts() { MovesCount.Clear(); foreach (var round in OpponentMoves.Keys) { Move move = OpponentMoves[round]; switch (move) { case Move.Scissors: if (MovesCount.ContainsKey(Move.Scissors)) { MovesCount[Move.Scissors]++; } else { MovesCount.Add(Move.Scissors, 1); } break; case Move.Rock: if (MovesCount.ContainsKey(Move.Rock)) { MovesCount[Move.Rock]++; } else { MovesCount.Add(Move.Rock, 1); } break; case Move.Paper: if (MovesCount.ContainsKey(Move.Paper)) { MovesCount[Move.Paper]++; } else { MovesCount.Add(Move.Paper, 1); } break; case Move.Lizard: if (MovesCount.ContainsKey(Move.Lizard)) { MovesCount[Move.Lizard]++; } else { MovesCount.Add(Move.Lizard, 1); } break; case Move.Spock: if (MovesCount.ContainsKey(Move.Spock)) { MovesCount[Move.Spock]++; } else { MovesCount.Add(Move.Spock, 1); } break; } } }