/// <summary>
        /// Parse entire stream and return root motif
        /// </summary>
        public Dictionary <string, Motif> ParseFile()
        {
            // Parse motifs into a dictionary
            var   motifs = new Dictionary <string, Motif>();
            Motif root   = null;

            while (true)
            {
                this.parseSpace(); // Skip meaningless spaces and linebreaks
                if (EndOfStream)
                {
                    break;
                }
                char c = this.peek();

                switch (c)
                {
                case '#':
                    this.parseComment();
                    break;

                default:
                    Motif motif = this.parseMotif();
                    if (root == null)
                    {
                        root = motif;
                    }
                    motifs.Add(motif.Name, motif);
                    break;
                }
            }

            // Set successors right for all motifs
            foreach (Motif motif in motifs.Values)
            {
                motif.Successors = motif.successorNames.Select(key => motifs[key]).ToArray();
            }

            //dump(motifs.Values);
            //foreach (Motif motif in motifs.Values) {
            //    Console.WriteLine(motif.ToString());
            //}

            return(motifs);
        }
Esempio n. 2
0
        void scheduleNextMotif()
        {
            if (this.currentMotif == null)
            {
                this.currentMotif = this.composition.Motifs["light1a"];
            }
            else
            {
                if (this.Parameters.GameOverState == GameState.GameOverState.Won)
                {
                    var win = this.currentMotif.Successors.Where(o => o.Name.Contains("win")).ToList();
                    if (win.Count() != 0)
                    {
                        this.currentMotif = win[0];
                        goto Rendering;
                    }
                }
                else if (this.Parameters.GameOverState == GameState.GameOverState.Lost)
                {
                    var lose = this.currentMotif.Successors.Where(o => o.Name.Contains("lose")).ToList();
                    if (lose.Count() != 0)
                    {
                        this.currentMotif = lose[0];
                        goto Rendering;
                    }
                }

                string tag         = this.Parameters.Lightness > .5 ? "light" : "dark";
                var    choiceSpace = this.currentMotif.Successors.Where(o => o.Name.Contains(tag));
                if (choiceSpace.Count() == 0)
                {
                    choiceSpace = this.currentMotif.Successors;
                }
                this.currentMotif = choiceSpace.RandomElement();
            }
Rendering:
            RenderParameters parameters = new RenderParameters(this.Parameters, this.Piano);

            this.Schedule(this.currentMotif.Render(parameters));
        }