no test, just back of script by jules
continuous-integration/drone/push Build is passing Details

test_old_branch
Jérémy Mouyon 11 months ago
parent 4cdcbae420
commit 8724cc88ed

@ -256,7 +256,7 @@ namespace QwirkleClassLibrary
return true;
}
public bool CheckExtendedSurroundingCells(Tile tile, int x, int y, int dx, int dy, Board b)
/* public bool CheckExtendedSurroundingCells(Tile tile, int x, int y, int dx, int dy, Board b)
{
for (int i = 1; i < 7; i++)
{
@ -287,6 +287,31 @@ namespace QwirkleClassLibrary
return true;
}
return false;
}*/
public bool CheckExtendedSurroundingCells(Tile tile, int x, int y, int dx, int dy, Board b)
{
for (int i = 1; i < 7; i++)
{
var extendedCell = b.GetCell(x + i * dx, y + i * dy);
if (extendedCell?.GetTile == null)
{
break;
}
if (extendedCell.GetTile.GetColor != tile.GetColor && extendedCell.GetTile.GetShape != tile.GetShape)
{
return false;
}
if (i == 6)
{
return false;
}
}
return true;
}
public bool CheckTilesInLine(List<Cell> cells, Board b, int x, int y)
@ -313,17 +338,12 @@ namespace QwirkleClassLibrary
return false;
}
public bool IsMoveCorrect(Tile t, int x, int y, Board b)
/*public bool IsMoveCorrect(Tile t, int x, int y, Board b)
{
if (!b.HasOccupiedCase())
{
if (this.PlaceTile(this.GetPlayingPlayer(), t, x, y))
{
this.AddCellUsed(this.GetBoard().GetCell(x, y));
OnPlaceTile(new PlaceTileNotifiedEventArgs(t, "Tile correctly placed"));
return true;
}
}
var surroundingCells = new List<Cell?>
{
@ -364,6 +384,45 @@ namespace QwirkleClassLibrary
}
OnPlaceTile(new PlaceTileNotifiedEventArgs(t, "La tuile n'a pu etre placé"));
return false;
} */
public bool IsMoveCorrect(Tile t, int x, int y, Board b)
{
if (!b.HasOccupiedCase())
{
return true;
}
var surroundingCells = new List<Cell?>
{
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)
{
if (cell?.GetTile == null)
{
continue;
}
if (cell.GetTile.GetColor != t.GetColor && cell.GetTile.GetShape != t.GetShape)
{
return false;
}
var dx = cell.GetX - x;
var dy = cell.GetY - y;
if (CheckExtendedSurroundingCells(t, x, y, dx, dy, b) == false)
{
return false;
}
}
return CheckTilesInLine(this.cellUsed, b, x, y) && surroundingCells.Any(cell => cell?.GetTile != null);
}
public int GetPlayerScore(Player player, ReadOnlyCollection<Cell> cellsPlayed, Board b)

@ -75,16 +75,25 @@ static void AddTile(Game game)
Write("Enter the y of the cell : ");
int y = Convert.ToInt32(ReadLine());
/* if (game.IsMoveCorrect(tile, x, y, game.GetBoard()) == true)
if (game.IsMoveCorrect(tile, x, y, game.GetBoard()) == true)
{
if (game.PlaceTile(game.GetPlayingPlayer(), tile, x, y) == true)
{
WriteLine("ok ! your tile is placed");
game.AddCellUsed(game.GetBoard().GetCell(x, y));
}
else
{
WriteLine("ERROR : Cell already used");
}
}
else
{
WriteLine("ERROR : Move not correct");
}
}*/
game.IsMoveCorrect(tile, x, y, game.GetBoard());
game.PlaceTileNotified -= nc.NotificationAddTile;
/* game.IsMoveCorrect(tile, x, y, game.GetBoard());
game.PlaceTileNotified -= nc.NotificationAddTile;*/
}
static void SwapTile(Game game)

Loading…
Cancel
Save