|
|
|
@ -3,31 +3,48 @@ using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Models.Game;
|
|
|
|
|
|
|
|
|
|
namespace Models.Rules
|
|
|
|
|
{
|
|
|
|
|
public class Rules
|
|
|
|
|
{
|
|
|
|
|
public static bool NearCell(Cell playerChoice, List<Cell> cells)
|
|
|
|
|
public bool IsCellExist(Position playerChoicePosition, SortedDictionary<Position, Cell> cells)
|
|
|
|
|
{
|
|
|
|
|
return cells.Any(item => playerChoice.Pos.X == item.Pos.X + 1 || playerChoice.Pos.X == item.Pos.X - 1 || playerChoice.Pos.Y == item.Pos.Y + 1 || playerChoice.Pos.Y == item.Pos.Y - 1);
|
|
|
|
|
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 (!IsCellEmpty(cell.Value))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool IsCellEmpty(Cell playerChoice)
|
|
|
|
|
public bool IsCellEmpty(Cell playerChoice)
|
|
|
|
|
{
|
|
|
|
|
return playerChoice.Value == null;
|
|
|
|
|
return !playerChoice.Value.HasValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool IsCellValid(Cell playerChoice, List<Cell> cells)
|
|
|
|
|
public bool IsCellValid(Position playerChoicePosition, SortedDictionary<Position, Cell> cells)
|
|
|
|
|
{
|
|
|
|
|
return NearCell(playerChoice, cells) && IsCellEmpty(playerChoice);
|
|
|
|
|
return NearCellIsValid(playerChoicePosition, cells) && IsCellEmpty(cells.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool IsZone(Cell playerChoice, List<Cell> cells)
|
|
|
|
|
public bool IsZone(Cell playerChoice, SortedDictionary<Position, Cell> cells)
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in cells)
|
|
|
|
|
foreach (var k,v in cells)
|
|
|
|
|
{
|
|
|
|
|
if (playerChoice.Pos.X != item.Pos.X + 1 && playerChoice.Pos.X != item.Pos.X - 1
|
|
|
|
|
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)
|
|
|
|
@ -38,29 +55,32 @@ namespace Models.Rules
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool IsRopePath(Cell playerChoice, List<Cell> cells, List<Cell> ropePaths)
|
|
|
|
|
/// <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 item in cells)
|
|
|
|
|
foreach (var path in ropePaths)
|
|
|
|
|
{
|
|
|
|
|
if (playerChoice.Pos.X != item.Pos.X + 1 && playerChoice.Pos.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 + 1 && playerChoice.Value != item.Value - 1) continue;
|
|
|
|
|
|
|
|
|
|
foreach (var path in ropePaths)
|
|
|
|
|
if (path.Cells.Contains(playerChoice))
|
|
|
|
|
{
|
|
|
|
|
if (path.Equals(playerChoice))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return IsRopePath(item, cells, ropePaths);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static int HowMany(Cell playerChoice, List<Cell> cells)
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
return IsCellValid(cell1, cells) && isSequence;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int HowMany(Cell playerChoice, SortedDictionary<Position, Cell> cells)
|
|
|
|
|
{
|
|
|
|
|
foreach(var pos in cells)
|
|
|
|
|
{
|
|
|
|
@ -72,7 +92,7 @@ namespace Models.Rules
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void SetValueAndPenalty(int valueChoice, Cell playerChoice, List<Cell> cells)
|
|
|
|
|
public void SetValueAndPenalty(int valueChoice, Cell playerChoice, SortedDictionary<Position, Cell> cells)
|
|
|
|
|
{
|
|
|
|
|
int val = HowMany(playerChoice, cells);
|
|
|
|
|
|
|
|
|
|