private void InitState(List <List <int> > levelBoard, ISPSimulationStrategy sim, MersenneTwister rng)
 {
     rnd   = rng;
     board = levelBoard;
     size  = board.Count;
     if (sim == null)
     {
         simulationStrategy = new SamegameRandomStrategy();
     }
     else
     {
         simulationStrategy = sim;
     }
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="levelBoardToTranspose">An array containing the rows of the level</param>
        /// <param name="sim"></param>
        public SamegameGameState(int[][] levelBoardToTranspose, MersenneTwister rng, ISPSimulationStrategy sim = null)
        {
            //Transform arrays into lists
            List <List <int> > levelBoard = new List <List <int> >();

            for (int i = 0; i < levelBoardToTranspose.Length; i++)
            {
                List <int> newList = new List <int>();
                for (int j = 0; j < levelBoardToTranspose[i].Length; j++)
                {
                    newList.Add(levelBoardToTranspose[j][i]);
                }
                levelBoard.Add(newList);
            }

            for (int i = 0; i < levelBoard.Count; i++)
            {
                levelBoard[i].Reverse();
            }
            InitState(levelBoard, sim, rng);
        }
        public SamegameGameState(string level, MersenneTwister rng, ISPSimulationStrategy sim = null)
        {
            rnd = rng;
            String[] levelRows = level.Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);
            board = new List <List <int> >();
            foreach (string row in levelRows)
            {
                board.Add(new List <int>());
            }
            int x;
            int val;

            foreach (string row in levelRows)
            {
                x = 0;
                foreach (char c in row)
                {
                    int.TryParse(c.ToString(), out val);
                    board[x].Add(val);
                    x++;
                }
            }
            foreach (List <int> column in board)
            {
                column.Reverse();
            }
            size = levelRows.Length;

            if (sim == null)
            {
                simulationStrategy = new SamegameRandomStrategy();
            }
            else
            {
                simulationStrategy = sim;
            }
        }
Example #4
0
 private void Init(SokobanGameState state, RewardType rewardType, bool useNormalizedPosition, bool useGoalMacro, bool useTunnelMacro, bool useGoalCut, ISPSimulationStrategy simulationStrategy, MersenneTwister rng = null)
 {
     this.useNormalizedPosition = useNormalizedPosition;
     this.state = (SokobanGameState)state;
     if (simulationStrategy == null)
     {
         simulationStrategy = new SokobanRandomStrategy();
     }
     if (rng == null)
     {
         rng = new MersenneTwister();
     }
     this.rng                 = rng;
     this.rewardType          = rewardType;
     this.simulationStrategy  = simulationStrategy;
     normalizedPlayerPosition = new Position(state.PlayerX, state.PlayerY);
     availableMoves           = null;
     this.useGoalMacro        = useGoalMacro;
     this.useTunnelMacro      = useTunnelMacro;
     this.useGoalCut          = useGoalCut;
     if (useGoalMacro)
     {
         goalMacroTree = GoalMacroWrapper.BuildMacroTree(this);
         if (goalMacroTree.Roots.Length > 0)
         {
             currentGoalMacroNode = GetInitialMacroNode(goalMacroTree.Roots[0], state.GetGoalMacroHash(goalMacroTree.GoalsInRoom));
             if (currentGoalMacroNode == null)
             {
                 this.useGoalMacro = false;
             }
         }
         else
         {
             this.useGoalMacro = false;
         }
     }
 }
 public SamegameGameState(List <List <int> > levelBoard, MersenneTwister rng, ISPSimulationStrategy sim = null)
 {
     InitState(levelBoard, sim, rng);
 }
Example #6
0
 public AbstractSokobanState(String level, RewardType rewardType, bool useNormalizedPosition, bool useGoalMacro, bool useTunnelMacro, bool useGoalCut, ISPSimulationStrategy simulationStrategy = null, MersenneTwister rng = null)
 {
     Init(new SokobanGameState(level, rewardType, simulationStrategy), rewardType, useNormalizedPosition, useGoalMacro, useTunnelMacro, useGoalCut, simulationStrategy, rng);
 }