Skip to content

Commit

Permalink
Merge pull request #26 from FaronBracy/V5PreRelease
Browse files Browse the repository at this point in the history
V5 pre release
  • Loading branch information
FaronBracy authored Jun 30, 2019
2 parents 0cd5650 + a8fef1d commit 57d8058
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 48 deletions.
42 changes: 41 additions & 1 deletion RogueSharp.Test/MapTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,46 @@ public void Create_MapCreatedWithCaveCreationStrategy_ExpectedMap()
Assert.AreEqual( RemoveWhiteSpace( expectedMapRepresentation ), RemoveWhiteSpace( actualMap.ToString() ) );
}

[TestMethod]
public void Create_DerivedMapCreatedWithCaveCreationStrategy_ExpectedMap()
{
int expectedWidth = 50;
int expectedHeight = 20;
IRandom random = new DotNetRandom( 27 );
IMapCreationStrategy<CaveMap> mapCreationStrategy = new CaveMapCreationStrategy<CaveMap>( expectedWidth, expectedHeight, 45, 3, 2, random );
string expectedMapRepresentation = @"##################################################
########...###################.#.#####....########
######.......##############......#####....########
####........###############......####......#######
###.........#################...######........####
##........#################.##..#####.....########
###.......#######.#.######..##..#######.#..#######
####......######.......#........#########..#######
#####.......#....##....###......#########..#######
######........#####..............#########..######
#..###......########....######...#########..######
#...##......########.....#####.....#.######..#####
#............##########..######......######..#####
#...........########.....######.#....#######..####
##...........#######.....###################..####
#............#.#####........#################..###
##.............#####................#########..###
###.............#####........######...........####
####.#....#.#.#######.#.#...######################
##################################################";

CaveMap actualMap = Map.Create( mapCreationStrategy );
Trace.Write( actualMap );

Assert.AreEqual( expectedWidth, actualMap.Width );
Assert.AreEqual( expectedHeight, actualMap.Height );
Assert.AreEqual( RemoveWhiteSpace( expectedMapRepresentation ), RemoveWhiteSpace( actualMap.ToString() ) );
}

public class CaveMap : Map
{
}

[TestMethod]
public void Create_MapCreatedWithWidth40Height20BorderOnlyStrategy_ExpectedMap()
{
Expand Down Expand Up @@ -155,7 +195,7 @@ public void Clone_SmallMap_MapAndCloneHaveDifferentReferencesButSameValues()
IMapCreationStrategy<Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy<Map>( mapRepresentation );
IMap originalMap = Map.Create( mapCreationStrategy );

IMap clonedMap = originalMap.Clone();
IMap clonedMap = originalMap.Clone<Map>();

Assert.AreNotEqual( originalMap, clonedMap );
Assert.AreEqual( RemoveWhiteSpace( originalMap.ToString() ), RemoveWhiteSpace( clonedMap.ToString() ) );
Expand Down
3 changes: 2 additions & 1 deletion RogueSharp/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage( "Usage", "CA2237:Mark ISerializable types with serializable", Justification = "Not available in .NET Standard 1.0", Scope = "type", Target = "~T:RogueSharp.NoMoreStepsException" )]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage( "Usage", "CA2237:Mark ISerializable types with serializable", Justification = "Not available in .NET Standard 1.0", Scope = "type", Target = "~T:RogueSharp.PathNotFoundException" )]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage( "Performance", "CA1814:Prefer jagged arrays over multidimensional", Justification = "The array in question represents a rectangular map", Scope = "member", Target = "~M:RogueSharp.GoalMap.#ctor(RogueSharp.IMap,System.Boolean)" )]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage( "Globalization", "CA1304:Specify CultureInfo", Justification = "Not available in .NET Standard 1.0", Scope = "member", Target = "~M:RogueSharp.DiceNotation.DiceParser.Parse(System.String)~RogueSharp.DiceNotation.DiceExpression" )]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage( "Globalization", "CA1304:Specify CultureInfo", Justification = "Not available in .NET Standard 1.0", Scope = "member", Target = "~M:RogueSharp.DiceNotation.DiceParser.Parse(System.String)~RogueSharp.DiceNotation.DiceExpression" )]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage( "Performance", "CA1814:Prefer jagged arrays over multidimensional", Justification = "<Pending>", Scope = "member", Target = "~M:RogueSharp.Map.#ctor(System.Int32,System.Int32)" )]
4 changes: 2 additions & 2 deletions RogueSharp/IMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ int Height
/// <summary>
/// Create and return a deep copy of an existing Map
/// </summary>
/// <returns>IMap deep copy of the original Map</returns>
IMap Clone();
/// <returns>T of type IMap which is a deep copy of the original Map</returns>
T Clone<T>() where T : IMap, new();

/// <summary>
/// Copies the Cell properties of a smaller source Map into this destination Map at location (0,0)
Expand Down
18 changes: 11 additions & 7 deletions RogueSharp/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ public Map()
/// <param name="height">How many Cells tall the Map will be</param>
public Map( int width, int height )
{
#pragma warning disable CA2214 // Do not call overridable methods in constructors
Initialize( width, height );
#pragma warning restore CA2214 // Do not call overridable methods in constructors
Width = width;
Height = height;
_isTransparent = new bool[width, height];
_isWalkable = new bool[width, height];
_isExplored = new bool[width, height];
_fieldOfView = new FieldOfView( this );
}

/// <summary>
Expand Down Expand Up @@ -204,12 +207,13 @@ public void Clear( bool isTransparent, bool isWalkable )
}

/// <summary>
/// Create and return a deep copy of an existing Map
/// Create and return a deep copy of an existing Map.
/// Override when a derived class has additional properties to clone.
/// </summary>
/// <returns>IMap deep copy of the original Map</returns>
public IMap Clone()
/// <returns>T of type IMap which is a deep copy of the original Map</returns>
public virtual T Clone<T>() where T : IMap, new()
{
var map = new Map( Width, Height );
T map = Create( new BorderOnlyMapCreationStrategy<T>( Width, Height ) );
foreach ( ICell cell in GetAllCells() )
{
map.SetCellProperties( cell.X, cell.Y, cell.IsTransparent, cell.IsWalkable, cell.IsExplored );
Expand Down
8 changes: 4 additions & 4 deletions RogueSharp/MapCreation/CaveMapCreationStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public T CreateMap()
}
else if ( i >= _cutoffOfBigAreaFill )
{
CellularAutomaNearestNeighborsAlgorithm();
CellularAutomataNearestNeighborsAlgorithm();
}
}

Expand Down Expand Up @@ -113,7 +113,7 @@ private void RandomlyFillCells()

private void CellularAutomataBigAreaAlgorithm()
{
var updatedMap = _map.Clone() as T;
T updatedMap = _map.Clone<T>();

foreach ( ICell cell in _map.GetAllCells() )
{
Expand All @@ -134,9 +134,9 @@ private void CellularAutomataBigAreaAlgorithm()
_map = updatedMap;
}

private void CellularAutomaNearestNeighborsAlgorithm()
private void CellularAutomataNearestNeighborsAlgorithm()
{
var updatedMap = _map.Clone() as T;
T updatedMap = _map.Clone<T>();

foreach ( ICell cell in _map.GetAllCells() )
{
Expand Down
58 changes: 25 additions & 33 deletions RogueSharp/RogueSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,35 @@

<PropertyGroup>
<TargetFrameworks>netstandard1.0;net40</TargetFrameworks>
<Version>4.2.0</Version>
<Version>5.0.0-pre</Version>
<Authors>Faron Bracy</Authors>
<Company />
<Description>A .NET Standard class library providing map generation, path-finding, and field-of-view utilities frequently used in roguelikes or 2D tile based games. Inspired by libtcod
<Description>
A .NET Standard class library providing map generation, path-finding, and field-of-view utilities frequently used in roguelikes or 2D tile based games. Inspired by libtcod

New features:
* Optimized cave map generator (Thanks to James Neal)
* Optimized DijkstraShortestPath.FindPath method (Thanks to flend for this update)
* Multiple new "Try" methods which return null instead of throwing exceptions
* Diagonal paths can be found by using new constructors on GoalMap and PathFinder
* Map.GetCellsInCircle and Map.GetBorderCellsInCircle to get cells within a circular radius
Breaking changes:
* Bug fix (4.2.0) - EdgeWeightedDigraph updates NumberOfEdges property when new edge is added
* Bug fix (4.1.0) - selecting border cells along edge of map no longer selects center cell
* Point and Rectangle classes are now structs (Thanks to James Neal)
* Updated all appropriate references to Cell with ICell (Thanks to Courtney Strachan)
* Map.ComputeFov and Map.AppendFov both return a ReadonlyCollection of ICell instead void
* The Path returned from PathFinder.ShortestPath now includes the source cell in the returned Path
* Map.GetCellsInArea was renamed to Map.GetCellsInSquare
* Map.GetCellsInRadius was renamed to Map.GetCellsInDiamond</Description>
<PackageReleaseNotes>A .NET Standard class library providing map generation, path-finding, and field-of-view utilities frequently used in roguelikes or 2D tile based games. Inspired by libtcod
New features:
* Weighted pool class for randomly picking items.
* Pathfinder class caches graph and dijkstra result for speedier performance with multiple lookups.
* Added Map.GetCellsInRectangle method. (Thanks to Andre Odendaal)
Breaking changes:
* Bug fix - Change Map.Create to be generic, returning the same map type as the creation strategy's map. (Thanks to Andre Odendaal)
* Bug fix - Update Map Save and Restore methods to track IsExplored status. (Thanks to Andre Odendaal)
* Map.Initialize is virtual so that it can be overridden in derived classes
* Map.Clone is now virtual and generic so that it can be overridden in derived classes.
</Description>
<PackageReleaseNotes>
A .NET Standard class library providing map generation, path-finding, and field-of-view utilities frequently used in roguelikes or 2D tile based games. Inspired by libtcod

New features:
* Optimized cave map generator (Thanks to James Neal)
* Optimized DijkstraShortestPath.FindPath method (Thanks to flend for this update)
* Multiple new "Try" methods which return null instead of throwing exceptions
* Diagonal paths can be found by using new constructors on GoalMap and PathFinder
* Map.GetCellsInCircle and Map.GetBorderCellsInCircle to get cells within a circular radius
Breaking changes:
* Bug fix (4.2.0) - EdgeWeightedDigraph updates NumberOfEdges property when new edge is added
* Bug fix (4.1.0) - selecting border cells along edge of map no longer selects center cell
* Point and Rectangle classes are now structs (Thanks to James Neal)
* Updated all appropriate references to Cell with ICell (Thanks to Courtney Strachan)
* Map.ComputeFov and Map.AppendFov both return a ReadonlyCollection of ICell instead void
* The Path returned from PathFinder.ShortestPath now includes the source cell in the returned Path
* Map.GetCellsInArea was renamed to Map.GetCellsInSquare
* Map.GetCellsInRadius was renamed to Map.GetCellsInDiamond</PackageReleaseNotes>
New features:
* Weighted pool class for randomly picking items.
* Pathfinder class caches graph and dijkstra result for speedier performance with multiple lookups.
* Added Map.GetCellsInRectangle method. (Thanks to Andre Odendaal)
Breaking changes:
* Bug fix - Change Map.Create to be generic, returning the same map type as the creation strategy's map. (Thanks to Andre Odendaal)
* Bug fix - Update Map Save and Restore methods to track IsExplored status. (Thanks to Andre Odendaal)
* Map.Initialize is virtual so that it can be overridden in derived classes
* Map.Clone is now virtual and generic so that it can be overridden in derived classes.
</PackageReleaseNotes>
<Copyright>Copyright 2014-2019 Faron Bracy</Copyright>
<PackageLicenseUrl>https://github.com/FaronBracy/RogueSharp/blob/master/LICENSE.txt</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/FaronBracy/RogueSharp</PackageProjectUrl>
Expand Down

0 comments on commit 57d8058

Please sign in to comment.