Пример #1
0
    private PuzzleController MakeTutorialTile(int idx)
    {
        PuzzleController tile = PoolManager.GetObject <PuzzleController>();

        TileData tileData = new TileData();

        tileData.SetNormalTile(idx);

        int tileType, rotation;

        switch (idx)
        {
        case 0:
            tileType = 0;
            rotation = 1;
            break;

        case 1:
            tileType = 5;
            rotation = 0;
            break;

        case 2:
        default:
            tileType = 3;
            rotation = 0;
            break;
        }

        PuzzleTable puzzleTable = DataManager.GetInstance().GetTileTable(tileType);

        tile.SetData(puzzleTable, tileData, rotation);
        return(tile);
    }
Пример #2
0
 private void InitTileTypeRandomTable()
 {
     tileTypeRandomTable = RandomTable.MakeRandomTable();
     for (int i = 0, max = DataManager.GetInstance().GetTileTableListCount(); i < max; i++)
     {
         PuzzleTable table = DataManager.GetInstance().GetTileTable(i);
         tileTypeRandomTable.AddRate(table.idx, table.rate);
     }
 }
Пример #3
0
    //랜덤하게 퍼즐 타일을 생성. //
    private PuzzleController MakeRandomTile()
    {
        PuzzleController tile = PoolManager.GetObject <PuzzleController>();

        TileData    tileData    = GetTileData();
        PuzzleTable puzzleTable = DataManager.GetInstance().GetTileTable(tileTypeRandomTable.GetRandomIdx());

        tile.SetData(puzzleTable, tileData, Random.Range(0, 4));
        return(tile);
    }
Пример #4
0
    private PuzzleController MakeTile(List <Define.PuzzleType> puzzleType)
    {
        PuzzleController tile = PoolManager.GetObject <PuzzleController>();

        TileData    tileData    = GetTileData();
        int         idx         = (int)puzzleType[Random.Range(0, puzzleType.Count)];
        PuzzleTable puzzleTable = DataManager.GetInstance().GetTileTable(idx);

        tile.SetData(puzzleTable, tileData, Random.Range(0, 4));
        return(tile);
    }
Пример #5
0
        private PuzzleTable Move(int round, MoveArrow moveArrow, PuzzleTable puzzle, PuzzleTable[] tablesStack)
        {
            var TempTable = new PuzzleTable(puzzle.PuzzleWeight, puzzle.PuzzleHeight);

            if (round > 0)
            {
                TempTable.SetPuzzle(tablesStack[round - 1]);
            }
            else
            {
                TempTable.SetPuzzle(puzzle);
            }

            TempTable.Move(moveArrow.StartIndex.Index_X, moveArrow.StartIndex.Index_Y, moveArrow.Move);
            return(TempTable);
        }
Пример #6
0
    public void SetData(PuzzleTable puzzleTable, TileData tileData, int rotation)
    {
        fBlockPos = Pos.Nullity();

        this.puzzleTable = puzzleTable;
        this.tileType    = tileData;

        if (rotation < 0)
        {
            rotation = 0;
        }
        else if (rotation > 3)
        {
            rotation = 3;
        }
        this.rotation = rotation;

        InitData();
        tileIdx = -1;
        mTrans.localPosition = Define.readyPosition;
    }
Пример #7
0
        private List <MoveArrow> GetMoveList(PuzzleTable puzzle)
        {
            var Movelist = new List <MoveArrow>();

            for (int x = 0; x < puzzle.PuzzleWeight - 1; x++)
            {
                for (int y = 0; y < puzzle.PuzzleHeight - 1; y++)
                {
                    for (int moveMode = 1; moveMode <= 2; moveMode++)
                    {
                        Movelist.Add(new MoveArrow()
                        {
                            Move = (MoveMode)moveMode, StartIndex = new BoxIndex()
                            {
                                Index_X = x, Index_Y = y
                            }
                        });
                    }
                }
            }

            return(Movelist);
        }
Пример #8
0
        public List <HumanMoveArrow> Solve(PuzzleTable puzzle, int moveLimit)
        {
            var solution = this.solve(puzzle, moveLimit);

            if (solution != null)
            {
                var newSolution = new List <HumanMoveArrow>();
                foreach (var item in solution)
                {
                    //Empty Move
                    if (item.FromMoveBoxType == BoxType.Empty && item.ToMoveBoxType == BoxType.Empty)
                    {
                        continue;
                    }

                    //FromMoveBoxType Empty
                    if (item.FromMoveBoxType == BoxType.Empty)
                    {
                        //transform to human
                        HumanMoveArrow humanMoveArrow = new HumanMoveArrow()
                        {
                            StartIndex      = item.StartIndex,
                            FromMoveBoxType = item.ToMoveBoxType,
                            ToMoveBoxType   = item.FromMoveBoxType
                        };

                        switch (item.Move)
                        {
                        case MoveMode.MoveRight:
                            humanMoveArrow.Move = HumanMoveMode.Left;
                            humanMoveArrow.StartIndex.Index_X = item.StartIndex.Index_X + 1;
                            break;

                        case MoveMode.MoveUp:
                            humanMoveArrow.Move = HumanMoveMode.Down;
                            humanMoveArrow.StartIndex.Index_Y = item.StartIndex.Index_Y + 1;
                            break;

                        default:
                            break;
                        }
                        newSolution.Add(humanMoveArrow);
                    }
                    else
                    {
                        HumanMoveArrow humanMoveArrow = new HumanMoveArrow()
                        {
                            StartIndex      = item.StartIndex,
                            FromMoveBoxType = item.FromMoveBoxType,
                            ToMoveBoxType   = item.ToMoveBoxType
                        };

                        switch (item.Move)
                        {
                        case MoveMode.MoveRight:
                            humanMoveArrow.Move = HumanMoveMode.Right;
                            break;

                        case MoveMode.MoveUp:
                            humanMoveArrow.Move = HumanMoveMode.Up;
                            break;

                        default:
                            break;
                        }
                        newSolution.Add(humanMoveArrow);
                    }
                }
                return(newSolution);
            }
            else
            {
                return(null);
            }
        }
Пример #9
0
 public async Task <List <HumanMoveArrow> > SolveAsync(PuzzleTable puzzle, int moveLimit)
 {
     return(await Task.Run(() => { return Solve(puzzle, moveLimit); }));
 }
Пример #10
0
        private MoveArrow[] solve(PuzzleTable puzzle, int moveLimit)
        {
            puzzle.Fall();

            PuzzleTable[]    TablesStack     = new PuzzleTable[moveLimit];
            MoveArrow[]      Solution        = new MoveArrow[moveLimit];
            int[]            IndexOfLastmove = new int[moveLimit];
            List <MoveArrow> MoveList        = GetMoveList(puzzle);
            int MovelistCount = MoveList.Count;

            for (int i = 0; i < IndexOfLastmove.Length; i++)
            {
                IndexOfLastmove[i] = 0;
            }

            for (int i = 0; i < TablesStack.Length; i++)
            {
                TablesStack[i] = new PuzzleTable(puzzle.PuzzleWeight, puzzle.PuzzleHeight);
            }

            for (int MoveRound = 0; MoveRound < moveLimit; MoveRound++)
            {
                var MoveDirectionIndex = IndexOfLastmove[MoveRound];
                var MoveDirection      = MoveList[MoveDirectionIndex];
                TablesStack[MoveRound] = Move(MoveRound, MoveDirection, puzzle, TablesStack);
                IndexOfLastmove[MoveRound]++;
                if (IndexOfLastmove[MoveRound] >= MovelistCount - 1)
                {
                    //รอบ แรก
                    if (MoveRound <= 0)
                    {
                        return(null);
                    }
                    IndexOfLastmove[MoveRound] = 0;
                    TablesStack[MoveRound].SetPuzzle(TablesStack[MoveRound - 1]);
                    MoveRound = MoveRound - 2;
                }

                //รอบสุดท้าย
                if (MoveRound >= moveLimit - 1)
                {
                    if (TablesStack[MoveRound].IsSuccess)
                    {
                        for (int i = 0; i < Solution.Length; i++)
                        {
                            Solution[i] = MoveList[IndexOfLastmove[i] - 1];
                            if (i == 0)
                            {
                                Solution[i].FromMoveBoxType = puzzle.GetBoxsType(Solution[i].StartIndex.Index_X, Solution[i].StartIndex.Index_Y);
                                switch (Solution[i].Move)
                                {
                                case MoveMode.MoveRight:
                                    Solution[i].ToMoveBoxType = puzzle.GetBoxsType(Solution[i].StartIndex.Index_X + 1, Solution[i].StartIndex.Index_Y);
                                    break;

                                case MoveMode.MoveUp:
                                    Solution[i].ToMoveBoxType = puzzle.GetBoxsType(Solution[i].StartIndex.Index_X, Solution[i].StartIndex.Index_Y + 1);
                                    break;

                                default:
                                    break;
                                }
                            }
                            else
                            {
                                Solution[i].FromMoveBoxType = TablesStack[i - 1].GetBoxsType(Solution[i].StartIndex.Index_X, Solution[i].StartIndex.Index_Y);
                                switch (Solution[i].Move)
                                {
                                case MoveMode.MoveRight:
                                    Solution[i].ToMoveBoxType = TablesStack[i - 1].GetBoxsType(Solution[i].StartIndex.Index_X + 1, Solution[i].StartIndex.Index_Y);
                                    break;

                                case MoveMode.MoveUp:
                                    Solution[i].ToMoveBoxType = TablesStack[i - 1].GetBoxsType(Solution[i].StartIndex.Index_X, Solution[i].StartIndex.Index_Y + 1);
                                    break;

                                default:
                                    break;
                                }
                            }
                        }
                        return(Solution);
                    }
                    else
                    {
                        if (MoveRound <= 0)
                        {
                            TablesStack[MoveRound].SetPuzzle(puzzle);
                        }
                        else
                        {
                            TablesStack[MoveRound].SetPuzzle(TablesStack[MoveRound - 1]);
                        }
                        MoveRound--;
                    }
                }
            }
            return(null);
        }
Пример #11
0
 public void CopyData(TileData data)
 {
     blockType = data.blockType;
     colorType = data.colorType;
     tileTable = data.tileTable;
 }
        private async void Solve_Clicked(object sender, EventArgs e)
        {
            string Text = Number_Of_Move.Text;
            int    Limit;

            if (int.TryParse(Text, out Limit))
            {
                if (Limit > 0 && Limit <= 10)
                {
                    if (BoxsToSolve.Count <= 0)
                    {
                        await DisplayAlert("Slover", "No Box in Puzzle", "OK");

                        return;
                    }

                    bool AllEmpty = true;
                    foreach (var item in BoxsToSolve)
                    {
                        if (item.Value != BoxType.Empty)
                        {
                            AllEmpty = false;
                            break;
                        }
                    }

                    if (AllEmpty)
                    {
                        await DisplayAlert("Slover", "No Box in Puzzle", "OK");

                        return;
                    }

                    foreach (var item in BoxsToSolve.Where(x => x.Value != BoxType.Empty).GroupBy(x => x.Value))
                    {
                        if (item.Count() < 3)
                        {
                            await DisplayAlert("Slover", "The number of each type of box must grater than 3", "OK");

                            return;
                        }
                    }

                    Number_Of_Move.BackgroundColor = Color.Default;
                    PuzzleTable puzzle = new PuzzleTable(7, 9);


                    puzzle.CreatePuzzle(BoxsToSolve);
                    Solver.Solver solver = new Solver.Solver();
                    if (!IsHasSolution)
                    {
                        try
                        {
                            IsLoading = true;
                            Solution  = await solver.SolveAsync(puzzle, Limit);
                        }
                        finally
                        {
                            IsLoading = false;
                        }
                        IsHasSolution = true;
                    }

                    if (Solution == null)
                    {
                        await DisplayAlert("Slover", "No Solution", "OK");
                    }
                    else
                    {
                        await Navigation.PushModalAsync(new SolutionPage(Solution));

                        //DisplayAlert("Slover", SolutionText, "OK");
                    }
                }
                else
                {
                    InvalidMoveText();
                }
            }
            else
            {
                InvalidMoveText();
            }
        }