-
Notifications
You must be signed in to change notification settings - Fork 1
Rock, Paper, Scissors, Lizard, Spock (Without regex) #5
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
andresmoschini
wants to merge
31
commits into
MakingSense:master
Choose a base branch
from
andresmoschini:rpsls
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
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
63113a0
Add .gitignore and .gitattributes.
andresmoschini d2cecd2
Add project files.
andresmoschini 0487f1f
Add system structure
andresmoschini 26f2405
Support Draw (RED)
andresmoschini 57a4a8b
Support Draw (GREEN)
andresmoschini 6c088d6
Avoid wrong Draw results (RED)
andresmoschini 3a0b451
Avoid wrong Draw results (GREEN)
andresmoschini 8afd357
Support right result for when not drawing (RED)
andresmoschini 12ecfac
Support right result for when not drawing (GREEN)
andresmoschini 12de524
Refactor tests
andresmoschini e8931a9
Add new implementation for rules defined by extension and support tes…
andresmoschini 9975412
Add new GameReferee with simple rules definition
andresmoschini 4025be9
Take advantage of HashSet O(1) search time complexity
andresmoschini 6380c00
Add support for Spock and Lizard (RED)
andresmoschini c4034e8
Add support for Spock and Lizard (RED/GREEN) - Fix SimpleGameReferee
andresmoschini 579c565
Add support for Spock and Lizard (RED/GREEN) - Fix ExtensionRulesGame…
andresmoschini de7a91f
fixup! Add new GameReferee with simple rules definition
andresmoschini 836a82d
Add support for Spock and Lizard (GREEN) - Fix WinnerRulesGameReferee
andresmoschini a6106c3
Move to solution folder based on repo standard
andresmoschini 405afbd
Add new OOP based solution (RED)
andresmoschini fd71e87
Add new OOP based solution (GREEN / UGLY)
andresmoschini d32f487
Add new OOP based solution (GREEN / REFACTOR / STILL UGLY)
andresmoschini e8c6dd6
Add new OOP based solution (GREEN)
andresmoschini 0e593e1
Merge remote-tracking branch 'upstream/master' into rpsls
andresmoschini bd41891
Refactor GameResult as a class in place of an enum
andresmoschini 81a4424
Add explanation to result (RED)
andresmoschini 75249f8
Add explanation to result (RED) - Fix draw results in all implementat…
andresmoschini a292bd7
Add explanation to result (RED) - Fix ExtensionRulesGameReferee results
andresmoschini b187a74
Add explanation to result (RED) - Fix SimpleGameReferee
andresmoschini 6aceebb
Add explanation to result (RED) - Fix WinnerRulesGameReferee
andresmoschini da2ba9f
Add explanation to result (GREEN) - Fix OopAdapterRulesGameReferee
andresmoschini 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
63 changes: 63 additions & 0 deletions
63
Miscellaneous/rock-paper-scissors-no-regex/Solutions/amoschini/.gitattributes
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,63 @@ | ||
| ############################################################################### | ||
| # Set default behavior to automatically normalize line endings. | ||
| ############################################################################### | ||
| * text=auto | ||
|
|
||
| ############################################################################### | ||
| # Set default behavior for command prompt diff. | ||
| # | ||
| # This is need for earlier builds of msysgit that does not have it on by | ||
| # default for csharp files. | ||
| # Note: This is only used by command line | ||
| ############################################################################### | ||
| #*.cs diff=csharp | ||
|
|
||
| ############################################################################### | ||
| # Set the merge driver for project and solution files | ||
| # | ||
| # Merging from the command prompt will add diff markers to the files if there | ||
| # are conflicts (Merging from VS is not affected by the settings below, in VS | ||
| # the diff markers are never inserted). Diff markers may cause the following | ||
| # file extensions to fail to load in VS. An alternative would be to treat | ||
| # these files as binary and thus will always conflict and require user | ||
| # intervention with every merge. To do so, just uncomment the entries below | ||
| ############################################################################### | ||
| #*.sln merge=binary | ||
| #*.csproj merge=binary | ||
| #*.vbproj merge=binary | ||
| #*.vcxproj merge=binary | ||
| #*.vcproj merge=binary | ||
| #*.dbproj merge=binary | ||
| #*.fsproj merge=binary | ||
| #*.lsproj merge=binary | ||
| #*.wixproj merge=binary | ||
| #*.modelproj merge=binary | ||
| #*.sqlproj merge=binary | ||
| #*.wwaproj merge=binary | ||
|
|
||
| ############################################################################### | ||
| # behavior for image files | ||
| # | ||
| # image files are treated as binary by default. | ||
| ############################################################################### | ||
| #*.jpg binary | ||
| #*.png binary | ||
| #*.gif binary | ||
|
|
||
| ############################################################################### | ||
| # diff behavior for common document formats | ||
| # | ||
| # Convert binary document formats to text before diffing them. This feature | ||
| # is only available from the command line. Turn it on by uncommenting the | ||
| # entries below. | ||
| ############################################################################### | ||
| #*.doc diff=astextplain | ||
| #*.DOC diff=astextplain | ||
| #*.docx diff=astextplain | ||
| #*.DOCX diff=astextplain | ||
| #*.dot diff=astextplain | ||
| #*.DOT diff=astextplain | ||
| #*.pdf diff=astextplain | ||
| #*.PDF diff=astextplain | ||
| #*.rtf diff=astextplain | ||
| #*.RTF diff=astextplain |
261 changes: 261 additions & 0 deletions
261
Miscellaneous/rock-paper-scissors-no-regex/Solutions/amoschini/.gitignore
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,261 @@ | ||
| ## Ignore Visual Studio temporary files, build results, and | ||
| ## files generated by popular Visual Studio add-ons. | ||
|
|
||
| # User-specific files | ||
| *.suo | ||
| *.user | ||
| *.userosscache | ||
| *.sln.docstates | ||
|
|
||
| # User-specific files (MonoDevelop/Xamarin Studio) | ||
| *.userprefs | ||
|
|
||
| # Build results | ||
| [Dd]ebug/ | ||
| [Dd]ebugPublic/ | ||
| [Rr]elease/ | ||
| [Rr]eleases/ | ||
| x64/ | ||
| x86/ | ||
| bld/ | ||
| [Bb]in/ | ||
| [Oo]bj/ | ||
| [Ll]og/ | ||
|
|
||
| # Visual Studio 2015 cache/options directory | ||
| .vs/ | ||
| # Uncomment if you have tasks that create the project's static files in wwwroot | ||
| #wwwroot/ | ||
|
|
||
| # MSTest test Results | ||
| [Tt]est[Rr]esult*/ | ||
| [Bb]uild[Ll]og.* | ||
|
|
||
| # NUNIT | ||
| *.VisualState.xml | ||
| TestResult.xml | ||
|
|
||
| # Build Results of an ATL Project | ||
| [Dd]ebugPS/ | ||
| [Rr]eleasePS/ | ||
| dlldata.c | ||
|
|
||
| # DNX | ||
| project.lock.json | ||
| project.fragment.lock.json | ||
| artifacts/ | ||
|
|
||
| *_i.c | ||
| *_p.c | ||
| *_i.h | ||
| *.ilk | ||
| *.meta | ||
| *.obj | ||
| *.pch | ||
| *.pdb | ||
| *.pgc | ||
| *.pgd | ||
| *.rsp | ||
| *.sbr | ||
| *.tlb | ||
| *.tli | ||
| *.tlh | ||
| *.tmp | ||
| *.tmp_proj | ||
| *.log | ||
| *.vspscc | ||
| *.vssscc | ||
| .builds | ||
| *.pidb | ||
| *.svclog | ||
| *.scc | ||
|
|
||
| # Chutzpah Test files | ||
| _Chutzpah* | ||
|
|
||
| # Visual C++ cache files | ||
| ipch/ | ||
| *.aps | ||
| *.ncb | ||
| *.opendb | ||
| *.opensdf | ||
| *.sdf | ||
| *.cachefile | ||
| *.VC.db | ||
| *.VC.VC.opendb | ||
|
|
||
| # Visual Studio profiler | ||
| *.psess | ||
| *.vsp | ||
| *.vspx | ||
| *.sap | ||
|
|
||
| # TFS 2012 Local Workspace | ||
| $tf/ | ||
|
|
||
| # Guidance Automation Toolkit | ||
| *.gpState | ||
|
|
||
| # ReSharper is a .NET coding add-in | ||
| _ReSharper*/ | ||
| *.[Rr]e[Ss]harper | ||
| *.DotSettings.user | ||
|
|
||
| # JustCode is a .NET coding add-in | ||
| .JustCode | ||
|
|
||
| # TeamCity is a build add-in | ||
| _TeamCity* | ||
|
|
||
| # DotCover is a Code Coverage Tool | ||
| *.dotCover | ||
|
|
||
| # NCrunch | ||
| _NCrunch_* | ||
| .*crunch*.local.xml | ||
| nCrunchTemp_* | ||
|
|
||
| # MightyMoose | ||
| *.mm.* | ||
| AutoTest.Net/ | ||
|
|
||
| # Web workbench (sass) | ||
| .sass-cache/ | ||
|
|
||
| # Installshield output folder | ||
| [Ee]xpress/ | ||
|
|
||
| # DocProject is a documentation generator add-in | ||
| DocProject/buildhelp/ | ||
| DocProject/Help/*.HxT | ||
| DocProject/Help/*.HxC | ||
| DocProject/Help/*.hhc | ||
| DocProject/Help/*.hhk | ||
| DocProject/Help/*.hhp | ||
| DocProject/Help/Html2 | ||
| DocProject/Help/html | ||
|
|
||
| # Click-Once directory | ||
| publish/ | ||
|
|
||
| # Publish Web Output | ||
| *.[Pp]ublish.xml | ||
| *.azurePubxml | ||
| # TODO: Comment the next line if you want to checkin your web deploy settings | ||
| # but database connection strings (with potential passwords) will be unencrypted | ||
| #*.pubxml | ||
| *.publishproj | ||
|
|
||
| # Microsoft Azure Web App publish settings. Comment the next line if you want to | ||
| # checkin your Azure Web App publish settings, but sensitive information contained | ||
| # in these scripts will be unencrypted | ||
| PublishScripts/ | ||
|
|
||
| # NuGet Packages | ||
| *.nupkg | ||
| # The packages folder can be ignored because of Package Restore | ||
| **/packages/* | ||
| # except build/, which is used as an MSBuild target. | ||
| !**/packages/build/ | ||
| # Uncomment if necessary however generally it will be regenerated when needed | ||
| #!**/packages/repositories.config | ||
| # NuGet v3's project.json files produces more ignoreable files | ||
| *.nuget.props | ||
| *.nuget.targets | ||
|
|
||
| # Microsoft Azure Build Output | ||
| csx/ | ||
| *.build.csdef | ||
|
|
||
| # Microsoft Azure Emulator | ||
| ecf/ | ||
| rcf/ | ||
|
|
||
| # Windows Store app package directories and files | ||
| AppPackages/ | ||
| BundleArtifacts/ | ||
| Package.StoreAssociation.xml | ||
| _pkginfo.txt | ||
|
|
||
| # Visual Studio cache files | ||
| # files ending in .cache can be ignored | ||
| *.[Cc]ache | ||
| # but keep track of directories ending in .cache | ||
| !*.[Cc]ache/ | ||
|
|
||
| # Others | ||
| ClientBin/ | ||
| ~$* | ||
| *~ | ||
| *.dbmdl | ||
| *.dbproj.schemaview | ||
| *.jfm | ||
| *.pfx | ||
| *.publishsettings | ||
| node_modules/ | ||
| orleans.codegen.cs | ||
|
|
||
| # Since there are multiple workflows, uncomment next line to ignore bower_components | ||
| # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) | ||
| #bower_components/ | ||
|
|
||
| # RIA/Silverlight projects | ||
| Generated_Code/ | ||
|
|
||
| # Backup & report files from converting an old project file | ||
| # to a newer Visual Studio version. Backup files are not needed, | ||
| # because we have git ;-) | ||
| _UpgradeReport_Files/ | ||
| Backup*/ | ||
| UpgradeLog*.XML | ||
| UpgradeLog*.htm | ||
|
|
||
| # SQL Server files | ||
| *.mdf | ||
| *.ldf | ||
|
|
||
| # Business Intelligence projects | ||
| *.rdl.data | ||
| *.bim.layout | ||
| *.bim_*.settings | ||
|
|
||
| # Microsoft Fakes | ||
| FakesAssemblies/ | ||
|
|
||
| # GhostDoc plugin setting file | ||
| *.GhostDoc.xml | ||
|
|
||
| # Node.js Tools for Visual Studio | ||
| .ntvs_analysis.dat | ||
|
|
||
| # Visual Studio 6 build log | ||
| *.plg | ||
|
|
||
| # Visual Studio 6 workspace options file | ||
| *.opt | ||
|
|
||
| # Visual Studio LightSwitch build output | ||
| **/*.HTMLClient/GeneratedArtifacts | ||
| **/*.DesktopClient/GeneratedArtifacts | ||
| **/*.DesktopClient/ModelManifest.xml | ||
| **/*.Server/GeneratedArtifacts | ||
| **/*.Server/ModelManifest.xml | ||
| _Pvt_Extensions | ||
|
|
||
| # Paket dependency manager | ||
| .paket/paket.exe | ||
| paket-files/ | ||
|
|
||
| # FAKE - F# Make | ||
| .fake/ | ||
|
|
||
| # JetBrains Rider | ||
| .idea/ | ||
| *.sln.iml | ||
|
|
||
| # CodeRush | ||
| .cr/ | ||
|
|
||
| # Python Tools for Visual Studio (PTVS) | ||
| __pycache__/ | ||
| *.pyc |
25 changes: 25 additions & 0 deletions
25
Miscellaneous/rock-paper-scissors-no-regex/Solutions/amoschini/RpsKata.sln
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 @@ | ||
| | ||
| Microsoft Visual Studio Solution File, Format Version 12.00 | ||
| # Visual Studio 15 | ||
| VisualStudioVersion = 15.0.27130.2010 | ||
| MinimumVisualStudioVersion = 10.0.40219.1 | ||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RpsKata", "RpsKata\RpsKata.csproj", "{8DFD4066-3694-4534-9F60-35B4C32F3711}" | ||
| EndProject | ||
| Global | ||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
| Debug|Any CPU = Debug|Any CPU | ||
| Release|Any CPU = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
| {8DFD4066-3694-4534-9F60-35B4C32F3711}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {8DFD4066-3694-4534-9F60-35B4C32F3711}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {8DFD4066-3694-4534-9F60-35B4C32F3711}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {8DFD4066-3694-4534-9F60-35B4C32F3711}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(SolutionProperties) = preSolution | ||
| HideSolutionNode = FALSE | ||
| EndGlobalSection | ||
| GlobalSection(ExtensibilityGlobals) = postSolution | ||
| SolutionGuid = {20C1E714-7B31-4776-8DB8-D66DDD3CD198} | ||
| EndGlobalSection | ||
| EndGlobal |
45 changes: 45 additions & 0 deletions
45
...ous/rock-paper-scissors-no-regex/Solutions/amoschini/RpsKata/ExtensionRulesGameReferee.cs
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,45 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
|
|
||
| namespace RpsKata | ||
| { | ||
| public class ExtensionRulesGameReferee : IGameReferee | ||
| { | ||
| private (GameChoice player1Choice, GameChoice player2Choice, GameResult result)[] _rules = new[] | ||
| { | ||
| (GameChoice.Rock, GameChoice.Rock, GameResult.Draw(GameChoice.Rock)), | ||
| (GameChoice.Paper, GameChoice.Paper, GameResult.Draw(GameChoice.Paper)), | ||
| (GameChoice.Scissors, GameChoice.Scissors, GameResult.Draw(GameChoice.Scissors)), | ||
| (GameChoice.Spock, GameChoice.Spock, GameResult.Draw(GameChoice.Spock)), | ||
| (GameChoice.Lizard, GameChoice.Lizard, GameResult.Draw(GameChoice.Lizard)), | ||
| (GameChoice.Rock, GameChoice.Scissors, GameResult.Player1Won(GameChoice.Rock, "crushes", GameChoice.Scissors)), | ||
| (GameChoice.Rock, GameChoice.Lizard, GameResult.Player1Won(GameChoice.Rock, "crushes", GameChoice.Lizard)), | ||
| (GameChoice.Paper, GameChoice.Rock, GameResult.Player1Won(GameChoice.Paper, "covers", GameChoice.Rock)), | ||
| (GameChoice.Paper, GameChoice.Spock, GameResult.Player1Won(GameChoice.Paper, "disproves", GameChoice.Spock)), | ||
| (GameChoice.Scissors, GameChoice.Paper, GameResult.Player1Won(GameChoice.Scissors, "cuts", GameChoice.Paper)), | ||
| (GameChoice.Scissors, GameChoice.Lizard, GameResult.Player1Won(GameChoice.Scissors, "decapitates", GameChoice.Lizard)), | ||
| (GameChoice.Spock, GameChoice.Scissors, GameResult.Player1Won(GameChoice.Spock, "smashes", GameChoice.Scissors)), | ||
| (GameChoice.Spock, GameChoice.Rock, GameResult.Player1Won(GameChoice.Spock, "vaporizes", GameChoice.Rock)), | ||
| (GameChoice.Lizard, GameChoice.Spock, GameResult.Player1Won(GameChoice.Lizard, "poisons", GameChoice.Spock)), | ||
| (GameChoice.Lizard, GameChoice.Paper, GameResult.Player1Won(GameChoice.Lizard, "eats", GameChoice.Paper)), | ||
| (GameChoice.Scissors, GameChoice.Rock, GameResult.Player2Won(GameChoice.Rock, "crushes", GameChoice.Scissors)), | ||
| (GameChoice.Scissors, GameChoice.Spock, GameResult.Player2Won(GameChoice.Spock, "smashes", GameChoice.Scissors)), | ||
| (GameChoice.Rock, GameChoice.Paper, GameResult.Player2Won(GameChoice.Paper, "covers", GameChoice.Rock)), | ||
| (GameChoice.Rock, GameChoice.Spock, GameResult.Player2Won(GameChoice.Spock, "vaporizes", GameChoice.Rock)), | ||
| (GameChoice.Paper, GameChoice.Scissors, GameResult.Player2Won(GameChoice.Scissors, "cuts", GameChoice.Paper)), | ||
| (GameChoice.Paper, GameChoice.Lizard, GameResult.Player2Won(GameChoice.Lizard, "eats", GameChoice.Paper)), | ||
| (GameChoice.Spock, GameChoice.Paper, GameResult.Player2Won(GameChoice.Paper, "disproves", GameChoice.Spock)), | ||
| (GameChoice.Spock, GameChoice.Lizard, GameResult.Player2Won(GameChoice.Lizard, "poisons", GameChoice.Spock)), | ||
| (GameChoice.Lizard, GameChoice.Rock, GameResult.Player2Won(GameChoice.Rock, "crushes", GameChoice.Lizard)), | ||
| (GameChoice.Lizard, GameChoice.Scissors, GameResult.Player2Won(GameChoice.Scissors, "decapitates", GameChoice.Lizard)) | ||
| }; | ||
|
|
||
| public GameResult Evaluate(GameSetup gameSetup) => _rules | ||
| .Where(x => x.player1Choice == gameSetup.Player1Choice) | ||
| .Where(x => x.player2Choice == gameSetup.Player2Choice) | ||
| .Select(x => x.result) | ||
| .FirstOrDefault() ?? throw new NotImplementedException("No rule defined for this scenario"); | ||
| } | ||
| } | ||
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.
Is this an array of tuples? It does look like them but I didn't know each tuple could have named values.
Or are these anonymous objects? In that case, I did not know they could be assigned to a class-level variable.
Please, enlight me!
Regardless, do you think that the complexity of the structure would have required a data structure? Something like a
GamePredictionclass?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.
It is an array of ValueTuple, you can see a detailed explanation in Mark Zhou's Tech Blog, for example:
You agree with you, a class would be better, but since I was using it internally I did not pay attention to that detail. Maybe the name should be related to rule in place of prediction.
Uh oh!
There was an error while loading. Please reload this page.
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.
Oh, I knew about ValueTypes, I did not know you could declare an array of value tuples with names in them. That blew my mind.
I probably (wrongly) assumed that ValueTuples where just associated objects without structure (like pretty much other language treat tuples) but it seems not to be the case.
Thank you!