diff --git a/Qwirkle/QwirkleClassLibrary/Games/Game.cs b/Qwirkle/QwirkleClassLibrary/Games/Game.cs
index 88ae11f..5eb18b8 100644
--- a/Qwirkle/QwirkleClassLibrary/Games/Game.cs
+++ b/Qwirkle/QwirkleClassLibrary/Games/Game.cs
@@ -550,7 +550,8 @@ namespace QwirkleClassLibrary.Games
}
int score = cellsPlayed.Count;
-
+ int nbCellsInLine = cellsPlayed.Count;
+
if (cellsPlayed.Count == 6)
{
score += 6;
@@ -579,8 +580,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))
{
@@ -598,8 +603,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;
@@ -620,8 +626,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;
@@ -636,9 +642,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;
@@ -651,20 +657,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
| | | | |