From c3e03004ab57551fab43d9a3d1f115733d2d850a Mon Sep 17 00:00:00 2001 From: "jules.lascret" Date: Sat, 25 May 2024 09:52:10 +0200 Subject: [PATCH] update on score calculation --- Qwirkle/QwirkleClassLibrary/Games/Game.cs | 31 ++++++++++---------- Qwirkle/QwirkleClassLibrary/Games/IPlayer.cs | 4 +-- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Qwirkle/QwirkleClassLibrary/Games/Game.cs b/Qwirkle/QwirkleClassLibrary/Games/Game.cs index 4a82dd7..b0268b6 100644 --- a/Qwirkle/QwirkleClassLibrary/Games/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Games/Game.cs @@ -542,7 +542,8 @@ namespace QwirkleClassLibrary.Games } int score = cellsPlayed.Count; - + int nbCellsInLine = cellsPlayed.Count; + if (cellsPlayed.Count == 6) { score += 6; @@ -571,8 +572,12 @@ namespace QwirkleClassLibrary.Games cellsX = cellsY = -1; } - score += cellsPlayed.Sum(cell => CalculateAdjacentScore(cell, b, cellsPlayed, cellsX, cellsY)); + score += cellsPlayed.Sum(cell => CalculateAdjacentScore(cell, b, cellsPlayed, cellsX, cellsY, ref nbCellsInLine)); + if (nbCellsInLine == 6) + { + score += 6; + } if (!scoreBoard.TryAdd(player, score)) { @@ -590,8 +595,9 @@ namespace QwirkleClassLibrary.Games /// /// /// + /// /// int - public int CalculateAdjacentScore(Cell cell, Board b, ReadOnlyCollection cellsPlayed, int cellsX, int cellsY) + public int CalculateAdjacentScore(Cell cell, Board b, ReadOnlyCollection cellsPlayed, int cellsX, int cellsY, ref int nbCellsInLine) { int score = 0; @@ -612,8 +618,8 @@ namespace QwirkleClassLibrary.Games int dx = adjacentCell.GetX - cell.GetX; int dy = adjacentCell.GetY - cell.GetY; - - score += CalculateLineScore(cell, dx, dy, b, cellsX, cellsY, cellsPlayed.Count); + + score += CalculateLineScore(cell, dx, dy, b, cellsX, cellsY, ref nbCellsInLine); } return score; @@ -628,9 +634,9 @@ namespace QwirkleClassLibrary.Games /// /// /// - /// + /// /// int - public int CalculateLineScore(Cell cell, int dx, int dy, Board b, int cellsX, int cellsY, int nbCellsPlayed) + public int CalculateLineScore(Cell cell, int dx, int dy, Board b, int cellsX, int cellsY, ref int nbCellsInLine) { int score = 0; @@ -643,20 +649,15 @@ namespace QwirkleClassLibrary.Games continue; } - if (dx == 0 && cellsY != -1 && i + 1 == 6 || dy == 0 && cellsX != -1 && i + 1 == 6) - { - score += 6; - } - - if (dx != 0 && cellsY != -1 && i + nbCellsPlayed == 6 || dy != 0 && cellsX != -1 && i + nbCellsPlayed == 6) + if (dx != 0 && cellsX == -1 || dy != 0 && cellsY == -1) { - score += 6; + nbCellsInLine++; } score++; } - if (dx == 0 && cellsX == -1 || dy == 0 && cellsY == -1) + if (dx == 0 && cellsX == -1 && cellsY != -1 || dy == 0 && cellsY == -1 && cellsX != -1) { score += 1; } diff --git a/Qwirkle/QwirkleClassLibrary/Games/IPlayer.cs b/Qwirkle/QwirkleClassLibrary/Games/IPlayer.cs index a10ad57..2cf746a 100644 --- a/Qwirkle/QwirkleClassLibrary/Games/IPlayer.cs +++ b/Qwirkle/QwirkleClassLibrary/Games/IPlayer.cs @@ -21,7 +21,7 @@ public interface IPlayer public int GetPlayerScore(Player player, ReadOnlyCollection cellsPlayed, Board b); - int CalculateAdjacentScore(Cell cell, Board b, ReadOnlyCollection cellsPlayed, int cellsX, int cellsY); + int CalculateAdjacentScore(Cell cell, Board b, ReadOnlyCollection cellsPlayed, int cellsX, int cellsY, ref int nbCellsInLine); - int CalculateLineScore(Cell cell, int dx, int dy, Board b, int cellsX, int cellsY, int nbCellsPlayed); + int CalculateLineScore(Cell cell, int dx, int dy, Board b, int cellsX, int cellsY, ref int nbCellsInLine); } \ No newline at end of file