Skip to content

Commit

Permalink
Adds UniqueTileInstanceRule
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee Richardson committed Jan 17, 2018
1 parent 4046fb4 commit 6495903
Show file tree
Hide file tree
Showing 15 changed files with 104 additions and 10 deletions.
3 changes: 2 additions & 1 deletion Sharpasonne.Models/Features/City.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ class City : IFeature
public IImmutableSet<Segment> Connections { get; }
public bool HasShield { get; }
}
}
}

3 changes: 2 additions & 1 deletion Sharpasonne.Models/Features/Field.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public Field(IImmutableSet<Segment> connections)

public IImmutableSet<Segment> Connections { get; }
}
}
}

3 changes: 2 additions & 1 deletion Sharpasonne.Models/Features/Monastery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ class Monastery : IFeature
{
public IImmutableSet<Segment> Connections { get; }
}
}
}

3 changes: 2 additions & 1 deletion Sharpasonne.Models/Features/Road.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ internal class Road : IFeature
{
public IImmutableSet<Segment> Connections { get; }
}
}
}

3 changes: 2 additions & 1 deletion Sharpasonne.Models/IFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ public interface IFeature
{
IImmutableSet<Segment> Connections { get; }
}
}
}

3 changes: 2 additions & 1 deletion Sharpasonne.Models/Orientation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ public enum Orientation
Bottom,
Left,
}
}
}

3 changes: 2 additions & 1 deletion Sharpasonne.Models/Point.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public Point(int x, int y)
this.Y = y;
}
}
}
}

3 changes: 2 additions & 1 deletion Sharpasonne.Models/Segment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ public enum Segment
Left,
LeftTop,
}
}
}

23 changes: 23 additions & 0 deletions Sharpasonne.Tests/Rules/UniqueTileInstanceRuleTests.cs
Original file line number Diff line number Diff line change
@@ -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<UniqueTileInstanceRule>(new Engine(), MakePlaceTile(0, 0));
}
}
}
32 changes: 32 additions & 0 deletions Sharpasonne.Tests/Rules/UnitTest.cs
Original file line number Diff line number Diff line change
@@ -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<TRule>(Engine engine, PlaceTileGameAction action)
where TRule : IRule<PlaceTileGameAction>, new()
{
Assert.True(new TRule().Verify(engine, action));
}

public PlaceTileGameAction MakePlaceTile(
int x,
int y)
{
var tile = new TileBuilder()
.CreateTile(Enumerable.Empty<IFeature>())
.ValueOrFailure();

return new PlaceTileGameAction(
new Point(x, y),
new Placement(tile, Orientation.Top)
);
}
}
}

2 changes: 1 addition & 1 deletion Sharpasonne/IEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ public interface IEngine
{
Board Board { get; }
}
}
}
2 changes: 1 addition & 1 deletion Sharpasonne/IGameAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ namespace Sharpasonne
public interface IGameAction
{
}
}
}
9 changes: 9 additions & 0 deletions Sharpasonne/Rules/AdjecentTileRule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Sharpasonne.GameActions;

namespace Sharpasonne.Rules
{
abstract class AdjecentTileRule : IRule<PlaceTileGameAction>
{
public abstract bool Verify<T1>(IEngine engine, T1 gameAction) where T1 : PlaceTileGameAction;
}
}
10 changes: 10 additions & 0 deletions Sharpasonne/Rules/MatchingAdjecentFeatureRule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Sharpasonne.GameActions;

namespace Sharpasonne.Rules
{
abstract class MatchingAdjecentFeatureRule : IRule<PlaceTileGameAction>
{
public abstract bool Verify<T1>(IEngine engine, T1 gameAction) where T1 : PlaceTileGameAction;
}
}

12 changes: 12 additions & 0 deletions Sharpasonne/Rules/UniqueTileInstanceRule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Sharpasonne.GameActions;

namespace Sharpasonne.Rules
{
public class UniqueTileInstanceRule : IRule<PlaceTileGameAction>
{
public bool Verify<T1>(IEngine engine, T1 gameAction) where T1 : PlaceTileGameAction
{
return true;
}
}
}

0 comments on commit 6495903

Please sign in to comment.