public List <MoveItem> GetSteps() { List <MoveItem> steps = new List <MoveItem>(); for (MoveProcess process = this; process.ProcessBefore != null; process = process.ProcessBefore) { steps.Insert(0, process.LastMove); } return(steps); }
public Game GetOriginGame() { MoveProcess process = this; while (process.ProcessBefore != null) { process = process.ProcessBefore; } return(process.CurrentGame); }
public MoveProcess SolveGame(Game game) { int blockCount = game.Blocks.Count; Dictionary <Game, object> appearedGames = new Dictionary <Game, object>(); appearedGames.Add(game, null); List <MoveProcess> currentMoveProcesses = new List <MoveProcess>(); MoveProcess mp = new MoveProcess(game); currentMoveProcesses.Add(mp); while (true) { if (currentMoveProcesses.Count == 0) { return(null); } List <MoveProcess> newMoveProcesses = new List <MoveProcess>(); Game newGame = null; foreach (MoveProcess process in currentMoveProcesses) { for (int blockId = 0; blockId < blockCount; blockId++) { var moves = process.CurrentGame.BlockMoves(blockId); foreach (var list in moves) { newGame = new Game(process.CurrentGame); var flag = true; foreach (var dr in list) { Application.DoEvents(); flag &= newGame.MoveBlock(blockId, dr); } if (!flag || appearedGames.ContainsKey(newGame)) { break; } MoveItem newStep = new MoveItem(blockId, list); MoveProcess newProcess = new MoveProcess(process, newStep, newGame); if (newGame.GameWin()) { return(newProcess); } newMoveProcesses.Add(newProcess); appearedGames.Add(newGame, null); } } } currentMoveProcesses = newMoveProcesses; } }
public MoveProcess(MoveProcess processBefore, MoveItem moveItem, Game currentGame) { this.ProcessBefore = processBefore; this.LastMove = moveItem; this.CurrentGame = currentGame; }
public MoveProcess(Game orgGame) { this.ProcessBefore = null; //this.LastStep = null; this.CurrentGame = orgGame; }