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
All checks were successful
check main state / build (9.0.x) (push) Successful in 2m46s
This commit was merged in pull request #29.
This commit is contained in:
@@ -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()
|
||||
{
|
||||
|
||||
@@ -27,7 +27,7 @@ public class PrepareMatchCommand : BaseMatchCommand<PrepareMatchResult>
|
||||
{
|
||||
if (nbSocle > 0)
|
||||
{
|
||||
player.PutPieceInVisibleArea(socle);
|
||||
player.PutPieceInHiddenArea(socle);
|
||||
nbSocle--;
|
||||
}
|
||||
else
|
||||
@@ -43,7 +43,7 @@ public class PrepareMatchCommand : BaseMatchCommand<PrepareMatchResult>
|
||||
{
|
||||
if (i < 2)
|
||||
{
|
||||
player.PutPieceInVisibleArea(marker);
|
||||
player.PutPieceInHiddenArea(marker);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -53,8 +53,37 @@ public class PrepareMatchCommand : BaseMatchCommand<PrepareMatchResult>
|
||||
}
|
||||
|
||||
//assigner les ouvriers (1 chef, 1 shaman et 1 worker chacun)
|
||||
match.AssignPiece(player.Chef, player.VisiblePosition);
|
||||
match.AssignPiece(player.Shaman, player.VisiblePosition);
|
||||
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()
|
||||
{
|
||||
|
||||
@@ -36,11 +36,15 @@ 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() + 1];
|
||||
|
||||
#endregion
|
||||
|
||||
#region Getters
|
||||
@@ -72,6 +76,16 @@ public class Match
|
||||
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];
|
||||
@@ -95,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;
|
||||
|
||||
@@ -110,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;
|
||||
}
|
||||
|
||||
@@ -48,16 +48,21 @@ public class Player
|
||||
{
|
||||
_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
|
||||
|
||||
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) { }
|
||||
}
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user