diff --git a/Qwirkle/QwirkleClassLibrary/Games/Game.cs b/Qwirkle/QwirkleClassLibrary/Games/Game.cs index ccd734b..00ac47f 100644 --- a/Qwirkle/QwirkleClassLibrary/Games/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Games/Game.cs @@ -709,6 +709,9 @@ namespace QwirkleClassLibrary.Games int score = cellsPlayed.Count; int nbCellsInLine = cellsPlayed.Count; + int nbCellsInPerpLine = 1; + + var checkedCells = new List(); if (cellsPlayed.Count == 6) { @@ -739,9 +742,9 @@ namespace QwirkleClassLibrary.Games } score += cellsPlayed.Sum(cell => - CalculateAdjacentScore(cell, b, cellsPlayed, cellsX, cellsY, ref nbCellsInLine)); + CalculateAdjacentScore(cell, b, cellsPlayed, new Tuple(cellsX, cellsY), ref nbCellsInLine, ref nbCellsInPerpLine, ref checkedCells)); - if (nbCellsInLine == 6) + if (nbCellsInLine == 6 || nbCellsInPerpLine == 6) { score += 6; } @@ -761,12 +764,12 @@ namespace QwirkleClassLibrary.Games /// /// /// - /// - /// + /// + /// + /// /// /// int - public int CalculateAdjacentScore(Cell cell, Board b, ReadOnlyCollection cellsPlayed, int cellsX, - int cellsY, ref int nbCellsInLine) + public int CalculateAdjacentScore(Cell cell, Board b, ReadOnlyCollection cellsPlayed, Tuple orientation, ref int nbCellsInLine, ref int nbCellsInPerpLine, ref List checkedCells) { int score = 0; @@ -778,12 +781,10 @@ namespace QwirkleClassLibrary.Games b.GetCell(cell.GetX, cell.GetY - 1) }; - var checkedSurroundingCells = new List(); - foreach (var adjacentCell in surroundingCells) { if (adjacentCell?.Tile! == null! || cellsPlayed.Contains(adjacentCell) || - checkedSurroundingCells.Contains(adjacentCell)) + checkedCells.Contains(adjacentCell)) { continue; } @@ -791,10 +792,10 @@ namespace QwirkleClassLibrary.Games int dx = adjacentCell.GetX - cell.GetX; int dy = adjacentCell.GetY - cell.GetY; - score += CalculateLineScore(cellsPlayed, cell, new Tuple(dx, dy), b, - new Tuple(cellsX, cellsY), ref nbCellsInLine); + score += CalculateLineScore(cellsPlayed, cell, new Tuple(dx, dy), + new Tuple(orientation.Item1, orientation.Item2), ref nbCellsInLine, ref nbCellsInPerpLine, ref checkedCells); - checkedSurroundingCells.Add(adjacentCell); + checkedCells.Add(adjacentCell); } return score; @@ -806,20 +807,20 @@ namespace QwirkleClassLibrary.Games /// /// /// - /// /// /// + /// + /// /// int - public int CalculateLineScore(ReadOnlyCollection cellsPlayed, Cell cell, Tuple direction, - Board b, Tuple orientation, ref int nbCellsInLine) + public int CalculateLineScore(ReadOnlyCollection cellsPlayed, Cell cell, Tuple direction, Tuple orientation, ref int nbCellsInLine, ref int nbCellsInPerpLine, ref List checkedCells) { int score = 0; for (int i = 1; i < 6; i++) { - var extendedCell = b.GetCell(cell.GetX + i * direction.Item1, cell.GetY + i * direction.Item2); + var extendedCell = board.GetCell(cell.GetX + i * direction.Item1, cell.GetY + i * direction.Item2); - if (extendedCell?.Tile! == null! || cellsPlayed.Contains(extendedCell)) + if (extendedCell?.Tile! == null! || cellsPlayed.Contains(extendedCell) || checkedCells.Contains(extendedCell)) { break; } @@ -828,7 +829,13 @@ namespace QwirkleClassLibrary.Games { nbCellsInLine++; } + + if (direction.Item1 != 0 && orientation.Item1 != -1 || direction.Item2 != 0 && orientation.Item2 != -1) + { + nbCellsInPerpLine++; + } + checkedCells.Add(extendedCell); score++; } diff --git a/Qwirkle/QwirkleClassLibrary/Games/IPlayer.cs b/Qwirkle/QwirkleClassLibrary/Games/IPlayer.cs index c6642b3..c49a85d 100644 --- a/Qwirkle/QwirkleClassLibrary/Games/IPlayer.cs +++ b/Qwirkle/QwirkleClassLibrary/Games/IPlayer.cs @@ -21,7 +21,9 @@ public interface IPlayer public int GetPlayerScore(Player player, ReadOnlyCollection cellsPlayed, Board b); - int CalculateAdjacentScore(Cell cell, Board b, ReadOnlyCollection cellsPlayed, int cellsX, int cellsY, ref int nbCellsInLine); + int CalculateAdjacentScore(Cell cell, Board b, ReadOnlyCollection cellsPlayed, Tuple orientation, + ref int nbCellsInLine, ref int nbCellsInPerpLine, ref List checkedCells); - int CalculateLineScore(ReadOnlyCollection cellsPlayed, Cell cell, Tuple direction, Board b, Tuple orientation, ref int nbCellsInLine); + int CalculateLineScore(ReadOnlyCollection cellsPlayed, Cell cell, Tuple direction, + Tuple orientation, ref int nbCellsInLine, ref int nbCellsInPerpLine, ref List checkedCells); } \ No newline at end of file diff --git a/Qwirkle/TestBase/TestGame.cs b/Qwirkle/TestBase/TestGame.cs index ff2cfac..ede3708 100644 --- a/Qwirkle/TestBase/TestGame.cs +++ b/Qwirkle/TestBase/TestGame.cs @@ -447,7 +447,7 @@ public class TestGame { var game = new Game(); var player = new Player("TestPlayer"); - var board = new Board(8, 8); + var board = game.GetBoard(); board.AddTileInCell(1, 1, new Tile(Shape.Club, Color.Red)); board.AddTileInCell(2, 1, new Tile(Shape.Square, Color.Red));