From 2cdbc4cecaec29e2c7d2f3e0cb4957f741aa8f41 Mon Sep 17 00:00:00 2001 From: chaim-Gluck Date: Tue, 26 Dec 2017 16:39:04 +0200 Subject: [PATCH] Give score for each empty cell according to its empty neighbors and then give the board a score as a sum of its cells score --- BlockPuzzleConsole/Players/FullEvalPlayer.cs | 50 +++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/BlockPuzzleConsole/Players/FullEvalPlayer.cs b/BlockPuzzleConsole/Players/FullEvalPlayer.cs index b461f12..c551485 100644 --- a/BlockPuzzleConsole/Players/FullEvalPlayer.cs +++ b/BlockPuzzleConsole/Players/FullEvalPlayer.cs @@ -110,7 +110,7 @@ class FullEvalPlayer : FullEvalPlayerBase { public override GamePath SelectBestPath(List paths) { - var topScorePath = from x in paths orderby x.ScoreGain descending, x.CellCount descending, x.PlacementScore select x; + var topScorePath = from x in paths orderby x.Tsiun descending select x; return topScorePath.First(); } @@ -132,6 +132,53 @@ public override void GatherPathStats(GamePath gamePath, Board board) { gamePath.MaxArea = (float)MaxArea.MaximalRectangle(board.Cells)/64; gamePath.FragScore = Fragmentation.GetFragmentationScore(board.Cells); + gamePath.Tsiun = GetTsiun(board); + } + + public int GetTsiun(Board myBoard) + { + int[,] myScore = new int[8, 8]; + + for (int i = 0; i < 8; i++) + for (int j = 0; j < 8; j++) + { + myScore[i, j] = 0; + if (!myBoard.Cells[i][j]) + { + if (j > 0 && !myBoard.Cells[i][j - 1]) + myScore[i, j] += 2; + if (j < 7 && !myBoard.Cells[i][j + 1]) + myScore[i, j] += 2; + if (i > 0 && j > 0 && !myBoard.Cells[i - 1][j - 1]) + myScore[i, j]++; + if (i > 0 && !myBoard.Cells[i - 1][j]) + myScore[i, j] += 2; + if (j < 7 && i > 0 && !myBoard.Cells[i - 1][j + 1]) + myScore[i, j]++; + if (i < 7 && !myBoard.Cells[i + 1][j]) + myScore[i, j] += 2; + if (j > 0 && i < 7 && !myBoard.Cells[i + 1][j - 1]) + myScore[i, j]++; + if (j < 7 && i < 7 && !myBoard.Cells[i + 1][j + 1]) + myScore[i, j]++; + if (j < 6 && !myBoard.Cells[i][j + 2] && !myBoard.Cells[i][j + 1]) + myScore[i, j] += 3; + if (j > 1 && !myBoard.Cells[i][j - 2] && !myBoard.Cells[i][j - 1]) + myScore[i, j] += 3; + if (i < 6 && !myBoard.Cells[i + 2][j] && !myBoard.Cells[i + 1][j]) + myScore[i, j] += 3; + if (i > 1 && !myBoard.Cells[i - 2][j] && !myBoard.Cells[i - 1][j]) + myScore[i, j] += 3; + if (j > 1 && j < 6 && !myBoard.Cells[i][j - 1] && !myBoard.Cells[i][j + 1] && !myBoard.Cells[i][j - 2] && !myBoard.Cells[i][j + 2]) + myScore[i, j] += 2; + } + } + int Score = 0; + for (int i = 0; i < 8; i++) + for (int j = 0; j < 8; j++) + Score += myScore[i, j]; + return Score; + } } @@ -144,6 +191,7 @@ class GamePath public int CellCount { get; set; } public float PlacementScore { get; set; } public float MaxArea { get; set; } + public int Tsiun { get; set; } public float FragScore { get; set; } public IList Moves { get; set; }