From 1073b2d802cf7aff57b07b6fb82a8a7a453f29aa Mon Sep 17 00:00:00 2001 From: "jules.lascret" Date: Fri, 7 Jun 2024 14:58:08 +0200 Subject: [PATCH 01/10] Boum le bibi --- Qwirkle/QwirkleClassLibrary/Boards/Board.cs | 2 +- Qwirkle/QwirkleClassLibrary/Games/Game.cs | 173 +++++++++++++++----- Qwirkle/QwirkleClassLibrary/Games/IRules.cs | 2 +- Qwirkle/QwirkleClassLibrary/Tiles/Tile.cs | 20 ++- 4 files changed, 151 insertions(+), 46 deletions(-) diff --git a/Qwirkle/QwirkleClassLibrary/Boards/Board.cs b/Qwirkle/QwirkleClassLibrary/Boards/Board.cs index 7dfc7e5..1a03e1e 100644 --- a/Qwirkle/QwirkleClassLibrary/Boards/Board.cs +++ b/Qwirkle/QwirkleClassLibrary/Boards/Board.cs @@ -53,7 +53,7 @@ namespace QwirkleClassLibrary.Boards { for (int b = 0; b < Columns; b++) { - Cell localcell = new(a, b); + Cell localcell = new(b, a); cells.Add(localcell); } } diff --git a/Qwirkle/QwirkleClassLibrary/Games/Game.cs b/Qwirkle/QwirkleClassLibrary/Games/Game.cs index a7d7385..d7766a6 100644 --- a/Qwirkle/QwirkleClassLibrary/Games/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Games/Game.cs @@ -11,39 +11,31 @@ using static System.Formats.Asn1.AsnWriter; namespace QwirkleClassLibrary.Games { - [DataContract] public class Game : IPlayer, IRules, INotifyPropertyChanged { - [DataMember] - private TileBag? bag = null; + [DataMember] private TileBag? bag = null; - [DataMember] - public bool GameRunning { get; set; } + [DataMember] public bool GameRunning { get; set; } - [DataMember] - private Board board = new(17, 14); + [DataMember] private Board board = new(17, 14); public bool PlayerSwapping { get; set; } public Board Board => board; public ReadOnlyCollection PlayerList => players.AsReadOnly(); - [DataMember] - private readonly List players = []; + [DataMember] private readonly List players = []; - [DataMember] - private readonly Dictionary scoreBoard = new Dictionary(); + [DataMember] private readonly Dictionary scoreBoard = new Dictionary(); public ReadOnlyDictionary ScoreBoard => scoreBoard.AsReadOnly(); - [DataMember] - private readonly ObservableCollection> observableScoreBoard = []; - + [DataMember] private readonly ObservableCollection> observableScoreBoard = []; + public ReadOnlyObservableCollection> ObservableScoreBoard => new(observableScoreBoard); - [DataMember] - private readonly List cellUsed = []; + [DataMember] private readonly List cellUsed = []; public ReadOnlyCollection CellsUsed => cellUsed.AsReadOnly(); @@ -104,9 +96,11 @@ namespace QwirkleClassLibrary.Games if (playersTag.Count <= 1 || playersTag.Count > 4) { playersTag.Clear(); - OnPlayerNotified(new AddPlayerNotifiedEventArgs("ERROR : It takes a minimum of 2 players and a maximum of 4 players to start a game.")); + OnPlayerNotified(new AddPlayerNotifiedEventArgs( + "ERROR : It takes a minimum of 2 players and a maximum of 4 players to start a game.")); return false; } + for (int i = playersTag.Count - 1; i >= 0; i--) { if (!CheckPlayerTag(playersTag, i)) @@ -131,7 +125,8 @@ namespace QwirkleClassLibrary.Games { if (string.IsNullOrWhiteSpace(playersTag[pos])) { - OnPlayerNotified(new AddPlayerNotifiedEventArgs("ERROR with " + (pos + 1) + " entry : The name is null or white space.")); + OnPlayerNotified(new AddPlayerNotifiedEventArgs("ERROR with " + (pos + 1) + + " entry : The name is null or white space.")); return false; } @@ -148,7 +143,6 @@ namespace QwirkleClassLibrary.Games new AddPlayerNotifiedEventArgs("ERROR with " + (pos + 1) + " entry : Name alreay taken")); return false; } - } return true; @@ -170,13 +164,19 @@ namespace QwirkleClassLibrary.Games /// Returns the Board of the game /// /// Board - public Board? GetBoard() { return board; } + public Board? GetBoard() + { + return board; + } /// /// Returns the tile bag of the game /// /// - public TileBag? GetTileBag() { return bag; } + public TileBag? GetTileBag() + { + return bag; + } /// /// Creates a Board with a number of columns and rows @@ -238,6 +238,7 @@ namespace QwirkleClassLibrary.Games { throw new ArgumentException("No player currently playing !"); } + return players[GetPlayingPlayerPosition()]; } @@ -254,6 +255,7 @@ namespace QwirkleClassLibrary.Games return i; } } + return -1; } @@ -312,11 +314,10 @@ namespace QwirkleClassLibrary.Games startingPlayer = player; } } - + startingPlayer!.IsPlaying = true; OnNextPlayer(new NextPlayerNotifiedEventArgs(players[0])); return startingPlayer.NameTag; - } /// @@ -354,11 +355,13 @@ namespace QwirkleClassLibrary.Games OnPlaceTile(new PlaceTileNotifiedEventArgs(tile, "you are swapping, you can't place tile !")); return false; } + if (!TileInbag(player, tile)) { OnPlaceTile(new PlaceTileNotifiedEventArgs(tile, "you can't play")); return false; } + if (!IsMoveCorrect(tile, x, y, board!)) return false; if (board!.AddTileInCell(x, y, tile)) { @@ -446,12 +449,12 @@ namespace QwirkleClassLibrary.Games { players[GetPlayingPlayerPosition()].AddTileToPlayer(t); } - - } + } /// /// Extension of IsMoveCorrect to check beyond the surrounding cells of the cell where the tile is placed /// + /// /// /// /// @@ -459,12 +462,23 @@ namespace QwirkleClassLibrary.Games /// used to get the direction on the y axis /// /// bool - public bool CheckExtendedSurroundingCells(Tile tile, int x, int y, int dx, int dy, Board b) + public bool CheckExtendedSurroundingCells(ref bool previousTilesFound, Tile tile, int x, int y, int dx, int dy, + Board b) { for (int i = 1; i < 7; i++) { var extendedCell = b.GetCell(x + i * dx, y + i * dy); + if (cellUsed.Count == 0) + { + previousTilesFound = true; + } + + if (cellUsed.Contains(extendedCell)) + { + previousTilesFound = true; + } + if (extendedCell?.Tile == null) { break; @@ -472,13 +486,15 @@ namespace QwirkleClassLibrary.Games if (extendedCell.Tile.GetColor != tile.GetColor && extendedCell.Tile.GetShape != tile.GetShape) { - OnPlaceTile(new PlaceTileNotifiedEventArgs(tile, " : Color / Shape does not match with the surrounding tiles !")); + OnPlaceTile(new PlaceTileNotifiedEventArgs(tile, + " : Color / Shape does not match with the surrounding tiles !")); return false; } if (extendedCell.Tile.GetColor == tile.GetColor && extendedCell.Tile.GetShape == tile.GetShape) { - OnPlaceTile(new PlaceTileNotifiedEventArgs(tile, " : Tile already placed on the same line / column !")); + OnPlaceTile(new PlaceTileNotifiedEventArgs(tile, + " : Tile already placed on the same line / column !")); return false; } @@ -527,6 +543,7 @@ namespace QwirkleClassLibrary.Games { return x == x1; } + if (y1 == y2) { return y == y1; @@ -534,6 +551,54 @@ namespace QwirkleClassLibrary.Games return false; } + + public bool CheckWrongCompletedLines(Tile tile, int x, int y, int dx, int dy, Board b, ref List checkdoubles) + { + int nbTiles = 1; + + for (int i = 1; i < 7; i++) + { + var extendedCell = b.GetCell(x + i * dx, y + i * dy); + var extendedCell2 = b.GetCell(x - i * dx, y - i * dy); + + if (extendedCell?.Tile == null && extendedCell2?.Tile == null) + { + break; + } + + if (extendedCell?.Tile != null) + { + nbTiles++; + + foreach (var t in checkdoubles) + { + if (t.CompareTo(extendedCell.Tile) == 0) + { + return false; + } + } + + checkdoubles.Add(extendedCell.Tile); + } + + if (extendedCell2?.Tile != null) + { + nbTiles++; + + foreach (var t in checkdoubles) + { + if (t.CompareTo(extendedCell2.Tile) == 0) + { + return false; + } + } + + checkdoubles.Add(extendedCell2.Tile); + } + } + + return nbTiles <= 6; + } /// /// Main method to check if the move the player is trying to make is correct @@ -545,6 +610,10 @@ namespace QwirkleClassLibrary.Games /// bool public bool IsMoveCorrect(Tile t, int x, int y, Board b) { + bool previousTilesFound = false; + + var checkDoubles = new List(); + if (!b.HasOccupiedCase()) { return true; @@ -572,7 +641,8 @@ namespace QwirkleClassLibrary.Games if (cell.Tile.GetColor != t.GetColor && cell.Tile.GetShape != t.GetShape) { - OnPlaceTile(new PlaceTileNotifiedEventArgs(t, " : Colors / Shapes do not match with the surrounding tiles !")); + OnPlaceTile(new PlaceTileNotifiedEventArgs(t, + " : Colors / Shapes do not match with the surrounding tiles !")); return false; } @@ -586,26 +656,38 @@ namespace QwirkleClassLibrary.Games var dx = cell.GetX - x; var dy = cell.GetY - y; - if (!CheckExtendedSurroundingCells(t, x, y, dx, dy, b)) + if (!CheckExtendedSurroundingCells(ref previousTilesFound, t, x, y, dx, dy, b)) { return false; } + + if (!CheckWrongCompletedLines(t, x, y, dx, dy, b, ref checkDoubles)) + { + OnPlaceTile(new PlaceTileNotifiedEventArgs(t, " : You can't complete this line ! (More than 6 tiles / same tiles on the line)")); + return false; + } } if (!CheckTilesInLine(cellUsed, b, x, y)) { - OnPlaceTile(new PlaceTileNotifiedEventArgs(t, "isn't on the same line as the ones previously placed !")); + OnPlaceTile(new PlaceTileNotifiedEventArgs(t, + "isn't on the same line as the ones previously placed !")); return false; } if (surroundingCells.All(cell => cell?.Tile == null)) { - OnPlaceTile(new PlaceTileNotifiedEventArgs(t, " : You can't place a tile that isn't adjacent to another one !")); + OnPlaceTile(new PlaceTileNotifiedEventArgs(t, + " : You can't place a tile that isn't adjacent to another one !")); return false; } - return true; + if (previousTilesFound) return true; + OnPlaceTile(new PlaceTileNotifiedEventArgs(t, + " : You must place your tile next / on the same line as the ones previously placed !")); + return false; + } @@ -654,7 +736,8 @@ namespace QwirkleClassLibrary.Games cellsX = cellsY = -1; } - score += cellsPlayed.Sum(cell => CalculateAdjacentScore(cell, b, cellsPlayed, cellsX, cellsY, ref nbCellsInLine)); + score += cellsPlayed.Sum(cell => + CalculateAdjacentScore(cell, b, cellsPlayed, cellsX, cellsY, ref nbCellsInLine)); if (nbCellsInLine == 6) { @@ -663,7 +746,6 @@ namespace QwirkleClassLibrary.Games if (!scoreBoard.TryAdd(player.NameTag, score)) { - scoreBoard.TryGetValue(player.NameTag, out int scoreold); SetScoreBoard(player.NameTag, score + scoreold); } @@ -681,7 +763,8 @@ namespace QwirkleClassLibrary.Games /// /// /// int - public int CalculateAdjacentScore(Cell cell, Board b, ReadOnlyCollection cellsPlayed, int cellsX, int cellsY, ref int nbCellsInLine) + public int CalculateAdjacentScore(Cell cell, Board b, ReadOnlyCollection cellsPlayed, int cellsX, + int cellsY, ref int nbCellsInLine) { int score = 0; @@ -697,7 +780,8 @@ namespace QwirkleClassLibrary.Games foreach (var adjacentCell in surroundingCells) { - if (adjacentCell?.Tile == null || cellsPlayed.Contains(adjacentCell) || checkedSurroundingCells.Contains(adjacentCell)) + if (adjacentCell?.Tile == null || cellsPlayed.Contains(adjacentCell) || + checkedSurroundingCells.Contains(adjacentCell)) { continue; } @@ -705,7 +789,8 @@ namespace QwirkleClassLibrary.Games int dx = adjacentCell.GetX - cell.GetX; int dy = adjacentCell.GetY - cell.GetY; - score += CalculateLineScore(cellsPlayed, cell, new Tuple(dx, dy), b, new Tuple(cellsX, cellsY), ref nbCellsInLine); + score += CalculateLineScore(cellsPlayed, cell, new Tuple(dx, dy), b, + new Tuple(cellsX, cellsY), ref nbCellsInLine); checkedSurroundingCells.Add(adjacentCell); } @@ -723,7 +808,8 @@ namespace QwirkleClassLibrary.Games /// /// /// int - public int CalculateLineScore(ReadOnlyCollection cellsPlayed, Cell cell, Tuple direction, Board b, Tuple orientation, ref int nbCellsInLine) + public int CalculateLineScore(ReadOnlyCollection cellsPlayed, Cell cell, Tuple direction, + Board b, Tuple orientation, ref int nbCellsInLine) { int score = 0; @@ -744,7 +830,8 @@ namespace QwirkleClassLibrary.Games score++; } - if (direction.Item1 == 0 && orientation.Item1 == -1 && orientation.Item2 != -1 || direction.Item2 == 0 && orientation.Item2 == -1 && orientation.Item1 != -1) + if (direction.Item1 == 0 && orientation.Item1 == -1 && orientation.Item2 != -1 || + direction.Item2 == 0 && orientation.Item2 == -1 && orientation.Item1 != -1) { score += 1; } @@ -770,7 +857,6 @@ namespace QwirkleClassLibrary.Games playerTilesBagPos.Add(i); } } - } return playerTilesBagPos; @@ -813,7 +899,8 @@ namespace QwirkleClassLibrary.Games { List playerTilesBagPos = CheckTilesBag(); - if (playerTilesBagPos.Count != 0 && !CheckPlacementPossibilities(playerTilesBagPos) || bag!.TilesBag!.Count == 0 && players[GetPlayingPlayerPosition()].Tiles.Count == 0) + if (playerTilesBagPos.Count != 0 && !CheckPlacementPossibilities(playerTilesBagPos) || + bag!.TilesBag!.Count == 0 && players[GetPlayingPlayerPosition()].Tiles.Count == 0) { OnEndOfGame(new EndOfGameNotifiedEventArgs(player)); GameRunning = false; @@ -838,7 +925,6 @@ namespace QwirkleClassLibrary.Games public void SetScoreBoard(string name, int score) { - if (!scoreBoard.TryAdd(name, score)) { scoreBoard[name] = score; @@ -849,6 +935,7 @@ namespace QwirkleClassLibrary.Games { observableScoreBoard.Add(item); } + OnPropertyChanged(nameof(ObservableScoreBoard)); } } diff --git a/Qwirkle/QwirkleClassLibrary/Games/IRules.cs b/Qwirkle/QwirkleClassLibrary/Games/IRules.cs index 064fde2..7e5b709 100644 --- a/Qwirkle/QwirkleClassLibrary/Games/IRules.cs +++ b/Qwirkle/QwirkleClassLibrary/Games/IRules.cs @@ -17,7 +17,7 @@ namespace QwirkleClassLibrary.Games bool IsMoveCorrect(Tile t, int x, int y, Board b); - bool CheckExtendedSurroundingCells(Tile tile, int x, int y, int dx, int dy, Board b); + bool CheckExtendedSurroundingCells(ref bool previousTilesFound, Tile tile, int x, int y, int dx, int dy, Board b); bool CheckTilesInLine(List cells, Board b, int x, int y); diff --git a/Qwirkle/QwirkleClassLibrary/Tiles/Tile.cs b/Qwirkle/QwirkleClassLibrary/Tiles/Tile.cs index 2a2efb9..de68ec4 100644 --- a/Qwirkle/QwirkleClassLibrary/Tiles/Tile.cs +++ b/Qwirkle/QwirkleClassLibrary/Tiles/Tile.cs @@ -9,7 +9,7 @@ using System.Threading.Tasks; namespace QwirkleClassLibrary.Tiles { [DataContract] - public class Tile + public class Tile : IComparable { [DataMember] private readonly Shape shape; @@ -63,5 +63,23 @@ namespace QwirkleClassLibrary.Tiles { return color.ToString() + " " + shape.ToString(); } + + public int CompareTo(object? obj) + { + if (obj == null) return 1; + + var otherTile = obj as Tile; + if (otherTile != null) + { + if (color == otherTile.color) + { + return shape.CompareTo(otherTile.shape); + } + + return color.CompareTo(otherTile.color); + } + + throw new ArgumentException("Object is not a Tile"); + } } } \ No newline at end of file From 317dbeaa83678bb10ea02137a884d63d3faf408f Mon Sep 17 00:00:00 2001 From: "jules.lascret" Date: Fri, 7 Jun 2024 15:06:04 +0200 Subject: [PATCH 02/10] reduce complexity for CheckWrongCompletedLines --- Qwirkle/QwirkleClassLibrary/Games/Game.cs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/Qwirkle/QwirkleClassLibrary/Games/Game.cs b/Qwirkle/QwirkleClassLibrary/Games/Game.cs index d7766a6..c374d43 100644 --- a/Qwirkle/QwirkleClassLibrary/Games/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Games/Game.cs @@ -474,7 +474,7 @@ namespace QwirkleClassLibrary.Games previousTilesFound = true; } - if (cellUsed.Contains(extendedCell)) + if (cellUsed.Contains(extendedCell!)) { previousTilesFound = true; } @@ -570,27 +570,21 @@ namespace QwirkleClassLibrary.Games { nbTiles++; - foreach (var t in checkdoubles) + if(checkdoubles.Any(t => t.CompareTo(extendedCell.Tile) == 0)) { - if (t.CompareTo(extendedCell.Tile) == 0) - { - return false; - } + return false; } checkdoubles.Add(extendedCell.Tile); } - - if (extendedCell2?.Tile != null) + + if (extendedCell2?.Tile == null) continue; { nbTiles++; - foreach (var t in checkdoubles) + if (checkdoubles.Any(t => t.CompareTo(extendedCell2.Tile) == 0)) { - if (t.CompareTo(extendedCell2.Tile) == 0) - { - return false; - } + return false; } checkdoubles.Add(extendedCell2.Tile); From ecfcc1cb3723d068df34eaecfa89fe5f6c99f9d7 Mon Sep 17 00:00:00 2001 From: "jules.lascret" Date: Fri, 7 Jun 2024 15:21:28 +0200 Subject: [PATCH 03/10] Fix 1 minor code smell (normally) --- Qwirkle/QwirkleClassLibrary/Games/Game.cs | 65 +++++++++++++---------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/Qwirkle/QwirkleClassLibrary/Games/Game.cs b/Qwirkle/QwirkleClassLibrary/Games/Game.cs index c374d43..9543a70 100644 --- a/Qwirkle/QwirkleClassLibrary/Games/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Games/Game.cs @@ -551,6 +551,35 @@ namespace QwirkleClassLibrary.Games return false; } + + public static bool CheckTileInCompletedLines(Tile? t1, Tile? t2, ref int nbTiles, ref List checkdoubles) + { + if (t1 != null) + { + nbTiles++; + + if (checkdoubles.Any(t => t.CompareTo(t1) == 0)) + { + return false; + } + + checkdoubles.Add(t1); + } + + if (t2 == null) return true; + { + nbTiles++; + + if (checkdoubles.Any(t => t.CompareTo(t2) == 0)) + { + return false; + } + + checkdoubles.Add(t2); + } + + return true; + } public bool CheckWrongCompletedLines(Tile tile, int x, int y, int dx, int dy, Board b, ref List checkdoubles) { @@ -566,34 +595,14 @@ namespace QwirkleClassLibrary.Games break; } - if (extendedCell?.Tile != null) - { - nbTiles++; - - if(checkdoubles.Any(t => t.CompareTo(extendedCell.Tile) == 0)) - { - return false; - } - - checkdoubles.Add(extendedCell.Tile); - } - - if (extendedCell2?.Tile == null) continue; - { - nbTiles++; - - if (checkdoubles.Any(t => t.CompareTo(extendedCell2.Tile) == 0)) - { - return false; - } - - checkdoubles.Add(extendedCell2.Tile); - } + return CheckTileInCompletedLines(extendedCell?.Tile, extendedCell2?.Tile, ref nbTiles, ref checkdoubles); } return nbTiles <= 6; } + + /// /// Main method to check if the move the player is trying to make is correct /// @@ -654,12 +663,10 @@ namespace QwirkleClassLibrary.Games { return false; } - - if (!CheckWrongCompletedLines(t, x, y, dx, dy, b, ref checkDoubles)) - { - OnPlaceTile(new PlaceTileNotifiedEventArgs(t, " : You can't complete this line ! (More than 6 tiles / same tiles on the line)")); - return false; - } + + if (CheckWrongCompletedLines(t, x, y, dx, dy, b, ref checkDoubles)) continue; + OnPlaceTile(new PlaceTileNotifiedEventArgs(t, " : You can't complete this line ! (More than 6 tiles / same tiles on the line)")); + return false; } From c45e859e83b009bd728f2fd688808b2507117b8b Mon Sep 17 00:00:00 2001 From: "jules.lascret" Date: Fri, 7 Jun 2024 16:58:21 +0200 Subject: [PATCH 04/10] fix some code smells --- Qwirkle/QwirkleClassLibrary/Games/Game.cs | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/Qwirkle/QwirkleClassLibrary/Games/Game.cs b/Qwirkle/QwirkleClassLibrary/Games/Game.cs index 9543a70..9e5bf92 100644 --- a/Qwirkle/QwirkleClassLibrary/Games/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Games/Game.cs @@ -552,7 +552,7 @@ namespace QwirkleClassLibrary.Games return false; } - public static bool CheckTileInCompletedLines(Tile? t1, Tile? t2, ref int nbTiles, ref List checkdoubles) + public static bool CheckTileInCompletedLines(Tile? t1, ref int nbTiles, ref List checkdoubles) { if (t1 != null) { @@ -565,19 +565,7 @@ namespace QwirkleClassLibrary.Games checkdoubles.Add(t1); } - - if (t2 == null) return true; - { - nbTiles++; - - if (checkdoubles.Any(t => t.CompareTo(t2) == 0)) - { - return false; - } - - checkdoubles.Add(t2); - } - + return true; } @@ -594,8 +582,10 @@ namespace QwirkleClassLibrary.Games { break; } - - return CheckTileInCompletedLines(extendedCell?.Tile, extendedCell2?.Tile, ref nbTiles, ref checkdoubles); + + if(!CheckTileInCompletedLines(extendedCell?.Tile, ref nbTiles, ref checkdoubles)) return false; + + if(!CheckTileInCompletedLines(extendedCell2?.Tile, ref nbTiles, ref checkdoubles)) return false; } return nbTiles <= 6; From 3455682073b8eecf7b427358f1e1cf8e73fb7001 Mon Sep 17 00:00:00 2001 From: "jules.lascret" Date: Fri, 7 Jun 2024 17:23:40 +0200 Subject: [PATCH 05/10] fixed all code smells normally now --- Qwirkle/QwirkleClassLibrary/Games/Game.cs | 90 +++++++++++++---------- Qwirkle/QwirkleClassLibrary/Tiles/Tile.cs | 72 ++++++++++++++---- 2 files changed, 107 insertions(+), 55 deletions(-) diff --git a/Qwirkle/QwirkleClassLibrary/Games/Game.cs b/Qwirkle/QwirkleClassLibrary/Games/Game.cs index 9e5bf92..b4d8f61 100644 --- a/Qwirkle/QwirkleClassLibrary/Games/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Games/Game.cs @@ -164,7 +164,7 @@ namespace QwirkleClassLibrary.Games /// Returns the Board of the game /// /// Board - public Board? GetBoard() + public Board GetBoard() { return board; } @@ -362,8 +362,8 @@ namespace QwirkleClassLibrary.Games return false; } - if (!IsMoveCorrect(tile, x, y, board!)) return false; - if (board!.AddTileInCell(x, y, tile)) + if (!IsMoveCorrect(tile, x, y, board)) return false; + if (board.AddTileInCell(x, y, tile)) { AddCellUsed(board.GetCell(x, y)); return player.RemoveTileToPlayer(tile); @@ -479,7 +479,7 @@ namespace QwirkleClassLibrary.Games previousTilesFound = true; } - if (extendedCell?.Tile == null) + if (extendedCell?.Tile! == null!) { break; } @@ -552,9 +552,16 @@ namespace QwirkleClassLibrary.Games return false; } - public static bool CheckTileInCompletedLines(Tile? t1, ref int nbTiles, ref List checkdoubles) + /// + /// Check that there isn't any same tile on a said line when a tile is forming a line + /// + /// + /// + /// + /// + private static bool CheckTileInCompletedLines(Tile? t1, ref int nbTiles, ref List checkdoubles) { - if (t1 != null) + if (t1! != null!) { nbTiles++; @@ -569,7 +576,18 @@ namespace QwirkleClassLibrary.Games return true; } - public bool CheckWrongCompletedLines(Tile tile, int x, int y, int dx, int dy, Board b, ref List checkdoubles) + /// + /// Check if the line is completed with the tile placed + /// + /// + /// + /// + /// + /// + /// + /// + /// + private static bool CheckWrongCompletedLines(int x, int y, int dx, int dy, Board b, ref List checkdoubles) { int nbTiles = 1; @@ -578,7 +596,7 @@ namespace QwirkleClassLibrary.Games var extendedCell = b.GetCell(x + i * dx, y + i * dy); var extendedCell2 = b.GetCell(x - i * dx, y - i * dy); - if (extendedCell?.Tile == null && extendedCell2?.Tile == null) + if (extendedCell?.Tile! == null! && extendedCell2?.Tile! == null!) { break; } @@ -591,30 +609,17 @@ namespace QwirkleClassLibrary.Games return nbTiles <= 6; } - - - /// - /// Main method to check if the move the player is trying to make is correct - /// - /// - /// - /// - /// - /// bool public bool IsMoveCorrect(Tile t, int x, int y, Board b) { - bool previousTilesFound = false; - - var checkDoubles = new List(); - if (!b.HasOccupiedCase()) { return true; } - if (b.GetCell(x, y)!.Tile != null) + if (b.GetCell(x, y)!.Tile! != null!) { OnPlaceTile(new PlaceTileNotifiedEventArgs(t, " : Cell already used !")); + return false; } var surroundingCells = new List @@ -624,10 +629,26 @@ namespace QwirkleClassLibrary.Games b.GetCell(x, y + 1), b.GetCell(x, y - 1) }; + + if (surroundingCells.All(cell => cell?.Tile! == null!)) + { + OnPlaceTile(new PlaceTileNotifiedEventArgs(t, + " : You can't place a tile that isn't adjacent to another one !")); + return false; + } + + return IsTilePlacementCorrect(t, x, y, b, surroundingCells); + } + + public bool IsTilePlacementCorrect(Tile t, int x, int y, Board b, List surroundingCells) + { + bool previousTilesFound = false; + + var checkDoubles = new List(); foreach (var cell in surroundingCells) { - if (cell?.Tile == null) + if (cell?.Tile! == null!) { continue; } @@ -642,7 +663,6 @@ namespace QwirkleClassLibrary.Games if (cell.Tile.GetColor == t.GetColor && cell.Tile.GetShape == t.GetShape) { OnPlaceTile(new PlaceTileNotifiedEventArgs(t, " is already placed on the same line / column !")); - return false; } @@ -654,12 +674,12 @@ namespace QwirkleClassLibrary.Games return false; } - if (CheckWrongCompletedLines(t, x, y, dx, dy, b, ref checkDoubles)) continue; - OnPlaceTile(new PlaceTileNotifiedEventArgs(t, " : You can't complete this line ! (More than 6 tiles / same tiles on the line)")); + if (CheckWrongCompletedLines(x, y, dx, dy, b, ref checkDoubles)) continue; + OnPlaceTile(new PlaceTileNotifiedEventArgs(t, + " : You can't complete this line ! (More than 6 tiles / same tiles on the line)")); return false; } - if (!CheckTilesInLine(cellUsed, b, x, y)) { OnPlaceTile(new PlaceTileNotifiedEventArgs(t, @@ -667,18 +687,10 @@ namespace QwirkleClassLibrary.Games return false; } - if (surroundingCells.All(cell => cell?.Tile == null)) - { - OnPlaceTile(new PlaceTileNotifiedEventArgs(t, - " : You can't place a tile that isn't adjacent to another one !")); - return false; - } - if (previousTilesFound) return true; OnPlaceTile(new PlaceTileNotifiedEventArgs(t, " : You must place your tile next / on the same line as the ones previously placed !")); return false; - } @@ -771,7 +783,7 @@ namespace QwirkleClassLibrary.Games foreach (var adjacentCell in surroundingCells) { - if (adjacentCell?.Tile == null || cellsPlayed.Contains(adjacentCell) || + if (adjacentCell?.Tile! == null! || cellsPlayed.Contains(adjacentCell) || checkedSurroundingCells.Contains(adjacentCell)) { continue; @@ -808,7 +820,7 @@ namespace QwirkleClassLibrary.Games { var extendedCell = b.GetCell(cell.GetX + i * direction.Item1, cell.GetY + i * direction.Item2); - if (extendedCell?.Tile == null || cellsPlayed.Contains(extendedCell)) + if (extendedCell?.Tile! == null! || cellsPlayed.Contains(extendedCell)) { break; } @@ -864,7 +876,7 @@ namespace QwirkleClassLibrary.Games { foreach (var t in players[t1].Tiles) { - for (int b = 0; b < board!.ReadCells.Count; b++) + for (int b = 0; b < board.ReadCells.Count; b++) { int x = board.ReadCells[b].GetX; int y = board.ReadCells[b].GetY; diff --git a/Qwirkle/QwirkleClassLibrary/Tiles/Tile.cs b/Qwirkle/QwirkleClassLibrary/Tiles/Tile.cs index de68ec4..4752c67 100644 --- a/Qwirkle/QwirkleClassLibrary/Tiles/Tile.cs +++ b/Qwirkle/QwirkleClassLibrary/Tiles/Tile.cs @@ -41,19 +41,13 @@ namespace QwirkleClassLibrary.Tiles /// A getter for the shape of the Tile. /// /// The shape attribute of the Tile. - public Shape GetShape - { - get { return shape; } - } + public Shape GetShape => shape; /// /// A getter for the color of the Tile. /// /// The color attribute of the Tile. - public Color GetColor - { - get { return color; } - } + public Color GetColor => color; /// /// This method is used to override the ToString() method. It is simply a tool to facilitate the development. @@ -66,20 +60,66 @@ namespace QwirkleClassLibrary.Tiles public int CompareTo(object? obj) { - if (obj == null) return 1; + if (obj == null) + { + throw new NullReferenceException(); + } var otherTile = obj as Tile; - if (otherTile != null) + + if (color == otherTile!.color) { - if (color == otherTile.color) - { - return shape.CompareTo(otherTile.shape); - } + return shape.CompareTo(otherTile.shape); + } + + return color.CompareTo(otherTile.color); + + } - return color.CompareTo(otherTile.color); + public override bool Equals(object? obj) + { + if (obj == null || GetType() != obj.GetType()) + { + return false; } - throw new ArgumentException("Object is not a Tile"); + var otherTile = obj as Tile; + return color == otherTile!.color && shape == otherTile.shape; + } + + public override int GetHashCode() + { + return HashCode.Combine(color, shape); + } + + public static bool operator ==(Tile tile1, Tile tile2) + { + return EqualityComparer.Default.Equals(tile1, tile2); + } + + public static bool operator !=(Tile tile1, Tile tile2) + { + return !(tile1 == tile2); + } + + public static bool operator <(Tile tile1, Tile tile2) + { + return tile1.CompareTo(tile2) < 0; + } + + public static bool operator >(Tile tile1, Tile tile2) + { + return tile1.CompareTo(tile2) > 0; + } + + public static bool operator <=(Tile tile1, Tile tile2) + { + return tile1.CompareTo(tile2) <= 0; + } + + public static bool operator >=(Tile tile1, Tile tile2) + { + return tile1.CompareTo(tile2) >= 0; } } } \ No newline at end of file From 9ea98eaa90280b68061b08b21c1865ef4854ad50 Mon Sep 17 00:00:00 2001 From: "jules.lascret" Date: Fri, 7 Jun 2024 17:38:12 +0200 Subject: [PATCH 06/10] Fixed code smell + added test --- Qwirkle/Files/Game.xml | 2 +- Qwirkle/QwirkleClassLibrary/Boards/Cell.cs | 4 ++-- Qwirkle/QwirkleClassLibrary/Games/Game.cs | 2 +- Qwirkle/QwirkleClassLibrary/Tiles/Tile.cs | 2 +- Qwirkle/TestBase/TestGame.cs | 17 +++++++++++++++++ 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Qwirkle/Files/Game.xml b/Qwirkle/Files/Game.xml index 1683161..c55059d 100644 --- a/Qwirkle/Files/Game.xml +++ b/Qwirkle/Files/Game.xml @@ -1 +1 @@ -false1714000102030405060708090100110120130140150161011121314151617181911011111211311411511620212223242526272829210211212213214215216303132333435363738393103113123133143153164041424344454647484941041141241341441541650515253545556575859510511512513514515516606162636465666768696106116126136146156167071727374757677787971071171271371471571680818283848586878889810811812813814815816909192939495969798999109119129139149159161001011021031041051061071081091010101110121013101410151016110111112113114115116117118119111011111112111311141115111612012112212312412512612712812912101211121212131214121512161301311321331341351361371381391310131113121313131413151316 \ No newline at end of file +false1714001020304050607080901001101201301401501600111213141516171819110111112113114115116102122232425262728292102112122132142152162031323334353637383931031131231331431531630414243444546474849410411412413414415416405152535455565758595105115125135145155165061626364656667686961061161261361461561660717273747576777879710711712713714715716708182838485868788898108118128138148158168091929394959697989991091191291391491591690101102103104105106107108109101010111012101310141015101610011111211311411511611711811911101111111211131114111511161101211221231241251261271281291210121112121213121412151216120131132133134135136137138139131013111312131313141315131613 \ No newline at end of file diff --git a/Qwirkle/QwirkleClassLibrary/Boards/Cell.cs b/Qwirkle/QwirkleClassLibrary/Boards/Cell.cs index 0f470dc..68deb01 100644 --- a/Qwirkle/QwirkleClassLibrary/Boards/Cell.cs +++ b/Qwirkle/QwirkleClassLibrary/Boards/Cell.cs @@ -61,7 +61,7 @@ public class Cell : INotifyPropertyChanged /// True if the cell is empty, false if the cell contains a tile. public bool IsFree { - get { return Tile == null; } + get { return Tile! == null!; } } @@ -72,7 +72,7 @@ public class Cell : INotifyPropertyChanged /// True if added succefully (if the cell didn't already contain a tile), false if there already was a tile in this cell. public bool SetTile(Tile addedTile) { - if (Tile == null) + if (Tile! == null!) { Tile = addedTile; diff --git a/Qwirkle/QwirkleClassLibrary/Games/Game.cs b/Qwirkle/QwirkleClassLibrary/Games/Game.cs index b4d8f61..2b1568e 100644 --- a/Qwirkle/QwirkleClassLibrary/Games/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Games/Game.cs @@ -559,7 +559,7 @@ namespace QwirkleClassLibrary.Games /// /// /// - private static bool CheckTileInCompletedLines(Tile? t1, ref int nbTiles, ref List checkdoubles) + public static bool CheckTileInCompletedLines(Tile? t1, ref int nbTiles, ref List checkdoubles) { if (t1! != null!) { diff --git a/Qwirkle/QwirkleClassLibrary/Tiles/Tile.cs b/Qwirkle/QwirkleClassLibrary/Tiles/Tile.cs index 4752c67..45bd8c6 100644 --- a/Qwirkle/QwirkleClassLibrary/Tiles/Tile.cs +++ b/Qwirkle/QwirkleClassLibrary/Tiles/Tile.cs @@ -62,7 +62,7 @@ namespace QwirkleClassLibrary.Tiles { if (obj == null) { - throw new NullReferenceException(); + throw new NullReferenceException("The object is null."); } var otherTile = obj as Tile; diff --git a/Qwirkle/TestBase/TestGame.cs b/Qwirkle/TestBase/TestGame.cs index d479be3..ee641ba 100644 --- a/Qwirkle/TestBase/TestGame.cs +++ b/Qwirkle/TestBase/TestGame.cs @@ -381,6 +381,23 @@ public class TestGame } + [Fact] + public void Test_CheckTileInCompletedLines() + { + + int nbTiles = 0; + var checkdoubles = new List() + { + new(Shape.Club, Color.Blue), + new(Shape.Club, Color.Red), + new(Shape.Club, Color.Green), + }; + + var t1 = new Tile(Shape.Club, Color.Green); + + Assert.False(Game.CheckTileInCompletedLines(t1, ref nbTiles, ref checkdoubles)); + } + [Theory] [InlineData(3, 1, 4, 1, 5, 1, 5)] [InlineData(2, 2, 3, 2, 4, 2, 5)] From 20323c92b552607ae14d85d453c4721390d0c3af Mon Sep 17 00:00:00 2001 From: "jules.lascret" Date: Fri, 7 Jun 2024 17:47:03 +0200 Subject: [PATCH 07/10] More tests and code smell fix (starting to feel bored) --- Qwirkle/QwirkleClassLibrary/Games/Game.cs | 2 +- Qwirkle/TestBase/TestGame.cs | 24 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Qwirkle/QwirkleClassLibrary/Games/Game.cs b/Qwirkle/QwirkleClassLibrary/Games/Game.cs index 2b1568e..739efb5 100644 --- a/Qwirkle/QwirkleClassLibrary/Games/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Games/Game.cs @@ -587,7 +587,7 @@ namespace QwirkleClassLibrary.Games /// /// /// - private static bool CheckWrongCompletedLines(int x, int y, int dx, int dy, Board b, ref List checkdoubles) + public static bool CheckWrongCompletedLines(int x, int y, int dx, int dy, Board b, ref List checkdoubles) { int nbTiles = 1; diff --git a/Qwirkle/TestBase/TestGame.cs b/Qwirkle/TestBase/TestGame.cs index ee641ba..5dd518e 100644 --- a/Qwirkle/TestBase/TestGame.cs +++ b/Qwirkle/TestBase/TestGame.cs @@ -398,6 +398,30 @@ public class TestGame Assert.False(Game.CheckTileInCompletedLines(t1, ref nbTiles, ref checkdoubles)); } + [Fact] + public void Test_CheckWrongCompletedLines() + { + // Arrange + var game = new Game(); + var board = new Board(17, 14); + var checkDoubles = new List(); + int x = 4, y = 1, dx = 1, dy = 0; + + // Add tiles to the board + board.AddTileInCell(1, 1, new Tile(Shape.Club, Color.Red)); + board.AddTileInCell(2, 1, new Tile(Shape.Square, Color.Red)); + board.AddTileInCell(3, 1, new Tile(Shape.Star, Color.Red)); + board.AddTileInCell(5, 1, new Tile(Shape.Round, Color.Red)); + board.AddTileInCell(6, 1, new Tile(Shape.Shuriken, Color.Red)); + board.AddTileInCell(7, 1, new Tile(Shape.Rhombus, Color.Red)); + + // Act + bool result = Game.CheckWrongCompletedLines(x, y, dx, dy, board, ref checkDoubles); + + // Assert + Assert.False(result); + } + [Theory] [InlineData(3, 1, 4, 1, 5, 1, 5)] [InlineData(2, 2, 3, 2, 4, 2, 5)] From 4cc3b3361d710d8cf82fc8ab961f334dd1f7fab3 Mon Sep 17 00:00:00 2001 From: "jules.lascret" Date: Fri, 7 Jun 2024 18:04:02 +0200 Subject: [PATCH 08/10] test issue #1 --- Qwirkle/QwirkleClassLibrary/Games/Game.cs | 5 ++--- Qwirkle/QwirkleClassLibrary/Tiles/Tile.cs | 2 +- Qwirkle/TestBase/TestGame.cs | 12 ++++-------- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/Qwirkle/QwirkleClassLibrary/Games/Game.cs b/Qwirkle/QwirkleClassLibrary/Games/Game.cs index 739efb5..d5e8d19 100644 --- a/Qwirkle/QwirkleClassLibrary/Games/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Games/Game.cs @@ -7,7 +7,6 @@ using QwirkleClassLibrary.Events; using QwirkleClassLibrary.Players; using System.ComponentModel; using System.Runtime.CompilerServices; -using static System.Formats.Asn1.AsnWriter; namespace QwirkleClassLibrary.Games { @@ -559,7 +558,7 @@ namespace QwirkleClassLibrary.Games /// /// /// - public static bool CheckTileInCompletedLines(Tile? t1, ref int nbTiles, ref List checkdoubles) + public bool CheckTileInCompletedLines(Tile? t1, ref int nbTiles, ref List checkdoubles) { if (t1! != null!) { @@ -587,7 +586,7 @@ namespace QwirkleClassLibrary.Games /// /// /// - public static bool CheckWrongCompletedLines(int x, int y, int dx, int dy, Board b, ref List checkdoubles) + public bool CheckWrongCompletedLines(int x, int y, int dx, int dy, Board b, ref List checkdoubles) { int nbTiles = 1; diff --git a/Qwirkle/QwirkleClassLibrary/Tiles/Tile.cs b/Qwirkle/QwirkleClassLibrary/Tiles/Tile.cs index 45bd8c6..4c72ccf 100644 --- a/Qwirkle/QwirkleClassLibrary/Tiles/Tile.cs +++ b/Qwirkle/QwirkleClassLibrary/Tiles/Tile.cs @@ -62,7 +62,7 @@ namespace QwirkleClassLibrary.Tiles { if (obj == null) { - throw new NullReferenceException("The object is null."); + return 1; } var otherTile = obj as Tile; diff --git a/Qwirkle/TestBase/TestGame.cs b/Qwirkle/TestBase/TestGame.cs index 5dd518e..6c5637a 100644 --- a/Qwirkle/TestBase/TestGame.cs +++ b/Qwirkle/TestBase/TestGame.cs @@ -384,7 +384,7 @@ public class TestGame [Fact] public void Test_CheckTileInCompletedLines() { - + var game = new Game(); int nbTiles = 0; var checkdoubles = new List() { @@ -395,30 +395,26 @@ public class TestGame var t1 = new Tile(Shape.Club, Color.Green); - Assert.False(Game.CheckTileInCompletedLines(t1, ref nbTiles, ref checkdoubles)); + Assert.False(game.CheckTileInCompletedLines(t1, ref nbTiles, ref checkdoubles)); } [Fact] public void Test_CheckWrongCompletedLines() { - // Arrange var game = new Game(); var board = new Board(17, 14); var checkDoubles = new List(); int x = 4, y = 1, dx = 1, dy = 0; - // Add tiles to the board board.AddTileInCell(1, 1, new Tile(Shape.Club, Color.Red)); board.AddTileInCell(2, 1, new Tile(Shape.Square, Color.Red)); board.AddTileInCell(3, 1, new Tile(Shape.Star, Color.Red)); board.AddTileInCell(5, 1, new Tile(Shape.Round, Color.Red)); board.AddTileInCell(6, 1, new Tile(Shape.Shuriken, Color.Red)); board.AddTileInCell(7, 1, new Tile(Shape.Rhombus, Color.Red)); + + bool result = game.CheckWrongCompletedLines(x, y, dx, dy, board, ref checkDoubles); - // Act - bool result = Game.CheckWrongCompletedLines(x, y, dx, dy, board, ref checkDoubles); - - // Assert Assert.False(result); } From f0a3185b4b34dfda83665095898f9c770281ae3c Mon Sep 17 00:00:00 2001 From: "jules.lascret" Date: Fri, 7 Jun 2024 18:21:06 +0200 Subject: [PATCH 09/10] Test issue #2 --- Qwirkle/QwirkleClassLibrary/Games/Game.cs | 2 +- Qwirkle/TestBase/TestGame.cs | 64 +++++++++++++++-------- 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/Qwirkle/QwirkleClassLibrary/Games/Game.cs b/Qwirkle/QwirkleClassLibrary/Games/Game.cs index d5e8d19..caca023 100644 --- a/Qwirkle/QwirkleClassLibrary/Games/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Games/Game.cs @@ -558,7 +558,7 @@ namespace QwirkleClassLibrary.Games /// /// /// - public bool CheckTileInCompletedLines(Tile? t1, ref int nbTiles, ref List checkdoubles) + public static bool CheckTileInCompletedLines(Tile? t1, ref int nbTiles, ref List checkdoubles) { if (t1! != null!) { diff --git a/Qwirkle/TestBase/TestGame.cs b/Qwirkle/TestBase/TestGame.cs index 6c5637a..e09f068 100644 --- a/Qwirkle/TestBase/TestGame.cs +++ b/Qwirkle/TestBase/TestGame.cs @@ -287,25 +287,6 @@ public class TestGame Assert.False(game.PlaceTile(game.GetPlayingPlayer(), game.PlayerList[game.GetPlayingPlayerPosition()].Tiles[0], -5, 1)); } - // [Fact] - // public void Test_DrawTile() - // { - // Game game = new Game(); - // game.AddPlayerInGame("Test1"); - // game.AddPlayerInGame(playerstest); - // - // game.StartGame(); - // game.SetNextPlayer(); - // - // Assert.True(game.DrawTiles(game.GetPlayingPlayer())); - // - // /*test*/ - // TileBag bag = new TileBag(0); - // Assert.False(game.DrawTiles(game.GetPlayingPlayer())); - // return; - // - // } - [Theory] [InlineData(true)] [InlineData(false)] @@ -342,6 +323,48 @@ public class TestGame Assert.Equal(p, events.Player); } + [Fact] + public void Test_IsTilePlacementCorrect() + { + var game = new Game(); + var board = new Board(17, 14); + var tile = new Tile(Shape.Club, Color.Red); + + board.AddTileInCell(0, 1, new Tile(Shape.Club, Color.Blue)); + + var x = 1; + var y = 1; + + var surroundingCells = new List + { + board.GetCell(x + 1, y), + board.GetCell(x - 1, y), + board.GetCell(x, y + 1), + board.GetCell(x, y - 1) + }; + + bool result = game.IsTilePlacementCorrect(tile, x, y, board, surroundingCells); + + Assert.True(result); + } + + [Fact] + public void Test_IsMoveCorrect() + { + var game = new Game(); + var board = new Board(17, 14); + var tile = new Tile(Shape.Club, Color.Red); + + board.AddTileInCell(0, 1, new Tile(Shape.Club, Color.Blue)); + + var x = 2; + var y = 1; + + bool result = game.IsMoveCorrect(tile, x, y, board); + + Assert.False(result); + } + [Fact] public void Test_IsMoveCorrectSixLine() { @@ -384,7 +407,6 @@ public class TestGame [Fact] public void Test_CheckTileInCompletedLines() { - var game = new Game(); int nbTiles = 0; var checkdoubles = new List() { @@ -395,7 +417,7 @@ public class TestGame var t1 = new Tile(Shape.Club, Color.Green); - Assert.False(game.CheckTileInCompletedLines(t1, ref nbTiles, ref checkdoubles)); + Assert.False(Game.CheckTileInCompletedLines(t1, ref nbTiles, ref checkdoubles)); } [Fact] From b0afa799aee0f28d7d03f4de2a82e244299411bd Mon Sep 17 00:00:00 2001 From: "jules.lascret" Date: Fri, 7 Jun 2024 18:23:39 +0200 Subject: [PATCH 10/10] Test issue #3, normally back at 0 code smells & +80% coverage --- Qwirkle/QwirkleClassLibrary/Games/Game.cs | 2 +- Qwirkle/TestBase/TestGame.cs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Qwirkle/QwirkleClassLibrary/Games/Game.cs b/Qwirkle/QwirkleClassLibrary/Games/Game.cs index caca023..ccd734b 100644 --- a/Qwirkle/QwirkleClassLibrary/Games/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Games/Game.cs @@ -586,7 +586,7 @@ namespace QwirkleClassLibrary.Games /// /// /// - public bool CheckWrongCompletedLines(int x, int y, int dx, int dy, Board b, ref List checkdoubles) + public static bool CheckWrongCompletedLines(int x, int y, int dx, int dy, Board b, ref List checkdoubles) { int nbTiles = 1; diff --git a/Qwirkle/TestBase/TestGame.cs b/Qwirkle/TestBase/TestGame.cs index e09f068..ff2cfac 100644 --- a/Qwirkle/TestBase/TestGame.cs +++ b/Qwirkle/TestBase/TestGame.cs @@ -423,7 +423,6 @@ public class TestGame [Fact] public void Test_CheckWrongCompletedLines() { - var game = new Game(); var board = new Board(17, 14); var checkDoubles = new List(); int x = 4, y = 1, dx = 1, dy = 0; @@ -435,7 +434,7 @@ public class TestGame board.AddTileInCell(6, 1, new Tile(Shape.Shuriken, Color.Red)); board.AddTileInCell(7, 1, new Tile(Shape.Rhombus, Color.Red)); - bool result = game.CheckWrongCompletedLines(x, y, dx, dy, board, ref checkDoubles); + bool result = Game.CheckWrongCompletedLines(x, y, dx, dy, board, ref checkDoubles); Assert.False(result); }