using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Dialog
{
class Program
{
static void Main(string[] args)
{
var title = "Powiedziała, powiedział";
var by = "Program.cs";
var dramatis_personae = new[] { "Jan", "Anna", "Marian" };
var dramatis_personae_sex = new[] { "M","F","M" };
var cur_person = 0;
var questions = new[] { "Czy mięso już doszło", "Czy jestem dobrze uczesan[y/a/e]", "Czy twoja matka jest Żydówką", "Czy jesteś głodn[y/a/e]" };
var cur_question = 0;
var answers = new[] { "Nie jestem pew[ien/na/ne]","Nie wiem","Tak","Nie","Być może" };
var cur_answer = 0;
var sentences = new[] { "Jestem głodn[y/a/e]", "Wątpię", "Czuję się świetnie", "Chyba będzie padać" };
var cur_sentence = 0;
var random_events = new[] { "Ktoś zakaszlał","Wszyscy zamilkli","Jakiś pies zaszczekał","Chmury rozpierzchły się","Nikt nic nie powiedział","Wszyscy się uśmiechnęli" };
var cur_event = 0;
var events = new[] { "Słońce wschodziło", "Słońce stało wysoko na niebie", "Było coraz ciemniej", "Słońce zaszło" };
var next_event = 0;
var joints = new[] {" i",", jednak",", mimo że"};
var cur_joint = 0;
var adverbs = new[] { "z miłością", "wściekle", "cicho", "niczym oszalały pies", "z uśmiechem", "otwarcie", "z pewnym zaskoczeniem", "z pasją", "z drwiną" };
var next_adverb = 0;
var last_sentence = dramatis_personae.Select((x,i)=>i).ToDictionary(i=>i,i=>-1);
var pre_last_sentence = dramatis_personae.Select((x, i) => i).ToDictionary(i => i, i => -1);
var last_question = dramatis_personae.Select((x, i) => i).ToDictionary(i => i, i => -1);
var pre_last_question = dramatis_personae.Select((x, i) => i).ToDictionary(i => i, i => -1);
var r = new Random();
Console.WriteLine(title);
Console.WriteLine(by);
var was_question = false;
Console.WriteLine();
while (next_event < events.Length-1)
{
Console.WriteLine(events[next_event]+".");
var len = 10;
do
{
if (r.Next(10) <1 data-blogger-escaped-br=""> {
Console.Write(Next(random_events, ref cur_event, r));
}
else if (was_question)
{
was_question = false;
if (r.Next(2) == 0)
{
var answer = Next(answers, ref cur_answer, r);
var person = Next(dramatis_personae, ref cur_person, r);
var sex = dramatis_personae_sex[cur_person];
var joint = "odparł[/a/o] {0}";
Console.Write("- {0} - {1}", Apply(answer,sex), Apply(joint, sex, person));
if (r.Next(3) == 0)
Console.Write(" " + Next(adverbs, ref next_adverb, r));
}
else
{
continue;
}
}
else if (r.Next(3) == 0)
{
was_question =true;
//question
var question = Next(questions, ref cur_question, r);
var person = Next(dramatis_personae, ref cur_person, r);
var sex = dramatis_personae_sex[cur_person];
var joint = last_question[cur_person] == cur_question ?
pre_last_question[cur_person] == cur_question ?
"powtórzył[/a/o] {0} znów" : Next(r, "powtórzył[/a/o] {0}", "zapytał[/a/o] {0} znów") : "zapytał[/a/o] {0}";
pre_last_question[cur_person] = last_question[cur_person];
last_question[cur_person] = cur_question;
Console.Write("- {0}? - {1}", Apply(question, sex), Apply(joint, sex, person));
if (r.Next(4) == 0)
Console.Write(" " + Next(adverbs, ref next_adverb, r));
}
else
{
var sentence = Next(sentences, ref cur_sentence, r);
var person = Next(dramatis_personae, ref cur_person, r);
var sex = dramatis_personae_sex[cur_person];
var joint = last_sentence[cur_person] == cur_sentence ?
pre_last_sentence[cur_person] == cur_sentence ?
"powtórzył[/a/o] {0} znów" : Next(r, "powtórzył[/a/o] {0}", "powiedział[/a/o] {0} znów") : "powiedział[/a/o] {0}";
pre_last_sentence[cur_person] = last_sentence[cur_person];
last_sentence[cur_person] = cur_sentence;
Console.Write("- {0} - {1}", Apply(sentence,sex), Apply(joint, sex, person));
if (r.Next(4) == 0)
Console.Write(" " + Next(adverbs, ref next_adverb, r));
}
if (r.Next(5) == 0)
{
var n2 = Next(random_events, ref cur_event, r);
var j = Next(joints, ref cur_joint, r);
var s = String.Format("{0} {1}{2}", j, n2.Substring(0, 1).ToLower(), n2.Substring(1));
Console.Write(s);
}
Console.WriteLine(".");
} while (len-->0 && r.Next(9) != 0);
next_event++;
}
Console.WriteLine(events[next_event] + ".");
Console.ReadLine();
}
private static string Apply(string joint, string sex, params string[] args)
{
//"powtórzył[/a/o] {0}";
var ptn = String.Format(joint, args);
var sexvar0 = ptn.IndexOf('[');
var sexvar1 = ptn.IndexOf(']');
if (sexvar0 == -1) return ptn;
var sv = ptn.Substring(sexvar0 + 1, sexvar1 - sexvar0-1).Split('/');
var sexact = sex=="M"?sv[0]:sex=="F"?sv[1]:sv[2];
return ptn.Substring(0, sexvar0) + sexact+ptn.Substring(1+sexvar1);
}
private static string Next(Random r, params string []choice)
{
var cur = 0;
return Next(choice, ref cur, r);
}
private static string Next(string[] choice, ref int cur, Random r)
{
cur = (cur + 1 + r.Next(choice.Length - 1)) % choice.Length;
return choice[cur];
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Dialog
{
class Program
{
static void Main(string[] args)
{
var title = "Powiedziała, powiedział";
var by = "Program.cs";
var dramatis_personae = new[] { "Jan", "Anna", "Marian" };
var dramatis_personae_sex = new[] { "M","F","M" };
var cur_person = 0;
var questions = new[] { "Czy mięso już doszło", "Czy jestem dobrze uczesan[y/a/e]", "Czy twoja matka jest Żydówką", "Czy jesteś głodn[y/a/e]" };
var cur_question = 0;
var answers = new[] { "Nie jestem pew[ien/na/ne]","Nie wiem","Tak","Nie","Być może" };
var cur_answer = 0;
var sentences = new[] { "Jestem głodn[y/a/e]", "Wątpię", "Czuję się świetnie", "Chyba będzie padać" };
var cur_sentence = 0;
var random_events = new[] { "Ktoś zakaszlał","Wszyscy zamilkli","Jakiś pies zaszczekał","Chmury rozpierzchły się","Nikt nic nie powiedział","Wszyscy się uśmiechnęli" };
var cur_event = 0;
var events = new[] { "Słońce wschodziło", "Słońce stało wysoko na niebie", "Było coraz ciemniej", "Słońce zaszło" };
var next_event = 0;
var joints = new[] {" i",", jednak",", mimo że"};
var cur_joint = 0;
var adverbs = new[] { "z miłością", "wściekle", "cicho", "niczym oszalały pies", "z uśmiechem", "otwarcie", "z pewnym zaskoczeniem", "z pasją", "z drwiną" };
var next_adverb = 0;
var last_sentence = dramatis_personae.Select((x,i)=>i).ToDictionary(i=>i,i=>-1);
var pre_last_sentence = dramatis_personae.Select((x, i) => i).ToDictionary(i => i, i => -1);
var last_question = dramatis_personae.Select((x, i) => i).ToDictionary(i => i, i => -1);
var pre_last_question = dramatis_personae.Select((x, i) => i).ToDictionary(i => i, i => -1);
var r = new Random();
Console.WriteLine(title);
Console.WriteLine(by);
var was_question = false;
Console.WriteLine();
while (next_event < events.Length-1)
{
Console.WriteLine(events[next_event]+".");
var len = 10;
do
{
if (r.Next(10) <1 data-blogger-escaped-br=""> {
Console.Write(Next(random_events, ref cur_event, r));
}
else if (was_question)
{
was_question = false;
if (r.Next(2) == 0)
{
var answer = Next(answers, ref cur_answer, r);
var person = Next(dramatis_personae, ref cur_person, r);
var sex = dramatis_personae_sex[cur_person];
var joint = "odparł[/a/o] {0}";
Console.Write("- {0} - {1}", Apply(answer,sex), Apply(joint, sex, person));
if (r.Next(3) == 0)
Console.Write(" " + Next(adverbs, ref next_adverb, r));
}
else
{
continue;
}
}
else if (r.Next(3) == 0)
{
was_question =true;
//question
var question = Next(questions, ref cur_question, r);
var person = Next(dramatis_personae, ref cur_person, r);
var sex = dramatis_personae_sex[cur_person];
var joint = last_question[cur_person] == cur_question ?
pre_last_question[cur_person] == cur_question ?
"powtórzył[/a/o] {0} znów" : Next(r, "powtórzył[/a/o] {0}", "zapytał[/a/o] {0} znów") : "zapytał[/a/o] {0}";
pre_last_question[cur_person] = last_question[cur_person];
last_question[cur_person] = cur_question;
Console.Write("- {0}? - {1}", Apply(question, sex), Apply(joint, sex, person));
if (r.Next(4) == 0)
Console.Write(" " + Next(adverbs, ref next_adverb, r));
}
else
{
var sentence = Next(sentences, ref cur_sentence, r);
var person = Next(dramatis_personae, ref cur_person, r);
var sex = dramatis_personae_sex[cur_person];
var joint = last_sentence[cur_person] == cur_sentence ?
pre_last_sentence[cur_person] == cur_sentence ?
"powtórzył[/a/o] {0} znów" : Next(r, "powtórzył[/a/o] {0}", "powiedział[/a/o] {0} znów") : "powiedział[/a/o] {0}";
pre_last_sentence[cur_person] = last_sentence[cur_person];
last_sentence[cur_person] = cur_sentence;
Console.Write("- {0} - {1}", Apply(sentence,sex), Apply(joint, sex, person));
if (r.Next(4) == 0)
Console.Write(" " + Next(adverbs, ref next_adverb, r));
}
if (r.Next(5) == 0)
{
var n2 = Next(random_events, ref cur_event, r);
var j = Next(joints, ref cur_joint, r);
var s = String.Format("{0} {1}{2}", j, n2.Substring(0, 1).ToLower(), n2.Substring(1));
Console.Write(s);
}
Console.WriteLine(".");
} while (len-->0 && r.Next(9) != 0);
next_event++;
}
Console.WriteLine(events[next_event] + ".");
Console.ReadLine();
}
private static string Apply(string joint, string sex, params string[] args)
{
//"powtórzył[/a/o] {0}";
var ptn = String.Format(joint, args);
var sexvar0 = ptn.IndexOf('[');
var sexvar1 = ptn.IndexOf(']');
if (sexvar0 == -1) return ptn;
var sv = ptn.Substring(sexvar0 + 1, sexvar1 - sexvar0-1).Split('/');
var sexact = sex=="M"?sv[0]:sex=="F"?sv[1]:sv[2];
return ptn.Substring(0, sexvar0) + sexact+ptn.Substring(1+sexvar1);
}
private static string Next(Random r, params string []choice)
{
var cur = 0;
return Next(choice, ref cur, r);
}
private static string Next(string[] choice, ref int cur, Random r)
{
cur = (cur + 1 + r.Next(choice.Length - 1)) % choice.Length;
return choice[cur];
}
}
}
Brak komentarzy:
Prześlij komentarz