Points update (still not working)
continuous-integration/drone/push Build is passing Details

test_old_branch
Jules LASCRET 11 months ago
parent b1f358faf7
commit a21fcfad9e

@ -200,7 +200,7 @@ namespace QwirkleClassLibrary.Games
players[i].IsPlaying = false; players[i].IsPlaying = false;
players[(i + 1) % players.Count].IsPlaying = true; players[(i + 1) % players.Count].IsPlaying = true;
OnNextPlayer(new NextPlayerNotifiedEventArgs(players[i])); OnNextPlayer(new NextPlayerNotifiedEventArgs(players[(i + 1) % players.Count]));
return players[GetPlayingPlayerPosition()].NameTag; return players[GetPlayingPlayerPosition()].NameTag;
} }
@ -369,7 +369,7 @@ namespace QwirkleClassLibrary.Games
if (cell.GetTile.GetColor == t.GetColor && cell.GetTile.GetShape == t.GetShape) if (cell.GetTile.GetColor == t.GetColor && cell.GetTile.GetShape == t.GetShape)
{ {
OnPlaceTile(new PlaceTileNotifiedEventArgs(t, " : Tile already placed on the same line / column !")); OnPlaceTile(new PlaceTileNotifiedEventArgs(t, " is already placed on the same line / column !"));
return false; return false;
} }
@ -383,24 +383,43 @@ namespace QwirkleClassLibrary.Games
} }
} }
if (!CheckTilesInLine(cellUsed, b, x, y)) if (!CheckTilesInLine(cellUsed, b, x, y))
{ {
OnPlaceTile(new PlaceTileNotifiedEventArgs(t, "isn't on the same line as the ones previously placed !")); OnPlaceTile(new PlaceTileNotifiedEventArgs(t, "isn't on the same line as the ones previously placed !"));
return false; return false;
} }
return surroundingCells.Any(cell => cell?.GetTile != null); if (!surroundingCells.Any(cell => cell?.GetTile != null))
{
OnPlaceTile(new PlaceTileNotifiedEventArgs(t, " : You can't place a tile that isn't adjacent to another one !"));
return false;
}
return true;
} }
public int GetPlayerScore(Player player, ReadOnlyCollection<Cell> cellsPlayed, Board b) public int GetPlayerScore(Player player, ReadOnlyCollection<Cell> cellsPlayed, Board b)
{ {
int score = cellsPlayed.Count; int score = cellsPlayed.Count;
int cellsX = cellsPlayed[0].GetX;
int cellsY = cellsPlayed[0].GetY;
foreach (var cell in cellsPlayed) foreach (var cell in cellsPlayed)
{ {
score += CalculateAdjacentScore(cell, b, cellsPlayed); if (cellsX != cell.GetX && cellsX != -1)
{
cellsX = -1;
}
else if (cellsY != cell.GetY && cellsY != -1)
{
cellsY = -1;
}
score += CalculateAdjacentScore(cell, b, cellsPlayed, cellsX, cellsY);
} }
@ -412,7 +431,7 @@ namespace QwirkleClassLibrary.Games
return score; return score;
} }
private static int CalculateAdjacentScore(Cell cell, Board b, ReadOnlyCollection<Cell> cellsPlayed) public int CalculateAdjacentScore(Cell cell, Board b, ReadOnlyCollection<Cell> cellsPlayed, int cellsX, int cellsY)
{ {
int score = 0; int score = 0;
@ -434,22 +453,13 @@ namespace QwirkleClassLibrary.Games
int dx = adjacentCell.GetX - cell.GetX; int dx = adjacentCell.GetX - cell.GetX;
int dy = adjacentCell.GetY - cell.GetY; int dy = adjacentCell.GetY - cell.GetY;
if (adjacentCell.GetX == cell.GetX) score += CalculateLineScore(cell, dx, dy, b, cellsX, cellsY);
{
score += CalculateLineScore(cell, 0, dy, b);
}
else if (adjacentCell.GetY == cell.GetY)
{
score += CalculateLineScore(cell, dx, 0, b);
}
} }
return score; return score;
} }
private static int CalculateLineScore(Cell cell, int dx, int dy, Board b) public int CalculateLineScore(Cell cell, int dx, int dy, Board b, int cellsX, int cellsY)
{ {
int score = 0; int score = 0;
@ -465,12 +475,18 @@ namespace QwirkleClassLibrary.Games
score++; score++;
} }
if (dx == 0 && cellsX == -1 || dy == 0 && cellsY == -1)
{
score += 1;
}
return score; return score;
} }
public List<int> CheckTilesBag() public List<int> CheckTilesBag()
{ {
List<int> PlayerTilesBagPos = []; List<int> playerTilesBagPos = [];
if (bag.TilesBag.Count == 0) if (bag.TilesBag.Count == 0)
{ {
@ -478,27 +494,27 @@ namespace QwirkleClassLibrary.Games
{ {
if (players[i].Tiles.Count != 0) if (players[i].Tiles.Count != 0)
{ {
PlayerTilesBagPos.Add(i); playerTilesBagPos.Add(i);
} }
} }
} }
return PlayerTilesBagPos; return playerTilesBagPos;
} }
public bool CheckBoardTile(List<int> PlayerTilesBagPos) public bool CheckBoardTile(List<int> playerTilesBagPos)
{ {
for (int i = 0; i < PlayerTilesBagPos.Count; i++) for (int i = 0; i < playerTilesBagPos.Count; i++)
{ {
for (int j = 0; j < players[PlayerTilesBagPos[i]].Tiles.Count; j++) for (int j = 0; j < players[playerTilesBagPos[i]].Tiles.Count; j++)
{ {
for (int b = 0; b < board.ReadCells.Count; b++) for (int b = 0; b < board.ReadCells.Count; b++)
{ {
int x = board.ReadCells[b].GetX; int x = board.ReadCells[b].GetX;
int y = board.ReadCells[b].GetY; int y = board.ReadCells[b].GetY;
if (IsMoveCorrect(players[PlayerTilesBagPos[i]].Tiles[j], x, y, board)) if (IsMoveCorrect(players[playerTilesBagPos[i]].Tiles[j], x, y, board))
{ {
return true; return true;
} }
@ -512,9 +528,9 @@ namespace QwirkleClassLibrary.Games
public bool CheckGameOver(Player player) public bool CheckGameOver(Player player)
{ {
List<int> PlayerTilesBagPos = CheckTilesBag(); List<int> playerTilesBagPos = CheckTilesBag();
if (PlayerTilesBagPos.Count != 0 && !CheckBoardTile(PlayerTilesBagPos)) if (playerTilesBagPos.Count != 0 && !CheckBoardTile(playerTilesBagPos))
{ {
OnEndOfGame(new EndOfGameNotifiedEventArgs(player)); OnEndOfGame(new EndOfGameNotifiedEventArgs(player));
GameRunning = false; GameRunning = false;

@ -20,4 +20,8 @@ public interface IPlayer
public bool SwapTiles(Player player, List<Tile> tilesToSwap); public bool SwapTiles(Player player, List<Tile> tilesToSwap);
public int GetPlayerScore(Player player, ReadOnlyCollection<Cell> cellsPlayed, Board b); public int GetPlayerScore(Player player, ReadOnlyCollection<Cell> cellsPlayed, Board b);
int CalculateAdjacentScore(Cell cell, Board b, ReadOnlyCollection<Cell> cellsPlayed, int cellsX, int cellsY);
int CalculateLineScore(Cell cell, int dx, int dy, Board b, int cellsX, int cellsY);
} }
Loading…
Cancel
Save