Inheritance: LineDrawer
Example #1
0
    public LevelSolver Clone()
    {
        LevelSolver n = new LevelSolver(board.GetLength(0), board.GetLength(1), board.Cast <PieceType>().ToArray());

        n.SetGoals(goals.ToArray());
        return(n);
    }
Example #2
0
 public bool EqualsTo(LevelSolver other)
 {
     return(other.board.Cast <PieceType>().ToArray().Zip(
                board.Cast <PieceType>().ToArray(),
                (a, b) => a == b
                ).Aggregate((a, b) => a && b));
 }
    public void ExecuteSolution()
    {
        editorManager.SetGameState(EditorManager.GameState.Solving);

        pieceBoard = boardManager.pieceBoard;

        PieceType[] board = new PieceType[pieceBoard.Length];
        int         k     = 0;

        for (int i = pieceBoard.GetLength(1) - 1; i >= 0; i--)
        {
            for (int j = 0; j < pieceBoard.GetLength(0); j++)
            {
                Piece x = pieceBoard[j, i];
                board[k++] = x && x.GetPieceType() != PieceType.objective ? x.GetPieceType() : PieceType.empty;
            }
        }

        LevelSolver newLevelSolver = new LevelSolver(pieceBoard.GetLength(0), pieceBoard.GetLength(1), board);

        newLevelSolver.SetGoals(new Tuple <int, int>(pieceBoard.GetLength(0) - (int)boardManager.GetObjectivePos().y - 1, (int)boardManager.GetObjectivePos().x));

        List <InputHandler.MoveDirection> moveDirections = newLevelSolver.Solve();

        if (moveDirections.Count > 0)
        {
            print(String.Join(" ", moveDirections.Select(x => x.ToString())));
            SaveLevelTemp(moveDirections);
        }
        else
        {
            print("Nao tem solução!");
        }
        editorManager.SetGameState(EditorManager.GameState.InGame);
    }
Example #4
0
    public List <InputHandler.MoveDirection> Solve()
    {
        List <LevelSolver> visited = new List <LevelSolver>();
        List <BoardStatus> queue   = new List <BoardStatus>();

        foreach (InputHandler.MoveDirection move in Enum.GetValues(typeof(InputHandler.MoveDirection)))
        {
            queue.Add(
                new BoardStatus
            {
                moves = new List <InputHandler.MoveDirection>(new InputHandler.MoveDirection[] { move }),
                board = Clone().Move(move)
            });
        }

        while (queue.Count > 0)
        {
            BoardStatus bs = queue[0];
            queue.RemoveAt(0);
            visited.Add(bs.board);

            if (bs.board.IsSolution())
            {
                return(bs.moves);
            }

            if (bs.moves.Count < MaxSteps)
            {
                foreach (InputHandler.MoveDirection move in Enum.GetValues(typeof(InputHandler.MoveDirection)))
                {
                    LevelSolver n = bs.board.Clone().Move(move);

                    if (!visited.Exists(b => b.EqualsTo(n)) && !queue.Exists(b => b.board.EqualsTo(n)))
                    {
                        List <InputHandler.MoveDirection> m = new List <InputHandler.MoveDirection>(bs.moves.ToArray());
                        m.Add(move);
                        queue.Add(
                            new BoardStatus
                        {
                            moves = m,
                            board = n
                        }
                            );
                    }
                }
            }
        }

        return(new List <InputHandler.MoveDirection>());
    }
Example #5
0
    public void Start()
    {
        if (QueryCalls.Instance != null)
        {
            queryCalls = QueryCalls.Instance;
            queryCalls.InitializeSolver();
        }

        if (LevelSolver.Instance != null)
        {
            levelSolver = LevelSolver.Instance;
        }

        menu = GameObject.Find("InModule");
    }
 // Functions
 private void Awake()
 {
     Instance = this;
 }
Example #7
0
 // Functions
 private void Awake()
 {
     Instance = this;
 }
Example #8
0
 void Start()
 {
     levelSolver = LevelSolver.Instance;
 }