Exemple #1
0
        public void PlaceCrateOnBoardOn11PlacesManAt11()
        {
            var sokoban = new Sokoban(5, 3);
            sokoban.PlaceCrate(1, 1);

            Assert.That(sokoban.Grid[1], Is.EqualTo("#o  #"));
        }
Exemple #2
0
        // To update IsFinal, HasActions and Actions
        private void Update()
        {
            var boxes = this.boxes;

            IsFinal    = levelInstance.goals.All(goal => boxes.Contains(goal));
            HasActions = !levelInstance.walls.Contains(this.player);

            foreach (var action in Sokoban <QLearning> .ACTIONS)
            {
                Vector2 move = Sokoban <QLearning> .PlayAction(action);

                Vector2 playerMove = this.player + move;

                bool isValidBoxMove = true;
                for (int i = 0; i < this.boxes.Count; i++)
                {
                    if (playerMove == this.boxes[i])
                    {
                        Vector2 movedBox = this.boxes[i] + move;
                        // On ne bouge pas la boite si elle est sur une autre boite ou sur un mur
                        isValidBoxMove = (!(this.boxes.Contains(movedBox) || levelInstance.walls.Contains(movedBox)));
                    }
                }

                // TODO : clamp value

                // C'est un coup valid si le joueur n'est pas allé sur un mur
                if ((!levelInstance.walls.Contains(playerMove)) && isValidBoxMove)
                {
                    Actions.Add(action);
                }
            }
        }
Exemple #3
0
        public void PlaceManOnBoardOn21PlacesManAt21()
        {
            var sokoban = new Sokoban(5, 3);
            sokoban.PlaceMan(2, 1);

            Assert.That(sokoban.Grid[1], Is.EqualTo("# @ #"));
        }
Exemple #4
0
        public void GridIsCreatedFromGiven5By3Size()
        {
            var sokoban = new Sokoban(5, 3);

            Assert.That(sokoban.Grid[0], Is.EqualTo("#####"));
            Assert.That(sokoban.Grid[1], Is.EqualTo("#   #"));
            Assert.That(sokoban.Grid[2], Is.EqualTo("#####"));
        }
Exemple #5
0
        public void PlaceStorageOnBoardOn11PlacesStorageAt11()
        {
            var sokoban = new Sokoban(5, 3);

            sokoban.PlaceStorage(1, 1);

            Assert.That(sokoban.Grid[1], Is.EqualTo("#.  #"));
        }
Exemple #6
0
        public void MovingLeftFrom21MovesManLeftTo11()
        {
            var sokoban = new Sokoban(5, 3);
            sokoban.PlaceMan(2, 1);

            sokoban.Move('A');
            Assert.That(sokoban.Grid[1], Is.EqualTo("#@  #"));
        }
Exemple #7
0
        public void MovingManLeftFrom31NearCrateMovesManLeftTo21AndCrateTo11()
        {
            var sokoban = new Sokoban(5, 3);
            sokoban.PlaceMan(3, 1);
            sokoban.PlaceCrate(2, 1);

            sokoban.Move('A');
            Assert.That(sokoban.Grid[1], Is.EqualTo("#o@ #"));
        }
Exemple #8
0
        public Maze Parse(Sokoban sokoban, int idMaze)
        {
            String[] lines;

            try
            {
                string path = Path.Combine(Path
                                           .GetDirectoryName(Assembly
                                                             .GetExecutingAssembly().Location), String.Format(MazesPath, idMaze));
                lines = File.ReadAllLines(path);
            }
            catch (Exception)
            {
                return(null);
            }

            if (lines == null || lines.Length == 0)
            {
                return(null);
            }

            return(InitMaze(idMaze, lines, getLongestLine(lines), sokoban));
        }
Exemple #9
0
        private Maze InitMaze(int idMaze, string[] lines, int length, Sokoban sokoban)
        {
            Maze maze = new Maze();

            maze.MazeNumber = idMaze;
            Tile[,] tiles   = new Tile[lines.Length, length];

            int x = 0;
            int y = 0;

            foreach (String line in lines)
            {
                y = 0;
                foreach (char character in line.ToCharArray())
                {
                    Tile tile = null;
                    switch (character)
                    {
                    case 'x':
                        tile = new Destination();
                        maze.DestinationsAmount++;
                        break;

                    case '.':
                        tile = new Normal();
                        break;

                    case 'o':
                        tile = new Normal();

                        Crate crate = new Crate(tile);
                        tile.Entity = crate;

                        maze.Crates.Add(crate);
                        break;

                    case '@':
                        tile = new Normal();

                        Player player = new Player(tile);
                        tile.Entity = player;

                        maze.Player = player;
                        break;

                    case '#':
                        tile = new Wall();
                        break;

                    case '0':
                        tile = new Destination();

                        crate = new Crate(tile);
                        crate.OnDestination = true;
                        tile.Entity         = crate;

                        maze.Crates.Add(crate);
                        break;

                    case '$':
                        tile = new Normal();

                        Worker worker = new Worker(tile);
                        tile.Entity = worker;

                        maze.Worker = worker;
                        break;

                    case ' ':
                        tile = new Empty();
                        break;

                    case '~':
                        tile = new PitFall(sokoban);
                        break;
                    }

                    tiles[x, y] = tile;
                    y++;
                }

                x++;
            }

            for (int i = 0; i < tiles.GetLength(0); i++)
            {
                for (int j = 0; j < tiles.GetLength(1); j++)
                {
                    Tile tile = tiles[i, j];

                    if (tile == null)
                    {
                        continue;
                    }

                    tile.North = getTile(tiles, i - 1, j);
                    tile.East  = getTile(tiles, i, j + 1);
                    tile.South = getTile(tiles, i + 1, j);
                    tile.West  = getTile(tiles, i, j - 1);

                    if (i == 0 && j == 0)
                    {
                        maze.First = tile;
                    }
                }
            }

            return(maze);
        }
Exemple #10
0
        public void MovingManOntoStorageShowsManOnStorage()
        {
            var sokoban = new Sokoban(5, 3);
            sokoban.PlaceMan(3, 1);
            sokoban.PlaceStorage(2, 1);

            sokoban.Move('A');
            Assert.That(sokoban.Grid[1], Is.EqualTo("# + #"));
        }
Exemple #11
0
        public void MovingManIntoWallDoesntMoveMan()
        {
            var sokoban = new Sokoban(5, 3);
            sokoban.PlaceMan(1, 1);

            sokoban.Move('A');
            Assert.That(sokoban.Grid[1], Is.EqualTo("#@  #"));
        }