Exemple #1
0
        public ObservationSpaceViewModel GetSpaceByPosition(ObservationRowViewModel row, int position)
        {
            if (row == null)
            {
                return(null);
            }

            var space = row.ObservationSpaces.Where(p => p.Position == position).FirstOrDefault();

            return(space);
        }
Exemple #2
0
        private int GetAdjacentSpace(
            ObservationRowViewModel row,
            ObservationSpaceViewModel space,
            WallClickedEventArgs e)
        {
            switch (e.WallName.ToLowerInvariant())
            {
            case "left":
                if (row.ObservationSpaces[0].Position == e.Position)
                {
                    return(-1);
                }
                else
                {
                    return(e.Position - 1);
                }

            case "right":
                if (row.ObservationSpaces[row.ObservationSpaces.Count - 1].Position == e.Position)
                {
                    return(-1);
                }
                else
                {
                    return(e.Position + 1);
                }

            case "top":
                if (row.RowIndex == 0)
                {
                    return(-1);
                }
                else
                {
                    return(e.Position - Maze.Columns);
                }

            case "bottom":
                if (row.RowIndex == Maze.Rows - 1)
                {
                    return(-1);
                }
                else
                {
                    return(e.Position + Maze.Columns);
                }

            default:
                return(-1);
            }
        }
Exemple #3
0
        public virtual void InitializeMaze()
        {
            int position = 0;
            ObservableCollection <ObservationRowViewModel> rows = new ObservableCollection <ObservationRowViewModel>();

            if (Maze == null)
            {
                return;
            }

            if (Maze.Rows == 0)
            {
                return;
            }

            for (int i = 0; i < Maze.Rows; i++)
            {
                var row = new ObservationRowViewModel();
                row.RowIndex          = i;
                row.ObservationSpaces = new ObservableCollection <ObservationSpaceViewModel>();

                for (int j = 0; j < Maze.Columns; j++)
                {
                    var observationSpace = new ObservationSpaceViewModel();
                    observationSpace.Position     = position;
                    observationSpace.WallClicked += ObservationSpace_WallClicked;

                    if (Maze.TerminalStates.Contains(position))
                    {
                        observationSpace.IsGoal = true;
                    }

                    if (position == Maze.GetInitialState())
                    {
                        observationSpace.IsStart = true;
                    }

                    var reward = Maze.AdditionalRewards.Where(p => p.State == position).FirstOrDefault();

                    if (reward != null)
                    {
                        observationSpace.Reward = reward.Value;
                    }

                    row.ObservationSpaces.Add(observationSpace);

                    position++;
                }

                rows.Add(row);
            }

            ObservationRows = rows;

            SetObstructions();

            var goalSpace = GetSpaceByPosition(Maze.GoalPosition);

            if (goalSpace != null)
            {
                goalSpace.IsGoal = true;
            }
        }