Merge branch 'master' of https://codefirst.iut.uca.fr/git/jeremy.mouyon/sae201_qwirkle
continuous-integration/drone/push Build is passing Details

test_old_branch
Jérémy Mouyon 11 months ago
commit 02a0fc8b65

@ -550,6 +550,7 @@ namespace QwirkleClassLibrary.Games
}
int score = cellsPlayed.Count;
int nbCellsInLine = cellsPlayed.Count;
if (cellsPlayed.Count == 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
/// <param name="cellsPlayed"></param>
/// <param name="cellsX"></param>
/// <param name="cellsY"></param>
/// <param name="nbCellsInLine"></param>
/// <returns>int</returns>
public int CalculateAdjacentScore(Cell cell, Board b, ReadOnlyCollection<Cell> cellsPlayed, int cellsX, int cellsY)
public int CalculateAdjacentScore(Cell cell, Board b, ReadOnlyCollection<Cell> cellsPlayed, int cellsX, int cellsY, ref int nbCellsInLine)
{
int score = 0;
@ -621,7 +627,7 @@ 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
/// <param name="b"></param>
/// <param name="cellsX"></param>
/// <param name="cellsY"></param>
/// <param name="nbCellsPlayed"></param>
/// <param name="nbCellsInLine"></param>
/// <returns>int</returns>
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;
}

@ -21,7 +21,7 @@ public interface IPlayer
public int GetPlayerScore(Player player, ReadOnlyCollection<Cell> cellsPlayed, Board b);
int CalculateAdjacentScore(Cell cell, Board b, ReadOnlyCollection<Cell> cellsPlayed, int cellsX, int cellsY);
int CalculateAdjacentScore(Cell cell, Board b, ReadOnlyCollection<Cell> 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);
}
Loading…
Cancel
Save