Skip to content
Open
Show file tree
Hide file tree
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 Dec 23, 2017
d2cecd2
Add project files.
andresmoschini Dec 23, 2017
0487f1f
Add system structure
andresmoschini Dec 23, 2017
26f2405
Support Draw (RED)
andresmoschini Dec 23, 2017
57a4a8b
Support Draw (GREEN)
andresmoschini Dec 23, 2017
6c088d6
Avoid wrong Draw results (RED)
andresmoschini Dec 23, 2017
3a0b451
Avoid wrong Draw results (GREEN)
andresmoschini Dec 23, 2017
8afd357
Support right result for when not drawing (RED)
andresmoschini Dec 23, 2017
12ecfac
Support right result for when not drawing (GREEN)
andresmoschini Dec 23, 2017
12de524
Refactor tests
andresmoschini Dec 23, 2017
e8931a9
Add new implementation for rules defined by extension and support tes…
andresmoschini Dec 23, 2017
9975412
Add new GameReferee with simple rules definition
andresmoschini Dec 24, 2017
4025be9
Take advantage of HashSet O(1) search time complexity
andresmoschini Dec 24, 2017
6380c00
Add support for Spock and Lizard (RED)
andresmoschini Dec 24, 2017
c4034e8
Add support for Spock and Lizard (RED/GREEN) - Fix SimpleGameReferee
andresmoschini Dec 24, 2017
579c565
Add support for Spock and Lizard (RED/GREEN) - Fix ExtensionRulesGame…
andresmoschini Dec 24, 2017
de7a91f
fixup! Add new GameReferee with simple rules definition
andresmoschini Dec 24, 2017
836a82d
Add support for Spock and Lizard (GREEN) - Fix WinnerRulesGameReferee
andresmoschini Dec 24, 2017
a6106c3
Move to solution folder based on repo standard
andresmoschini Dec 27, 2017
405afbd
Add new OOP based solution (RED)
andresmoschini Dec 27, 2017
fd71e87
Add new OOP based solution (GREEN / UGLY)
andresmoschini Dec 27, 2017
d32f487
Add new OOP based solution (GREEN / REFACTOR / STILL UGLY)
andresmoschini Dec 27, 2017
e8c6dd6
Add new OOP based solution (GREEN)
andresmoschini Dec 27, 2017
0e593e1
Merge remote-tracking branch 'upstream/master' into rpsls
andresmoschini Dec 27, 2017
bd41891
Refactor GameResult as a class in place of an enum
andresmoschini Dec 27, 2017
81a4424
Add explanation to result (RED)
andresmoschini Dec 27, 2017
75249f8
Add explanation to result (RED) - Fix draw results in all implementat…
andresmoschini Dec 27, 2017
a292bd7
Add explanation to result (RED) - Fix ExtensionRulesGameReferee results
andresmoschini Dec 27, 2017
b187a74
Add explanation to result (RED) - Fix SimpleGameReferee
andresmoschini Dec 27, 2017
6aceebb
Add explanation to result (RED) - Fix WinnerRulesGameReferee
andresmoschini Dec 27, 2017
da2ba9f
Add explanation to result (GREEN) - Fix OopAdapterRulesGameReferee
andresmoschini Dec 27, 2017
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
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
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
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
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[]
Copy link
Member

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 GamePrediction class?

Copy link
Member Author

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.

It is an array of ValueTuple, you can see a detailed explanation in Mark Zhou's Tech Blog, for example:

You can even give a name to every element in the value tuple, like this:

public (string name, int age) GetStudentInfo(string id)
{
    // Search by ID and find the student.
    return (name: "Annie", age: 25);
}
 
public void Test()
{
    (string name, int age) info = GetStudentInfo("100-000-1000"); 
    Console.WriteLine($"Name: {info.name}, Age: {info.age}");
}

Regardless, do you think that the complexity of the structure would have required a data structure? Something like a GamePrediction class?

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.

Copy link
Member

@AlphaGit AlphaGit Jan 22, 2018

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!

{
(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");
}
}
Loading