diff --git a/Qwirkle/QwirkleClassLibrary/Games/Game.cs b/Qwirkle/QwirkleClassLibrary/Games/Game.cs index c94d56b..f8bb8d2 100644 --- a/Qwirkle/QwirkleClassLibrary/Games/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Games/Game.cs @@ -401,8 +401,13 @@ namespace QwirkleClassLibrary.Games -public int GetPlayerScore(Player player, ReadOnlyCollection cellsPlayed, Board b) + public int GetPlayerScore(Player player, ReadOnlyCollection cellsPlayed, Board b) { + if (cellsPlayed.Count == 0) + { + return 0; + } + int score = cellsPlayed.Count; int cellsX = cellsPlayed[0].GetX; @@ -414,11 +419,15 @@ public int GetPlayerScore(Player player, ReadOnlyCollection cellsPlayed, B { cellsX = -1; } + else if (cellsY != cell.GetY && cellsY != -1) { cellsY = -1; } - + } + + foreach (var cell in cellsPlayed) + { score += CalculateAdjacentScore(cell, b, cellsPlayed, cellsX, cellsY); } @@ -434,7 +443,7 @@ public int GetPlayerScore(Player player, ReadOnlyCollection cellsPlayed, B public int CalculateAdjacentScore(Cell cell, Board b, ReadOnlyCollection cellsPlayed, int cellsX, int cellsY) { int score = 0; - + var surroundingCells = new[] { b.GetCell(cell.GetX + 1, cell.GetY), @@ -442,20 +451,20 @@ public int GetPlayerScore(Player player, ReadOnlyCollection cellsPlayed, B b.GetCell(cell.GetX, cell.GetY + 1), b.GetCell(cell.GetX, cell.GetY - 1) }; - + foreach (var adjacentCell in surroundingCells) { if (adjacentCell?.GetTile == null || cellsPlayed.Contains(adjacentCell)) { continue; } - + int dx = adjacentCell.GetX - cell.GetX; int dy = adjacentCell.GetY - cell.GetY; score += CalculateLineScore(cell, dx, dy, b, cellsX, cellsY); } - + return score; }