Compare commits
15 Commits
1046d45060
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5cebb9a800 | ||
|
|
3d11413e6b | ||
|
|
503d8e60c3 | ||
|
|
425e97c912 | ||
|
|
1348b78420 | ||
|
|
3206c99073 | ||
| 3dba66344d | |||
| c1c5f6bab8 | |||
| 90c93df9c9 | |||
|
|
e83dd938e4 | ||
| 1fbce5a4fd | |||
| a1a1d94a14 | |||
| 80b3d71104 | |||
|
|
4a4446ea48 | ||
|
|
10dc874d43 |
@@ -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; }
|
||||
}
|
||||
13
Src/Giants.Core/Src/Commands/BaseMatchCommand.cs
Normal file
13
Src/Giants.Core/Src/Commands/BaseMatchCommand.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace Giants.Core.Commands;
|
||||
|
||||
public abstract class BaseMatchCommand<T> : BaseCommand<T> where T : BaseCommandResult
|
||||
{
|
||||
public required Match InputMatch { get; init; }
|
||||
|
||||
protected abstract T LocalMatchExecute(Match match);
|
||||
|
||||
protected override T LocalExecute()
|
||||
{
|
||||
return LocalMatchExecute(InputMatch.Clone());
|
||||
}
|
||||
}
|
||||
110
Src/Giants.Core/Src/Commands/PrepareMatchCommand.cs
Normal file
110
Src/Giants.Core/Src/Commands/PrepareMatchCommand.cs
Normal file
@@ -0,0 +1,110 @@
|
||||
using Giants.Core.Enums;
|
||||
using Giants.Core.Exceptions;
|
||||
|
||||
namespace Giants.Core.Commands;
|
||||
|
||||
public class PrepareMatchCommand : BaseMatchCommand<PrepareMatchResult>
|
||||
{
|
||||
public required IList<int> PlayerIDs { get; init; }
|
||||
|
||||
protected override PrepareMatchResult LocalMatchExecute(Match match)
|
||||
{
|
||||
if (PlayerIDs.Count < 3 || PlayerIDs.Count > 5 || null == match)
|
||||
return new PrepareMatchResult();
|
||||
|
||||
|
||||
//Gestion des assets des joueurs
|
||||
for (int itePlayer = 0; itePlayer < PlayerIDs.Count; itePlayer++)
|
||||
{
|
||||
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()
|
||||
{
|
||||
Success = true,
|
||||
Match = match
|
||||
};
|
||||
}
|
||||
|
||||
private static int NbSoclePerPlayer(int nbTotalPlayer)
|
||||
{
|
||||
return nbTotalPlayer switch
|
||||
{
|
||||
3 => 7,
|
||||
4 => 6,
|
||||
5 => 5,
|
||||
_ => throw new DataConversionException("Wrong player count for NbMarkerPerPlayer")
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class PrepareMatchResult : BaseCommandResult
|
||||
{
|
||||
public Match? Match { get; init; }
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using Giants.Core.Interfaces;
|
||||
using System.Collections;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using Giants.Core.Enums;
|
||||
|
||||
namespace Giants.Core;
|
||||
|
||||
@@ -18,15 +19,117 @@ public class Match
|
||||
#endregion
|
||||
|
||||
#region données dynamiques
|
||||
/// <summary>
|
||||
/// IDs des joueurs qui participent a cette partie,
|
||||
// -2 Pour une place non ouverte
|
||||
// -1 pour une place non occupée mais ouverte
|
||||
/// </summary>
|
||||
int[] players = [-1, -1, -1, -1, -1];
|
||||
|
||||
/// <summary> Les scores des joueurs </summary>
|
||||
int[] scores = [-1, -1, -1, -1, -1];
|
||||
|
||||
/// <summary>
|
||||
/// etat des dés, -1 indique non utilisé et positif donne le numero de la face,
|
||||
/// les 3 premiers dés sont les blanc et les 2 suivant les marrons
|
||||
/// 4e dé utile pour la partie a 4 joueur, le 5e pour les parties a 5 joueurs
|
||||
/// </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() + 1];
|
||||
#endregion
|
||||
|
||||
#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>
|
||||
/// Cloner ce match pour pouvoir le modifier
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Match Clone()
|
||||
{
|
||||
Match result = new Match()
|
||||
{
|
||||
Board = Board,
|
||||
Id = Id,
|
||||
};
|
||||
|
||||
Buffer.BlockCopy(players, 0, result.players, 0, players.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(pieces, 0, result.pieces, 0, pieces.Length * sizeof(PieceIndex));
|
||||
Buffer.BlockCopy(forestUsed, 0, result.forestUsed, 0, forestUsed.Length * sizeof(bool));
|
||||
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
/// <summary> Permet de comparer des Match, cette methode est critique pour l'ia pour reduire son parcour d'arbre </summary>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns> <summary>
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return base.Equals(obj);
|
||||
if (obj is Match match)
|
||||
{
|
||||
return Enumerable.SequenceEqual(players, match.players) &&
|
||||
Enumerable.SequenceEqual(scores, match.scores) &&
|
||||
Enumerable.SequenceEqual(dices, match.dices) &&
|
||||
Enumerable.SequenceEqual(pieces, match.pieces) &&
|
||||
Enumerable.SequenceEqual(forestUsed, match.forestUsed);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
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
|
||||
}
|
||||
112
Src/Giants.Core/Src/Enums/PieceIndex.cs
Normal file
112
Src/Giants.Core/Src/Enums/PieceIndex.cs
Normal file
@@ -0,0 +1,112 @@
|
||||
namespace Giants.Core.Enums;
|
||||
|
||||
public enum PieceIndex
|
||||
{
|
||||
Unknown,
|
||||
StartPlayer,
|
||||
player1Chief,
|
||||
player1Shaman,
|
||||
player1Worker1,
|
||||
player1Worker2,
|
||||
player1Worker3,
|
||||
player1Worker4,
|
||||
player1Worker5,
|
||||
player1Worker6,
|
||||
player1Base1,
|
||||
player1Base2,
|
||||
player1Base3,
|
||||
player1Base4,
|
||||
player1Base5,
|
||||
player1Base6,
|
||||
player1Base7,
|
||||
player1TribalMarker1,
|
||||
player1TribalMarker2,
|
||||
player1TribalMarker3,
|
||||
player1TribalMarker4,
|
||||
player1TribalMarker5,
|
||||
player1TribalMarker6,
|
||||
player2Chief,
|
||||
player2Shaman,
|
||||
player2Worker1,
|
||||
player2Worker2,
|
||||
player2Worker3,
|
||||
player2Worker4,
|
||||
player2Worker5,
|
||||
player2Worker6,
|
||||
player2Base1,
|
||||
player2Base2,
|
||||
player2Base3,
|
||||
player2Base4,
|
||||
player2Base5,
|
||||
player2Base6,
|
||||
player2Base7,
|
||||
player2TribalMarker1,
|
||||
player2TribalMarker2,
|
||||
player2TribalMarker3,
|
||||
player2TribalMarker4,
|
||||
player2TribalMarker5,
|
||||
player2TribalMarker6,
|
||||
player3Chief,
|
||||
player3Shaman,
|
||||
player3Worker1,
|
||||
player3Worker2,
|
||||
player3Worker3,
|
||||
player3Worker4,
|
||||
player3Worker5,
|
||||
player3Worker6,
|
||||
player3Base1,
|
||||
player3Base2,
|
||||
player3Base3,
|
||||
player3Base4,
|
||||
player3Base5,
|
||||
player3Base6,
|
||||
player3Base7,
|
||||
player3TribalMarker1,
|
||||
player3TribalMarker2,
|
||||
player3TribalMarker3,
|
||||
player3TribalMarker4,
|
||||
player3TribalMarker5,
|
||||
player3TribalMarker6,
|
||||
player4Chief,
|
||||
player4Shaman,
|
||||
player4Worker1,
|
||||
player4Worker2,
|
||||
player4Worker3,
|
||||
player4Worker4,
|
||||
player4Worker5,
|
||||
player4Worker6,
|
||||
player4Base1,
|
||||
player4Base2,
|
||||
player4Base3,
|
||||
player4Base4,
|
||||
player4Base5,
|
||||
player4Base6,
|
||||
player4Base7,
|
||||
player4TribalMarker1,
|
||||
player4TribalMarker2,
|
||||
player4TribalMarker3,
|
||||
player4TribalMarker4,
|
||||
player4TribalMarker5,
|
||||
player4TribalMarker6,
|
||||
player5Chief,
|
||||
player5Shaman,
|
||||
player5Worker1,
|
||||
player5Worker2,
|
||||
player5Worker3,
|
||||
player5Worker4,
|
||||
player5Worker5,
|
||||
player5Worker6,
|
||||
player5Base1,
|
||||
player5Base2,
|
||||
player5Base3,
|
||||
player5Base4,
|
||||
player5Base5,
|
||||
player5Base6,
|
||||
player5Base7,
|
||||
player5TribalMarker1,
|
||||
player5TribalMarker2,
|
||||
player5TribalMarker3,
|
||||
player5TribalMarker4,
|
||||
player5TribalMarker5,
|
||||
player5TribalMarker6
|
||||
}
|
||||
98
Src/Giants.Core/Src/Enums/PiecePosition.cs
Normal file
98
Src/Giants.Core/Src/Enums/PiecePosition.cs
Normal file
@@ -0,0 +1,98 @@
|
||||
using System.Xml.XPath;
|
||||
|
||||
namespace Giants.Core.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// Position que peut prendre une piece dans le jeu
|
||||
/// </summary>
|
||||
public enum PiecePosition
|
||||
{
|
||||
boite,
|
||||
player1Visible,
|
||||
player2Visible,
|
||||
player3Visible,
|
||||
player4Visible,
|
||||
player5Visible,
|
||||
player1Hidden,
|
||||
player2Hidden,
|
||||
player3Hidden,
|
||||
player4Hidden,
|
||||
player5Hidden,
|
||||
Carry,
|
||||
Urne,
|
||||
tile22,
|
||||
tile39,
|
||||
tile38,
|
||||
tile37,
|
||||
tile36,
|
||||
tile54,
|
||||
tile53,
|
||||
tile52,
|
||||
tile51,
|
||||
tile50,
|
||||
tile49,
|
||||
tile70,
|
||||
tile69,
|
||||
tile68,
|
||||
tile67,
|
||||
tile66,
|
||||
tile65,
|
||||
tile64,
|
||||
tile84,
|
||||
tile83,
|
||||
tile82,
|
||||
tile81,
|
||||
tile80,
|
||||
tile79,
|
||||
tile100,
|
||||
tile99,
|
||||
tile98,
|
||||
tile97,
|
||||
tile96,
|
||||
tile95,
|
||||
tile115,
|
||||
tile114,
|
||||
tile113,
|
||||
tile112,
|
||||
tile111,
|
||||
tile130,
|
||||
tile129,
|
||||
tile128,
|
||||
tile127,
|
||||
tile145,
|
||||
tile144,
|
||||
tile143,
|
||||
tile161,
|
||||
tile160,
|
||||
tile159,
|
||||
tile177,
|
||||
tile176,
|
||||
tile175,
|
||||
tile192,
|
||||
tile191,
|
||||
tile208,
|
||||
tile207,
|
||||
tile206,
|
||||
tile223,
|
||||
tile222
|
||||
}
|
||||
|
||||
public static class PiecePositionExtension
|
||||
{
|
||||
|
||||
public static PiecePosition FromTileIndex(this BoardLayout piece, int index)
|
||||
{
|
||||
string tmp = $"tile{index}";
|
||||
|
||||
object? result;
|
||||
if (Enum.TryParse(typeof(PiecePosition), tmp, out result))
|
||||
{
|
||||
if (null != result)
|
||||
{
|
||||
return (PiecePosition)result;
|
||||
}
|
||||
}
|
||||
|
||||
throw new InvalidCastException($"Cannot cast tile index {index}");
|
||||
}
|
||||
}
|
||||
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="16.11.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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using Giants.Core.Enums;
|
||||
using Giants.Core.Interfaces;
|
||||
using Giants.Infrastructure;
|
||||
|
||||
@@ -43,4 +44,24 @@ public class BoardLayoutTests
|
||||
}
|
||||
Assert.Equal(3, test.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CheckIndexToEnum()
|
||||
{
|
||||
IHexagonalGrid grid = new HexagonalGridImpl();
|
||||
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);
|
||||
}
|
||||
}
|
||||
34
Tests/Giants.Core.Tests/Entities/MatchTests.cs
Normal file
34
Tests/Giants.Core.Tests/Entities/MatchTests.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Reflection;
|
||||
using Giants.Application;
|
||||
using Giants.Core.Interfaces;
|
||||
using Giants.Infrastructure;
|
||||
|
||||
namespace Giants.Core.Tests;
|
||||
|
||||
public class MatchTests
|
||||
{
|
||||
|
||||
private readonly IMatchRepository _repo;
|
||||
|
||||
public MatchTests()
|
||||
{
|
||||
IHexagonalGrid _grid = new HexagonalGridImpl();
|
||||
BoardLayout layout = new BoardLayout(_grid);
|
||||
_repo = new MatchRepositoryMock(layout);
|
||||
|
||||
var match1 = _repo.CreateMatch();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MatchClone()
|
||||
{
|
||||
Match? match = _repo.CreateMatch();
|
||||
Assert.NotNull(match);
|
||||
|
||||
match.AssignPiece(Enums.PieceIndex.StartPlayer, Enums.PiecePosition.player1Visible);
|
||||
|
||||
Match clone = match.Clone();
|
||||
|
||||
Assert.Equal(clone, match);
|
||||
}
|
||||
}
|
||||
@@ -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