public FarmerWolfGoatCabbageState( FarmerWolfGoatCabbageState parent, Side farmer, Side wolf, Side goat, Side cabbage) { base.Parent = parent; this.cabbage = cabbage; this.farmer = farmer; this.goat = goat; this.wolf = wolf; }
public override bool Equals(object obj) { if (obj == null || !(obj is FarmerWolfGoatCabbageState)) { return(false); } FarmerWolfGoatCabbageState fwgc = (FarmerWolfGoatCabbageState)obj; return (farmer.Bank == fwgc.farmer.Bank && wolf.Bank == fwgc.wolf.Bank && goat.Bank == fwgc.goat.Bank && cabbage.Bank == fwgc.cabbage.Bank); }
private void Work(int i) { FarmerWolfGoatCabbageState fwgc = new FarmerWolfGoatCabbageState(); LinkedList <State> moves = null; if (i == 1) { DepthFirstSolver solver = new DepthFirstSolver(); moves = solver.Solve(fwgc); textBox1.Text += "Depth First Solution\r\n"; } else if (i == 2) { BreadthFirstSolver solver = new BreadthFirstSolver(); moves = solver.Solve(fwgc); textBox1.Text += "Breadth First Solution\r\n"; } else if (i == 3) { BestFirstSolver solver = new BestFirstSolver(); moves = solver.Solve(fwgc); textBox1.Text += "Best First Solution\r\n"; } int number = 1; foreach (State s in moves) { FarmerWolfGoatCabbageState ns = (FarmerWolfGoatCabbageState)s; textBox1.Text += number.ToString("D2") + " "; if (ns.IsSolution()) { textBox1.Text += "S "; } else { textBox1.Text += "N "; } textBox1.Text += ns.ToString(); number++; } }