From 64959030cc587adb58398feda7502a3e09277153 Mon Sep 17 00:00:00 2001 From: Lee Richardson Date: Wed, 17 Jan 2018 20:53:39 +0000 Subject: [PATCH] Adds UniqueTileInstanceRule --- Sharpasonne.Models/Features/City.cs | 3 +- Sharpasonne.Models/Features/Field.cs | 3 +- Sharpasonne.Models/Features/Monastery.cs | 3 +- Sharpasonne.Models/Features/Road.cs | 3 +- Sharpasonne.Models/IFeature.cs | 3 +- Sharpasonne.Models/Orientation.cs | 3 +- Sharpasonne.Models/Point.cs | 3 +- Sharpasonne.Models/Segment.cs | 3 +- .../Rules/UniqueTileInstanceRuleTests.cs | 23 +++++++++++++ Sharpasonne.Tests/Rules/UnitTest.cs | 32 +++++++++++++++++++ Sharpasonne/IEngine.cs | 2 +- Sharpasonne/IGameAction.cs | 2 +- Sharpasonne/Rules/AdjecentTileRule.cs | 9 ++++++ .../Rules/MatchingAdjecentFeatureRule.cs | 10 ++++++ Sharpasonne/Rules/UniqueTileInstanceRule.cs | 12 +++++++ 15 files changed, 104 insertions(+), 10 deletions(-) create mode 100644 Sharpasonne.Tests/Rules/UniqueTileInstanceRuleTests.cs create mode 100644 Sharpasonne.Tests/Rules/UnitTest.cs create mode 100644 Sharpasonne/Rules/AdjecentTileRule.cs create mode 100644 Sharpasonne/Rules/MatchingAdjecentFeatureRule.cs create mode 100644 Sharpasonne/Rules/UniqueTileInstanceRule.cs diff --git a/Sharpasonne.Models/Features/City.cs b/Sharpasonne.Models/Features/City.cs index 39ec439..e91e36e 100644 --- a/Sharpasonne.Models/Features/City.cs +++ b/Sharpasonne.Models/Features/City.cs @@ -7,4 +7,5 @@ class City : IFeature public IImmutableSet Connections { get; } public bool HasShield { get; } } -} \ No newline at end of file +} + diff --git a/Sharpasonne.Models/Features/Field.cs b/Sharpasonne.Models/Features/Field.cs index 21142fe..3a20d8d 100644 --- a/Sharpasonne.Models/Features/Field.cs +++ b/Sharpasonne.Models/Features/Field.cs @@ -11,4 +11,5 @@ public Field(IImmutableSet connections) public IImmutableSet Connections { get; } } -} \ No newline at end of file +} + diff --git a/Sharpasonne.Models/Features/Monastery.cs b/Sharpasonne.Models/Features/Monastery.cs index f0938db..c826a48 100644 --- a/Sharpasonne.Models/Features/Monastery.cs +++ b/Sharpasonne.Models/Features/Monastery.cs @@ -6,4 +6,5 @@ class Monastery : IFeature { public IImmutableSet Connections { get; } } -} \ No newline at end of file +} + diff --git a/Sharpasonne.Models/Features/Road.cs b/Sharpasonne.Models/Features/Road.cs index 9ac55ec..7f2998e 100644 --- a/Sharpasonne.Models/Features/Road.cs +++ b/Sharpasonne.Models/Features/Road.cs @@ -6,4 +6,5 @@ internal class Road : IFeature { public IImmutableSet Connections { get; } } -} \ No newline at end of file +} + diff --git a/Sharpasonne.Models/IFeature.cs b/Sharpasonne.Models/IFeature.cs index 2b33be2..fb5b3d0 100644 --- a/Sharpasonne.Models/IFeature.cs +++ b/Sharpasonne.Models/IFeature.cs @@ -6,4 +6,5 @@ public interface IFeature { IImmutableSet Connections { get; } } -} \ No newline at end of file +} + diff --git a/Sharpasonne.Models/Orientation.cs b/Sharpasonne.Models/Orientation.cs index d50e43e..0d1eaa6 100644 --- a/Sharpasonne.Models/Orientation.cs +++ b/Sharpasonne.Models/Orientation.cs @@ -7,4 +7,5 @@ public enum Orientation Bottom, Left, } -} \ No newline at end of file +} + diff --git a/Sharpasonne.Models/Point.cs b/Sharpasonne.Models/Point.cs index 3c07083..3597de0 100644 --- a/Sharpasonne.Models/Point.cs +++ b/Sharpasonne.Models/Point.cs @@ -11,4 +11,5 @@ public Point(int x, int y) this.Y = y; } } -} \ No newline at end of file +} + diff --git a/Sharpasonne.Models/Segment.cs b/Sharpasonne.Models/Segment.cs index b0986af..ef1d043 100644 --- a/Sharpasonne.Models/Segment.cs +++ b/Sharpasonne.Models/Segment.cs @@ -15,4 +15,5 @@ public enum Segment Left, LeftTop, } -} \ No newline at end of file +} + diff --git a/Sharpasonne.Tests/Rules/UniqueTileInstanceRuleTests.cs b/Sharpasonne.Tests/Rules/UniqueTileInstanceRuleTests.cs new file mode 100644 index 0000000..815cb8a --- /dev/null +++ b/Sharpasonne.Tests/Rules/UniqueTileInstanceRuleTests.cs @@ -0,0 +1,23 @@ +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Security.Cryptography; +using Sharpasonne.GameActions; +using Sharpasonne.Rules; +using Xunit; +using Moq; +using Optional.Unsafe; +using Sharpasonne.Models; +using Sharpasonne.Models.Features; + +namespace Sharpasonne.Tests.Rules +{ + public class UniqueTileInstanceRuleTests : UnitTest + { + [Fact] + public void When_BoardIsEmpty_Then_True() + { + AssertPlaceTileTrue(new Engine(), MakePlaceTile(0, 0)); + } + } +} diff --git a/Sharpasonne.Tests/Rules/UnitTest.cs b/Sharpasonne.Tests/Rules/UnitTest.cs new file mode 100644 index 0000000..230a1c1 --- /dev/null +++ b/Sharpasonne.Tests/Rules/UnitTest.cs @@ -0,0 +1,32 @@ +using System.Linq; +using Optional.Unsafe; +using Sharpasonne.GameActions; +using Sharpasonne.Models; +using Xunit; + +namespace Sharpasonne.Tests.Rules +{ + public abstract class UnitTest + { + protected void AssertPlaceTileTrue(Engine engine, PlaceTileGameAction action) + where TRule : IRule, new() + { + Assert.True(new TRule().Verify(engine, action)); + } + + public PlaceTileGameAction MakePlaceTile( + int x, + int y) + { + var tile = new TileBuilder() + .CreateTile(Enumerable.Empty()) + .ValueOrFailure(); + + return new PlaceTileGameAction( + new Point(x, y), + new Placement(tile, Orientation.Top) + ); + } + } +} + diff --git a/Sharpasonne/IEngine.cs b/Sharpasonne/IEngine.cs index 8baa751..ae79326 100644 --- a/Sharpasonne/IEngine.cs +++ b/Sharpasonne/IEngine.cs @@ -6,4 +6,4 @@ public interface IEngine { Board Board { get; } } -} \ No newline at end of file +} diff --git a/Sharpasonne/IGameAction.cs b/Sharpasonne/IGameAction.cs index 7a9c322..a72a2d3 100644 --- a/Sharpasonne/IGameAction.cs +++ b/Sharpasonne/IGameAction.cs @@ -3,4 +3,4 @@ namespace Sharpasonne public interface IGameAction { } -} \ No newline at end of file +} diff --git a/Sharpasonne/Rules/AdjecentTileRule.cs b/Sharpasonne/Rules/AdjecentTileRule.cs new file mode 100644 index 0000000..487654e --- /dev/null +++ b/Sharpasonne/Rules/AdjecentTileRule.cs @@ -0,0 +1,9 @@ +using Sharpasonne.GameActions; + +namespace Sharpasonne.Rules +{ + abstract class AdjecentTileRule : IRule + { + public abstract bool Verify(IEngine engine, T1 gameAction) where T1 : PlaceTileGameAction; + } +} diff --git a/Sharpasonne/Rules/MatchingAdjecentFeatureRule.cs b/Sharpasonne/Rules/MatchingAdjecentFeatureRule.cs new file mode 100644 index 0000000..13fd145 --- /dev/null +++ b/Sharpasonne/Rules/MatchingAdjecentFeatureRule.cs @@ -0,0 +1,10 @@ +using Sharpasonne.GameActions; + +namespace Sharpasonne.Rules +{ + abstract class MatchingAdjecentFeatureRule : IRule + { + public abstract bool Verify(IEngine engine, T1 gameAction) where T1 : PlaceTileGameAction; + } +} + diff --git a/Sharpasonne/Rules/UniqueTileInstanceRule.cs b/Sharpasonne/Rules/UniqueTileInstanceRule.cs new file mode 100644 index 0000000..8447663 --- /dev/null +++ b/Sharpasonne/Rules/UniqueTileInstanceRule.cs @@ -0,0 +1,12 @@ +using Sharpasonne.GameActions; + +namespace Sharpasonne.Rules +{ + public class UniqueTileInstanceRule : IRule + { + public bool Verify(IEngine engine, T1 gameAction) where T1 : PlaceTileGameAction + { + return true; + } + } +}