forked from AustinCodingAcademy/csharp-workbook
-
Notifications
You must be signed in to change notification settings - Fork 0
Master mind #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Smangumb
wants to merge
4
commits into
master
Choose a base branch
from
MasterMind
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Master mind #11
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| { | ||
|
|
||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}" | ||
| } | ||
| ,] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
|
|
||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 ""; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.