Skip to content

Commit 469bc8b

Browse files
authored
Merge pull request #190 from Tiagobuzzz/codex/adicionar-sistemas-de-linguagem-cifrada-e-contra-informação
2 parents 1136c49 + 17ec531 commit 469bc8b

File tree

6 files changed

+218
-0
lines changed

6 files changed

+218
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace UltraWorldAI.Communication;
5+
6+
public class SecretBook
7+
{
8+
public string Title { get; set; } = string.Empty;
9+
public string Culture { get; set; } = string.Empty;
10+
public Dictionary<string, string> Vocabulary { get; set; } = new();
11+
public string EncodedText { get; set; } = string.Empty;
12+
}
13+
14+
public static class CulturalCipherBookSystem
15+
{
16+
public static List<SecretBook> Books { get; } = new();
17+
18+
public static void AddBook(string title, string culture, Dictionary<string, string> vocab, string text)
19+
{
20+
var words = text.Split(' ');
21+
for (var i = 0; i < words.Length; i++)
22+
{
23+
if (vocab.ContainsKey(words[i]))
24+
words[i] = vocab[words[i]];
25+
}
26+
27+
Books.Add(new SecretBook
28+
{
29+
Title = title,
30+
Culture = culture,
31+
Vocabulary = vocab,
32+
EncodedText = string.Join(" ", words)
33+
});
34+
35+
Console.WriteLine($"\uD83D\uDCD6 Livro secreto criado: {title} | Cultura: {culture}");
36+
}
37+
38+
public static string? ReadBook(string title, string culture)
39+
{
40+
var book = Books.Find(b => b.Title == title);
41+
if (book == null) return null;
42+
43+
if (book.Culture != culture)
44+
{
45+
Console.WriteLine($"\u274C {culture} n\u00e3o consegue decifrar o livro '{title}'.");
46+
return null;
47+
}
48+
49+
var decoded = Decode(book.EncodedText, book.Vocabulary);
50+
Console.WriteLine($"\uD83D\uDCDA Conte\u00fado decifrado de '{title}': {decoded}");
51+
return decoded;
52+
}
53+
54+
private static string Decode(string text, Dictionary<string, string> vocab)
55+
{
56+
var reverse = new Dictionary<string, string>();
57+
foreach (var kv in vocab)
58+
reverse[kv.Value] = kv.Key;
59+
60+
var words = text.Split(' ');
61+
for (var i = 0; i < words.Length; i++)
62+
{
63+
if (reverse.ContainsKey(words[i]))
64+
words[i] = reverse[words[i]];
65+
}
66+
67+
return string.Join(" ", words);
68+
}
69+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace UltraWorldAI.Doctrine;
5+
6+
public class DoctrineNarrativeConflict
7+
{
8+
public string Kingdom { get; set; } = string.Empty;
9+
public string OfficialDoctrine { get; set; } = string.Empty;
10+
public string PopularVersion { get; set; } = string.Empty;
11+
public int PopularSupport { get; set; }
12+
public bool RegimeChanged { get; set; }
13+
}
14+
15+
public static class DoctrineNarrativeConflictSystem
16+
{
17+
public static List<DoctrineNarrativeConflict> Conflicts { get; } = new();
18+
19+
public static void AddConflict(string kingdom, string official, string popular, int support)
20+
{
21+
Conflicts.Add(new DoctrineNarrativeConflict
22+
{
23+
Kingdom = kingdom,
24+
OfficialDoctrine = official,
25+
PopularVersion = popular,
26+
PopularSupport = support,
27+
RegimeChanged = false
28+
});
29+
30+
Console.WriteLine($"\uD83D\uDD04 Conflito doutrin\u00e1rio iniciado em {kingdom} (apoio popular: {support}% )");
31+
}
32+
33+
public static void Escalate(string kingdom, int change)
34+
{
35+
var conflict = Conflicts.Find(c => c.Kingdom == kingdom);
36+
if (conflict == null) return;
37+
38+
conflict.PopularSupport += change;
39+
if (conflict.PopularSupport >= 70 && !conflict.RegimeChanged)
40+
{
41+
conflict.RegimeChanged = true;
42+
Console.WriteLine($"\uD83C\uDFDB\uFE0F O reino {kingdom} mudou de regime devido \u00e0 press\u00e3o popular!");
43+
}
44+
}
45+
46+
public static void PrintConflicts()
47+
{
48+
foreach (var c in Conflicts)
49+
{
50+
Console.WriteLine($"\n\uD83D\uDD04 {c.Kingdom} | Doutrina: {c.OfficialDoctrine} | Vers\u00e3o popular: {c.PopularVersion} | Apoio: {c.PopularSupport}% | Mudou? {c.RegimeChanged}");
51+
}
52+
}
53+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace UltraWorldAI.History;
5+
6+
public static class RegionalHistoryBeliefSystem
7+
{
8+
private static readonly Dictionary<Person, string> Birthplaces = new();
9+
private static readonly Dictionary<string, string> OfficialVersions = new();
10+
private static readonly Dictionary<string, Dictionary<string, string>> RegionalVersions = new();
11+
12+
public static void RegisterBirthPlace(Person person, string region)
13+
{
14+
Birthplaces[person] = region;
15+
}
16+
17+
public static void AddEvent(string eventName, string officialVersion)
18+
{
19+
OfficialVersions[eventName] = officialVersion;
20+
}
21+
22+
public static void AddRegionalVersion(string eventName, string region, string version)
23+
{
24+
if (!RegionalVersions.ContainsKey(eventName))
25+
RegionalVersions[eventName] = new();
26+
27+
RegionalVersions[eventName][region] = version;
28+
}
29+
30+
public static string Teach(Person person, string eventName)
31+
{
32+
var region = Birthplaces.TryGetValue(person, out var r) ? r : "unknown";
33+
var version = OfficialVersions.TryGetValue(eventName, out var off) ? off : "desconhecido";
34+
35+
if (RegionalVersions.ContainsKey(eventName) && RegionalVersions[eventName].TryGetValue(region, out var alt))
36+
version = alt;
37+
38+
person.Mind.Memory.AddMemory($"Aprendeu sobre {eventName}: {version}", 0.3f, 0f, new() { "hist\u00f3ria" }, "ensino");
39+
return version;
40+
}
41+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System.Collections.Generic;
2+
using UltraWorldAI.Communication;
3+
using Xunit;
4+
5+
public class CulturalCipherBookSystemTests
6+
{
7+
[Fact]
8+
public void ReadBookReturnsDecodedForCorrectCulture()
9+
{
10+
CulturalCipherBookSystem.Books.Clear();
11+
var vocab = new Dictionary<string, string>
12+
{
13+
["paz"] = "thakar",
14+
["alian\u00e7a"] = "morn"
15+
};
16+
17+
CulturalCipherBookSystem.AddBook("Codex", "Solarianos", vocab, "paz alian\u00e7a");
18+
var decoded = CulturalCipherBookSystem.ReadBook("Codex", "Solarianos");
19+
20+
Assert.Equal("paz alian\u00e7a", decoded);
21+
}
22+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using UltraWorldAI.Doctrine;
2+
using Xunit;
3+
4+
public class DoctrineNarrativeConflictSystemTests
5+
{
6+
[Fact]
7+
public void EscalateChangesRegimeWhenSupportHigh()
8+
{
9+
DoctrineNarrativeConflictSystem.Conflicts.Clear();
10+
DoctrineNarrativeConflictSystem.AddConflict("Reino", "Oficial", "Popular", 60);
11+
DoctrineNarrativeConflictSystem.Escalate("Reino", 15);
12+
13+
Assert.True(DoctrineNarrativeConflictSystem.Conflicts[0].RegimeChanged);
14+
}
15+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using UltraWorldAI;
2+
using UltraWorldAI.History;
3+
using Xunit;
4+
5+
public class RegionalHistoryBeliefSystemTests
6+
{
7+
[Fact]
8+
public void TeachReturnsRegionalVersion()
9+
{
10+
var person = new Person("Historian");
11+
RegionalHistoryBeliefSystem.RegisterBirthPlace(person, "Norte");
12+
RegionalHistoryBeliefSystem.AddEvent("Batalha", "O rei venceu");
13+
RegionalHistoryBeliefSystem.AddRegionalVersion("Batalha", "Norte", "O povo rebelde triunfou");
14+
15+
var result = RegionalHistoryBeliefSystem.Teach(person, "Batalha");
16+
Assert.Equal("O povo rebelde triunfou", result);
17+
}
18+
}

0 commit comments

Comments
 (0)