Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions AnimalClassification/AnimalClassification.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>

</Project>
12 changes: 12 additions & 0 deletions AnimalClassification/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace AnimalClassification
{
class Program
{
static void Main(string[] args)
{

}
}
}
28 changes: 28 additions & 0 deletions Mastermind/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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}"
}
,]
}
15 changes: 15 additions & 0 deletions Mastermind/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/Mastermind.csproj"
],
"problemMatcher": "$msCompile"
}
]
}
File renamed without changes.
91 changes: 65 additions & 26 deletions Mastermind/Mastermind.cs → Mastermind/MasterMind/Mastermind.cs
Original file line number Diff line number Diff line change
@@ -1,59 +1,86 @@
using System;
using System.Collections.Generic;

namespace Mastermind
{

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job on Mastermind. You could have added in the hint that tells you how many of each letter you got right or almost right, but still a good job.

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 = GenerateRandomCode();

// 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();

// leave this command at the end so your program does not close automatically
Console.ReadLine();
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!");
}

}

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;
}

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++)
Expand All @@ -65,22 +92,34 @@ 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 PlaceMark(char[] guess)
{
// your code goes here
for (int i = 0; i < guess.Length; i++)
{
board[numTry][i] = guess[i].ToString();
}

}

public static char[] GenerateRandomCode()
{
char[] solution = new char[codeSize];
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)];
}
return solution;
}
}
}
15 changes: 15 additions & 0 deletions Mastermind/MasterMind/ball.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
namespace Mastermind
{

class Ball
{
public string letter { get; private set; }

public Ball(string letter)
{
this.letter = letter;

}
}
}
65 changes: 65 additions & 0 deletions Mastermind/MasterMind/game.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;

namespace Mastermind
{

class Game
{
private List<Row> rows = new List<Row>();
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;
}
}
}
}
25 changes: 25 additions & 0 deletions Mastermind/MasterMind/row.cs
Original file line number Diff line number Diff line change
@@ -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 "";
}
}
}

}
69 changes: 69 additions & 0 deletions Mastermind/TowersOfHanoi/TowersOfHanoi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
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<string, Tower> towers = new Dictionary<string, Tower>();

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<string, Tower> 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<string, Tower> item in towers)
{
towers.Values.Pop();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This throws an exception. I am not sure you finished this assignment or not. Please finish out the Towers of Hanoi for an update grade.

}
}
}
}
Loading