|
|
|
@ -207,99 +207,153 @@ namespace QwirkleClassLibrary
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// public bool IsMoveCorrect(Tile t, int x, int y, Board b)
|
|
|
|
|
// {
|
|
|
|
|
// if (b.HasOccupiedCase() == false)
|
|
|
|
|
// {
|
|
|
|
|
// return true;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// var surroundingCells = new List<Cell?>();
|
|
|
|
|
//
|
|
|
|
|
// surroundingCells.Add(b.GetCell(x + 1, y));
|
|
|
|
|
// surroundingCells.Add(b.GetCell(x - 1, y));
|
|
|
|
|
// surroundingCells.Add(b.GetCell(x, y + 1));
|
|
|
|
|
// surroundingCells.Add(b.GetCell(x, y - 1));
|
|
|
|
|
//
|
|
|
|
|
// foreach (var cell in surroundingCells.ToList())
|
|
|
|
|
// {
|
|
|
|
|
// if (cell?.GetTile == null)
|
|
|
|
|
// {
|
|
|
|
|
// surroundingCells.Remove(cell);
|
|
|
|
|
// continue;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// if (cell?.GetTile.GetColor != t.GetColor && cell?.GetTile.GetShape != t.GetShape)
|
|
|
|
|
// {
|
|
|
|
|
// return false;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// if(surroundingCells.Count == 0) return false;
|
|
|
|
|
//
|
|
|
|
|
// foreach (var cell in surroundingCells.ToList())
|
|
|
|
|
// {
|
|
|
|
|
// var extendedCells = new List<Cell?>();
|
|
|
|
|
//
|
|
|
|
|
// if (cell?.GetX == x && cell?.GetY == y + 1)
|
|
|
|
|
// {
|
|
|
|
|
// for (int i = 1; i < 7; i++)
|
|
|
|
|
// {
|
|
|
|
|
// if (b.GetCell(x, y + i)?.GetTile != null)
|
|
|
|
|
// {
|
|
|
|
|
// extendedCells.Add(b.GetCell(x, y + i));
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// else if (cell?.GetX == x && cell?.GetY == y - 1)
|
|
|
|
|
// {
|
|
|
|
|
// for (int i = 1; i < 7; i++)
|
|
|
|
|
// {
|
|
|
|
|
// if (b.GetCell(x, y - i)?.GetTile != null)
|
|
|
|
|
// {
|
|
|
|
|
// extendedCells.Add(b.GetCell(x, y - i));
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// else if (cell?.GetX == x + 1 && cell?.GetY == y)
|
|
|
|
|
// {
|
|
|
|
|
// for (int i = 1; i < 7; i++)
|
|
|
|
|
// {
|
|
|
|
|
// if (b.GetCell(x + i, y)?.GetTile != null)
|
|
|
|
|
// {
|
|
|
|
|
// extendedCells.Add(b.GetCell(x + i, y));
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// else if (cell?.GetX == x - 1 && cell?.GetY == y)
|
|
|
|
|
// {
|
|
|
|
|
// for (int i = 1; i < 7; i++)
|
|
|
|
|
// {
|
|
|
|
|
// if (b.GetCell(x - i, y)?.GetTile != null)
|
|
|
|
|
// {
|
|
|
|
|
// extendedCells.Add(b.GetCell(x - i, y));
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// foreach (var e in extendedCells)
|
|
|
|
|
// {
|
|
|
|
|
// if (e?.GetTile?.GetColor != t.GetColor && e?.GetTile?.GetShape != t.GetShape)
|
|
|
|
|
// {
|
|
|
|
|
// return false;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// if (extendedCells.Count == 6)
|
|
|
|
|
// {
|
|
|
|
|
// return false;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// return true;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
public bool IsMoveCorrect(Tile t, int x, int y, Board b)
|
|
|
|
|
{
|
|
|
|
|
if (b.HasOccupiedCase() == false)
|
|
|
|
|
if (!b.HasOccupiedCase())
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var surroundingCells = new List<Cell?>();
|
|
|
|
|
|
|
|
|
|
surroundingCells.Add(b.GetCell(x + 1, y));
|
|
|
|
|
surroundingCells.Add(b.GetCell(x - 1, y));
|
|
|
|
|
surroundingCells.Add(b.GetCell(x, y + 1));
|
|
|
|
|
surroundingCells.Add(b.GetCell(x, y - 1));
|
|
|
|
|
var surroundingCells = new[]
|
|
|
|
|
{
|
|
|
|
|
b.GetCell(x + 1, y),
|
|
|
|
|
b.GetCell(x - 1, y),
|
|
|
|
|
b.GetCell(x, y + 1),
|
|
|
|
|
b.GetCell(x, y - 1)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
foreach (var cell in surroundingCells.ToList())
|
|
|
|
|
foreach (var cell in surroundingCells)
|
|
|
|
|
{
|
|
|
|
|
if (cell?.GetTile == null)
|
|
|
|
|
{
|
|
|
|
|
surroundingCells.Remove(cell);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cell?.GetTile.GetColor != t.GetColor && cell?.GetTile.GetShape != t.GetShape)
|
|
|
|
|
if (cell.GetTile.GetColor != t.GetColor && cell.GetTile.GetShape != t.GetShape)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(surroundingCells.Count == 0) return false;
|
|
|
|
|
var dx = cell.GetX - x;
|
|
|
|
|
var dy = cell.GetY - y;
|
|
|
|
|
|
|
|
|
|
foreach (var cell in surroundingCells.ToList())
|
|
|
|
|
{
|
|
|
|
|
var extendedCells = new List<Cell?>();
|
|
|
|
|
|
|
|
|
|
if (cell?.GetX == x && cell?.GetY == y + 1)
|
|
|
|
|
for (int i = 1; i < 7; i++)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 1; i < 7; i++)
|
|
|
|
|
{
|
|
|
|
|
if (b.GetCell(x, y + i)?.GetTile != null)
|
|
|
|
|
{
|
|
|
|
|
extendedCells.Add(b.GetCell(x, y + i));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var extendedCell = b.GetCell(x + i * dx, y + i * dy);
|
|
|
|
|
|
|
|
|
|
else if (cell?.GetX == x && cell?.GetY == y - 1)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 1; i < 7; i++)
|
|
|
|
|
if (extendedCell?.GetTile == null)
|
|
|
|
|
{
|
|
|
|
|
if (b.GetCell(x, y - i)?.GetTile != null)
|
|
|
|
|
{
|
|
|
|
|
extendedCells.Add(b.GetCell(x, y - i));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (cell?.GetX == x + 1 && cell?.GetY == y)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 1; i < 7; i++)
|
|
|
|
|
if (extendedCell.GetTile.GetColor != t.GetColor && extendedCell.GetTile.GetShape != t.GetShape)
|
|
|
|
|
{
|
|
|
|
|
if (b.GetCell(x + i, y)?.GetTile != null)
|
|
|
|
|
{
|
|
|
|
|
extendedCells.Add(b.GetCell(x + i, y));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (cell?.GetX == x - 1 && cell?.GetY == y)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 1; i < 7; i++)
|
|
|
|
|
{
|
|
|
|
|
if (b.GetCell(x - i, y)?.GetTile != null)
|
|
|
|
|
{
|
|
|
|
|
extendedCells.Add(b.GetCell(x - i, y));
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var e in extendedCells)
|
|
|
|
|
{
|
|
|
|
|
if (e?.GetTile?.GetColor != t.GetColor && e?.GetTile?.GetShape != t.GetShape)
|
|
|
|
|
if (i == 6)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (extendedCells.Count == 6)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
return surroundingCells.Any(cell => cell?.GetTile != null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|