Score improvement (close to be good but not yet)
continuous-integration/drone/push Build is passing Details

test_old_branch
Jules LASCRET 11 months ago
parent bb59acaf57
commit 1f994f7b83

@ -160,7 +160,7 @@ namespace QwirkleClassLibrary.Games
/// <returns>Board</returns> /// <returns>Board</returns>
public Board CreateBoard() public Board CreateBoard()
{ {
Board = new Board(15, 12); Board = new Board(7, 7);
return Board; return Board;
} }
@ -627,7 +627,7 @@ 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;
score += CalculateLineScore(cell, dx, dy, b, cellsX, cellsY, ref nbCellsInLine); score += CalculateLineScore(cellsPlayed, cell, dx, dy, b, cellsX, cellsY, ref nbCellsInLine);
} }
return score; return score;
@ -636,6 +636,7 @@ namespace QwirkleClassLibrary.Games
/// <summary> /// <summary>
/// Extension of GetPlayerScore to calculate the score of the player based on the line/column of the adjacent cells /// Extension of GetPlayerScore to calculate the score of the player based on the line/column of the adjacent cells
/// </summary> /// </summary>
/// <param name="cellsPlayed"></param>
/// <param name="cell"></param> /// <param name="cell"></param>
/// <param name="dx"></param> /// <param name="dx"></param>
/// <param name="dy"></param> /// <param name="dy"></param>
@ -644,7 +645,7 @@ namespace QwirkleClassLibrary.Games
/// <param name="cellsY"></param> /// <param name="cellsY"></param>
/// <param name="nbCellsInLine"></param> /// <param name="nbCellsInLine"></param>
/// <returns>int</returns> /// <returns>int</returns>
public int CalculateLineScore(Cell cell, int dx, int dy, Board b, int cellsX, int cellsY, ref int nbCellsInLine) public int CalculateLineScore(ReadOnlyCollection<Cell> cellsPlayed, Cell cell, int dx, int dy, Board b, int cellsX, int cellsY, ref int nbCellsInLine)
{ {
int score = 0; int score = 0;
@ -652,9 +653,9 @@ namespace QwirkleClassLibrary.Games
{ {
var extendedCell = b.GetCell(cell.GetX + i * dx, cell.GetY + i * dy); var extendedCell = b.GetCell(cell.GetX + i * dx, cell.GetY + i * dy);
if (extendedCell?.GetTile == null) if (extendedCell?.GetTile == null || cellsPlayed.Contains(extendedCell))
{ {
continue; break;
} }
if (dx != 0 && cellsX == -1 || dy != 0 && cellsY == -1) if (dx != 0 && cellsX == -1 || dy != 0 && cellsY == -1)
@ -704,23 +705,23 @@ namespace QwirkleClassLibrary.Games
/// <returns></returns> /// <returns></returns>
public bool CheckPlacementPossibilities(List<int> playerTilesBagPos) public bool CheckPlacementPossibilities(List<int> playerTilesBagPos)
{ {
for (int i = 0; i < playerTilesBagPos.Count; i++) foreach (var t1 in playerTilesBagPos)
{ {
for (int j = 0; j < players[playerTilesBagPos[i]].Tiles.Count; j++) foreach (var t in players[t1].Tiles)
{ {
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(t, x, y, Board))
{ {
return true; return true;
} }
} }
} }
} }
return false; return false;
} }

@ -23,5 +23,6 @@ public interface IPlayer
int CalculateAdjacentScore(Cell cell, Board b, ReadOnlyCollection<Cell> cellsPlayed, int cellsX, int cellsY, ref int nbCellsInLine); int CalculateAdjacentScore(Cell cell, Board b, ReadOnlyCollection<Cell> cellsPlayed, int cellsX, int cellsY, ref int nbCellsInLine);
int CalculateLineScore(Cell cell, int dx, int dy, Board b, int cellsX, int cellsY, ref int nbCellsInLine); int CalculateLineScore(ReadOnlyCollection<Cell> cellsPlayed, Cell cell, int dx, int dy, Board b, int cellsX,
int cellsY, ref int nbCellsInLine);
} }
Loading…
Cancel
Save