|
|
|
@ -7,105 +7,40 @@ using Models.Game;
|
|
|
|
|
|
|
|
|
|
namespace Models.Rules
|
|
|
|
|
{
|
|
|
|
|
public class Rules
|
|
|
|
|
public class Rules : IRules
|
|
|
|
|
{
|
|
|
|
|
public bool IsCellExist(Position playerChoicePosition, SortedDictionary<Position, Cell> cells)
|
|
|
|
|
public bool IsCellAdjacent(Cell choosenCell, Cell targetCell)
|
|
|
|
|
{
|
|
|
|
|
return cells.ContainsKey(playerChoicePosition);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool NearCellIsValid(Position playerChoicePosition, SortedDictionary<Position, Cell> cells)
|
|
|
|
|
{
|
|
|
|
|
if (!IsCellExist(playerChoicePosition, cells)) return false;
|
|
|
|
|
|
|
|
|
|
foreach (var cell in cells)
|
|
|
|
|
{
|
|
|
|
|
if (Math.Abs(playerChoicePosition.X - cell.Key.X) > 1 || Math.Abs(playerChoicePosition.Y - cell.Key.Y) > 1) continue;
|
|
|
|
|
if (Math.Abs(choosenCell.Pos.X - targetCell.Cell.X) > 1 || Math.Abs(choosenCell.Pos.Y - targetCell.Cell.Y) > 1)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (!IsCellEmpty(cell.Value))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsCellEmpty(Cell playerChoice)
|
|
|
|
|
public bool NearCellIsValid(Cell choosenCell, List<List<Cell>> cells)
|
|
|
|
|
{
|
|
|
|
|
return !playerChoice.Value.HasValue;
|
|
|
|
|
}
|
|
|
|
|
if (choosenCell == null) return false;
|
|
|
|
|
|
|
|
|
|
IEnumerable<Cellule> PlayedCellsQuery =
|
|
|
|
|
from cell in cells
|
|
|
|
|
where cell.Value != null
|
|
|
|
|
select cell;
|
|
|
|
|
|
|
|
|
|
public bool IsCellValid(Position playerChoicePosition, SortedDictionary<Position, Cell> cells)
|
|
|
|
|
{
|
|
|
|
|
return NearCellIsValid(playerChoicePosition, cells) && IsCellEmpty(cells.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsZone(Cell playerChoice, SortedDictionary<Position, Cell> cells)
|
|
|
|
|
{
|
|
|
|
|
foreach (var k,v in cells)
|
|
|
|
|
foreach (var cell in PlayedCellsQuery)
|
|
|
|
|
{
|
|
|
|
|
if (playerChoice.X != item.X + 1 && playerChoice.X != item.Pos.X - 1
|
|
|
|
|
&& playerChoice.Pos.Y != item.Pos.Y + 1 &&
|
|
|
|
|
playerChoice.Pos.Y != item.Pos.Y - 1) continue;
|
|
|
|
|
if (playerChoice.Value == item.Value)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Determines if a given cell is part of any rope path.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="playerChoice">The cell to check.</param>
|
|
|
|
|
/// <param name="ropePaths">A collection of rope paths to check against.</param>
|
|
|
|
|
/// <returns>True if the cell is part of any rope path, false otherwise.</returns>
|
|
|
|
|
public bool IsRopePath(Cell playerChoice, HashSet<RopePath> ropePaths)
|
|
|
|
|
{
|
|
|
|
|
foreach (var path in ropePaths)
|
|
|
|
|
{
|
|
|
|
|
if (path.Cells.Contains(playerChoice))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsAdjacent(Cell cell1, Cell cell2, SortedDictionary<Position, Cell> cells)
|
|
|
|
|
{
|
|
|
|
|
bool isSequence = cell1.Value.HasValue && cell2.Value.HasValue && Math.Abs(cell1.Value.Value - cell2.Value.Value) == 1;
|
|
|
|
|
if(!IsCellAdjacent(choosenCell, cell)) continue;
|
|
|
|
|
|
|
|
|
|
return IsCellValid(cell1, cells) && isSequence;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int HowMany(Cell playerChoice, SortedDictionary<Position, Cell> cells)
|
|
|
|
|
{
|
|
|
|
|
foreach(var pos in cells)
|
|
|
|
|
{
|
|
|
|
|
if (pos.Equals(playerChoice))
|
|
|
|
|
{
|
|
|
|
|
return pos.GetCellType() ? 6 : 12;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetValueAndPenalty(int valueChoice, Cell playerChoice, SortedDictionary<Position, Cell> cells)
|
|
|
|
|
public bool IsZone(Cell choosen, List<List<Cell>> cells)
|
|
|
|
|
{
|
|
|
|
|
int val = HowMany(playerChoice, cells);
|
|
|
|
|
|
|
|
|
|
foreach (var pos in cells)
|
|
|
|
|
{
|
|
|
|
|
if (!pos.Equals(playerChoice)) continue;
|
|
|
|
|
|
|
|
|
|
if (valueChoice > val)
|
|
|
|
|
{
|
|
|
|
|
playerChoice.Background = "penalty";
|
|
|
|
|
}
|
|
|
|
|
playerChoice.Value = valueChoice;
|
|
|
|
|
}
|
|
|
|
|
IEnumerable<Cellule> PlayedCellsQuery =
|
|
|
|
|
from cell in cells
|
|
|
|
|
where cell.Value != null
|
|
|
|
|
select cell;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|