private void FindPossibleMatch(int row, int col, int round) { if (this.hasFoundAllCombinations || !this.AreParramsCorrect(row, col, round)) { return; } if (this.IsMatchAvailable(row, col, round)) { var match = new RoundMatch(row, col, round); this.tempMatches.Push(match); this.roundMatches[round, row, col] = true; this.roundsOccupiedRowsAndCols[round, row] = true; this.roundsOccupiedRowsAndCols[round, col] = true; this.board[row, col] = true; this.FindPossibleMatch(row + 1, 0, round); if (this.HasFullRound(round)) { if (round == this.maxRound) { this.hasFoundAllCombinations = true; this.finalBoard = (bool[, ]) this.board.Clone(); this.matches = this.tempMatches.ToArray(); return; } this.FindPossibleMatch(2, 0, round + 1); } this.tempMatches.Pop(); this.roundMatches[round, row, col] = false; this.roundsOccupiedRowsAndCols[round, row] = false; this.roundsOccupiedRowsAndCols[round, col] = false; this.board[row, col] = false; } else { if (this.roundsOccupiedRowsAndCols[round, row] == false) { this.FindPossibleMatch(row, col + 1, round); } this.FindPossibleMatch(row + 1, 0, round); if (this.HasFullRound(round)) { this.FindPossibleMatch(2, 0, round + 1); } } }
private void FindPossibleMatch(int row, int col, int round) { if (this.hasFoundAllCombinations || !this.AreParramsCorrect(row, col, round)) { return; } if (this.IsMatchAvailable(row, col, round)) { var match = new RoundMatch(row, col, round); this.tempMatches.Push(match); this.roundMatches[round, row, col] = true; this.roundsOccupiedRowsAndCols[round, row] = true; this.roundsOccupiedRowsAndCols[round, col] = true; this.board[row, col] = true; this.FindPossibleMatch(row + 1, 0, round); if (this.HasFullRound(round)) { if (round == this.maxRound) { this.hasFoundAllCombinations = true; this.finalBoard = (bool[,])this.board.Clone(); this.matches = this.tempMatches.ToArray(); return; } this.FindPossibleMatch(2, 0, round + 1); } this.tempMatches.Pop(); this.roundMatches[round, row, col] = false; this.roundsOccupiedRowsAndCols[round, row] = false; this.roundsOccupiedRowsAndCols[round, col] = false; this.board[row, col] = false; } else { if (this.roundsOccupiedRowsAndCols[round, row] == false) { this.FindPossibleMatch(row, col + 1, round); } this.FindPossibleMatch(row + 1, 0, round); if (this.HasFullRound(round)) { this.FindPossibleMatch(2, 0, round + 1); } } }