diff --git a/Master Mind/AI.cs b/Master Mind/AI.cs index 2d54cc1..a6fcd65 100644 --- a/Master Mind/AI.cs +++ b/Master Mind/AI.cs @@ -33,12 +33,46 @@ namespace Master_Mind public static int[] ShittyGuess(Game.GameData game) { + int[] guess = new int[4]; + if (game.go == 0) { // RANDOM + + Random r = new Random(); + + guess[0] = r.Next(6); + guess[1] = r.Next(6); + guess[2] = r.Next(6); + guess[3] = r.Next(6); + + return guess; } - // LOOP thru + while (!IsThisValidGivenWhatIKnow(game, guess)) + { + if (++guess[0] >= 6) + { + guess[0] = 0; + + if (++guess[1] >= 6) + { + guess[1] = 0; + + if (++guess[2] >= 6) + { + guess[2] = 0; + + if (++guess[3] >= 6) + { + throw new Exception("UM WTF"); + } + } + } + } + } + + return guess; } public static bool IsThisValidGivenWhatIKnow(Game.GameData game, int[] guess) @@ -51,6 +85,7 @@ namespace Master_Mind { if ( + ((gDat[y] == 0) && (guess[y] == game.board[x, y])) || ((gDat[y] == 1) && (guess[y] != game.board[x, y])) || ((gDat[y] == 2) && (guess[y] == game.board[x, y])) ) @@ -58,6 +93,28 @@ namespace Master_Mind } } + for (int x = 0; x < game.go; x++) + { + int[] gDat = game.ContainsCalcIHateThis(x); + + for (int y = 0; y < 4; y++) + { + if (gDat[y] == 2 && !(guess.Contains(game.board[x, y]))) + return false; + } + } + + /*for (int x = 0; x < game.go; x++) + { + int[] gDat = game.ContainsCalcIHateThis(x); + + for (int y = 0; y < 4; y++) + { + if (gDat[y] == 0 && (guess.Contains(game.board[x, y]))) + return false; + } + }*/ + return true; } } diff --git a/Master Mind/Game.cs b/Master Mind/Game.cs index b6a2b0c..a8b391c 100644 --- a/Master Mind/Game.cs +++ b/Master Mind/Game.cs @@ -100,36 +100,46 @@ namespace Master_Mind Console.WriteLine("Loading..."); - GameData game = new GameData(); + int g = 0; - if (opt == 1) + for (int x = 0; x < 100; x++) { - Random rand = new Random(); + GameData game = new GameData(); - for (int i = 0; i < 4; i++) + if (opt == 1) { - int col = rand.Next(6); - - game.sequence[i] = col; + Random rand = new Random(); + + for (int i = 0; i < 4; i++) + { + int col = rand.Next(6); + + game.sequence[i] = col; + } } - } - else - { - Console.WriteLine("Please select your colors"); + else + { + Console.WriteLine("Please select your colors"); - return; + return; + } + + do + { + //game.AddRow(Render.GetColorInput()); + game.AddRow(AI.ShittyGuess(game)); + + Console.Clear(); + + Render.RenderBoard(game); + + //Console.ReadLine(); + + g++; + } while (game.won == 0); } - do - { - game.AddRow(Render.GetColorInput()); - - Console.Clear(); - - Render.RenderBoard(game); - - Console.ReadLine(); - } while (game.won == 0); + Console.WriteLine(((float)g / 100f).ToString()); } } } diff --git a/Master Mind/Render.cs b/Master Mind/Render.cs index 13c8a9e..063e62c 100644 --- a/Master Mind/Render.cs +++ b/Master Mind/Render.cs @@ -55,6 +55,14 @@ namespace Master_Mind } Console.WriteLine("\n"); + + for (int y = 0; y < 4; y++) + { + Console.BackgroundColor = Values.colors[board.sequence[y]]; + Console.Write(" "); + Console.BackgroundColor = ConsoleColor.Black; + Console.Write(" "); + } } public static int[] GetColorInput()