コード例 #1
0
        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);
        }
コード例 #2
0
        public Game GetOriginGame()
        {
            MoveProcess process = this;

            while (process.ProcessBefore != null)
            {
                process = process.ProcessBefore;
            }
            return(process.CurrentGame);
        }
コード例 #3
0
ファイル: Solver.cs プロジェクト: lipz89/HuaRongDao
        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;
            }
        }
コード例 #4
0
 public MoveProcess(MoveProcess processBefore, MoveItem moveItem, Game currentGame)
 {
     this.ProcessBefore = processBefore;
     this.LastMove      = moveItem;
     this.CurrentGame   = currentGame;
 }
コード例 #5
0
 public MoveProcess(Game orgGame)
 {
     this.ProcessBefore = null;
     //this.LastStep = null;
     this.CurrentGame = orgGame;
 }