public int CleverBruteForce() { var numberOfWrongMoves = 0; bool Work() { var gameValidator = new GameValidator(); var nextUnknownCell = GetMostLikelyUnknownCell(); if (nextUnknownCell.IsUnused) { return(true); } var probabilty = CalculateProbability(nextUnknownCell.Column, nextUnknownCell.Row); _cells[nextUnknownCell.Column, nextUnknownCell.Row] = probabilty > 0.5M ? Mine : Empty; if (gameValidator.Validate(this).IsValid) { var result = Work(); if (result) { return(true); } } else { numberOfWrongMoves++; } _cells[nextUnknownCell.Column, nextUnknownCell.Row] = probabilty > 0.5M ? Empty : Mine; if (gameValidator.Validate(this).IsValid) { var result = Work(); if (result) { return(true); } } else { numberOfWrongMoves++; } _cells[nextUnknownCell.Column, nextUnknownCell.Row] = UnknownCell; return(false); } Work(); return(numberOfWrongMoves); }
public int BruteForce() { var numberOfWrongMoves = 0; bool Work() { var gameValidator = new GameValidator(); var nextUnknownCell = GetNextUnknownCell(); if (nextUnknownCell.IsUnused) { return(true); } _cells[nextUnknownCell.Column, nextUnknownCell.Row] = Mine; if (gameValidator.Validate(this).IsValid) { var result = Work(); if (result) { return(true); } } else { numberOfWrongMoves++; } _cells[nextUnknownCell.Column, nextUnknownCell.Row] = Empty; if (gameValidator.Validate(this).IsValid) { var result = Work(); if (result) { return(true); } } else { numberOfWrongMoves++; } _cells[nextUnknownCell.Column, nextUnknownCell.Row] = UnknownCell; return(false); } Work(); return(numberOfWrongMoves); }