Example #1
0
 public void OnEditCurrentButtonPressed()
 {
     // Commit what's currently on screen to the editor layout, and then edit that.
     m_editLayout    = m_visibleLayout.Duplicate();
     m_layoutChanged = true;
     SwitchMode(EditorMode.Edit);
 }     // OnEditCurrentButtonPressed
Example #2
0
	public void StartSolving( MapLayout _initialLayout, Scorer _scorer )
	{
		StopSolving();

		m_initialLayout = _initialLayout.Duplicate();
		m_initialLayout.FloodFillAreas();
		m_scorer = _scorer;
		m_numIterations = 0;
		m_bestSolution = new Solution(){
			EmptySpaces = m_initialLayout.NumEmptySpaces,
			Score = 0,
			GameScore = 0,
		};
		m_scorer.ScoreLayout( m_initialLayout, out m_bestSolution.Score, out m_bestSolution.GameScore );

		m_solveCo = StartCoroutine( RunSolve_MonteCarlo() );
	} // Start
Example #3
0
	} // RunSolve_MonteCarlo

	private Solution TryRandomSolution()
	{
		Solution solution = new Solution();
		MapLayout layout = m_initialLayout.Duplicate();
		while ( layout.NumAreas > 0 )
		{
			int areaToRemove = Random.Range( 0, layout.NumAreas );
			layout.RemoveArea( areaToRemove );
			solution.AreaIDs.Add( areaToRemove );
		}

		// Score the solution somehow:
		solution.FinalLayout = layout;
		solution.EmptySpaces = layout.NumEmptySpaces;
		m_scorer.ScoreLayout( layout, out solution.Score, out solution.GameScore );

		return solution;
	} // TryRandomSolution
Example #4
0
    }     // Playback_ClearTileUnderCursor

    private void SwitchMode(EditorMode _newMode)
    {
        if (_newMode == m_editorMode)
        {
            return;
        }

        switch (m_editorMode)
        {
        case EditorMode.Edit:
        {
            // If any edits were made to the map then this invalidates our play history.
            if (m_layoutChanged)
            {
                m_playbackLayouts.Clear();
                m_playbackLayouts.Add(m_editLayout.Duplicate());
            }

            // Enable UI:
            m_editButton.interactable        = true;
            m_editCurrentButton.interactable = true;
            break;
        }

        case EditorMode.Solve:
        {
            m_cursor.gameObject.SetActive(true);
            m_solver.StopSolving();
            UpdateProgressText();

            // Update the playback mode history with what we've generated so far.
            m_playbackLayouts = m_solver.SolutionLayouts;

            // Enable UI:
            m_editCurrentButton.interactable = true;
            m_solveButton.interactable       = true;

            break;
        }

        case EditorMode.Playback:
        {
            m_playbackButton.interactable = true;
            break;
        }
        }

        m_editorMode = _newMode;

        switch (m_editorMode)
        {
        case EditorMode.Edit:
        {
            UpdateMapVisuals(m_editLayout, false);
            UpdateProgressText();
            m_editButton.interactable        = false;
            m_editCurrentButton.interactable = false;
            break;
        }

        case EditorMode.Solve:
        {
            m_cursor.gameObject.SetActive(false);
            if (m_layoutChanged)
            {
                m_layoutChanged = false;
                m_solver.StartSolving(m_editLayout, m_scorer);
            }
            else
            {
                m_solver.ResumeSolving();
            }
            m_editCurrentButton.interactable = false;
            m_solveButton.interactable       = false;
            break;
        }

        case EditorMode.Playback:
        {
            m_playbackIndex = 0;
            UpdatePlaybackText();
            UpdateMapVisuals(m_playbackLayouts[m_playbackIndex], false);
            m_playbackButton.interactable = false;
            break;
        }
        }
    }     // SwitchMode