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

test_old_branch
Jérémy Mouyon 11 months ago
commit 90f9c1b819

@ -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;
}

@ -23,6 +23,5 @@ public interface IPlayer
int CalculateAdjacentScore(Cell cell, Board b, ReadOnlyCollection<Cell> cellsPlayed, int cellsX, int cellsY, ref int nbCellsInLine);
int CalculateLineScore(ReadOnlyCollection<Cell> cellsPlayed, Cell cell, int dx, int dy, Board b, int cellsX,
int cellsY, ref int nbCellsInLine);
int CalculateLineScore(ReadOnlyCollection<Cell> cellsPlayed, Cell cell, Tuple<int, int> direction, Board b, Tuple<int, int> orientation, ref int nbCellsInLine);
}

@ -24,18 +24,31 @@ namespace QwirkleClassLibrary.Tiles
throw new ArgumentException(nbSet.ToString());
}
for (int i = 0; i < nbSet; i++)
{
foreach (Shape s in Enum.GetValues(typeof(Shape)))
{
foreach (Color c in Enum.GetValues(typeof(Color)))
{
Tile t = new Tile(s, c);
tiles.Add(t);
}
}
}
// for (int i = 0; i < nbSet; i++)
// {
// foreach (Shape s in Enum.GetValues(typeof(Shape)))
// {
// foreach (Color c in Enum.GetValues(typeof(Color)))
// {
// Tile t = new Tile(s, c);
// tiles.Add(t);
// }
// }
// }
tiles.Add(new Tile(Shape.Club, Color.Blue));
tiles.Add(new Tile(Shape.Club, Color.Green));
tiles.Add(new Tile(Shape.Club, Color.Orange));
tiles.Add(new Tile(Shape.Club, Color.Purple));
tiles.Add(new Tile(Shape.Club, Color.Red));
tiles.Add(new Tile(Shape.Club, Color.Yellow));
tiles.Add(new Tile(Shape.Square, Color.Blue));
tiles.Add(new Tile(Shape.Square, Color.Green));
tiles.Add(new Tile(Shape.Square, Color.Orange));
tiles.Add(new Tile(Shape.Square, Color.Purple));
tiles.Add(new Tile(Shape.Square, Color.Red));
tiles.Add(new Tile(Shape.Square, Color.Yellow));
TilesBag = tiles.AsReadOnly();
}

Loading…
Cancel
Save