Advances in off-the-shelf sensor technology have aided the collection of psychophysiological data in real-time. Utilizing these low-cost sensors, researchers can monitor a person's cognitive, behavioral, and affective states (in real-time) as they interact within virtual environments. Moreover, this psychophysiological data can be used to develop adaptive virtual environments. In this paper, we explore electroencephalography-based algorithms to optimize flow models. These algorithms use various combinations of brain wave channels to develop indices of task engagement (Beta / (Alpha + Theta)), arousal (BetaF3 + BetaF4) / (AlphaF3 + AlphaF4), and valence (AlphaF4 / BetaF4) - (AlphaF3 / BetaF3). Results support accurate determination of when a person has left a state of flow. Moreover, the reported results can be further modeled using machine learning (e.g., Support Vector Machine, Naive Bayes, and K-Nearest Neighbor) to develop training classifiers used in our adaptive virtual environments. We purpose a set of rules for the development of an adaptive virtual environment that can adjust environmental stimuli to keep the user in a state of flow.