Ajout des règles des zones👍
continuous-integration/drone/push Build is failing Details

pull/65/head
Remi NEVEU 12 months ago
parent e303b97a39
commit c377a107c0

@ -1,20 +1,37 @@
namespace Models.Interfaces;
using Models.Game;
namespace Models.Interfaces;
public interface IRules
{
public bool NearCellIsValid(Position playerChoicePosition, SortedDictionary<Position, Cell> cells);
{
//public bool NearCellIsValid(Position playerChoicePosition, SortedDictionary<Position, Cell> cells);
//public bool IsCellEmpty(Cell playerChoice);
//public bool IsCellValid(Position playerChoicePosition, List<Position, Cell> cells);
//public bool IsRopePath(Cell playerChoice, HashSet<RopePath> ropePaths);
//public bool IsAdjacent(Cell cell1, Cell cell2, List<Position, Cell> cells);
//public int HowMany(Cell playerChoice, List<Position, Cell> cells);
//public void SetValueAndPenalty(int valueChoice, Cell playerChoice, List<Position, Cell> cells);
public bool IsCellAdjacent(Cell choosenCell, Cell targetCell);
public bool NearCellIsValid(Cell choosenCell, List<Cell> cells);
public bool IsZoneValidAndAddToZones(Cell chosenCell, Map map);
public bool IsValueInZones(Cell chosenCell, List<List<Cell>> zones);
public void AddToZone(Cell chosenCell, List<List<Cell>> zones);
public bool IsCellEmpty(Cell playerChoice);
public void NewZoneIsCreated(Cell firstCell, Cell secondCell, Map map);
public bool IsCellValid(Position playerChoicePosition, List<Position, Cell> cells);
public bool IsZone(Cell playerChoice, List<Position, Cell> cells);
public List<Cell> EveryAdjacentCells(Cell choosenCell, List<Cell> cells);
public bool IsRopePath(Cell playerChoice, HashSet<RopePath> ropePaths);
public bool IsAdjacent(Cell cell1, Cell cell2, List<Position, Cell> cells);
public int HowMany(Cell playerChoice, List<Position, Cell> cells);
public int FinalCalculusOfZones(List<List<Cell>> zones);
public void SetValueAndPenalty(int valueChoice, Cell playerChoice, List<Position, Cell> cells);
}

@ -35,12 +35,94 @@ namespace Models.Rules
}
}
public bool IsZone(Cell choosen, List<Cell> cells,List<List<Cell>> zones)
public bool IsZoneValidAndAddToZones(Cell chosenCell, Map map)
{
IEnumerable<Cell> PlayedCellsQuery =
from cell in cells
where cell.Value != null
select cell;
if (chosenCell == null) return false;
List<Cell> adjacentCells = new List<Cell>();
adjacentCells = EveryAdjacentCells(chosenCell, map.Boards);
foreach(var cells in adjacentCells)
{
if (cells.Value == chosenCell.Value)
{
if(IsValueInZones(cells, map.Zones))
{
AddToZone(chosenCell, map.Zones);
}
else
{
NewZoneIsCreated(chosenCell, cells, map);
}
return true; // Il y a une cellule adjacente avec la même valeur donc une zone est créée si elle n'est pas déjà existante
// Si il return true, tout c'est bien passer
}
}
return false;
}
public bool IsValueInZones(Cell chosenCell, List<List<Cell>> zones)
{
if (chosenCell == null) return false;
for (int i = 0; i < zones.Count; i++)
{
if (zones[i][0].Value == chosenCell.Value)
{
return true;
}
}
return false;
}
public void AddToZone(Cell chosenCell, List<List<Cell>> zones)
{
if (chosenCell == null) return;
for (int i = 0; i < zones.Count; i++)
{
if (zones[i][0].Value == chosenCell.Value)
{
zones[i].Add(chosenCell);
return;
}
}
return;
}
public void NewZoneIsCreated(Cell firstCell, Cell secondCell, Map map)
{
List<Cell> newZone = new List<Cell>();
newZone.Add(firstCell);
newZone.Add(secondCell);
map.Zones.Add(newZone);
}
public List<Cell> EveryAdjacentCells(Cell choosenCell, List<Cell> cells)
{
List<Cell> adjacentCells = new List<Cell>();
foreach (var cell in cells)
{
if (IsCellAdjacent(choosenCell, cell))
{
adjacentCells.Add(cell);
}
}
return adjacentCells;
}
public int FinalCalculusOfZones(List<List<Cell>> zones)
{
int calculus = 0;
for(int i = 0; i < zones.Count; i++)
{
calculus += zones[i].Count * zones[i][0].Value;
}
return calculus;
}
}

Loading…
Cancel
Save