|
|
|
@ -359,6 +359,11 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bag!.TilesBag.Count < tilesToSwap.Count)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var t in tilesToSwap)
|
|
|
|
|
{
|
|
|
|
|
if (!player.RemoveTileToPlayer(t))
|
|
|
|
@ -616,10 +621,12 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
|
b.GetCell(cell.GetX, cell.GetY + 1),
|
|
|
|
|
b.GetCell(cell.GetX, cell.GetY - 1)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var checkedSurroundingCells = new List<Cell>();
|
|
|
|
|
|
|
|
|
|
foreach (var adjacentCell in surroundingCells)
|
|
|
|
|
{
|
|
|
|
|
if (adjacentCell?.GetTile == null || cellsPlayed.Contains(adjacentCell))
|
|
|
|
|
if (adjacentCell?.GetTile == null || cellsPlayed.Contains(adjacentCell) || checkedSurroundingCells.Contains(adjacentCell))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
@ -627,7 +634,9 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
|
int dx = adjacentCell.GetX - cell.GetX;
|
|
|
|
|
int dy = adjacentCell.GetY - cell.GetY;
|
|
|
|
|
|
|
|
|
|
score += CalculateLineScore(cellsPlayed, cell, dx, dy, b, cellsX, cellsY, ref nbCellsInLine);
|
|
|
|
|
score += CalculateLineScore(cellsPlayed, cell, new Tuple<int, int>(dx, dy), b, new Tuple<int, int>(cellsX, cellsY), ref nbCellsInLine);
|
|
|
|
|
|
|
|
|
|
checkedSurroundingCells.Add(adjacentCell);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return score;
|
|
|
|
@ -638,27 +647,25 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="cellsPlayed"></param>
|
|
|
|
|
/// <param name="cell"></param>
|
|
|
|
|
/// <param name="dx"></param>
|
|
|
|
|
/// <param name="dy"></param>
|
|
|
|
|
/// <param name="direction"></param>
|
|
|
|
|
/// <param name="b"></param>
|
|
|
|
|
/// <param name="cellsX"></param>
|
|
|
|
|
/// <param name="cellsY"></param>
|
|
|
|
|
/// <param name="orientation"></param>
|
|
|
|
|
/// <param name="nbCellsInLine"></param>
|
|
|
|
|
/// <returns>int</returns>
|
|
|
|
|
public int CalculateLineScore(ReadOnlyCollection<Cell> cellsPlayed, Cell cell, int dx, int dy, Board b, int cellsX, int cellsY, ref int nbCellsInLine)
|
|
|
|
|
public int CalculateLineScore(ReadOnlyCollection<Cell> cellsPlayed, Cell cell, Tuple<int, int> direction, Board b, Tuple<int, int> orientation, ref int nbCellsInLine)
|
|
|
|
|
{
|
|
|
|
|
int score = 0;
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i < 6; i++)
|
|
|
|
|
{
|
|
|
|
|
var extendedCell = b.GetCell(cell.GetX + i * dx, cell.GetY + i * dy);
|
|
|
|
|
var extendedCell = b.GetCell(cell.GetX + i * direction.Item1, cell.GetY + i * direction.Item2);
|
|
|
|
|
|
|
|
|
|
if (extendedCell?.GetTile == null || cellsPlayed.Contains(extendedCell))
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dx != 0 && cellsX == -1 || dy != 0 && cellsY == -1)
|
|
|
|
|
if (direction.Item1 != 0 && orientation.Item1 == -1 || direction.Item2 != 0 && orientation.Item2 == -1)
|
|
|
|
|
{
|
|
|
|
|
nbCellsInLine++;
|
|
|
|
|
}
|
|
|
|
@ -666,7 +673,7 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
|
score++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dx == 0 && cellsX == -1 && cellsY != -1 || dy == 0 && cellsY == -1 && cellsX != -1)
|
|
|
|
|
if (direction.Item1 == 0 && orientation.Item1 == -1 && orientation.Item2 != -1 || direction.Item2 == 0 && orientation.Item2 == -1 && orientation.Item1 != -1)
|
|
|
|
|
{
|
|
|
|
|
score += 1;
|
|
|
|
|
}
|
|
|
|
|