diff --git a/Sharpasonne.Tests/Rules/UniqueTileInstanceRuleTests.cs b/Sharpasonne.Tests/Rules/UniqueTileInstanceRuleTests.cs index c6a81dd..fc139e2 100644 --- a/Sharpasonne.Tests/Rules/UniqueTileInstanceRuleTests.cs +++ b/Sharpasonne.Tests/Rules/UniqueTileInstanceRuleTests.cs @@ -1,4 +1,7 @@ -using Sharpasonne.GameActions; +using System.Collections.Generic; +using System.Linq; +using Sharpasonne.GameActions; +using Sharpasonne.Models; using Sharpasonne.Rules; using Xunit; @@ -9,7 +12,26 @@ public class UniqueTileInstanceRuleTests : UnitTest [Fact] public void When_BoardIsEmpty_Then_True() { - AssertTrue(new Engine(), MakePlaceTile(0, 0)); + this.AssertTrue(new Engine(), this.MakePlaceTile(0, 0)); + } + + [Fact] + public void Given_BoardHasInstanceofTile_When_PlaceSameInstanceAgain_Then_False() + { + var action = MakePlaceTile(0, 0); + var board = new[] { action }.ToDictionary( + a => a.Point, + a => a.Placement + ); + + var engine = this.MockEngine(new Board(board)); + + var secondPlaceTileGameAction = new PlaceTileGameAction( + new Point(0, 0), + new Placement(action.Placement.Tile, Orientation.Top) + ); + + this.AssertFalse(engine, secondPlaceTileGameAction); } } } diff --git a/Sharpasonne/Rules/UniqueTileInstanceRule.cs b/Sharpasonne/Rules/UniqueTileInstanceRule.cs index 8447663..6919e68 100644 --- a/Sharpasonne/Rules/UniqueTileInstanceRule.cs +++ b/Sharpasonne/Rules/UniqueTileInstanceRule.cs @@ -1,3 +1,4 @@ +using System.Linq; using Sharpasonne.GameActions; namespace Sharpasonne.Rules @@ -6,7 +7,13 @@ public class UniqueTileInstanceRule : IRule { public bool Verify(IEngine engine, T1 gameAction) where T1 : PlaceTileGameAction { - return true; + var allTiles = engine.Board + .ToImmutableDictionary() + .Values + .Select(placement => placement.Tile); + + return !allTiles + .Contains(gameAction.Placement.Tile); } } }