Scores bloody working now, I hope otherwise I might quit

master
Jules LASCRET 11 months ago
parent b0afa799ae
commit 897bc547d7

@ -709,6 +709,9 @@ namespace QwirkleClassLibrary.Games
int score = cellsPlayed.Count;
int nbCellsInLine = cellsPlayed.Count;
int nbCellsInPerpLine = 1;
var checkedCells = new List<Cell>();
if (cellsPlayed.Count == 6)
{
@ -739,9 +742,9 @@ namespace QwirkleClassLibrary.Games
}
score += cellsPlayed.Sum(cell =>
CalculateAdjacentScore(cell, b, cellsPlayed, cellsX, cellsY, ref nbCellsInLine));
CalculateAdjacentScore(cell, b, cellsPlayed, new Tuple<int, int>(cellsX, cellsY), ref nbCellsInLine, ref nbCellsInPerpLine, ref checkedCells));
if (nbCellsInLine == 6)
if (nbCellsInLine == 6 || nbCellsInPerpLine == 6)
{
score += 6;
}
@ -761,12 +764,12 @@ namespace QwirkleClassLibrary.Games
/// <param name="cell"></param>
/// <param name="b"></param>
/// <param name="cellsPlayed"></param>
/// <param name="cellsX"></param>
/// <param name="cellsY"></param>
/// <param name="orientation"></param>
/// <param name="nbCellsInPerpLine"></param>
/// <param name="checkedCells"></param>
/// <param name="nbCellsInLine"></param>
/// <returns>int</returns>
public int CalculateAdjacentScore(Cell cell, Board b, ReadOnlyCollection<Cell> cellsPlayed, int cellsX,
int cellsY, ref int nbCellsInLine)
public int CalculateAdjacentScore(Cell cell, Board b, ReadOnlyCollection<Cell> cellsPlayed, Tuple<int, int> orientation, ref int nbCellsInLine, ref int nbCellsInPerpLine, ref List<Cell> checkedCells)
{
int score = 0;
@ -778,12 +781,10 @@ namespace QwirkleClassLibrary.Games
b.GetCell(cell.GetX, cell.GetY - 1)
};
var checkedSurroundingCells = new List<Cell>();
foreach (var adjacentCell in surroundingCells)
{
if (adjacentCell?.Tile! == null! || cellsPlayed.Contains(adjacentCell) ||
checkedSurroundingCells.Contains(adjacentCell))
checkedCells.Contains(adjacentCell))
{
continue;
}
@ -791,10 +792,10 @@ namespace QwirkleClassLibrary.Games
int dx = adjacentCell.GetX - cell.GetX;
int dy = adjacentCell.GetY - cell.GetY;
score += CalculateLineScore(cellsPlayed, cell, new Tuple<int, int>(dx, dy), b,
new Tuple<int, int>(cellsX, cellsY), ref nbCellsInLine);
score += CalculateLineScore(cellsPlayed, cell, new Tuple<int, int>(dx, dy),
new Tuple<int, int>(orientation.Item1, orientation.Item2), ref nbCellsInLine, ref nbCellsInPerpLine, ref checkedCells);
checkedSurroundingCells.Add(adjacentCell);
checkedCells.Add(adjacentCell);
}
return score;
@ -806,20 +807,20 @@ namespace QwirkleClassLibrary.Games
/// <param name="cellsPlayed"></param>
/// <param name="cell"></param>
/// <param name="direction"></param>
/// <param name="b"></param>
/// <param name="orientation"></param>
/// <param name="nbCellsInLine"></param>
/// <param name="nbCellsInPerpLine"></param>
/// <param name="checkedCells"></param>
/// <returns>int</returns>
public int CalculateLineScore(ReadOnlyCollection<Cell> cellsPlayed, Cell cell, Tuple<int, int> direction,
Board b, Tuple<int, int> orientation, ref int nbCellsInLine)
public int CalculateLineScore(ReadOnlyCollection<Cell> cellsPlayed, Cell cell, Tuple<int, int> direction, Tuple<int, int> orientation, ref int nbCellsInLine, ref int nbCellsInPerpLine, ref List<Cell> checkedCells)
{
int score = 0;
for (int i = 1; i < 6; i++)
{
var extendedCell = b.GetCell(cell.GetX + i * direction.Item1, cell.GetY + i * direction.Item2);
var extendedCell = board.GetCell(cell.GetX + i * direction.Item1, cell.GetY + i * direction.Item2);
if (extendedCell?.Tile! == null! || cellsPlayed.Contains(extendedCell))
if (extendedCell?.Tile! == null! || cellsPlayed.Contains(extendedCell) || checkedCells.Contains(extendedCell))
{
break;
}
@ -829,6 +830,12 @@ namespace QwirkleClassLibrary.Games
nbCellsInLine++;
}
if (direction.Item1 != 0 && orientation.Item1 != -1 || direction.Item2 != 0 && orientation.Item2 != -1)
{
nbCellsInPerpLine++;
}
checkedCells.Add(extendedCell);
score++;
}

@ -21,7 +21,9 @@ public interface IPlayer
public int GetPlayerScore(Player player, ReadOnlyCollection<Cell> cellsPlayed, Board b);
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, Tuple<int, int> orientation,
ref int nbCellsInLine, ref int nbCellsInPerpLine, ref List<Cell> checkedCells);
int CalculateLineScore(ReadOnlyCollection<Cell> cellsPlayed, Cell cell, Tuple<int, int> direction, Board b, Tuple<int, int> orientation, ref int nbCellsInLine);
int CalculateLineScore(ReadOnlyCollection<Cell> cellsPlayed, Cell cell, Tuple<int, int> direction,
Tuple<int, int> orientation, ref int nbCellsInLine, ref int nbCellsInPerpLine, ref List<Cell> checkedCells);
}

@ -447,7 +447,7 @@ public class TestGame
{
var game = new Game();
var player = new Player("TestPlayer");
var board = new Board(8, 8);
var board = game.GetBoard();
board.AddTileInCell(1, 1, new Tile(Shape.Club, Color.Red));
board.AddTileInCell(2, 1, new Tile(Shape.Square, Color.Red));

Loading…
Cancel
Save