|
|
|
@ -318,54 +318,119 @@ namespace QwirkleClassLibrary
|
|
|
|
|
return CheckTilesInLine(this.cellUsed, b, x, y) && surroundingCells.Any(cell => cell?.GetTile != null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int GetPlayerScore(Player player, List<Cell> cellsPlayed, Board board)
|
|
|
|
|
// public int GetPlayerScore(Player player, List<Cell> cellsPlayed, Board b)
|
|
|
|
|
// {
|
|
|
|
|
// // Compte le nombre de tuiles et ajoute ce nombre au score
|
|
|
|
|
// int score = cellsPlayed.Count;
|
|
|
|
|
//
|
|
|
|
|
// // Check les lignes / colonnes adjacentes aux tuiles placées
|
|
|
|
|
// for(int i= 0; i < cellsPlayed.Count; i++)
|
|
|
|
|
// {
|
|
|
|
|
// // A chaque tour, crée la liste des 4 cellules adjacentes à la cellule sélectionnée
|
|
|
|
|
// var surroundingCells = new[]
|
|
|
|
|
// {
|
|
|
|
|
// b.GetCell(cellsPlayed[i].GetX + 1, cellsPlayed[i].GetY),
|
|
|
|
|
// b.GetCell(cellsPlayed[i].GetX - 1, cellsPlayed[i].GetY),
|
|
|
|
|
// b.GetCell(cellsPlayed[i].GetX, cellsPlayed[i].GetY + 1),
|
|
|
|
|
// b.GetCell(cellsPlayed[i].GetX, cellsPlayed[i].GetY - 1)
|
|
|
|
|
// };
|
|
|
|
|
//
|
|
|
|
|
// // Parcourt le tableau dans la direction par rapport à ces cellules adjacentes
|
|
|
|
|
// foreach (var cell in surroundingCells)
|
|
|
|
|
// {
|
|
|
|
|
// // Si la cellule adjacente ne contient pas de tuile, on passe à la cellule adjacente suivante
|
|
|
|
|
// if (cell?.GetTile == null) break;
|
|
|
|
|
//
|
|
|
|
|
// if (cellsPlayed.Contains(cell) != true)
|
|
|
|
|
// {
|
|
|
|
|
//
|
|
|
|
|
// var dx = cell.GetX - cellsPlayed[i].GetX;
|
|
|
|
|
// var dy = cell.GetY - cellsPlayed[i].GetY;
|
|
|
|
|
//
|
|
|
|
|
// for (int j = 1; j < b.Rows; j++)
|
|
|
|
|
// {
|
|
|
|
|
// var extendedCell = b.GetCell(cellsPlayed[i].GetX + j * dx, cellsPlayed[i].GetY + j * dy);
|
|
|
|
|
//
|
|
|
|
|
// if (extendedCell?.GetTile == null)
|
|
|
|
|
// {
|
|
|
|
|
// break;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// score += 1;
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// ScoreBoard.Add(player, score);
|
|
|
|
|
//
|
|
|
|
|
// return score;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
public int GetPlayerScore(Player player, ReadOnlyCollection<Cell> cellsPlayed, Board b)
|
|
|
|
|
{
|
|
|
|
|
// Compte le nombre de tuiles et ajoute ce nombre au score
|
|
|
|
|
int score = cellsPlayed.Count;
|
|
|
|
|
|
|
|
|
|
// Check les lignes / colonnes adjacentes aux tuiles placées
|
|
|
|
|
for(int i= 0; i < cellsPlayed.Count; i++)
|
|
|
|
|
foreach (var cell in cellsPlayed)
|
|
|
|
|
{
|
|
|
|
|
// A chaque tour, crée la liste des 4 cellules adjacentes à la cellule sélectionnée
|
|
|
|
|
var surroundingCells = new[]
|
|
|
|
|
{
|
|
|
|
|
board.GetCell(cellsPlayed[i].GetX + 1, cellsPlayed[i].GetY),
|
|
|
|
|
board.GetCell(cellsPlayed[i].GetX - 1, cellsPlayed[i].GetY),
|
|
|
|
|
board.GetCell(cellsPlayed[i].GetX, cellsPlayed[i].GetY + 1),
|
|
|
|
|
board.GetCell(cellsPlayed[i].GetX, cellsPlayed[i].GetY - 1)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Parcourt le tableau dans la direction par rapport à ces cellules adjacentes
|
|
|
|
|
foreach (var cell in surroundingCells)
|
|
|
|
|
score += CalculateAdjacentScore(cell, b, cellsPlayed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(ScoreBoard.TryAdd(player, score) == false)
|
|
|
|
|
{
|
|
|
|
|
ScoreBoard[player] += score;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return score;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int CalculateAdjacentScore(Cell cell, Board b, ReadOnlyCollection<Cell> cellsPlayed)
|
|
|
|
|
{
|
|
|
|
|
int score = 0;
|
|
|
|
|
|
|
|
|
|
var surroundingCells = new[]
|
|
|
|
|
{
|
|
|
|
|
b.GetCell(cell.GetX + 1, cell.GetY),
|
|
|
|
|
b.GetCell(cell.GetX - 1, cell.GetY),
|
|
|
|
|
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))
|
|
|
|
|
{
|
|
|
|
|
// Si la cellule adjacente ne contient pas de tuile, on passe à la cellule adjacente suivante
|
|
|
|
|
if (cell?.GetTile == null) break;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (cellsPlayed.Contains(cell) != true)
|
|
|
|
|
{
|
|
|
|
|
int dx = adjacentCell.GetX - cell.GetX;
|
|
|
|
|
int dy = adjacentCell.GetY - cell.GetY;
|
|
|
|
|
|
|
|
|
|
var dx = cell.GetX - cellsPlayed[i].GetX;
|
|
|
|
|
var dy = cell.GetY - cellsPlayed[i].GetY;
|
|
|
|
|
score += CalculateLineScore(cell, dx, dy, b);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int j = 1; j < board.Rows; j++)
|
|
|
|
|
{
|
|
|
|
|
var extendedCell = board.GetCell(cellsPlayed[i].GetX + j * dx, cellsPlayed[i].GetY + j * dy);
|
|
|
|
|
return score;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (extendedCell?.GetTile == null)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
private int CalculateLineScore(Cell cell, int dx, int dy, Board b)
|
|
|
|
|
{
|
|
|
|
|
int score = 0;
|
|
|
|
|
|
|
|
|
|
score += 1;
|
|
|
|
|
for (int i = 1; i < b.Rows; i++)
|
|
|
|
|
{
|
|
|
|
|
var extendedCell = b.GetCell(cell.GetX + i * dx, cell.GetY + i * dy);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (extendedCell?.GetTile == null)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
score++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ScoreBoard.Add(player, score);
|
|
|
|
|
|
|
|
|
|
return score;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|