Exemplo n.º 1
0
        public NPuzzle UnMove()
        {
            NPuzzle PuzzleCopy = (NPuzzle)this.Clone();

            if (PuzzleCopy.m_PreviousMoves.Count > 0)
            {
                MOVE Move = PuzzleCopy.m_PreviousMoves[PuzzleCopy.m_PreviousMoves.Count - 1];

                PuzzleCopy.m_PreviousMoves.RemoveAt(m_PreviousMoves.Count - 1);

                iVec2 Empty = PuzzleCopy.EmptyTile();

                switch (Move)
                {
                case MOVE.UP:
                    PuzzleCopy.SwitchTiles(Empty, new iVec2(Empty.x, Empty.y - 1));
                    break;

                case MOVE.RIGHT:
                    PuzzleCopy.SwitchTiles(Empty, new iVec2(Empty.x + 1, Empty.y));
                    break;

                case MOVE.LEFT:
                    PuzzleCopy.SwitchTiles(Empty, new iVec2(Empty.x - 1, Empty.y));
                    break;

                case MOVE.DOWN:
                    PuzzleCopy.SwitchTiles(Empty, new iVec2(Empty.x, Empty.y + 1));
                    break;
                }
            }

            return(PuzzleCopy);
        }
Exemplo n.º 2
0
        public NPuzzle Move(MOVE Move)
        {
            NPuzzle PuzzleCopy = (NPuzzle)this.Clone();

            PuzzleCopy.m_PreviousMoves.Add(Move);

            iVec2 Empty = EmptyTile();

#if DEBUG
            System.Diagnostics.Debug.WriteLineIf(!this.AvalibleMoves.Contains(Move), "UnValid Move Maid");
#endif

            switch (Move)
            {
            case MOVE.DOWN:
                PuzzleCopy.SwitchTiles(Empty, new iVec2(Empty.x, Empty.y - 1));
                break;

            case MOVE.LEFT:
                PuzzleCopy.SwitchTiles(Empty, new iVec2(Empty.x + 1, Empty.y));
                break;

            case MOVE.RIGHT:
                PuzzleCopy.SwitchTiles(Empty, new iVec2(Empty.x - 1, Empty.y));
                break;

            case MOVE.UP:
                PuzzleCopy.SwitchTiles(Empty, new iVec2(Empty.x, Empty.y + 1));
                break;
            }

            return(PuzzleCopy);
        }
Exemplo n.º 3
0
        protected void SwitchTiles(iVec2 TC1, iVec2 TC2)
        {
            Tile T1 = RawTiles[TC1.x, TC1.y];

            RawTiles[TC1.x, TC1.y] = RawTiles[TC2.x, TC2.y];
            RawTiles[TC2.x, TC2.y] = T1;
        }
Exemplo n.º 4
0
        public virtual iVec2 EmptyTile()
        {
            iVec2 E = new iVec2();

            foreach (PlacedTile T in Tiles)
            {
                if (T.T.Number == 0)
                {
                    E = T.Coord;
                    break;
                }
            }
            return(E);
        }
Exemplo n.º 5
0
        public float Evaluate(NPuzzle Puzzle)
        {
            float f = 0.0f;

            foreach (PlacedTile T in Puzzle.Tiles)
            {
                iVec2 Target = new iVec2();
                Target.x = T.T.Number % Puzzle.Width;
                Target.y = T.T.Number / Puzzle.Width;


                f += Math.Abs(T.Coord.x - Target.x) + Math.Abs(T.Coord.y - Target.y);
            }

            return(f);
        }
Exemplo n.º 6
0
 public PlacedTile(iVec2 _Coords, Tile _t)
 {
     Coord = _Coords;
     T     = _t;
 }