LINQ optimizations + fix exception for the ShowBoard in Program.cs
continuous-integration/drone/push Build is passing Details

test_old_branch
Jules LASCRET 11 months ago
parent c99a0fec4e
commit 0b237dacd2

@ -46,14 +46,15 @@ namespace QwirkleClassLibrary.Boards
public bool AddTileInCell(int x, int y, Tile tile)
{
for (int i = 0; i < cells.Count; i++)
foreach (var t in cells)
{
if (cells[i].GetX != x || cells[i].GetY != y) continue;
if (cells[i].IsFree)
if (t.GetX != x || t.GetY != y) continue;
if (t.IsFree)
{
return cells[i].SetTile(tile);
return t.SetTile(tile);
}
}
return false;
}
@ -69,13 +70,14 @@ namespace QwirkleClassLibrary.Boards
public Cell? GetCell(int x, int y)
{
for (int i = 0; i < cells.Count; i++)
foreach (var t in cells)
{
if (cells[i].GetX == x && cells[i].GetY == y)
if (t.GetX == x && t.GetY == y)
{
return cells[i];
return t;
}
}
return null;
}
}

@ -107,7 +107,7 @@ namespace QwirkleClassLibrary.Games
public Board CreateBoard()
{
board = new Board(8, 8);
board = new Board(15, 12);
return board;
}
@ -117,11 +117,10 @@ namespace QwirkleClassLibrary.Games
return bag;
}
public bool StartGame()
public void StartGame()
{
if (players.Count < 2 || players.Count >= 5) return false;
if (players.Count < 2 || players.Count >= 5) return;
GameRunning = true;
return true;
}
public void AddCellUsed(Cell? c)
@ -430,11 +429,8 @@ namespace QwirkleClassLibrary.Games
cellsY = -1;
}
}
foreach (var cell in cellsPlayed)
{
score += CalculateAdjacentScore(cell, b, cellsPlayed, cellsX, cellsY);
}
score += cellsPlayed.Sum(cell => CalculateAdjacentScore(cell, b, cellsPlayed, cellsX, cellsY));
if (!scoreBoard.TryAdd(player, score))

@ -226,12 +226,14 @@ static void ShowBoard(Game game)
{
for (int y = 0; y < board.Columns; y++)
{
if (board.GetCell(y, i)!.IsFree == false)
Cell? cell = board.GetCell(y, i);
if (cell != null && cell.IsFree == false)
{
Tile? tile = board.GetCell(y, i)?.GetTile;
Tile? tile = cell.GetTile;
if (tile != null)
{
Console.Write("| " + tile.GetShape.ToString()[0] + tile.GetShape.ToString()[1] + tile.GetColor.ToString()[0] + " |");
Console.Write("| " + tile.GetShape.ToString()[0] + tile.GetShape.ToString()[1] +
tile.GetColor.ToString()[0] + " |");
}
}
else
@ -239,6 +241,7 @@ static void ShowBoard(Game game)
Console.Write("| |");
}
}
Console.WriteLine();
}
}

Loading…
Cancel
Save