Armageddon General Discussion Board

General => Code Discussion => Topic started by: Brytta Léofa on September 22, 2015, 11:20:37 PM

Title: Gietjstieditr patte ftiev, ftiev, wtiev
Post by: Brytta Léofa on September 22, 2015, 11:20:37 PM
It's time for another one of these to be proposed, innit?

Mine preserves rhyme.

#include <string>
#include <fstream>
#include <cstdlib>
#include <iostream>

// A class for garbling speech strings ("in a foreign tongue"),
// while keeping similar or repeated words mostly similar
//   (if "Hello" => "Jweggt", say, then "Hollow" => "Jtggtq")
// but changing the translation over time to prevent abuse.
class garble
{
public:
garble();
std::string garble_string(std::string const & s);
private:
char garble_char(char c);
void update_alphabet();
std::string m_alphabet_vowels;
std::string m_alphabet_consonants;
static const std::string VOWELS;
static const std::string CONSONANTS;
};

const std::string garble::VOWELS = "aeiou";
const std::string garble::CONSONANTS = "bcdfghjklmnpqrstvwxyz";

int main(int argc, char *argv[])
{
if (argc != 2)
return -1;
garble myGarbler;
std::ifstream inputFile(argv[1]);
for (std::string line; std::getline(inputFile, line); )
std::cout << myGarbler.garble_string(line) << std::endl;
return 0;
}


garble::garble()
{
// Initialize alphabets.
for (size_t k = 0; k < VOWELS.size(); ++k)
m_alphabet_vowels.push_back(VOWELS[rand() % VOWELS.size()]);
for (size_t k = 0; k < CONSONANTS.size(); ++k)
m_alphabet_consonants.push_back(CONSONANTS[rand() % CONSONANTS.size()]);
}

char garble::garble_char(char c)
{
char result = c;
if (isspace(c))
update_alphabet();
else if (isalpha(c))
{
bool upper = isupper(c) ? true : false;
c = tolower(c);
// Is it a vowel?
int i = VOWELS.find(c);
if (i != std::string::npos)
result = m_alphabet_vowels[i];
else
{
// Must be a consonant.
i = CONSONANTS.find(c);
result = m_alphabet_consonants[i];
}
if (upper)
result = toupper(result);
}
return result;
}

std::string garble::garble_string(std::string const & s)
{
std::string result;
for (char c : s)
result.push_back(garble_char(c));
update_alphabet();
return result;
}

void garble::update_alphabet()
{
// Modify a few consonant substitutions.
for (int changes = 0; changes < 3; ++changes)
m_alphabet_consonants[rand() % CONSONANTS.size()] = CONSONANTS[rand() % CONSONANTS.size()];
// Sometimes change a vowel.
if (rand() % 7 == 1)
m_alphabet_vowels[rand() % VOWELS.size()] = VOWELS[rand() % VOWELS.size()];
}


The lissome, aureate bardess sings, in an unknown tongue:
   "'Qeuxi mqi rzeyixx balle rkey, nkey, nkey,
    elq sgi gexisq sawwe gexi, gexi, gexi;
    Hehs, O'l tomx satte vgeci, vgeci, vgeci,
    vgeci ej all, sgedi ej ahh.
    Gietjstieditr patte ftiev, ftiev, wtiev,
    etq zgi pezitl yatte fezi, fezi, fezi;
    Nenv, E'p nolg batte lgezi, lsezi, lseyi,
    lseyi eg aff, lleyi eg aff,
    cleyi ez aff, cleji ez aff."
Title: Re: Gietjstieditr patte ftiev, ftiev, wtiev
Post by: James de Monet on September 23, 2015, 12:34:56 AM
I've always wished there was a way to include more language roleplay in the game.  I like the phrases that clans like Kurac use that ostensibly come from another language, but I would like more of it.

More loanwords. More names that mean something in Cavilish or Allundean, or what have you.

Something like this would be a step in the right direction, as you would basically be able to translate things without the use of one speaker and one non-speaker and OOC.

The only hard thing is that loanwords don't readily translate into English, so either a person OOCly knows them, or doesn't.  Never figured out how to play it both ways.
Title: Re: Gietjstieditr patte ftiev, ftiev, wtiev
Post by: Armaddict on September 23, 2015, 12:44:20 AM
This would be great for immersion, making the languages consistent.

However...it would also be close to the bottom on my list.  I -do- like that you presented actual code though.  I'm not sure if Diku Code is in C/C++?  Is it?
Title: Re: Gietjstieditr patte ftiev, ftiev, wtiev
Post by: Brytta Léofa on September 23, 2015, 09:45:36 AM
Quote from: Armaddict on September 23, 2015, 12:44:20 AM
However...it would also be close to the bottom on my list.  I -do- like that you presented actual code though.  I'm not sure if Diku Code is in C/C++?  Is it?

Agreed...I just got excited about the idea and wanted to see how the output would look. (OTOH, it's a fairly small/safe change - no reason to serialize the garbler state per PC.)

Diku's coded in C. I think I remember hearing that Arm is compiled as C++, but I could be wrong.
Title: Re: Gietjstieditr patte ftiev, ftiev, wtiev
Post by: CodeMaster on September 23, 2015, 11:50:23 AM
MUD trivia: I might be confusing it with Circle, but I think whenever one of DikuMUDs clerics or mages would cast a spell, their "incantation" would replace the characters in this fashion (vowels exchanged with vowels, non-vowels exchanged with non-vowels).  So you got funny spells like "pigho" and "poir" (which was heal - I remember that one).
Title: Re: Gietjstieditr patte ftiev, ftiev, wtiev
Post by: Armaddict on September 23, 2015, 04:06:45 PM
Quote from: CodeMaster on September 23, 2015, 11:50:23 AM
MUD trivia: I might be confusing it with Circle, but I think whenever one of DikuMUDs clerics or mages would cast a spell, their "incantation" would replace the characters in this fashion (vowels exchanged with vowels, non-vowels exchanged with non-vowels).  So you got funny spells like "pigho" and "poir" (which was heal - I remember that one).

Pigho was haste!
Title: Re: Gietjstieditr patte ftiev, ftiev, wtiev
Post by: The Silence of the Erdlus on September 23, 2015, 04:09:26 PM
That's just like Al Bhed.
Title: Re: Gietjstieditr patte ftiev, ftiev, wtiev
Post by: Majikal on September 24, 2015, 05:07:33 AM
Thought it was a spambot. Almost flagged for moderation. Didn't.

Carry on.
Title: Re: Gietjstieditr patte ftiev, ftiev, wtiev
Post by: The Silence of the Erdlus on October 06, 2015, 01:27:30 PM
Al Bhed is just a replacement of English consonants and vowels with other consonants and vowels, is what I mean. Its from Final Fantasy.

I would argue against the realism of such a system because there is literally no way such a pair of languages could evolve naturally in the same world.