public void TestNumPlaced() { Grid g = new Grid(9, 0); Assert.AreEqual(0, g.GetNumPlaced()); g.Place(3, 1, 1); g.Place(4, 0, 1); Assert.AreEqual(2, g.GetNumPlaced()); }
public void TestNumErrors() { Grid g = new Grid(9, 0); Assert.AreEqual(0, g.GetNumMistakes()); g.Place(3,1,1); g.Place(3,0,1); Assert.AreEqual(2, g.GetNumMistakes()); g.Place(0, 0, 1); Assert.AreEqual(0, g.GetNumMistakes()); }
public void TestFitness() { Grid g = new Grid(9,10); EvolutionarySolver es = new EvolutionarySolver(); Assert.AreEqual(71,es.GetFitness(g)); g.Place(8,g.GetEmptyPositions().First()); Assert.AreEqual(70, es.GetFitness(g)); g.Place(8, g.GetEmptyPositions().First()); Assert.AreEqual(2069, es.GetFitness(g)); }
private bool SolveAux(Grid initial) { if (initial.IsSolved()) return true; int pos = GetNextPosition(initial); var listMoves = initial.GetAvailableNumbersFor(pos); foreach (var move in listMoves) { initial.Place(move,pos); if (SolveAux(initial)) return true; initial.Place(0,pos); } return false; }
public void TestCanPlace() { Grid g = new Grid(9,0); g.Place(3,1,1); for (int i = 0; i < 9; i++) { Assert.AreEqual(false, g.CanPlace(3, i, 1)); //test row Assert.AreEqual(false, g.CanPlace(3, 1, i)); //test col } for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++ ) Assert.AreEqual(false, g.CanPlace(3, i, j)); //test row Assert.AreEqual(true, g.CanPlace(3, 5, 5)); //test col }
public Grid GetNewInitialSolution(Grid initialGrid) { Random r = new Random(); Grid g = new Grid(initialGrid); for (int i = 0; i < InitiPopulationIterationCount;i++ ) { var n = r.Next(1, g.Size+1); var row = r.Next(0, g.Size); var col = r.Next(0, g.Size); if (g.Get(row, col) != 0) { g.Place(n,row,col); } } return g; }
public void TestGet() { Grid g = new Grid(9,0); g.Place(3,1,1); Assert.AreEqual(3,g.Get(1,1)); }