コード例 #1
0
ファイル: ThoughtFocus.cs プロジェクト: Raud0/Last-Call
 public ThoughtFocus(Thought mainThought, string topic, Topic.Stage myStage, float complexity, HashSet <string> tangents, float finalMultiplier, bool removeThought, bool tangent)
 {
     MainThought     = mainThought;
     Topic           = topic;
     MyStage         = myStage;
     Complexity      = complexity;
     Tangents        = tangents;
     FinalMultiplier = finalMultiplier;
     RemoveThought   = removeThought;
     Tangent         = tangent;
 }
コード例 #2
0
ファイル: AttentionImp.cs プロジェクト: Raud0/Last-Call
    private void ExitTo(Topic topic, Topic.Stage stage)
    {
        topic.MyStage = stage;

        Queue <ThoughtRequest> requests = new Queue <ThoughtRequest>();

        switch (stage)
        {
        case Topic.Stage.Orientation:
            requests.Enqueue(new ThoughtRequest(topic.TopicName, Topic.Stage.Orientation));
            requests.Enqueue(new ThoughtRequest(topic.TopicName, Topic.Stage.Complication));
            break;

        case Topic.Stage.Complication:
            requests.Enqueue(new ThoughtRequest(topic.TopicName, Topic.Stage.Orientation));
            requests.Enqueue(new ThoughtRequest(topic.TopicName, Topic.Stage.Complication));
            requests.Enqueue(new ThoughtRequest(topic.TopicName, Topic.Stage.Climax));
            requests.Enqueue(new ThoughtRequest(topic.TopicName, Topic.Stage.Denouement));
            break;

        case Topic.Stage.Climax:
            requests.Enqueue(new ThoughtRequest(topic.TopicName, Topic.Stage.Complication));
            requests.Enqueue(new ThoughtRequest(topic.TopicName, Topic.Stage.Climax));
            requests.Enqueue(new ThoughtRequest(topic.TopicName, Topic.Stage.Denouement));
            RemoveThoughts(topic, Topic.Stage.Orientation);
            break;

        case Topic.Stage.Denouement:
            requests.Enqueue(new ThoughtRequest(topic.TopicName, Topic.Stage.Complication));
            requests.Enqueue(new ThoughtRequest(topic.TopicName, Topic.Stage.Denouement));
            requests.Enqueue(new ThoughtRequest(topic.TopicName, Topic.Stage.Coda));
            RemoveThoughts(topic, Topic.Stage.Orientation);
            RemoveThoughts(topic, Topic.Stage.Climax);
            break;

        case Topic.Stage.Coda:
            requests.Enqueue(new ThoughtRequest(topic.TopicName, Topic.Stage.Coda));
            RemoveThoughts(topic, Topic.Stage.Complication);
            RemoveThoughts(topic, Topic.Stage.Denouement);
            break;

        case Topic.Stage.Ended:
            RemoveThoughts(topic, Topic.Stage.Coda);
            break;
        }

        while (requests.Count > 0)
        {
            Send(requests.Dequeue());
        }
    }
コード例 #3
0
 public Thought(string topic, Topic.Stage stage, string actor, float complexity, string text,
                Interrupt interruptStrategy, Turn turnStrategy, Affinity myAffinity, HashSet <string> tangents,
                int eventCode, HashSet <Argument> arguments, HashSet <Emotion> emotions)
 {
     Topic             = topic;
     Stage             = stage;
     Actor             = actor;
     Complexity        = complexity;
     Text              = text;
     InterruptStrategy = interruptStrategy;
     TurnStrategy      = turnStrategy;
     MyAffinity        = myAffinity;
     Tangents          = tangents;
     EventCode         = eventCode;
     Arguments         = arguments;
     Emotions          = emotions;
 }
コード例 #4
0
ファイル: AttentionImp.cs プロジェクト: Raud0/Last-Call
    private void RemoveThoughts(Topic topic, Topic.Stage stage)
    {
        Queue <FocusedThought> delete = new Queue <FocusedThought>();

        foreach (FocusedThought thought in thoughts)
        {
            if (topicsByName[thought.Topic].Equals(topic) && thought.Stage.Equals(stage))
            {
                delete.Enqueue(thought);
            }
        }

        while (delete.Count > 0)
        {
            thoughts.Remove(delete.Dequeue());
        }
    }
コード例 #5
0
    private void LoadThought(Thought thought)
    {
        string topic = thought.Topic;

        if (!thoughts.ContainsKey(topic))
        {
            Dictionary <Topic.Stage, HashSet <Thought> > stages = new Dictionary <Topic.Stage, HashSet <Thought> >();
            stages[Topic.Stage.None]         = new HashSet <Thought>();
            stages[Topic.Stage.Hidden]       = new HashSet <Thought>();
            stages[Topic.Stage.Orientation]  = new HashSet <Thought>();
            stages[Topic.Stage.Complication] = new HashSet <Thought>();
            stages[Topic.Stage.Climax]       = new HashSet <Thought>();
            stages[Topic.Stage.Denouement]   = new HashSet <Thought>();
            stages[Topic.Stage.Coda]         = new HashSet <Thought>();
            stages[Topic.Stage.Ended]        = new HashSet <Thought>();
            thoughts[topic] = stages;
        }

        Topic.Stage stage = thought.Stage;
        thoughts[topic][stage].Add(thought);
    }
コード例 #6
0
    public override void Receive(ThoughtRequest thoughtRequest)
    {
        Topic.Stage requestStage = thoughtRequest.MyStage;
        string      topic        = thoughtRequest.Topic;

        if (!thoughts.ContainsKey(topic))
        {
            return;
        }
        if (!thoughts[topic].ContainsKey(requestStage))
        {
            return;
        }
        if (thoughts[topic][requestStage].Count <= 0)
        {
            return;
        }

        ThoughtResponse thoughtResponse = new ThoughtResponse(new HashSet <Thought>(thoughts[topic][requestStage]));

        thoughts[topic][requestStage].Clear();
        Send(thoughtResponse);
    }
コード例 #7
0
    public static Dictionary <string, HashSet <Thought> > LoadThoughts(TextAsset textAsset)
    {
        char[] nextLineChars     = { '\n' };
        char[] nextValueChars    = { '\t' };
        char[] nextSubValueChars = { ';' };

        string text = textAsset.text;

        string[] lines = text.Split(nextLineChars);

        Dictionary <string, HashSet <Thought> > newThoughts = new Dictionary <string, HashSet <Thought> >();
        string topic = null;

        Topic.Stage stage = Topic.Stage.None;
        string      actor = null;

        for (int i = 1; i < lines.Length; i++)
        {
            string   line   = lines[i];
            string[] values = line.Split(nextValueChars, 25);

            try
            {
                // Update running values: Topic, Stage, Actor
                if (!values[0].Equals(""))
                {
                    topic = values[0].Trim();
                }
                string stageText = values[1].Trim().ToLower();
                if (stageMap.ContainsKey(stageText))
                {
                    stage = stageMap[stageText];
                }
                string actorText = values[2].Trim();
                if (!actorText.Equals(""))
                {
                    actor = actorText;
                    if (!newThoughts.ContainsKey(actor))
                    {
                        newThoughts[actor] = new HashSet <Thought>();
                    }
                }

                // Read Complexity
                float complexity = 0f;
                if (!float.TryParse(values[3].Trim(), out complexity))
                {
                    Debug.Log("Failed to read: \"" + line + "\".");
                    continue;
                }

                // Read Text
                string thoughtText = values[4].Trim();
                if (values[4].Equals(""))
                {
                    continue;
                }

                // bruh moment (I get it, but still)
                if (thoughtText.Contains(",") || thoughtText.Contains("\"") &&
                    thoughtText[0] == '\"' &&
                    thoughtText[thoughtText.Length - 1] == '\"')
                {
                    thoughtText = thoughtText.Substring(1, thoughtText.Length - 2);
                }

                while (thoughtText.Contains("\"\""))
                {
                    thoughtText = thoughtText.Replace("\"\"", "\"");
                }

                // Read Social Expectations
                Thought.Interrupt interruptStrategy = Thought.Interrupt.None;
                string            interruptText     = values[5].Trim().ToLower();
                if (interruptMap.ContainsKey(interruptText))
                {
                    interruptStrategy = interruptMap[interruptText];
                }

                Thought.Turn turnStrategy = Thought.Turn.None;
                string       turnText     = values[6].Trim().ToLower();
                if (turnMap.ContainsKey(turnText))
                {
                    turnStrategy = turnMap[turnText];
                }

                Thought.Affinity affinity     = Thought.Affinity.None;
                string           affinityText = values[7].Trim().ToLower();
                if (affinityMap.ContainsKey(affinityText))
                {
                    affinity = affinityMap[affinityText];
                }

                // Read Tangental Topics
                string[]         tangentStrings = values[8].Trim().Split(nextSubValueChars);
                HashSet <string> tangents       = new HashSet <string>();
                foreach (var tangent in tangentStrings)
                {
                    if (!tangent.Equals(""))
                    {
                        tangents.Add(tangent.Trim());
                    }
                }

                // Read Special Event Codes
                int eventCode = -1;
                int.TryParse(values[9].Trim(), out eventCode);

                // Read Emotional Weight Values
                HashSet <Emotion> emotions = new HashSet <Emotion>();
                foreach (KeyValuePair <int, Emotion.Type> pair in emotionIndexMap)
                {
                    int index = pair.Key;
                    if (index > values.Length - 1)
                    {
                        continue;
                    }

                    Emotion.Type type = pair.Value;

                    float strength = 0f;
                    if (float.TryParse(values[index].Trim(), out strength))
                    {
                        Emotion emotion = new Emotion(type, strength);
                        emotions.Add(emotion);
                    }
                }

                // Read Emotional Attack Values
                HashSet <Argument> arguments = new HashSet <Argument>();
                foreach (KeyValuePair <int, Argument.Type> pair in argumentIndexMap)
                {
                    int index = pair.Key;
                    if (index > values.Length - 1)
                    {
                        continue;
                    }

                    Argument.Type type = pair.Value;

                    float strength = 0f;
                    if (float.TryParse(values[index].Trim(), out strength))
                    {
                        Argument argument = new Argument(type, strength);
                        arguments.Add(argument);
                    }
                }

                Thought thought = new Thought(topic, stage, actor, complexity, thoughtText, interruptStrategy, turnStrategy, affinity, tangents, eventCode, arguments, emotions);
                newThoughts[actor].Add(thought);
            } catch (Exception e)
            {
                Debug.Log("Skipped reading: \"" + line + "\" with value count " + values.Length + ". (" + e.Message + ")");
            }
        }

        foreach (KeyValuePair <string, HashSet <Thought> > pair in newThoughts)
        {
            string actorName = pair.Key;
            int    length    = pair.Value.Count;

            Debug.Log("Read in " + length + " thoughts for " + actorName + ".");
        }

        return(newThoughts);
    }
コード例 #8
0
ファイル: AttentionImp.cs プロジェクト: Raud0/Last-Call
    private void FocusThoughts()
    {
        List <FocusedThought> focusedThoughts = new List <FocusedThought>();

        foreach (FocusedThought focusedThought in thoughts)
        {
            Appraise(focusedThought);
            Topic       topic = topicsByName[focusedThought.Topic];
            Topic.Stage stage = focusedThought.Stage;

            bool add = false;

            // TODO: Check for climaxes and ignore other topics?

            switch (topic.MyStage)
            {
            case Topic.Stage.Orientation:
                add = stage.Equals(Topic.Stage.Orientation) ||
                      stage.Equals(Topic.Stage.Complication);
                break;

            case Topic.Stage.Complication:
                add = stage.Equals(Topic.Stage.Orientation) ||
                      stage.Equals(Topic.Stage.Complication) ||
                      stage.Equals(Topic.Stage.Climax) ||
                      stage.Equals(Topic.Stage.Denouement);
                break;

            case Topic.Stage.Climax:
                add = stage.Equals(Topic.Stage.Complication) ||
                      stage.Equals(Topic.Stage.Climax) ||
                      stage.Equals(Topic.Stage.Denouement);
                break;

            case Topic.Stage.Denouement:
                add = stage.Equals(Topic.Stage.Complication) ||
                      stage.Equals(Topic.Stage.Denouement) ||
                      stage.Equals(Topic.Stage.Coda);
                break;

            case Topic.Stage.Coda:
                add = stage.Equals(Topic.Stage.Coda);
                break;
            }

            if (add)
            {
                focusedThoughts.Add(focusedThought);
            }
        }

        if (false)
        {
            ClimaxFilter(focusedThoughts);
        }
        if (true)
        {
            FocusFilter(focusedThoughts, 10f);
        }

        focusedThoughts = focusedThoughts.GetRange(0, Math.Min(focusedThoughts.Count, 10));
        List <RankedThought> rankedThoughts = new List <RankedThought>();

        foreach (FocusedThought focusedThought in focusedThoughts)
        {
            RankedThought rankedThought = new RankedThought(focusedThought);
            rankedThoughts.Add(rankedThought);
        }

        Send(rankedThoughts);
    }
コード例 #9
0
ファイル: ThoughtRequest.cs プロジェクト: Raud0/Last-Call
 public ThoughtRequest(string topic, Topic.Stage stage)
 {
     Topic   = topic;
     MyStage = stage;
 }