public static void DrawBoard(ValidMoveSpot m, bool[,] takenPositions) { for(int i = 0; i < maxY; i++) { for (int j = 0; j < maxX; j++) { if (j == m.X && i == m.Y) { Console.Write("K "); } else if (takenPositions[i, j]) { Console.Write("* "); } else { Console.Write("- "); } } Console.WriteLine(); } }
public async Task<bool> FindSolution(bool[,] takenPositions, int x, int y) { takenPositions[y, x] = true; ValidMoveSpot prueba = new ValidMoveSpot { X = x, Y = y }; _solutionMoves.Push(prueba); DrawBoard(prueba, takenPositions); await Task.Delay(tiempo); if (_solutionMoves.Count == maxX * maxY) { return true; } foreach (var validMove in FindValidMoves(takenPositions, x, y)) { var isFilled = await FindSolution(takenPositions, validMove.X, validMove.Y); if (isFilled) { return true; } } takenPositions[y, x] = false; _solutionMoves.Pop(); return false; }
public void DrawBoard(ValidMoveSpot m, bool[,] takenPositions) { var clr1 = Color.DarkGray; var clr2 = Color.White; for (int i = 0; i < maxY; i++) { for (int j = 0; j < maxX; j++) { if (j == m.X && i == m.Y) { _chessBoardPanels[j, i].Text = "K"; _chessBoardPanels[j, i].BackColor = Color.Red; } else if (takenPositions[i, j]) { _chessBoardPanels[j, i].Text = "*"; _chessBoardPanels[j, i].BackColor = Color.LimeGreen; } else { _chessBoardPanels[j, i].Text = ""; if (i % 2 == 0) _chessBoardPanels[j, i].BackColor = j % 2 != 0 ? clr1 : clr2; else _chessBoardPanels[j, i].BackColor = j % 2 != 0 ? clr2 : clr1; } } } }