From 9d22b46d0ff89c4204b3a43a9c9049ad479c72f6 Mon Sep 17 00:00:00 2001 From: "jeremy.mouyon" Date: Mon, 6 May 2024 11:42:16 +0200 Subject: [PATCH 1/8] test --- Qwirkle/QwirkleClassLibrary/Score.cs | 4 ++ Qwirkle/QwirkleClassLibrary/TileBag.cs | 4 +- .../Properties/launchSettings.json | 11 +++++ Qwirkle/TestBase/TestPlayer.cs | 8 ++-- Qwirkle/TestBase/TestScore.cs | 42 +++++++++++++++++++ Qwirkle/TestBase/TestTileBag.cs | 20 ++++++++- 6 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 Qwirkle/QwirkleConsoleApp/Properties/launchSettings.json create mode 100644 Qwirkle/TestBase/TestScore.cs diff --git a/Qwirkle/QwirkleClassLibrary/Score.cs b/Qwirkle/QwirkleClassLibrary/Score.cs index 14b5763..60adc70 100644 --- a/Qwirkle/QwirkleClassLibrary/Score.cs +++ b/Qwirkle/QwirkleClassLibrary/Score.cs @@ -13,6 +13,10 @@ namespace QwirkleClassLibrary public Score(Player p) { + if(p == null) + { + throw new ArgumentException(p.ToString()); + } score = 0; playerTag = p.NameTag; } diff --git a/Qwirkle/QwirkleClassLibrary/TileBag.cs b/Qwirkle/QwirkleClassLibrary/TileBag.cs index 9b16b4b..01ed06d 100644 --- a/Qwirkle/QwirkleClassLibrary/TileBag.cs +++ b/Qwirkle/QwirkleClassLibrary/TileBag.cs @@ -14,7 +14,7 @@ namespace QwirkleClassLibrary public TileBag(int nbSet) { - if (nbSet < 0 || nbSet < 3) + if (nbSet < 0 || nbSet > 3) { throw new ArgumentException(nbSet.ToString()); } @@ -35,7 +35,7 @@ namespace QwirkleClassLibrary public bool AddTileInBag(Tile tile) { - if (tiles == null) + if (tile == null) { return false; } diff --git a/Qwirkle/QwirkleConsoleApp/Properties/launchSettings.json b/Qwirkle/QwirkleConsoleApp/Properties/launchSettings.json new file mode 100644 index 0000000..c2bcc14 --- /dev/null +++ b/Qwirkle/QwirkleConsoleApp/Properties/launchSettings.json @@ -0,0 +1,11 @@ +{ + "profiles": { + "QwirkleConsoleApp": { + "commandName": "Project" + }, + "WSL": { + "commandName": "WSL2", + "distributionName": "" + } + } +} \ No newline at end of file diff --git a/Qwirkle/TestBase/TestPlayer.cs b/Qwirkle/TestBase/TestPlayer.cs index a619600..37b92e5 100644 --- a/Qwirkle/TestBase/TestPlayer.cs +++ b/Qwirkle/TestBase/TestPlayer.cs @@ -1,8 +1,7 @@ using QwirkleClassLibrary; +namespace TestBase; -namespace TestBase -{ - public class TestPlayers +public class TestPlayers { [Theory] [InlineData(true, "Mathis")] @@ -61,5 +60,4 @@ namespace TestBase } Assert.True(r); } - } -} \ No newline at end of file + } \ No newline at end of file diff --git a/Qwirkle/TestBase/TestScore.cs b/Qwirkle/TestBase/TestScore.cs new file mode 100644 index 0000000..b001591 --- /dev/null +++ b/Qwirkle/TestBase/TestScore.cs @@ -0,0 +1,42 @@ +using QwirkleClassLibrary; +namespace TestBase; + +public class TestScore +{ + public static IEnumerable Data_Score() + { + yield return new object[] + { + true, + new Player("Test"), + }; + yield return new object[] + { + false, + null, + }; + } + + [Theory] + [MemberData(nameof(Data_Score))] + public void Test_CellScoreConstructor(bool except, Player p) + { + if (!except) + { + Assert.Throws(() => new Score(p)); + return; + } + Score score = new Score(p); + Assert.True(true); + } + + + + + + + + + +} + diff --git a/Qwirkle/TestBase/TestTileBag.cs b/Qwirkle/TestBase/TestTileBag.cs index c06f72d..350f0f6 100644 --- a/Qwirkle/TestBase/TestTileBag.cs +++ b/Qwirkle/TestBase/TestTileBag.cs @@ -16,7 +16,7 @@ public class TestTileBag return; } TileBag bag = new TileBag(nbset); - Assert.Equal(bag.TilesBag.Count, nbset); + Assert.Equal(bag.TilesBag.Count, nbset*36); } [Fact] @@ -33,5 +33,23 @@ public class TestTileBag } } + + [Fact] + public void Test_RemoveTileInBag() + { + Tile t = null; + Tile tok = new(Shape.Club, Color.Green); + TileBag bag = new TileBag(2); + bag.AddTileInBag(tok); + + if (bag.RemoveTileInBag(t) == false) + { + Assert.True(bag.RemoveTileInBag(tok)); + + } + + } + + } From ebc768683c53349bacb038f4c59adf3eee2b41f7 Mon Sep 17 00:00:00 2001 From: "jeremy.mouyon" Date: Mon, 6 May 2024 12:58:19 +0200 Subject: [PATCH 2/8] test --- Qwirkle/QwirkleClassLibrary/Score.cs | 4 +-- Qwirkle/TestBase/TestBoard.cs | 38 ++++++++++++++++++++++++++++ Qwirkle/TestBase/TestScore.cs | 26 +++++-------------- 3 files changed, 47 insertions(+), 21 deletions(-) create mode 100644 Qwirkle/TestBase/TestBoard.cs diff --git a/Qwirkle/QwirkleClassLibrary/Score.cs b/Qwirkle/QwirkleClassLibrary/Score.cs index 60adc70..c47bff0 100644 --- a/Qwirkle/QwirkleClassLibrary/Score.cs +++ b/Qwirkle/QwirkleClassLibrary/Score.cs @@ -13,9 +13,9 @@ namespace QwirkleClassLibrary public Score(Player p) { - if(p == null) + if(p==null) { - throw new ArgumentException(p.ToString()); + throw new ArgumentException(); } score = 0; playerTag = p.NameTag; diff --git a/Qwirkle/TestBase/TestBoard.cs b/Qwirkle/TestBase/TestBoard.cs new file mode 100644 index 0000000..1cffe4c --- /dev/null +++ b/Qwirkle/TestBase/TestBoard.cs @@ -0,0 +1,38 @@ +using QwirkleClassLibrary; +namespace TestBase; + +public class TestBoard +{ + + + + public static IEnumerable Data_Board() + { + yield return new object[] + { + true, + new Cell(0,0), + new Tile(Shape.Round, Color.Red) + }; + yield return new object[] + { + false, + new Cell(0,0), + new Tile(Shape.Round, Color.Red) + }; + } + + [Theory] + [MemberData(nameof(Data_Board))] + public void Test_AddTile(bool except, Cell c, Tile t) + { + if (!except) + { + c.SetTile(t); + Assert.False(c.SetTile(t)); + return; + } + Assert.True(c.SetTile(t)); + } +} + diff --git a/Qwirkle/TestBase/TestScore.cs b/Qwirkle/TestBase/TestScore.cs index b001591..7f1fd02 100644 --- a/Qwirkle/TestBase/TestScore.cs +++ b/Qwirkle/TestBase/TestScore.cs @@ -3,29 +3,17 @@ namespace TestBase; public class TestScore { - public static IEnumerable Data_Score() - { - yield return new object[] - { - true, - new Player("Test"), - }; - yield return new object[] - { - false, - null, - }; - } - [Theory] - [MemberData(nameof(Data_Score))] - public void Test_CellScoreConstructor(bool except, Player p) + [InlineData(false)] + //[InlineData(true)] + public void Test_CellScoreConstructor(bool except) { - if (!except) + /*if (!except) { - Assert.Throws(() => new Score(p)); + Assert.Throws(() => new Score(null)); return; - } + }*/ + Player p = new Player("test"); Score score = new Score(p); Assert.True(true); } From 689aaa9e7d8985ff42fd9ef5b89db3d01f809a1b Mon Sep 17 00:00:00 2001 From: "jeremy.mouyon" Date: Mon, 6 May 2024 13:10:32 +0200 Subject: [PATCH 3/8] add scores in game --- Qwirkle/QwirkleClassLibrary/Game.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Qwirkle/QwirkleClassLibrary/Game.cs b/Qwirkle/QwirkleClassLibrary/Game.cs index 3783c16..f93bc10 100644 --- a/Qwirkle/QwirkleClassLibrary/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Game.cs @@ -18,6 +18,9 @@ namespace QwirkleClassLibrary public ReadOnlyCollection PlayerList => players.AsReadOnly(); private readonly List players = new(); + public ReadOnlyCollection ScoreList => scores.AsReadOnly(); + private readonly List scores = new(); + public Game() { bag = new TileBag(3); @@ -45,6 +48,7 @@ namespace QwirkleClassLibrary } players.Add(CreatePlayer(playerTag)); + scores.Add(new Score(players[players.Count])); return true; } From 66ebbc6069de7abf5c9d6f19cd37bb4487d7f945 Mon Sep 17 00:00:00 2001 From: "jeremy.mouyon" Date: Mon, 6 May 2024 13:14:49 +0200 Subject: [PATCH 4/8] getter --- Qwirkle/QwirkleClassLibrary/Score.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Qwirkle/QwirkleClassLibrary/Score.cs b/Qwirkle/QwirkleClassLibrary/Score.cs index c47bff0..8e70d6a 100644 --- a/Qwirkle/QwirkleClassLibrary/Score.cs +++ b/Qwirkle/QwirkleClassLibrary/Score.cs @@ -13,7 +13,7 @@ namespace QwirkleClassLibrary public Score(Player p) { - if(p==null) + if (p == null) { throw new ArgumentException(); } @@ -21,5 +21,10 @@ namespace QwirkleClassLibrary playerTag = p.NameTag; } + public int GetScore + { + get { return score; } + } + } } From 12da82978de12594f7f358be604eb6d0a7353f53 Mon Sep 17 00:00:00 2001 From: "jeremy.mouyon" Date: Mon, 6 May 2024 13:25:16 +0200 Subject: [PATCH 5/8] hot fix --- Qwirkle/QwirkleClassLibrary/Score.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Qwirkle/QwirkleClassLibrary/Score.cs b/Qwirkle/QwirkleClassLibrary/Score.cs index 8e70d6a..b6c9503 100644 --- a/Qwirkle/QwirkleClassLibrary/Score.cs +++ b/Qwirkle/QwirkleClassLibrary/Score.cs @@ -17,8 +17,11 @@ namespace QwirkleClassLibrary { throw new ArgumentException(); } - score = 0; - playerTag = p.NameTag; + else + { + score = 0; + playerTag = p.NameTag; + } } public int GetScore From 7d4fb356fd602cf0606d5d5483f2427373b1b2f6 Mon Sep 17 00:00:00 2001 From: "jeremy.mouyon" Date: Mon, 6 May 2024 13:39:40 +0200 Subject: [PATCH 6/8] code smelles --- Qwirkle/QwirkleClassLibrary/Cell.cs | 4 ++-- Qwirkle/QwirkleClassLibrary/Game.cs | 4 ++-- Qwirkle/QwirkleClassLibrary/Score.cs | 10 ++-------- Qwirkle/QwirkleClassLibrary/Tile.cs | 4 ++-- 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/Qwirkle/QwirkleClassLibrary/Cell.cs b/Qwirkle/QwirkleClassLibrary/Cell.cs index 911ee73..88ad90b 100644 --- a/Qwirkle/QwirkleClassLibrary/Cell.cs +++ b/Qwirkle/QwirkleClassLibrary/Cell.cs @@ -5,8 +5,8 @@ namespace QwirkleClassLibrary; public class Cell { - private int x; - private int y; + private readonly int x; + private readonly int y; private Tile? tile = null; public Cell(int x, int y) diff --git a/Qwirkle/QwirkleClassLibrary/Game.cs b/Qwirkle/QwirkleClassLibrary/Game.cs index f93bc10..c4460a8 100644 --- a/Qwirkle/QwirkleClassLibrary/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Game.cs @@ -11,7 +11,7 @@ namespace QwirkleClassLibrary { public class Game : IPlayer, IRules { - private TileBag bag; + private readonly TileBag bag; public bool GameRunning { get; private set; } private Board board; @@ -48,7 +48,7 @@ namespace QwirkleClassLibrary } players.Add(CreatePlayer(playerTag)); - scores.Add(new Score(players[players.Count])); + scores.Add(new Score(players[players.Count-1])); return true; } diff --git a/Qwirkle/QwirkleClassLibrary/Score.cs b/Qwirkle/QwirkleClassLibrary/Score.cs index b6c9503..50822f2 100644 --- a/Qwirkle/QwirkleClassLibrary/Score.cs +++ b/Qwirkle/QwirkleClassLibrary/Score.cs @@ -8,8 +8,8 @@ namespace QwirkleClassLibrary { public struct Score { - private int score; - private string playerTag; + private int score { get; set; } + public string playerTag { get; } public Score(Player p) { @@ -23,11 +23,5 @@ namespace QwirkleClassLibrary playerTag = p.NameTag; } } - - public int GetScore - { - get { return score; } - } - } } diff --git a/Qwirkle/QwirkleClassLibrary/Tile.cs b/Qwirkle/QwirkleClassLibrary/Tile.cs index df68a5f..f6adb00 100644 --- a/Qwirkle/QwirkleClassLibrary/Tile.cs +++ b/Qwirkle/QwirkleClassLibrary/Tile.cs @@ -10,8 +10,8 @@ namespace QwirkleClassLibrary { public class Tile { - private Shape shape; - private Color color; + private readonly Shape shape; + private readonly Color color; public Tile(Shape sh, Color co) { shape = sh; From 500a50ee71ae49f4ff1201159be8e21aabea746a Mon Sep 17 00:00:00 2001 From: "jeremy.mouyon" Date: Mon, 6 May 2024 14:34:20 +0200 Subject: [PATCH 7/8] code check --- Qwirkle/QwirkleClassLibrary/Game.cs | 25 +++++- Qwirkle/TestBase/TestBoard.cs | 40 +++++++-- Qwirkle/TestBase/TestGame.cs | 127 ++++++++++++++++++++++++++++ 3 files changed, 179 insertions(+), 13 deletions(-) create mode 100644 Qwirkle/TestBase/TestGame.cs diff --git a/Qwirkle/QwirkleClassLibrary/Game.cs b/Qwirkle/QwirkleClassLibrary/Game.cs index c4460a8..68360de 100644 --- a/Qwirkle/QwirkleClassLibrary/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Game.cs @@ -65,13 +65,22 @@ namespace QwirkleClassLibrary return board; } - public void StartGame() + public bool StartGame() { - this.GameRunning = true; + if(players.Count>= 2 && players.Count < 5) + { + this.GameRunning = true; + return true; + } + return false; } public Player GetPlayingPlayer() { + if(GetPlayingPlayerPosition() == -1) + { + throw new ArgumentException(); + } return players[GetPlayingPlayerPosition()]; } @@ -108,8 +117,16 @@ namespace QwirkleClassLibrary public string SetFirstPlayer() { - players[0].IsPlaying = true; - return players[0].NameTag; + if (GameRunning == true) + { + players[0].IsPlaying = true; + return players[0].NameTag; + } + else + { + throw new ArgumentException("Game is not running"); + } + } public string SetNextPlayer() diff --git a/Qwirkle/TestBase/TestBoard.cs b/Qwirkle/TestBase/TestBoard.cs index 1cffe4c..7428165 100644 --- a/Qwirkle/TestBase/TestBoard.cs +++ b/Qwirkle/TestBase/TestBoard.cs @@ -3,36 +3,58 @@ namespace TestBase; public class TestBoard { - - - public static IEnumerable Data_Board() { yield return new object[] { true, - new Cell(0,0), + 1, + 2, new Tile(Shape.Round, Color.Red) }; yield return new object[] { false, - new Cell(0,0), + -5, + 9999, new Tile(Shape.Round, Color.Red) }; } [Theory] [MemberData(nameof(Data_Board))] - public void Test_AddTile(bool except, Cell c, Tile t) + public void Test_BoardAddSolo(bool except, int x, int y, Tile t) { + + Board b = new Board(); + if (!except) { - c.SetTile(t); - Assert.False(c.SetTile(t)); + Assert.False(b.AddTileInCell(x, y, t)); return; + } - Assert.True(c.SetTile(t)); + Assert.True(b.AddTileInCell(x, y, t)); } + + public static IEnumerable Data_BoardDouble() + { + yield return new object[] + { + 1, + 2, + new Tile(Shape.Round, Color.Red) + }; + } + + [Theory] + [MemberData(nameof(Data_BoardDouble))] + public void Test_BoardFree(int x, int y, Tile t) + { + Board board = new Board(); + board.AddTileInCell(x, y, t); + Assert.False(board.AddTileInCell(x,y, t)); + } + } diff --git a/Qwirkle/TestBase/TestGame.cs b/Qwirkle/TestBase/TestGame.cs new file mode 100644 index 0000000..121e8de --- /dev/null +++ b/Qwirkle/TestBase/TestGame.cs @@ -0,0 +1,127 @@ +using QwirkleClassLibrary; +namespace TestBase; + +public class TestGame +{ + + + [Theory] + [InlineData(true, false, "testt")] + [InlineData(false, false, "testt")] + public void Test_GameAddPlayerIngame(bool result, bool gamestate, string p) + { + Game game = new Game(); + + if (!result) { + game.AddPlayerInGame(p); + Assert.False(game.AddPlayerInGame(p)); + } + else + { + Assert.True(game.AddPlayerInGame(p)); + } + + if (gamestate) + { + Assert.False(game.AddPlayerInGame(p)); + } + + + + + + } + + [Theory] + [InlineData(false, null)] + [InlineData(true, "test")] + public void Test_GameAddPlayerIngame2(bool result, string p) + { + Game game = new Game(); + + if (!result) + { + Assert.False(game.AddPlayerInGame(p)); + } + + for (int i = 0; i < 4; i++) + { + string name = p + i; + game.AddPlayerInGame(name); + } + Assert.False(game.AddPlayerInGame(p)); + + } + + [Theory] + [InlineData("test")] + public void Test_GameCreatePlayers(string p) + { + Game game = new Game(); + Player player = new Player(p); + Assert.Equal(game.CreatePlayer(p).NameTag, player.NameTag); + } + + [Theory] + [InlineData(true, "test1", "test2")] + [InlineData(false, "test1", "test2")] + public void Test_GameState(bool result, string p1, string p2) + { + Game game = new Game(); + + if (!result) + { + game.StartGame(); + Assert.False(game.GameRunning); + } + game.AddPlayerInGame(p1); + game.AddPlayerInGame(p2); + game.StartGame(); + + Assert.True(game.GameRunning); + } + + + [Theory] + [InlineData(true, "test1", "test2", "test3")] + [InlineData(false, "test1", "test2", "test3")] + public void Test_GameGetPlayingPlayerPosition(bool result, string p1, string p2, string p3) + { + Game game = new Game(); + game.AddPlayerInGame(p1); + game.AddPlayerInGame(p2); + game.AddPlayerInGame(p3); + + if (!result) + { + Assert.Equal(-1, game.GetPlayingPlayerPosition()); + return; + } + game.StartGame(); + game.SetFirstPlayer(); + Assert.Equal(0, game.GetPlayingPlayerPosition()); + } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public void Test_GameGetPlaylingPlayer(bool result) + { + Game game = new Game(); + game.AddPlayerInGame("patrick"); + game.AddPlayerInGame("jean"); + if (!result) + { + Assert.Throws(() => game.GetPlayingPlayer()); + } + game.StartGame(); + game.SetFirstPlayer(); + + Assert.Equal(game.PlayerList[0], game.GetPlayingPlayer()); + + } + + + +} + From 32985a4b6e14cc32e470ee2b2d7262fca2f3a0b1 Mon Sep 17 00:00:00 2001 From: "jules.lascret" Date: Mon, 6 May 2024 15:32:00 +0200 Subject: [PATCH 8/8] added the two files of the 6th cm --- Qwirkle/cm6(suite).cs | 35 ++++++++++++ Qwirkle/cm6.cs | 128 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 163 insertions(+) create mode 100644 Qwirkle/cm6(suite).cs create mode 100644 Qwirkle/cm6.cs diff --git a/Qwirkle/cm6(suite).cs b/Qwirkle/cm6(suite).cs new file mode 100644 index 0000000..b19f94c --- /dev/null +++ b/Qwirkle/cm6(suite).cs @@ -0,0 +1,35 @@ +public interface IDisplayer +{ + void OnGameStart(Board board); + void OnPlayerNotified(Player player); + void OnMoveChosen(Player player, int row, int col); + void OnValidMove(Player player, Board board, int row, int col, bool isValid); + void OnBoardChanged(Board board); +} + +public class ConsoleDisplayer : IDisplayer +{ + public void OnGameStarted(Board board) + { + Console.WriteLine("Game has started !"); + DisplayBoard(board); + } + + public void DisplayBoard(Board board) + { + for(int row = 0; row < board.NbRows; row++) + { + for(int col = 0; col < board.NbCols; col++) + { + var playerSymbol = board[row, col] ?.Player == 1 ? "X" : "O"; + Console.Write($"{playerSymbol} ") + } + Console.WriteLine(); + } + } +} + + +// program.cs + +OnGameStarted += _ => Console.WriteLine("Game has started !"); // j'ai pas compris mais ça à l'air complètement fumé \ No newline at end of file diff --git a/Qwirkle/cm6.cs b/Qwirkle/cm6.cs new file mode 100644 index 0000000..a030e06 --- /dev/null +++ b/Qwirkle/cm6.cs @@ -0,0 +1,128 @@ +// Cours sur les évènements + +/* +Pour la faire courte, y a 3 possibilités pour les affichages : +- les Console.WriteLine qui sont absolument interdits dans les classes de logique (Game, Board, Rules, Player) +- l'implémentations d'une interface IDisplayer qui permet de définir des méthodes qui seront appelées par les classes de logique +- Définition du type délégué (delegate) => ça prend un board, ça rend rien + - + +*/ + + +public class Game // Game.cs file +{ + public /*delegate*/ event void GameStarted(); // c'est pas une méthode, c'est un type de méthode !!! + // le event est une propriété qui permet de s'abonner à un évènement : elle empêche de faire = + + + public event EventHandler GameStarted; + protected virtual void OnGameStarted() + { + GameStarted?.Invoke(this, EventArgs.Empty); + } + + private GameStarted onGameStarted; + + private Board board { get; init; } // je sais pas ce que fait le init + + private IRules Rules { get; init; } + + private Player Player1 { get; init; } + private Player Player2 { get; init; } + + private IDisplayer displayer + + public Game(Irules rules, Player player1, Player player2) + { + Player1 = player1; + Player2 = player2; + Rules = rules; + Board = rules.InitBoard(); + } + + { + + } + + public void start() + { + displayer.OnGameStart(Board); + + Console.WriteLine("Game started !"); + while(true) + { + // Get next player + Player nextPlayer = Rules.GetNextPlayer(Board) == 1 ? Player1 : Player2; + // displayer.OnPlayerNotified(nextPlayer); + onGameStarted(board); + + // Notify player to make a move + (int chosenRow, int chosenCol) = nextPlayer.ChooseMove(Board, Rules); + displayer.OnMoveChosen(nextPlayer, chosenRow, chosenCol); + + // If move is valid (check with rules) + if(Rules.IsValidMove(Board, chosenRow, chosenCol, nextPlayer.Id)) + { + // true => modify board + Board.InsertPiece(chosenRow, chosenCol, nextPlayer.Id); + displayer.OnValidMove(nextPlayer, Board, chosenRow, chosenCol, true); + + displayer.OnGameOver(Board, nextPlayer, Rules); + + // is game over? (check with rules) + if(Rules.IsGameOver(Board, chosenRow, chosenCol, out int winner, out Case[] winningPlaces)) + { + Console.WriteLine($"Player {winner} won the game !"); + + for(int row = 0; row < Board.NbRows; row++) + { + for(int col = 0; col < Board.NbCols; col++) + { + Console.Write($"{playerSymbol} ") + } + Console.WriteLine(); + } + + return; + } + } + // gets the winner, winning places, return + // false => nothing + } + + } +} + +public abstract class Player // Player.cs file +{ + public string Name { get; private set; } + + public int Id { get; private init; } + + public Player(string name, int id) + { + Id = id; + Name = name; + } + + public abstract (int row, int col) ChooseMove(Board board, IRules rules); +} + +public class RandomPlayer : Player // RandomPlayer.cs file +{ + public RandomPlayer(int id) : base(id, "Jérôme") + { + } + + public static Random random = new Random(); + + public override (int row, int col) ChooseMove(Board board, IRules rules) + { + var moves = rules.GetPossibleMoves(board, Id); + var chosenMoveId = random.Next(0, moves.Count()); + Case chosenCase = moves.ElementAt(chosenMoveId); + + return (chosenCase.Row, chosenCase.Col); + } +} \ No newline at end of file