Ejemplo n.º 1
0
        private void DrawBoardCell()
        {
            int x = 1;
            int y = 8;

            for (int i = 0; i < 64; i++)
            {
                if (x > 8)
                {
                    x = 1;
                    y--;
                }

                var cell = new CellView();
                cell.SetPosition(x++, y);
                if ((x % 2 == 0 && y % 2 == 0) || (x % 2 != 0 && y % 2 != 0))
                {
                    cell.Color = Brushes.BurlyWood;
                }
                else
                {
                    cell.Color = Brushes.SaddleBrown;
                }

                BoardGrid.Children.Add(cell);
            }

            _cells = BoardGrid.Children.OfType <CellView>().ToList();
        }
Ejemplo n.º 2
0
        private void Move()
        {
            if (_step == 63)
            {
                _timer.Stop(); StartBtn.IsEnabled = true;
            }

            var possibleMoves = GetPossibleMoves(_horseMoves, _currentX, _currentY);

            var nextPossibleMovesCount = new List <int>();

            foreach (CellView cellView in possibleMoves)
            {
                int x = cellView.X;
                int y = cellView.Y;
                nextPossibleMovesCount.Add(GetPossibleMoves(_horseMoves, x, y).Count);
            }

            int index = nextPossibleMovesCount.IndexOf(nextPossibleMovesCount.Min());

            _cells[_currentCell].IsHorse = false;
            _cells[_currentCell].Text    = (_step++).ToString();
            StepTextLog.Text             = _step.ToString();
            // set new cell
            CellView nextCell = possibleMoves[index];

            nextCell.IsHorse = true;
            nextCell.IsSet   = true;
            nextCell.Text    = "H";

            _currentX = nextCell.X;
            _currentY = nextCell.Y;

            _currentCell = _cells.IndexOf(nextCell);
        }