Skip to content

Commit

Permalink
added method to retrieve cross diagonal cells from origin one
Browse files Browse the repository at this point in the history
  • Loading branch information
ninetailsrabbit committed Jul 15, 2024
1 parent 184ef55 commit d8b15f3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
25 changes: 25 additions & 0 deletions Match3Maker.Tests/tests/src/components/BoardTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,31 @@ public void Should_Retrieve_Cross_Cells_From_Origin_One() {
Assert.Equal((board.GridWidth + board.GridHeight) - 1, crossCells.Count);
}

[Fact]
public void Should_Retrieve_Cross_Diagonal_Cells_From_Origin_One() {
var board = new Board(5, 6, 10, _mockPieceSelector.Object, _mockSequenceFinder.Object);

board.PrepareGridCells();

var originCell = board.TopLeftCornerCell();
var crossDiagonalCells = board.CrossDiagonalCellsFrom(originCell);

Assert.Equal(board.GridWidth - 1, crossDiagonalCells.Count);

foreach (var cell in crossDiagonalCells) {
Assert.False(cell.InSameRowAs(originCell) && cell.InSameColumnAs(originCell));
}

originCell = board.Cell(3, 2);
crossDiagonalCells = board.CrossDiagonalCellsFrom(originCell);

Assert.Equal(7, crossDiagonalCells.Count);

foreach (var cell in crossDiagonalCells) {
Assert.False(cell.InSameRowAs(originCell) && cell.InSameColumnAs(originCell));
}
}

[Fact]
public void Should_Detect_Border_And_Corners() {
var board = new Board(8, 7, 10, _mockPieceSelector.Object, _mockSequenceFinder.Object);
Expand Down
2 changes: 1 addition & 1 deletion Match3Maker/Match3Maker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<PropertyGroup>
<Title>Ninetailsrabbit.Match3Maker</Title>
<Version>1.2.2</Version>
<Version>1.2.3</Version>
<Description>This lightweight library provides the core logic and functionality you need to build engaging match-3 games. Focus on game design and mechanics while leaving the complex logic to this library</Description>
<Copyright>© 2024 Ninetailsrabbit</Copyright>
<Authors>Ninetailsrabbit</Authors>
Expand Down
13 changes: 12 additions & 1 deletion Match3Maker/src/components/Board.cs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,18 @@ public List<GridCell> CrossCellsFrom(GridCell originCell) {
return CellsFromRow(originCell.Row)
.Concat(CellsFromColumn(originCell.Column))
.RemoveDuplicates()
.Select(cell => GridCells[cell.Column][cell.Row])
.ToList();
}

public List<GridCell> CrossDiagonalCellsFrom(GridCell originCell) {
var distance = GridWidth + GridHeight;

return DiagonalTopLeftCellsFrom(originCell, distance)
.Concat(DiagonalTopRightCellsFrom(originCell, distance))
.Concat(DiagonalBottomLeftCellsFrom(originCell, distance))
.Concat(DiagonalBottomRightCellsFrom(originCell, distance))
.RemoveDuplicates()
.RemoveNullables()
.ToList();
}

Expand Down

0 comments on commit d8b15f3

Please sign in to comment.