Compare commits
12 Commits
80b3d71104
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5cebb9a800 | ||
|
|
3d11413e6b | ||
|
|
503d8e60c3 | ||
|
|
425e97c912 | ||
|
|
1348b78420 | ||
|
|
3206c99073 | ||
| 3dba66344d | |||
| c1c5f6bab8 | |||
| 90c93df9c9 | |||
|
|
e83dd938e4 | ||
| 1fbce5a4fd | |||
| a1a1d94a14 |
@@ -5,6 +5,8 @@ root = true
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
charset = utf-8
|
||||
dotnet_diagnostic.CA1307.severity = none
|
||||
dotnet_diagnostic.CA5394.severity = none //Pour l'utilisation de random
|
||||
|
||||
[Src/HexagonalLib/**]
|
||||
generated_code = true
|
||||
@@ -4,6 +4,10 @@
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<EnableNETAnalyzers>true</EnableNETAnalyzers>
|
||||
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
|
||||
<AnalysisMode>All</AnalysisMode>
|
||||
<GenerateDocumentationFile>false</GenerateDocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -8,6 +8,9 @@ public abstract class BaseCommand<T> where T : BaseCommandResult
|
||||
{
|
||||
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>
|
||||
public T Execute()
|
||||
{
|
||||
|
||||
@@ -7,5 +7,5 @@ namespace Giants.Core.Commands;
|
||||
public abstract class BaseCommandResult
|
||||
{
|
||||
/// <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; }
|
||||
}
|
||||
@@ -1,41 +1,110 @@
|
||||
using System.Security.Claims;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using Giants.Core.Enums;
|
||||
using Giants.Core.Exceptions;
|
||||
|
||||
namespace Giants.Core.Commands;
|
||||
|
||||
public class PrepareMatchCommand : BaseMatchCommand<PrepareMatchResult>
|
||||
{
|
||||
public required int NbPlayer { get; init; }
|
||||
public required IList<int> PlayerIDs { get; init; }
|
||||
|
||||
protected override PrepareMatchResult LocalMatchExecute(Match match)
|
||||
{
|
||||
if (NbPlayer < 3 || NbPlayer > 5)
|
||||
if (PlayerIDs.Count < 3 || PlayerIDs.Count > 5 || null == match)
|
||||
return new PrepareMatchResult();
|
||||
|
||||
|
||||
//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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//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();
|
||||
return new PrepareMatchResult()
|
||||
{
|
||||
Success = true,
|
||||
Match = match
|
||||
};
|
||||
}
|
||||
|
||||
private int NbMarkerPerPlayer(int nbTotalPlayer)
|
||||
private static int NbSoclePerPlayer(int nbTotalPlayer)
|
||||
{
|
||||
return nbTotalPlayer switch
|
||||
{
|
||||
3 => 7,
|
||||
4 => 6,
|
||||
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; }
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using System.Collections;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using Giants.Core.Enums;
|
||||
|
||||
namespace Giants.Core;
|
||||
@@ -34,19 +36,61 @@ public class Match
|
||||
/// </summary>
|
||||
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>
|
||||
/// 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>
|
||||
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
|
||||
|
||||
#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)
|
||||
{
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
@@ -65,6 +109,8 @@ public class Match
|
||||
Buffer.BlockCopy(scores, 0, result.scores, 0, scores.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(forestUsed, 0, result.forestUsed, 0, forestUsed.Length * sizeof(bool));
|
||||
|
||||
|
||||
return result;
|
||||
|
||||
@@ -80,7 +126,8 @@ public class Match
|
||||
return Enumerable.SequenceEqual(players, match.players) &&
|
||||
Enumerable.SequenceEqual(scores, match.scores) &&
|
||||
Enumerable.SequenceEqual(dices, match.dices) &&
|
||||
Enumerable.SequenceEqual(pieces, match.pieces);
|
||||
Enumerable.SequenceEqual(pieces, match.pieces) &&
|
||||
Enumerable.SequenceEqual(forestUsed, match.forestUsed);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
74
Src/Giants.Core/Src/Entities/Player.cs
Normal file
74
Src/Giants.Core/Src/Entities/Player.cs
Normal 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
|
||||
}
|
||||
@@ -2,6 +2,7 @@ namespace Giants.Core.Enums;
|
||||
|
||||
public enum PieceIndex
|
||||
{
|
||||
Unknown,
|
||||
StartPlayer,
|
||||
player1Chief,
|
||||
player1Shaman,
|
||||
|
||||
14
Src/Giants.Core/Src/Exceptions/DataConversionException.cs
Normal file
14
Src/Giants.Core/Src/Exceptions/DataConversionException.cs
Normal 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) { }
|
||||
}
|
||||
14
Src/Giants.Core/Src/Exceptions/InitialisationException.cs
Normal file
14
Src/Giants.Core/Src/Exceptions/InitialisationException.cs
Normal 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) { }
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace Giants.Core;
|
||||
|
||||
public struct AxialCoords
|
||||
public record struct AxialCoords
|
||||
{
|
||||
public int Q { get; init; }
|
||||
public int R { get; init; }
|
||||
|
||||
@@ -16,6 +16,18 @@ public class BoardLayout
|
||||
|
||||
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;
|
||||
|
||||
public BoardLayout(IHexagonalGrid gridSystem)
|
||||
@@ -31,6 +43,21 @@ public class BoardLayout
|
||||
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))]
|
||||
private void BuildDefaultBoard()
|
||||
{
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="nunit" Version="4.3.2" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="5.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
|
||||
<PackageReference Include="nunit" Version="4.4.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="5.2.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.3" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.12" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="xunit" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -21,10 +21,13 @@ public class GetMatchCommandTest
|
||||
[Fact]
|
||||
public void GetMatchNotExisting()
|
||||
{
|
||||
Random random = new Random(1);
|
||||
GetMatchCommand command = new GetMatchCommand(_repo)
|
||||
{
|
||||
MatchId = 2
|
||||
MatchId = 2,
|
||||
Random = random
|
||||
};
|
||||
|
||||
GetMatchResult result = command.Execute();
|
||||
Assert.False(result.Success);
|
||||
Assert.Null(result.Match);
|
||||
@@ -33,9 +36,11 @@ public class GetMatchCommandTest
|
||||
[Fact]
|
||||
public void GetMatchSimple()
|
||||
{
|
||||
Random random = new Random(1);
|
||||
GetMatchCommand command = new GetMatchCommand(_repo)
|
||||
{
|
||||
MatchId = 1
|
||||
MatchId = 1,
|
||||
Random = random
|
||||
};
|
||||
GetMatchResult result = command.Execute();
|
||||
Assert.True(result.Success);
|
||||
|
||||
@@ -19,7 +19,8 @@ public class NewMatchCommandTest
|
||||
[Fact]
|
||||
public void CreateBasicMatch()
|
||||
{
|
||||
NewMatchCommand command = new NewMatchCommand(_repo);
|
||||
Random random = new Random(1);
|
||||
NewMatchCommand command = new NewMatchCommand(_repo) { Random = random };
|
||||
NewMatchResult result = command.Execute();
|
||||
Assert.True(result.Success);
|
||||
}
|
||||
@@ -27,12 +28,13 @@ public class NewMatchCommandTest
|
||||
[Fact]
|
||||
public void TwoNewMatchShouldHaveDifferentID()
|
||||
{
|
||||
NewMatchCommand command = new NewMatchCommand(_repo);
|
||||
Random random = new Random(1);
|
||||
NewMatchCommand command = new NewMatchCommand(_repo) { Random = random };
|
||||
NewMatchResult result = command.Execute();
|
||||
Assert.True(result.Success);
|
||||
Assert.NotNull(result.Match);
|
||||
|
||||
NewMatchCommand command2 = new NewMatchCommand(_repo);
|
||||
NewMatchCommand command2 = new NewMatchCommand(_repo) { Random = random };
|
||||
NewMatchResult result2 = command2.Execute();
|
||||
Assert.True(result2.Success);
|
||||
Assert.NotNull(result2.Match);
|
||||
|
||||
115
Tests/Giants.Core.Tests/Commands/PrepareMatchCommandTest.cs
Normal file
115
Tests/Giants.Core.Tests/Commands/PrepareMatchCommandTest.cs
Normal 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,4 +52,16 @@ public class BoardLayoutTests
|
||||
BoardLayout layout = new BoardLayout(grid);
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -8,10 +8,10 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.2" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.4" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="xunit" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user