Mise en place des MatchCommand
All checks were successful
check main state / build (9.0.x) (push) Successful in 1m28s
All checks were successful
check main state / build (9.0.x) (push) Successful in 1m28s
Ajout des données dynamiques au match
This commit was merged in pull request #21.
This commit is contained in:
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());
|
||||
}
|
||||
}
|
||||
41
Src/Giants.Core/Src/Commands/PrepareMatchCommand.cs
Normal file
41
Src/Giants.Core/Src/Commands/PrepareMatchCommand.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System.Security.Claims;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
namespace Giants.Core.Commands;
|
||||
|
||||
public class PrepareMatchCommand : BaseMatchCommand<PrepareMatchResult>
|
||||
{
|
||||
public required int NbPlayer { get; init; }
|
||||
|
||||
protected override PrepareMatchResult LocalMatchExecute(Match match)
|
||||
{
|
||||
if (NbPlayer < 3 || NbPlayer > 5)
|
||||
return new PrepareMatchResult();
|
||||
|
||||
|
||||
//Gestion des assets des joueurs
|
||||
for (int i = 0; i < NbPlayer; i++)
|
||||
{
|
||||
//marqueurs tribaux
|
||||
int nbMarker = NbMarkerPerPlayer(NbPlayer);
|
||||
for (int t = 0; t < nbMarker; t++)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
return new PrepareMatchResult();
|
||||
}
|
||||
|
||||
private int NbMarkerPerPlayer(int nbTotalPlayer)
|
||||
{
|
||||
return nbTotalPlayer switch
|
||||
{
|
||||
3 => 7,
|
||||
4 => 6,
|
||||
5 => 5,
|
||||
_ => throw new Exception("Wrong player count for NbMarkerPerPlayer")
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class PrepareMatchResult : BaseCommandResult { }
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using Giants.Core.Interfaces;
|
||||
using Giants.Core.Enums;
|
||||
|
||||
namespace Giants.Core;
|
||||
|
||||
@@ -18,15 +17,72 @@ 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>
|
||||
/// 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()];
|
||||
|
||||
#endregion
|
||||
|
||||
#region acessors for commands
|
||||
public void AssignPiece(PieceIndex piece, PiecePosition position)
|
||||
{
|
||||
pieces[(int)piece] = position;
|
||||
|
||||
}
|
||||
#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));
|
||||
|
||||
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);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
111
Src/Giants.Core/Src/Enums/PieceIndex.cs
Normal file
111
Src/Giants.Core/Src/Enums/PieceIndex.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
namespace Giants.Core.Enums;
|
||||
|
||||
public enum PieceIndex
|
||||
{
|
||||
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}");
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using Giants.Core.Enums;
|
||||
using Giants.Core.Interfaces;
|
||||
using Giants.Infrastructure;
|
||||
|
||||
@@ -43,4 +44,12 @@ 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));
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user