diff --git a/Qwirkle/QwirkleClassLibrary/Games/Game.cs b/Qwirkle/QwirkleClassLibrary/Games/Game.cs index 23464c5..7249d2b 100644 --- a/Qwirkle/QwirkleClassLibrary/Games/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Games/Game.cs @@ -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(); 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(dx, dy), b, new Tuple(cellsX, cellsY), ref nbCellsInLine); + + checkedSurroundingCells.Add(adjacentCell); } return score; @@ -638,27 +647,25 @@ namespace QwirkleClassLibrary.Games /// /// /// - /// - /// + /// /// - /// - /// + /// /// /// int - public int CalculateLineScore(ReadOnlyCollection cellsPlayed, Cell cell, int dx, int dy, Board b, int cellsX, int cellsY, ref int nbCellsInLine) + public int CalculateLineScore(ReadOnlyCollection cellsPlayed, Cell cell, Tuple direction, Board b, Tuple 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; } diff --git a/Qwirkle/QwirkleClassLibrary/Games/IPlayer.cs b/Qwirkle/QwirkleClassLibrary/Games/IPlayer.cs index ac5241e..f534458 100644 --- a/Qwirkle/QwirkleClassLibrary/Games/IPlayer.cs +++ b/Qwirkle/QwirkleClassLibrary/Games/IPlayer.cs @@ -23,6 +23,5 @@ public interface IPlayer int CalculateAdjacentScore(Cell cell, Board b, ReadOnlyCollection cellsPlayed, int cellsX, int cellsY, ref int nbCellsInLine); - int CalculateLineScore(ReadOnlyCollection cellsPlayed, Cell cell, int dx, int dy, Board b, int cellsX, - int cellsY, ref int nbCellsInLine); + int CalculateLineScore(ReadOnlyCollection cellsPlayed, Cell cell, Tuple direction, Board b, Tuple orientation, ref int nbCellsInLine); } \ No newline at end of file diff --git a/Qwirkle/QwirkleClassLibrary/Tiles/TileBag.cs b/Qwirkle/QwirkleClassLibrary/Tiles/TileBag.cs index 57cf565..b9d7183 100644 --- a/Qwirkle/QwirkleClassLibrary/Tiles/TileBag.cs +++ b/Qwirkle/QwirkleClassLibrary/Tiles/TileBag.cs @@ -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(); }