From 5815fa5d4bc16e38bccb37c351401ad919b03ae5 Mon Sep 17 00:00:00 2001 From: Sam Mangum-Bostick Date: Sun, 10 Feb 2019 15:03:58 -0600 Subject: [PATCH 1/4] Seperate folders for classes --- .../AnimalClassification.csproj | 8 +++ AnimalClassification/Program.cs | 12 ++++ Mastermind/.vscode/launch.json | 28 ++++++++ Mastermind/.vscode/tasks.json | 15 +++++ Mastermind/Mastermind.cs | 44 ++++++++----- Mastermind/ball.cs | 14 ++++ Mastermind/game.cs | 65 +++++++++++++++++++ Mastermind/row.cs | 25 +++++++ 8 files changed, 193 insertions(+), 18 deletions(-) create mode 100644 AnimalClassification/AnimalClassification.csproj create mode 100644 AnimalClassification/Program.cs create mode 100644 Mastermind/.vscode/launch.json create mode 100644 Mastermind/.vscode/tasks.json create mode 100644 Mastermind/ball.cs create mode 100644 Mastermind/game.cs create mode 100644 Mastermind/row.cs diff --git a/AnimalClassification/AnimalClassification.csproj b/AnimalClassification/AnimalClassification.csproj new file mode 100644 index 00000000..21dff5ca --- /dev/null +++ b/AnimalClassification/AnimalClassification.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp2.2 + + + diff --git a/AnimalClassification/Program.cs b/AnimalClassification/Program.cs new file mode 100644 index 00000000..54d0ce96 --- /dev/null +++ b/AnimalClassification/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace AnimalClassification +{ + class Program + { + static void Main(string[] args) + { + + } + } +} diff --git a/Mastermind/.vscode/launch.json b/Mastermind/.vscode/launch.json new file mode 100644 index 00000000..60c9449e --- /dev/null +++ b/Mastermind/.vscode/launch.json @@ -0,0 +1,28 @@ +{ + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/bin/Debug/netcoreapp2.0/Mastermind.dll", + "args": [], + "cwd": "${workspaceFolder}", + // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window + "console": "internalConsole", + "stopAtEntry": false, + "internalConsoleOptions": "openOnSessionStart" + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + } + ,] +} \ No newline at end of file diff --git a/Mastermind/.vscode/tasks.json b/Mastermind/.vscode/tasks.json new file mode 100644 index 00000000..ccfc68f7 --- /dev/null +++ b/Mastermind/.vscode/tasks.json @@ -0,0 +1,15 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/Mastermind.csproj" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/Mastermind/Mastermind.cs b/Mastermind/Mastermind.cs index 365fb84c..39ab95c1 100644 --- a/Mastermind/Mastermind.cs +++ b/Mastermind/Mastermind.cs @@ -1,59 +1,66 @@ using System; +using System.Collections.Generic; namespace Mastermind { + class Program { // possible letters in code public static char[] letters = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' }; - + // size of code public static int codeSize = 4; - + // number of allowed attempts to crack the code public static int allowedAttempts = 10; - + // number of tried guesses public static int numTry = 0; - + // test solution - public static char[] solution = new char[] {'a', 'b', 'c', 'd'}; - + public static char[] solution = new char[] { 'a', 'b', 'c', 'd' }; + // game board public static string[][] board = new string[allowedAttempts][]; - - + + public static void Main() { char[] guess = new char[4]; - CreateBoard(); DrawBoard(); Console.WriteLine("Enter Guess:"); guess = Console.ReadLine().ToCharArray(); + //place balls on board + //check for solution + //Give you hints + //Guess again + //Say you won and exit + // leave this command at the end so your program does not close automatically Console.ReadLine(); } - + public static bool CheckSolution(char[] guess) { // Your code here return false; } - + public static string GenerateHint(char[] guess) { // Your code here return " "; } - + public static void InsertCode(char[] guess) { // Your code here } - + public static void CreateBoard() { for (var i = 0; i < allowedAttempts; i++) @@ -65,19 +72,20 @@ public static void CreateBoard() } } } - + public static void DrawBoard() { for (var i = 0; i < board.Length; i++) { Console.WriteLine("|" + String.Join("|", board[i])); } - + } - - public static void GenerateRandomCode() { + + public static void GenerateRandomCode() + { Random rnd = new Random(); - for(var i = 0; i < codeSize; i++) + for (var i = 0; i < codeSize; i++) { solution[i] = letters[rnd.Next(0, letters.Length)]; } diff --git a/Mastermind/ball.cs b/Mastermind/ball.cs new file mode 100644 index 00000000..38024b9f --- /dev/null +++ b/Mastermind/ball.cs @@ -0,0 +1,14 @@ +using System; +namespace Mastermind +{ + + class Ball + { + public string letter { get; private set; } + + public Ball(string letter) + { + this.letter = letter; + } + } +} \ No newline at end of file diff --git a/Mastermind/game.cs b/Mastermind/game.cs new file mode 100644 index 00000000..5ece5369 --- /dev/null +++ b/Mastermind/game.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; + +namespace Mastermind +{ + + class Game + { + private List rows = new List(); + private string[] answer = new string[4]; + + public Game(string[] answer) + { + this.answer = answer; + } + + private string Score(Row row) + { + string[] answerClone = (string[])this.answer.Clone(); + // red is correct letter and correct position + // white is correct letters minus red + // this.answer => ["a", "b", "c", "d"] + // row.balls => [{ Letter: "c" }, { Letter: "b" }, { Letter: "d" }, { Letter: "a" }] + int red = 0; + for (int i = 0; i < 4; i++) + { + if (answerClone[i] == row.balls[i].letter) + { + red++; + } + } + + int white = 0; + for (int i = 0; i < 4; i++) + { + int foundIndex = Array.IndexOf(answerClone, row.balls[i].letter); + if (foundIndex > -1) + { + white++; + answerClone[foundIndex] = null; + } + } + return $" {red} - {white - red}"; + } + + public void AddRow(Row row) + { + this.rows.Add(row); + } + + public string Rows + { + get + { + string temp = ""; + foreach (var row in this.rows) + { + string score = this.Score(row); + temp = temp + row.Balls + score + "\n"; + } + return temp; + } + } + } +} \ No newline at end of file diff --git a/Mastermind/row.cs b/Mastermind/row.cs new file mode 100644 index 00000000..156fd252 --- /dev/null +++ b/Mastermind/row.cs @@ -0,0 +1,25 @@ +using System; +namespace Mastermind +{ + class Row + { + public Ball[] balls = new Ball[4]; + + public Row(Ball[] balls) + { + this.balls = balls; + } + public string Balls + { + get + { + foreach (var ball in this.balls) + { + Console.Write(ball.letter); + } + return ""; + } + } + } + +} \ No newline at end of file From 6b484128caaf65626700a2cd5ef874150a453e4c Mon Sep 17 00:00:00 2001 From: Sam Mangum-Bostick Date: Wed, 13 Feb 2019 18:43:51 -0600 Subject: [PATCH 2/4] Can place mark and check for win --- Mastermind/Mastermind.cs | 60 ++++++++++++++++++++++++++++++++++------ Mastermind/ball.cs | 1 + 2 files changed, 52 insertions(+), 9 deletions(-) diff --git a/Mastermind/Mastermind.cs b/Mastermind/Mastermind.cs index 39ab95c1..10af58bc 100644 --- a/Mastermind/Mastermind.cs +++ b/Mastermind/Mastermind.cs @@ -30,8 +30,29 @@ public static void Main() char[] guess = new char[4]; CreateBoard(); DrawBoard(); - Console.WriteLine("Enter Guess:"); - guess = Console.ReadLine().ToCharArray(); + do + { + Console.WriteLine("Enter Guess:"); + string input = Console.ReadLine(); + guess = input.ToCharArray(); + PlaceMark(guess); + DrawBoard(); + numTry++; + } while (!CheckSolution(guess) && (numTry < allowedAttempts)); + if (CheckSolution(guess)) + { + System.Console.WriteLine("You win!"); + } + else + { + System.Console.WriteLine("You lost!"); + } + + // System.Console.WriteLine(board[0][0]); + // foreach (var item in guess) + // { + // System.Console.WriteLine(item); + // } //place balls on board //check for solution //Give you hints @@ -40,12 +61,29 @@ public static void Main() // leave this command at the end so your program does not close automatically - Console.ReadLine(); + // Console.ReadLine(); } public static bool CheckSolution(char[] guess) { // Your code here + for (int i = 0; i < guess.Length; i++) + { + if (guess[i] == solution[i]) + { + if (i == guess.Length - 1) + { + return true; + } + continue; + + } + else + { + break; + } + } + return false; } @@ -56,11 +94,6 @@ public static string GenerateHint(char[] guess) return " "; } - public static void InsertCode(char[] guess) - { - // Your code here - } - public static void CreateBoard() { for (var i = 0; i < allowedAttempts; i++) @@ -72,7 +105,6 @@ public static void CreateBoard() } } } - public static void DrawBoard() { for (var i = 0; i < board.Length; i++) @@ -82,6 +114,16 @@ public static void DrawBoard() } + public static void PlaceMark(char[] guess) + { + // your code goes here + for (int i = 0; i < guess.Length; i++) + { + board[numTry][i] = guess[i].ToString(); + } + + } + public static void GenerateRandomCode() { Random rnd = new Random(); diff --git a/Mastermind/ball.cs b/Mastermind/ball.cs index 38024b9f..d906b877 100644 --- a/Mastermind/ball.cs +++ b/Mastermind/ball.cs @@ -9,6 +9,7 @@ class Ball public Ball(string letter) { this.letter = letter; + } } } \ No newline at end of file From f59f4e0960d49afb6cb3ab92772a369d52b4bf04 Mon Sep 17 00:00:00 2001 From: Sam Mangum-Bostick Date: Sun, 17 Feb 2019 18:01:41 -0600 Subject: [PATCH 3/4] Safety Commit --- Mastermind/Mastermind.cs | 21 ++---- Mastermind/TowersOfHanoi/TowersOfHanoi.cs | 68 +++++++++++++++++++ Mastermind/TowersOfHanoi/TowersOfHanoi.csproj | 8 +++ 3 files changed, 81 insertions(+), 16 deletions(-) create mode 100644 Mastermind/TowersOfHanoi/TowersOfHanoi.cs create mode 100644 Mastermind/TowersOfHanoi/TowersOfHanoi.csproj diff --git a/Mastermind/Mastermind.cs b/Mastermind/Mastermind.cs index 10af58bc..ffd66690 100644 --- a/Mastermind/Mastermind.cs +++ b/Mastermind/Mastermind.cs @@ -19,7 +19,7 @@ class Program public static int numTry = 0; // test solution - public static char[] solution = new char[] { 'a', 'b', 'c', 'd' }; + public static char[] solution = GenerateRandomCode(); // game board public static string[][] board = new string[allowedAttempts][]; @@ -30,6 +30,7 @@ public static void Main() char[] guess = new char[4]; CreateBoard(); DrawBoard(); + do { Console.WriteLine("Enter Guess:"); @@ -48,20 +49,6 @@ public static void Main() System.Console.WriteLine("You lost!"); } - // System.Console.WriteLine(board[0][0]); - // foreach (var item in guess) - // { - // System.Console.WriteLine(item); - // } - //place balls on board - //check for solution - //Give you hints - //Guess again - //Say you won and exit - - - // leave this command at the end so your program does not close automatically - // Console.ReadLine(); } public static bool CheckSolution(char[] guess) @@ -124,13 +111,15 @@ public static void PlaceMark(char[] guess) } - public static void GenerateRandomCode() + public static char[] GenerateRandomCode() { + char[] solution = new char[codeSize]; Random rnd = new Random(); for (var i = 0; i < codeSize; i++) { solution[i] = letters[rnd.Next(0, letters.Length)]; } + return solution; } } } diff --git a/Mastermind/TowersOfHanoi/TowersOfHanoi.cs b/Mastermind/TowersOfHanoi/TowersOfHanoi.cs new file mode 100644 index 00000000..d4c93fe7 --- /dev/null +++ b/Mastermind/TowersOfHanoi/TowersOfHanoi.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections; +using System.Collections.Generic; + +namespace Tower +{ + class Program + { + static void Main(string[] args) + { + Game game = new Game(); + + game.PrintBoard(); + } + } + class Block + { + public int weight { get; private set; } + + public Block(int weight) + { + this.weight = weight; + } + } + class Tower + { + public Stack blocks = new Stack(); + } + class Game + { + Dictionary towers = new Dictionary(); + + public Game() + { + Tower towerA = new Tower(); + Tower towerB = new Tower(); + Tower towerC = new Tower(); + towers["A"] = towerA; + towers["B"] = towerB; + towers["C"] = towerC; + towerA.blocks.Push(new Block(1)); + towerA.blocks.Push(new Block(2)); + towerA.blocks.Push(new Block(3)); + towerA.blocks.Push(new Block(4)); + } + + public void PrintBoard() + { + foreach (KeyValuePair item in towers) + { + string blocks = ""; + foreach (Block block in item.Value.blocks) + { + blocks += block.weight.ToString(); + } + System.Console.WriteLine(item.Key + "| " + blocks); + + } + } + public void MovePiece() + { + foreach (KeyValuePair item in towers) + { + + } + } + } +} diff --git a/Mastermind/TowersOfHanoi/TowersOfHanoi.csproj b/Mastermind/TowersOfHanoi/TowersOfHanoi.csproj new file mode 100644 index 00000000..ce1697ae --- /dev/null +++ b/Mastermind/TowersOfHanoi/TowersOfHanoi.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp2.0 + + + From 3de95a1661f26383f11db02e7a42039f25597007 Mon Sep 17 00:00:00 2001 From: Sam Mangum-Bostick Date: Mon, 18 Feb 2019 18:30:32 -0600 Subject: [PATCH 4/4] Print Board finished --- Mastermind/{Mastermind.csproj => MasterMind/MasterMind.csproj} | 0 Mastermind/{ => MasterMind}/Mastermind.cs | 0 Mastermind/{ => MasterMind}/ball.cs | 0 Mastermind/{ => MasterMind}/game.cs | 0 Mastermind/{ => MasterMind}/row.cs | 0 Mastermind/TowersOfHanoi/TowersOfHanoi.cs | 3 ++- 6 files changed, 2 insertions(+), 1 deletion(-) rename Mastermind/{Mastermind.csproj => MasterMind/MasterMind.csproj} (100%) rename Mastermind/{ => MasterMind}/Mastermind.cs (100%) rename Mastermind/{ => MasterMind}/ball.cs (100%) rename Mastermind/{ => MasterMind}/game.cs (100%) rename Mastermind/{ => MasterMind}/row.cs (100%) diff --git a/Mastermind/Mastermind.csproj b/Mastermind/MasterMind/MasterMind.csproj similarity index 100% rename from Mastermind/Mastermind.csproj rename to Mastermind/MasterMind/MasterMind.csproj diff --git a/Mastermind/Mastermind.cs b/Mastermind/MasterMind/Mastermind.cs similarity index 100% rename from Mastermind/Mastermind.cs rename to Mastermind/MasterMind/Mastermind.cs diff --git a/Mastermind/ball.cs b/Mastermind/MasterMind/ball.cs similarity index 100% rename from Mastermind/ball.cs rename to Mastermind/MasterMind/ball.cs diff --git a/Mastermind/game.cs b/Mastermind/MasterMind/game.cs similarity index 100% rename from Mastermind/game.cs rename to Mastermind/MasterMind/game.cs diff --git a/Mastermind/row.cs b/Mastermind/MasterMind/row.cs similarity index 100% rename from Mastermind/row.cs rename to Mastermind/MasterMind/row.cs diff --git a/Mastermind/TowersOfHanoi/TowersOfHanoi.cs b/Mastermind/TowersOfHanoi/TowersOfHanoi.cs index d4c93fe7..a0b927d7 100644 --- a/Mastermind/TowersOfHanoi/TowersOfHanoi.cs +++ b/Mastermind/TowersOfHanoi/TowersOfHanoi.cs @@ -59,9 +59,10 @@ public void PrintBoard() } public void MovePiece() { + foreach (KeyValuePair item in towers) { - + towers.Values.Pop(); } } }