about summary refs log tree commit diff stats
path: root/data/maps/the_gallery/connections.txtpb
blob: 15189379ee6c8707f6e35227605f26c95cd7ecb7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
connections {
  from_room: "Daedalus Extension"
  to_room: "Main Area"
  door { name: "Gallery Extension" }
}
connections {
  from_room: "Main Area"
  to_room: "Back Room"
  door { name: "Back Door" }
}
connections {
  from_room: "Back Room"
  to_room: "Ending"
  door { name: "Ending Door" }
}
bbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#include "malaprop.h"
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstdio>

bool removeIfM(char c)
{
  return !isalpha(c);
}

char soundID(char l)
{
  switch (l)
  {
    case 'b':
    case 'f':
    case 'p':
    case 'v':
      return '1';
      
    case 'c':
    case 'g':
    case 'j':
    case 'k':
    case 'q':
    case 's':
    case 'x':
    case 'z':
      return '2';
      
    case 'd':
    case 't':
      return '3';
      
    case 'l':
      return '4';
      
    case 'm':
    case 'n':
      return '5';
      
    case 'r':
      return '6';
  }
  
  return l;
}

std::string canonizetwo(std::string f)
{
	std::string canonical(f);
	std::transform(canonical.begin(), canonical.end(), canonical.begin(), ::tolower);
  
  std::string result;
  std::remove_copy_if(canonical.begin(), canonical.end(), std::back_inserter(result), removeIfM);
  
  return result;
}

malaprop::soundex malaprop::soundify(std::string f)
{
	std::string result(canonizetwo(f));
  
  soundex ex;
  ex.prefix = result[0];
  
  std::string output;
  
  for (int i = 1; i<result.length(); i++)
  {
    int c = soundID(result[i]);
    if (
      (isdigit(c)) // Not a vowel
      && (c != soundID(result[i-1])) // Not the same as the previous character
      && ((i < 2) || ((result[i-1] = 'h' || result[i-1] == 'w') && (c != soundID(result[i-2])))) // Not same as before h/w
        )
    {
      output += c;
    }
  }
  
  output.resize(3, '0');
  ex.code = atoi(output.c_str());
	
	return ex;
}

void malaprop::addWord(std::string word)
{
  soundex ex = soundify(word);

  if (ex.prefix != 0)
  {  
    dict[ex].insert(canonizetwo(word));
  }
}

void malaprop::stats()
{
  for (std::map<soundex, std::set<std::string> >::iterator it = dict.begin(); it != dict.end(); it++)
  {
    printf("%c%03d (%d): ", it->first.prefix, it->first.code, it->second.size());
    
    for (std::set<std::string>::iterator jt = it->second.begin(); jt != it->second.end(); jt++)
    {
      std::cout << *jt << ", ";
    }
    
    std::cout << std::endl;
  }
  
  exit(0);
}

std::string malaprop::alternate(std::string word)
{
  soundex ex = soundify(word);
  std::set<std::string>& opts = dict[ex];
  if (opts.size() == 0)
  {
    return word;
  }

  int opt = rand() % opts.size();
  for (std::set<std::string>::iterator it = opts.begin(); it != opts.end(); it++)
  {
    if (opt == 0)
    {
      return *it;
    }
    
    opt--;
  }
  
  return word;
}