From 60ce786b37971ef18826e485f065befe3ab573dc Mon Sep 17 00:00:00 2001 From: AUnicornWithNoLife <55228370+AUnicornWithNoLife@users.noreply.github.com> Date: Thu, 25 May 2023 13:07:02 +0100 Subject: [PATCH] began AI --- Master Mind/AI.cs | 64 +++++++++++++++++++++++++++++++++++++++++++ Master Mind/Render.cs | 4 +-- 2 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 Master Mind/AI.cs diff --git a/Master Mind/AI.cs b/Master Mind/AI.cs new file mode 100644 index 0000000..2d54cc1 --- /dev/null +++ b/Master Mind/AI.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Master_Mind +{ + internal class AI + { + public static int[] Guess(Game.GameData game) + { + int[] guess = new int[4]; + + for (int i = 0; i < 4; i++) + guess[i] = -1; + + for (int x = 0; x < game.go; x++) + { + int[] stat = game.ContainsCalcIHateThis(x); + + for (int y = 0; y < 4; y++) + { + if (stat[y] == 1) + { + guess[y] = game.board[x, y]; + } + } + } + + return guess; + } + + public static int[] ShittyGuess(Game.GameData game) + { + if (game.go == 0) + { + // RANDOM + } + + // LOOP thru + } + + public static bool IsThisValidGivenWhatIKnow(Game.GameData game, int[] guess) + { + for (int x = 0; x < game.go; x++) + { + int[] gDat = game.ContainsCalcIHateThis(x); + + for (int y = 0; y < 4; y++) + { + if + ( + ((gDat[y] == 1) && (guess[y] != game.board[x, y])) || + ((gDat[y] == 2) && (guess[y] == game.board[x, y])) + ) + return false; + } + } + + return true; + } + } +} diff --git a/Master Mind/Render.cs b/Master Mind/Render.cs index 73b9c02..13c8a9e 100644 --- a/Master Mind/Render.cs +++ b/Master Mind/Render.cs @@ -24,7 +24,7 @@ namespace Master_Mind int[] checks = board.ContainsCalcIHateThis(x); - Console.BackgroundColor = ConsoleColor.White; + Console.BackgroundColor = ConsoleColor.Gray; Console.Write(" "); for (int y = 0; y < 4; y++) @@ -47,7 +47,7 @@ namespace Master_Mind Console.Write(" "); } - Console.BackgroundColor = ConsoleColor.White; + Console.BackgroundColor = ConsoleColor.Gray; Console.Write(" "); Console.BackgroundColor = ConsoleColor.Black;