Skip to content

Commit

Permalink
Optimizacija odabira poteza računara
Browse files Browse the repository at this point in the history
  • Loading branch information
laxsrbija committed Jul 2, 2018
1 parent 0fe1d93 commit b6bd720
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
31 changes: 20 additions & 11 deletions FloodIt/Logic/Gameplay/ComputerFloodRace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,26 +135,35 @@ private List<Tuple<int, Color>> AquisitionsByColor()
{

List<Tuple<int, Color>> ret = new List<Tuple<int, Color>>();
Dictionary<Color, int> dict = new Dictionary<Color, int>();
HashSet<int> uniqueTiles = new HashSet<int>();

foreach (var color in Tile.colors)
for (var i = 0; i < game.GameGrid.GridDimension; i++)
{

HashSet<int> uniqueTiles = new HashSet<int>();

for (var i = 0; i < game.GameGrid.GridDimension; i++)
for (var j = 0; j < game.GameGrid.GridDimension; j++)
{
for (var j = 0; j < game.GameGrid.GridDimension; j++)
Tile tile = game.GameGrid[i, j];
if (!uniqueTiles.Contains(tile.Id)
&& tile.Owner == TileOwner.None
&& HasSameOwnerTileNeighbor(TileOwner.Computer, i, j))
{
Tile tile = game.GameGrid[i, j];
if (tile.TileColor == color && tile.Owner == TileOwner.None && HasSameOwnerTileNeighbor(TileOwner.Computer, i, j))

uniqueTiles.Add(tile.Id);

if (!dict.ContainsKey(tile.TileColor))
{
uniqueTiles.Add(tile.Id);
dict[tile.TileColor] = 0;
}

++dict[tile.TileColor];

}
}
}

ret.Add(new Tuple<int, Color>(uniqueTiles.Count, color));

foreach (var color in dict.Keys)
{
ret.Add(new Tuple<int, Color>(dict[color], color));
}

return ret.OrderByDescending(o => o.Item1).ToList();
Expand Down
1 change: 1 addition & 0 deletions FloodIt/Logic/Gameplay/TwoPlayerFloodRace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public override void OnColorSelect(Color color)
turn = -turn;

game.Painter.Repaint();
OnScoreboardChanged();

if (HasEnded())
{
Expand Down

0 comments on commit b6bd720

Please sign in to comment.