private static void EndAnalyze(Board _board)
 {
     foreach (var cell in _board.Cells)
     {
         cell.EndAnalize();
     }
 }
 private static void BeginAnalyze(Board _board)
 {
     foreach (var cell in _board.Cells)
     {
         cell.BeginAnalyze();
     }
 }
        public PlayersTurn GetNextTurn(Board _board)
        {
            var unwantedCells = _board.Triplets.GroupBy(_triplet => _triplet.UnwantedCell);

            var tryRotate = new List<Triplet>();
            foreach (var group in unwantedCells)
            {
                if (group.Key == null)
                {
                    //not matched
                    continue;
                }
                tryRotate.AddRange(group);
                tryRotate.AddRange(_board.Triplets.Where(_triplet => _triplet.Cells.Contains(group.Key)));
            }

            Debug.WriteLine(tryRotate.Distinct().Count());

            var maxPoints = 0;
            PlayersTurn result = null;
            foreach (var triplet in tryRotate.Distinct())
            {
                foreach (var clockwise in new[]{false,true})
                {
                    BeginAnalyze(_board);
                    for (var i = 0; i < 2; ++i)
                    {
                        triplet.Rotate(clockwise);
                        var points = _board.FindAndRemoveMatchesTotal();
                        if (points > 0)
                        {
                            if (points > maxPoints)
                            {
                                maxPoints = points;
                                result = new PlayersTurn(triplet, clockwise);
                            }
                            break;
                        }
                    }
                }
            }

            EndAnalyze(_board);
            return result;
        }
        private static void CheckAllGeneratedTriplets(IRenderer _renderer, Board _board)
        {
            foreach (var triplet in _board.Triplets)
            {
                foreach (var cell in _board.Cells)
                {
                    cell.Clear();
                }

                triplet.Cells[0].Value = 3;
                triplet.Cells[1].Value = 1;
                triplet.Cells[2].Value = 1;

                _renderer.Render();

                Console.WriteLine("Triplet: " + triplet);
                Console.ReadKey(true);
            }
        }
Example #5
0
 public Game(IHexValuesGenerator _hexValuesGenerator, IPlayer _player)
 {
     Player = _player;
     Board = new Board(_hexValuesGenerator);
 }