diff --git a/Qwirkle/QwirkleClassLibrary/Games/Game.cs b/Qwirkle/QwirkleClassLibrary/Games/Game.cs index 5eb18b8..9c85287 100644 --- a/Qwirkle/QwirkleClassLibrary/Games/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Games/Game.cs @@ -160,7 +160,7 @@ namespace QwirkleClassLibrary.Games /// Board public Board CreateBoard() { - Board = new Board(15, 12); + Board = new Board(7, 7); return Board; } @@ -627,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, ref nbCellsInLine); + score += CalculateLineScore(cellsPlayed, cell, dx, dy, b, cellsX, cellsY, ref nbCellsInLine); } return score; @@ -636,6 +636,7 @@ namespace QwirkleClassLibrary.Games /// /// Extension of GetPlayerScore to calculate the score of the player based on the line/column of the adjacent cells /// + /// /// /// /// @@ -644,7 +645,7 @@ namespace QwirkleClassLibrary.Games /// /// /// int - public int CalculateLineScore(Cell cell, int dx, int dy, Board b, int cellsX, int cellsY, ref int nbCellsInLine) + public int CalculateLineScore(ReadOnlyCollection cellsPlayed, Cell cell, int dx, int dy, Board b, int cellsX, int cellsY, ref int nbCellsInLine) { int score = 0; @@ -652,9 +653,9 @@ namespace QwirkleClassLibrary.Games { var extendedCell = b.GetCell(cell.GetX + i * dx, cell.GetY + i * dy); - if (extendedCell?.GetTile == null) + if (extendedCell?.GetTile == null || cellsPlayed.Contains(extendedCell)) { - continue; + break; } if (dx != 0 && cellsX == -1 || dy != 0 && cellsY == -1) @@ -704,23 +705,23 @@ namespace QwirkleClassLibrary.Games /// public bool CheckPlacementPossibilities(List playerTilesBagPos) { - for (int i = 0; i < playerTilesBagPos.Count; i++) + foreach (var t1 in playerTilesBagPos) { - for (int j = 0; j < players[playerTilesBagPos[i]].Tiles.Count; j++) + foreach (var t in players[t1].Tiles) { for (int b = 0; b < Board!.ReadCells.Count; b++) { int x = Board.ReadCells[b].GetX; int y = Board.ReadCells[b].GetY; - if (IsMoveCorrect(players[playerTilesBagPos[i]].Tiles[j], x, y, Board)) + if (IsMoveCorrect(t, x, y, Board)) { return true; } } - } } + return false; } diff --git a/Qwirkle/QwirkleClassLibrary/Games/IPlayer.cs b/Qwirkle/QwirkleClassLibrary/Games/IPlayer.cs index 2cf746a..ac5241e 100644 --- a/Qwirkle/QwirkleClassLibrary/Games/IPlayer.cs +++ b/Qwirkle/QwirkleClassLibrary/Games/IPlayer.cs @@ -23,5 +23,6 @@ public interface IPlayer int CalculateAdjacentScore(Cell cell, Board b, ReadOnlyCollection cellsPlayed, int cellsX, int cellsY, ref int nbCellsInLine); - int CalculateLineScore(Cell cell, int dx, int dy, Board b, 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); } \ No newline at end of file