19 Commits

Author SHA1 Message Date
Renovate Bot
5cebb9a800 Update dependency NUnit3TestAdapter to 5.2.0
All checks were successful
check main state / build (9.0.x) (push) Successful in 2m31s
2026-02-05 18:28:38 +00:00
Renovate Bot
3d11413e6b Update dependency xunit.runner.visualstudio to 3.1.5
All checks were successful
check main state / build (9.0.x) (push) Successful in 2m21s
2026-02-05 16:52:11 +00:00
Renovate Bot
503d8e60c3 Update dependency nunit to 4.4.0
All checks were successful
check main state / build (9.0.x) (push) Successful in 2m56s
2026-02-05 15:43:29 +00:00
Renovate Bot
425e97c912 Update dependency Microsoft.NET.Test.Sdk to 17.14.1
All checks were successful
check main state / build (9.0.x) (push) Successful in 2m24s
2026-02-05 15:34:34 +00:00
Renovate Bot
1348b78420 Update dependency coverlet.collector to 6.0.4
All checks were successful
check main state / build (9.0.x) (push) Successful in 2m26s
2026-02-05 14:34:19 +00:00
Renovate Bot
3206c99073 Update dependency Microsoft.Extensions.DependencyInjection to 9.0.12
All checks were successful
check main state / build (9.0.x) (push) Successful in 2m30s
2026-02-05 14:13:22 +00:00
3dba66344d fin de l'initialisation d'un match et ajout du random aux commandes
All checks were successful
check main state / build (9.0.x) (push) Successful in 2m46s
2025-04-24 22:31:19 +02:00
c1c5f6bab8 ajout des chef et shaman a la creation du match
All checks were successful
check main state / build (9.0.x) (push) Successful in 1m23s
2025-04-24 09:20:26 +02:00
90c93df9c9 ajout des marker et des socles aux joueurs au debut de la partie
All checks were successful
check main state / build (9.0.x) (push) Successful in 1m26s
2025-04-23 16:38:26 +02:00
Renovate Bot
e83dd938e4 Update dependency Microsoft.Extensions.DependencyInjection to v9.0.4
All checks were successful
check main state / build (9.0.x) (push) Successful in 1m27s
2025-04-23 11:52:14 +02:00
1fbce5a4fd augmentation des niveaux de warning dans la solution
Some checks failed
check main state / build (9.0.x) (push) Has been cancelled
2025-04-23 10:44:20 +02:00
a1a1d94a14 Ajout de la base de PrepareMatchCommand avec un test
All checks were successful
check main state / build (9.0.x) (push) Successful in 1m26s
2025-04-17 11:06:21 +02:00
80b3d71104 Mise en place des MatchCommand
All checks were successful
check main state / build (9.0.x) (push) Successful in 1m28s
Ajout des données dynamiques au match
2025-04-03 00:15:11 +02:00
Renovate Bot
4a4446ea48 Update dependency NUnit3TestAdapter to v5
All checks were successful
check main state / build (9.0.x) (push) Successful in 1m22s
2025-04-02 14:29:36 +00:00
Renovate Bot
10dc874d43 Update dependency Microsoft.NET.Test.Sdk to v17
All checks were successful
check main state / build (9.0.x) (push) Successful in 1m25s
2025-04-02 14:04:28 +00:00
Renovate Bot
a558bd16ea Update dependency NUnit3TestAdapter to v3.17.0
All checks were successful
check main state / build (9.0.x) (push) Successful in 1m21s
2025-04-02 13:53:44 +00:00
Renovate Bot
0ebca20478 Update vstest monorepo
All checks were successful
check main state / build (9.0.x) (push) Successful in 1m28s
2025-04-02 15:42:39 +02:00
Renovate Bot
a24e9c9470 Update dependency nunit to v4
Some checks failed
check main state / build (9.0.x) (push) Has been cancelled
2025-04-02 15:41:29 +02:00
Renovate Bot
334f3a45b1 Update dependency xunit.runner.visualstudio to v3
Some checks failed
check main state / build (9.0.x) (push) Has been cancelled
2025-03-31 00:00:33 +00:00
19 changed files with 424 additions and 35 deletions

View File

@@ -5,6 +5,8 @@ root = true
indent_style = space indent_style = space
indent_size = 4 indent_size = 4
charset = utf-8 charset = utf-8
dotnet_diagnostic.CA1307.severity = none
dotnet_diagnostic.CA5394.severity = none //Pour l'utilisation de random
[Src/HexagonalLib/**] [Src/HexagonalLib/**]
generated_code = true generated_code = true

View File

@@ -4,6 +4,10 @@
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<AnalysisMode>All</AnalysisMode>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View File

@@ -8,6 +8,9 @@ public abstract class BaseCommand<T> where T : BaseCommandResult
{ {
protected abstract T LocalExecute(); protected abstract T LocalExecute();
public required Random Random { get; init; }
/// <summary> Executer la commande, si nécessaire il faut avoir rempli les parametres en amont </summary> /// <summary> Executer la commande, si nécessaire il faut avoir rempli les parametres en amont </summary>
public T Execute() public T Execute()
{ {

View File

@@ -7,5 +7,5 @@ namespace Giants.Core.Commands;
public abstract class BaseCommandResult public abstract class BaseCommandResult
{ {
/// <summary> indique si le resultat est un success (true) ou un echec(false) </summary> /// <summary> indique si le resultat est un success (true) ou un echec(false) </summary>
public bool Success { get; init; } = false; public bool Success { get; init; }
} }

View File

@@ -1,41 +1,110 @@
using System.Security.Claims; using Giants.Core.Enums;
using System.Security.Cryptography.X509Certificates; using Giants.Core.Exceptions;
namespace Giants.Core.Commands; namespace Giants.Core.Commands;
public class PrepareMatchCommand : BaseMatchCommand<PrepareMatchResult> public class PrepareMatchCommand : BaseMatchCommand<PrepareMatchResult>
{ {
public required int NbPlayer { get; init; } public required IList<int> PlayerIDs { get; init; }
protected override PrepareMatchResult LocalMatchExecute(Match match) protected override PrepareMatchResult LocalMatchExecute(Match match)
{ {
if (NbPlayer < 3 || NbPlayer > 5) if (PlayerIDs.Count < 3 || PlayerIDs.Count > 5 || null == match)
return new PrepareMatchResult(); return new PrepareMatchResult();
//Gestion des assets des joueurs //Gestion des assets des joueurs
for (int i = 0; i < NbPlayer; i++) for (int itePlayer = 0; itePlayer < PlayerIDs.Count; itePlayer++)
{
//marqueurs tribaux
int nbMarker = NbMarkerPerPlayer(NbPlayer);
for (int t = 0; t < nbMarker; t++)
{ {
match.SetPlayer(itePlayer, PlayerIDs[itePlayer]);
Player? player = match.GetPlayer(itePlayer);
if (null == player)
throw new ArgumentException($"Cannot get player {itePlayer} in PrepareMatchCommand");
//socles
int nbSocle = NbSoclePerPlayer(PlayerIDs.Count);
foreach (var socle in player.Bases)
{
if (nbSocle > 0)
{
player.PutPieceInHiddenArea(socle);
nbSocle--;
} }
else
{
break;
} }
return new PrepareMatchResult();
} }
private int NbMarkerPerPlayer(int nbTotalPlayer)
//marqueurs tribaux (on ajoute 2 par joueurs et le reste dans l'urne)
int i = 0;
foreach (var marker in player.Markers)
{
if (i < 2)
{
player.PutPieceInHiddenArea(marker);
}
else
{
match.AssignPiece(marker, PiecePosition.Urne);
}
i++;
}
//assigner les ouvriers (1 chef, 1 shaman et 1 worker chacun)
match.AssignPiece(player.Chef, player.HiddenPosition);
match.AssignPiece(player.Shaman, player.HiddenPosition);
int nbWorker = 1;
foreach (PieceIndex worker in player.Workers)
{
if (nbWorker > 0)
{
match.AssignPiece(worker, player.HiddenPosition);
nbWorker--;
}
else
{
match.AssignPiece(worker, PiecePosition.Urne);
}
}
match.AssignPiece(player.Workers.First(), player.HiddenPosition);
//score a zero
for (int iteScore = 0; iteScore < match.NbPlayer; iteScore++)
{
match.SetScore(iteScore, 0);
}
//choix d'un 1er joueur
Player? firstPlayer = match.GetPlayer(Random.Next(match.NbPlayer));
if (null == firstPlayer)
throw new InitialisationException("Cannot select first player, indexOutOfRange");
match.AssignPiece(PieceIndex.StartPlayer, firstPlayer.VisiblePosition);
}
return new PrepareMatchResult()
{
Success = true,
Match = match
};
}
private static int NbSoclePerPlayer(int nbTotalPlayer)
{ {
return nbTotalPlayer switch return nbTotalPlayer switch
{ {
3 => 7, 3 => 7,
4 => 6, 4 => 6,
5 => 5, 5 => 5,
_ => throw new Exception("Wrong player count for NbMarkerPerPlayer") _ => throw new DataConversionException("Wrong player count for NbMarkerPerPlayer")
}; };
} }
} }
public class PrepareMatchResult : BaseCommandResult { } public class PrepareMatchResult : BaseCommandResult
{
public Match? Match { get; init; }
}

View File

@@ -1,3 +1,5 @@
using System.Collections;
using System.Reflection.Metadata.Ecma335;
using Giants.Core.Enums; using Giants.Core.Enums;
namespace Giants.Core; namespace Giants.Core;
@@ -34,19 +36,61 @@ public class Match
/// </summary> /// </summary>
int[] dices = [0, 0, 0, 0, 0,]; int[] dices = [0, 0, 0, 0, 0,];
/// <summary>
/// Indique si pour une foret donnée le bois a ete ramassé, l'index et les quantités sont dans le boardLayout
/// </summary>
bool[] forestUsed = [false, false, false, false, false, false, false];
/// <summary> /// <summary>
/// un tableau indiquant ou sont placé les pieces, l'index est l'id de la piece et la valeur la position de la piece /// /// un tableau indiquant ou sont placé les pieces, l'index est l'id de la piece et la valeur la position de la piece ///
/// </summary> /// </summary>
PiecePosition[] pieces = new PiecePosition[(int)Enum.GetValues(typeof(PieceIndex)).Cast<PieceIndex>().Max()]; PiecePosition[] pieces = new PiecePosition[(int)Enum.GetValues(typeof(PieceIndex)).Cast<PieceIndex>().Max() + 1];
#endregion #endregion
#region acessors for commands #region Getters
public static int MaxTribalMarker { get => 6; }
public static int MaxSocle { get => 7; }
public int NbPlayer { get => players.Count(p => p != -1); }
public Player? GetPlayer(int index)
{
if (index >= 0 && index < players.Length && players[index] != -1)
return new Player(this)
{
Index = index,
};
return null;
}
#endregion
#region Setters for commands
public void AssignPiece(PieceIndex piece, PiecePosition position) public void AssignPiece(PieceIndex piece, PiecePosition position)
{ {
pieces[(int)piece] = position; pieces[(int)piece] = position;
} }
public void SetPlayer(int index, int playerId)
{
players[index] = playerId;
}
public void SetScore(int index, int score)
{
scores[index] = score;
}
public int GetScore(int index)
{
return scores[index];
}
public PiecePosition GetPiece(PieceIndex PieceIndex)
{
return pieces[(int)PieceIndex];
}
#endregion #endregion
/// <summary> /// <summary>
@@ -65,6 +109,8 @@ public class Match
Buffer.BlockCopy(scores, 0, result.scores, 0, scores.Length * sizeof(int)); Buffer.BlockCopy(scores, 0, result.scores, 0, scores.Length * sizeof(int));
Buffer.BlockCopy(dices, 0, result.dices, 0, dices.Length * sizeof(int)); Buffer.BlockCopy(dices, 0, result.dices, 0, dices.Length * sizeof(int));
Buffer.BlockCopy(pieces, 0, result.pieces, 0, pieces.Length * sizeof(PieceIndex)); Buffer.BlockCopy(pieces, 0, result.pieces, 0, pieces.Length * sizeof(PieceIndex));
Buffer.BlockCopy(forestUsed, 0, result.forestUsed, 0, forestUsed.Length * sizeof(bool));
return result; return result;
@@ -80,7 +126,8 @@ public class Match
return Enumerable.SequenceEqual(players, match.players) && return Enumerable.SequenceEqual(players, match.players) &&
Enumerable.SequenceEqual(scores, match.scores) && Enumerable.SequenceEqual(scores, match.scores) &&
Enumerable.SequenceEqual(dices, match.dices) && Enumerable.SequenceEqual(dices, match.dices) &&
Enumerable.SequenceEqual(pieces, match.pieces); Enumerable.SequenceEqual(pieces, match.pieces) &&
Enumerable.SequenceEqual(forestUsed, match.forestUsed);
} }
return false; return false;
} }

View File

@@ -0,0 +1,74 @@
using System.Collections.ObjectModel;
using System.Reflection.Metadata.Ecma335;
using Giants.Core.Enums;
namespace Giants.Core;
/// <summary>
/// Structure pour agréger les getters liés aux informations d'un joueur
/// </summary>
public class Player
{
private Match _match;
public required int Index { get; init; }
static Player()
{
// preparation des données statiques
return;
}
public Player(Match match)
{
_match = match;
}
#region Collections
public static readonly ICollection<PieceIndex>[] PlayerPieces ={
[.. Enum.GetValues<PieceIndex>().Where(p => p.ToString().Contains("player1"))],
[.. Enum.GetValues<PieceIndex>().Where(p => p.ToString().Contains("player2"))],
[.. Enum.GetValues<PieceIndex>().Where(p => p.ToString().Contains("player3"))],
[.. Enum.GetValues<PieceIndex>().Where(p => p.ToString().Contains("player4"))],
[.. Enum.GetValues<PieceIndex>().Where(p => p.ToString().Contains("player5"))]
};
public static readonly PiecePosition[] PlayerVisibileAreas = { PiecePosition.player1Visible, PiecePosition.player2Visible, PiecePosition.player3Visible, PiecePosition.player4Visible, PiecePosition.player5Visible };
public static readonly PiecePosition[] PlayerHiddenAreas = { PiecePosition.player1Hidden, PiecePosition.player2Hidden, PiecePosition.player3Hidden, PiecePosition.player4Hidden, PiecePosition.player5Hidden };
#endregion Collections
#region Generics
public PiecePosition HiddenPosition => PlayerHiddenAreas[Index];
public PiecePosition VisiblePosition => PlayerVisibileAreas[Index];
public void PutPieceInVisibleArea(PieceIndex piece)
{
_match.AssignPiece(piece, VisiblePosition);
}
public void PutPieceInHiddenArea(PieceIndex piece)
{
_match.AssignPiece(piece, HiddenPosition);
}
public int Score => _match.GetScore(Index);
#endregion
#region workers
public PieceIndex Chef => PlayerPieces[Index].Where(p => p.ToString().Contains("Chief")).FirstOrDefault();
public PieceIndex Shaman => PlayerPieces[Index].Where(p => p.ToString().Contains("Shaman")).FirstOrDefault();
public ICollection<PieceIndex> Workers => [.. PlayerPieces[Index].Where(p => p.ToString().Contains("Worker"))];
#endregion
#region socles
public ICollection<PieceIndex> Bases => PlayerPieces[Index]?.Where(p => p.ToString().Contains("Base")).ToList() ?? [];
public int NbVisibleBase => Bases.Count(p => _match.GetPiece(p) == VisiblePosition);
public int NbHiddenBase => Bases.Count(p => _match.GetPiece(p) == HiddenPosition);
#endregion
#region Tribal markers
public ICollection<PieceIndex> Markers => PlayerPieces[Index]?.Where(p => p.ToString().Contains("TribalMarker")).ToList() ?? [];
public int NbVisibleTribalTokenCount => Markers.Count(p => _match.GetPiece(p) == VisiblePosition);
public int NbHiddenTribalTokenCount => Markers.Count(p => _match.GetPiece(p) == HiddenPosition);
public int NbUrnTribalTokenCount => Markers.Count(p => _match.GetPiece(p) == PiecePosition.Urne);
#endregion
}

View File

@@ -2,6 +2,7 @@ namespace Giants.Core.Enums;
public enum PieceIndex public enum PieceIndex
{ {
Unknown,
StartPlayer, StartPlayer,
player1Chief, player1Chief,
player1Shaman, player1Shaman,

View File

@@ -0,0 +1,14 @@
namespace Giants.Core.Exceptions;
/// <summary>
/// Exception levée lors d'un probleme de conversion d'un objet du core
/// </summary>
public class DataConversionException : System.Exception
{
/// <inheritdoc/>>
public DataConversionException() { }
/// <inheritdoc/>>
public DataConversionException(string message) : base(message) { }
/// <inheritdoc/>>
public DataConversionException(string message, System.Exception inner) : base(message, inner) { }
}

View File

@@ -0,0 +1,14 @@
namespace Giants.Core.Exceptions;
/// <summary>
/// Exception levée lors d'un probleme pendant l'initialisation de la partie
/// </summary>
public class InitialisationException : System.Exception
{
/// <inheritdoc/>>
public InitialisationException() { }
/// <inheritdoc/>>
public InitialisationException(string message) : base(message) { }
/// <inheritdoc/>>
public InitialisationException(string message, System.Exception inner) : base(message, inner) { }
}

View File

@@ -1,6 +1,6 @@
namespace Giants.Core; namespace Giants.Core;
public struct AxialCoords public record struct AxialCoords
{ {
public int Q { get; init; } public int Q { get; init; }
public int R { get; init; } public int R { get; init; }

View File

@@ -16,6 +16,18 @@ public class BoardLayout
Dictionary<int, TileInfos> _tiles; Dictionary<int, TileInfos> _tiles;
Dictionary<AxialCoords, int> _forest = new Dictionary<AxialCoords, int>(){
{new AxialCoords(4,2),0},
{new AxialCoords(4,1),1},
{new AxialCoords(5,0),2},
{new AxialCoords(5,1),3},
{new AxialCoords(5,2),4},
{new AxialCoords(6,0),5},
{new AxialCoords(6,1),6},
};
int[] _forestQte = [5, 5, 4, 4, 3, 3, 3];
int width = 16; int width = 16;
public BoardLayout(IHexagonalGrid gridSystem) public BoardLayout(IHexagonalGrid gridSystem)
@@ -31,6 +43,21 @@ public class BoardLayout
return tmp.Where(t => _tiles.ContainsKey(Index(t.Q, t.R))).ToList(); return tmp.Where(t => _tiles.ContainsKey(Index(t.Q, t.R))).ToList();
} }
public int ForestQte(AxialCoords coords)
{
int index = _forest[coords];
return ForestQte(index);
}
public int ForestIndex(AxialCoords coords)
{
if (_forest.TryGetValue(coords, out int value))
{
return value;
}
return -1;
}
public int ForestQte(int index) => _forestQte[index];
[MemberNotNull(nameof(_tiles))] [MemberNotNull(nameof(_tiles))]
private void BuildDefaultBoard() private void BuildDefaultBoard()
{ {

View File

@@ -15,9 +15,9 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="nunit" Version="3.12.0" /> <PackageReference Include="nunit" Version="4.4.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" /> <PackageReference Include="NUnit3TestAdapter" Version="5.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -8,11 +8,11 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2" /> <PackageReference Include="coverlet.collector" Version="6.0.4" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.3" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.12" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="xunit" Version="2.9.2" /> <PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" /> <PackageReference Include="xunit.runner.visualstudio" Version="3.1.5" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -21,10 +21,13 @@ public class GetMatchCommandTest
[Fact] [Fact]
public void GetMatchNotExisting() public void GetMatchNotExisting()
{ {
Random random = new Random(1);
GetMatchCommand command = new GetMatchCommand(_repo) GetMatchCommand command = new GetMatchCommand(_repo)
{ {
MatchId = 2 MatchId = 2,
Random = random
}; };
GetMatchResult result = command.Execute(); GetMatchResult result = command.Execute();
Assert.False(result.Success); Assert.False(result.Success);
Assert.Null(result.Match); Assert.Null(result.Match);
@@ -33,9 +36,11 @@ public class GetMatchCommandTest
[Fact] [Fact]
public void GetMatchSimple() public void GetMatchSimple()
{ {
Random random = new Random(1);
GetMatchCommand command = new GetMatchCommand(_repo) GetMatchCommand command = new GetMatchCommand(_repo)
{ {
MatchId = 1 MatchId = 1,
Random = random
}; };
GetMatchResult result = command.Execute(); GetMatchResult result = command.Execute();
Assert.True(result.Success); Assert.True(result.Success);

View File

@@ -19,7 +19,8 @@ public class NewMatchCommandTest
[Fact] [Fact]
public void CreateBasicMatch() public void CreateBasicMatch()
{ {
NewMatchCommand command = new NewMatchCommand(_repo); Random random = new Random(1);
NewMatchCommand command = new NewMatchCommand(_repo) { Random = random };
NewMatchResult result = command.Execute(); NewMatchResult result = command.Execute();
Assert.True(result.Success); Assert.True(result.Success);
} }
@@ -27,12 +28,13 @@ public class NewMatchCommandTest
[Fact] [Fact]
public void TwoNewMatchShouldHaveDifferentID() public void TwoNewMatchShouldHaveDifferentID()
{ {
NewMatchCommand command = new NewMatchCommand(_repo); Random random = new Random(1);
NewMatchCommand command = new NewMatchCommand(_repo) { Random = random };
NewMatchResult result = command.Execute(); NewMatchResult result = command.Execute();
Assert.True(result.Success); Assert.True(result.Success);
Assert.NotNull(result.Match); Assert.NotNull(result.Match);
NewMatchCommand command2 = new NewMatchCommand(_repo); NewMatchCommand command2 = new NewMatchCommand(_repo) { Random = random };
NewMatchResult result2 = command2.Execute(); NewMatchResult result2 = command2.Execute();
Assert.True(result2.Success); Assert.True(result2.Success);
Assert.NotNull(result2.Match); Assert.NotNull(result2.Match);

View File

@@ -0,0 +1,115 @@
using Giants.Application;
using Giants.Core.Commands;
using Giants.Core.Enums;
using Giants.Core.Interfaces;
using Giants.Infrastructure;
namespace Giants.Core.Tests;
public class PrepareMatchCommandTest
{
private readonly IMatchRepository _repo;
public PrepareMatchCommandTest()
{
IHexagonalGrid _grid = new HexagonalGridImpl();
BoardLayout layout = new BoardLayout(_grid);
_repo = new MatchRepositoryMock(layout);
}
[Fact]
void SimpleInit5Players()
{
Random random = new Random(1);
NewMatchCommand command = new NewMatchCommand(_repo) { Random = random };
NewMatchResult result = command.Execute();
Match? m = result.Match;
Assert.NotNull(m);
PrepareMatchCommand prepCommand = new PrepareMatchCommand() { InputMatch = m, PlayerIDs = new List<int>() { 12, 15, 5, 14, 9 }, Random = random };
var resultPrep = prepCommand.Execute();
Assert.True(resultPrep.Success);
Assert.NotNull(resultPrep?.Match);
for (int i = 0; i < 5; i++)
{
Player? p = resultPrep.Match.GetPlayer(i);
Assert.NotNull(p);
Assert.Equal(0, p.NbVisibleTribalTokenCount);
Assert.Equal(2, p.NbHiddenTribalTokenCount);
Assert.Equal(4, p.NbUrnTribalTokenCount);
Assert.Equal(5, p.NbHiddenBase);
Assert.Equal(p.HiddenPosition, resultPrep.Match.GetPiece(p.Chef));
Assert.Equal(p.HiddenPosition, resultPrep.Match.GetPiece(p.Shaman));
Assert.Equal(1, p.Workers.Count(w => resultPrep.Match.GetPiece(w) == p.HiddenPosition));
Assert.Equal(5, p.Workers.Count(w => resultPrep.Match.GetPiece(w) == Enums.PiecePosition.Urne));
Assert.Equal(0, p.Score);
Assert.NotEqual(PiecePosition.boite, resultPrep.Match.GetPiece(PieceIndex.StartPlayer));
}
}
[Fact]
void SimpleInit4Players()
{
Random random = new Random(1);
NewMatchCommand command = new NewMatchCommand(_repo) { Random = random };
NewMatchResult result = command.Execute();
Match? m = result.Match;
Assert.NotNull(m);
PrepareMatchCommand prepCommand = new PrepareMatchCommand() { InputMatch = m, PlayerIDs = new List<int>() { 12, 15, 5, 14 }, Random = random };
var resultPrep = prepCommand.Execute();
Assert.True(resultPrep.Success);
Assert.NotNull(resultPrep?.Match);
for (int i = 0; i < 4; i++)
{
Player? p = resultPrep.Match.GetPlayer(i);
Assert.NotNull(p);
Assert.Equal(0, p.NbVisibleTribalTokenCount);
Assert.Equal(2, p.NbHiddenTribalTokenCount);
Assert.Equal(4, p.NbUrnTribalTokenCount);
Assert.Equal(6, p.NbHiddenBase);
Assert.Equal(p.HiddenPosition, resultPrep.Match.GetPiece(p.Chef));
Assert.Equal(p.HiddenPosition, resultPrep.Match.GetPiece(p.Shaman));
Assert.Equal(1, p.Workers.Count(w => resultPrep.Match.GetPiece(w) == p.HiddenPosition));
Assert.Equal(5, p.Workers.Count(w => resultPrep.Match.GetPiece(w) == Enums.PiecePosition.Urne));
Assert.Equal(0, p.Score);
Assert.NotEqual(PiecePosition.boite, resultPrep.Match.GetPiece(PieceIndex.StartPlayer));
}
}
[Fact]
void SimpleInit3Players()
{
Random random = new Random(1);
NewMatchCommand command = new NewMatchCommand(_repo) { Random = random };
NewMatchResult result = command.Execute();
Match? m = result.Match;
Assert.NotNull(m);
PrepareMatchCommand prepCommand = new PrepareMatchCommand() { InputMatch = m, PlayerIDs = new List<int>() { 12, 15, 5 }, Random = random };
var resultPrep = prepCommand.Execute();
Assert.True(resultPrep.Success);
Assert.NotNull(resultPrep?.Match);
for (int i = 0; i < 3; i++)
{
Player? p = resultPrep.Match.GetPlayer(i);
Assert.NotNull(p);
Assert.Equal(0, p.NbVisibleTribalTokenCount);
Assert.Equal(2, p.NbHiddenTribalTokenCount);
Assert.Equal(4, p.NbUrnTribalTokenCount);
Assert.Equal(7, p.NbHiddenBase);
Assert.Equal(p.HiddenPosition, resultPrep.Match.GetPiece(p.Chef));
Assert.Equal(p.HiddenPosition, resultPrep.Match.GetPiece(p.Shaman));
Assert.Equal(1, p.Workers.Count(w => resultPrep.Match.GetPiece(w) == p.HiddenPosition));
Assert.Equal(5, p.Workers.Count(w => resultPrep.Match.GetPiece(w) == Enums.PiecePosition.Urne));
Assert.Equal(0, p.Score);
Assert.NotEqual(PiecePosition.boite, resultPrep.Match.GetPiece(PieceIndex.StartPlayer));
}
}
}

View File

@@ -52,4 +52,16 @@ public class BoardLayoutTests
BoardLayout layout = new BoardLayout(grid); BoardLayout layout = new BoardLayout(grid);
Assert.Equal(PiecePosition.tile144, layout.FromTileIndex(144)); Assert.Equal(PiecePosition.tile144, layout.FromTileIndex(144));
} }
[Fact]
public void CheckForestQuantities()
{
IHexagonalGrid grid = new HexagonalGridImpl();
BoardLayout layout = new BoardLayout(grid);
int forest1Index = layout.ForestIndex(new AxialCoords(4, 2));
Assert.Equal(0, forest1Index);
int qteForest1 = layout.ForestQte(forest1Index);
Assert.Equal(5, qteForest1);
}
} }

View File

@@ -8,10 +8,10 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2" /> <PackageReference Include="coverlet.collector" Version="6.0.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="xunit" Version="2.9.2" /> <PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" /> <PackageReference Include="xunit.runner.visualstudio" Version="3.1.5" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>