regles des chemins de corde
continuous-integration/drone/push Build is failing Details
continuous-integration/drone/pr Build is failing Details

pull/64/head
Lucas DUFLOT 11 months ago
parent 0c9d1f60ee
commit 74d6248e0a

@ -1,6 +1,6 @@
namespace Models;
public class Cell : Position
public class Cell : Position, IEquatable<Cell>
{
private int? _value;
public int? Value {
@ -26,4 +26,11 @@ public class Cell : Position
}
public bool GetCellType() => IsDangerous;
public bool Equals(Cell? other)
{
if (other == null) return false;
if (this.X == other.X && this.Y == other.Y) return true;
return false;
}
}

@ -88,38 +88,48 @@ namespace Models.Game
}
}
public void AddToRopePath(Cell playerChoice, List<List<Cell>> ropePaths,Cell adjacente)
public void AddToRopePath(Cell playerChoice,List<Cell> adjacentes)
{
int index =0;
List<List<Cell>> possiblePaths;
// {adjacentes} ne doit pas etre egale a {playerChoice}
if (adjacente.Value == playerChoice.Value) return;
// {adjacentes} doit etre croissant ou decroissant
if ((adjacente.Value - playerChoice.Value > 1) || (adjacente.Value - playerChoice.Value < -1)) return;
// Un nombre ne peut appartenir qu'a un seul chemin de corde
foreach (List<Cell> paths in ropePaths)
{
foreach (var cells in paths)
foreach (var cells in adjacentes)
{
// La cellule choisi peut creer/s'ajouter a un chemin de corde
if (cells.Value - playerChoice.Value == 1 || cells.Value - playerChoice.Value == -1)
{
if (adjacente.X == cells.X && adjacente.Y == adjacente.Y)
// Le cas si il n'existe aucun chemin de corde
if (UsedMap.RopePaths.Count == 0)
{
possiblePaths.Add(paths);
// Creer un nouveau chemin de corde avec la cellule choisi par le joueur et celle adjacente
UsedMap.RopePaths.Add(new List<Cell> {playerChoice, cells});
}
}
// A modifier dans le cas ou il est possible de fusionner deux chemins de corde
if (GameRules.IsInRopePaths(playerChoice, UsedMap.RopePaths, index)) break;
}
// Le cas si il existe des chemins de corde
// Est-ce que la cellule adjacentes fait parti d'un chemin de corde
if (!GameRules.IsInRopePaths(cells,UsedMap.RopePaths,index))
{
UsedMap.RopePaths.Add(new List<Cell> { playerChoice, cells });
continue;
}
// Si {ropePaths} est vide, il faut alors creer un chemin de corde entre {playerChoice}
if (ropePaths.Count == 0)
{
if (!GameRules.AsValue(playerChoice,UsedMap.RopePaths,index))
{
UsedMap.RopePaths[index].Add(playerChoice);
}
// Si oui, est-ce que le chemin possede deja la valeur correspondante a la valeur de la cellule du joueur choisi
// {playerChoice.Value} n'est pas dans le chemin de corde
// Ajouter au chemin
// {playerChoice.Value} existe dans le chemin de corde pas possible
}
}
}
/// <summary>

@ -36,4 +36,8 @@ public interface IRules
public int? FinalCalculusOfZones(List<List<Cell>> zones);
public bool IsInRopePaths(Cell adjacente, List<List<Cell>> ropePaths, int index);
public bool AsValue(Cell choosenCell, List<List<Cell>> ropePaths, int index);
}

@ -18,13 +18,29 @@ namespace Models.Rules
return false;
return true;
}
public bool IsInRopePaths (Cell adjacente,List<List<Cell>> ropePaths,int index)
{
foreach (List<Cell> path in ropePaths)
{
if (path.Contains(adjacente))
{
index=ropePaths.IndexOf(path);
return true;
}
}
return false;
}
public bool ropePathCellIsValid (Cell choosenCell, Cell targetCell)
public bool AsValue (Cell choosenCell, List<List<Cell>> ropePaths,int index)
{
if (Math.Abs(choosenCell.Value - targetCell.Value )
foreach (var item in ropePaths[index])
{
if (choosenCell.Value == item.Value) return true;
}
return false;
}
public bool NearCellIsValid(Cell choosenCell, List<Cell> cells)
{
if (choosenCell == null || cells == null) return false;

Loading…
Cancel
Save