Exemplo n.º 1
0
bool F12Protocol::isSingleShot(
  const CommandSequence &bits)
{
  // We're expecting "firstcode" to contain exactly 8 bits here.  Probably
  // should throw an exception if not!
  CommandSequence::const_reverse_iterator i = bits.rbegin();
  if (i == bits.rend())
  {
    // Throw exception here?
    return false;
  }

  if (*i)
  {
    // This is a single-shot command.
    return true;
  }

  ++i;

  if (i == bits.rend())
  {
    // Throw exception here?
    return false;
  }

  if (*i)
  {
    // This is a single-shot command.
    return true;
  }

  // At this point, it could only be a repeatable command.
  return false;
}
Exemplo n.º 2
0
Command* CommandSkill::createBullet(SkillResult* result)
{
	CommandParallel* cmds = CommandParallel::create();
	for (int i = 0; i < result->numRecipients; i++)
	{
		CommandSequence * seq = CommandSequence::create();
		CommandSkill* skill = new CommandSkill();
		skill->addEffect(BulletEffect::create(result->skill.effect, result->giver, result->recipients[i]));
		seq->push(skill, false);
		CommandHit* hit = CommandHit::create(result->recipients[i]);
		seq->push(hit, false);
		Actor* victim = Engine::world->getActor(result->recipients[i]);
		if (result->value[i] != 0)
		{
			CommandProgress* progress = CommandProgress::create(result->value[i], victim);
			seq->push(progress, false);
		}
		
		if (result->healthLeft[i] <= 0)
		{
			CommandDie* die = CommandDie::create(victim);
			seq->push(die, false);
		}
		cmds->addCommand(seq);
		
	}
	return cmds;
}
Exemplo n.º 3
0
bool F12Protocol::isSingleShot(
  const CommandSequence &bits)
{
  CommandSequence::const_reverse_iterator i = bits.rbegin();
  if (i == bits.rend())
  {
    // Throw exception here?
    return false;
  }

  if (*i)
  {
    // This is a single-shot command.
    return true;
  }

  ++i;

  if (i == bits.rend())
  {
    // Throw exception here?
    return false;
  }

  if (*i)
  {
    // This is a single-shot command.
    return true;
  }

  // At this point, it could only be a repeatable command.
  return false;
}
Exemplo n.º 4
0
  static Seq<CommandSequence> shrinkIndividual(const CommandSequence &s) {
    return seq::mapcat(
        seq::range(s.numFixed, s.entries.size()),
        [=](std::size_t i) {
          const auto &preState = s.stateAt(i);
          auto valid =
              seq::filter(s.entries[i].shrinkable.shrinks(),
                          [=](const Shrinkable<CmdSP> &s) {
                            return isValidCommand(*s.value(), preState);
                          });

          return seq::map(std::move(valid),
                          [=](Shrinkable<CmdSP> &&cmd) {
                            auto shrunk = s;
                            auto &entry = shrunk.entries[i];

                            entry.shrinkable = std::move(cmd);
                            entry.postState = shrunk.stateAt(i);
                            entry.shrinkable.value()->apply(entry.postState);
                            shrunk.regenerateEntriesFrom(i + 1);

                            shrunk.numFixed = i;
                            return shrunk;
                          });
        });
  }
Exemplo n.º 5
0
CAssemblerCommand* parseDirectivePool(Parser& parser, int flags)
{
    CommandSequence* seq = new CommandSequence();
    seq->addCommand(new CDirectiveAlignFill(4,CDirectiveAlignFill::Align));
    seq->addCommand(new ArmPoolCommand());

    return seq;
}
Exemplo n.º 6
0
Command* CommandBuff::create(BuffResult* result)
{
	CommandSequence * seq = CommandSequence::create();
	//to do implement command buff
	Actor* owner = Engine::world->getActor(result->owner);
	CommandProgress* progress = CommandProgress::create(result->value, owner);
	seq->push(progress, false);
	return seq;
}
Exemplo n.º 7
0
unsigned int XMPProtocol::calculateChecksumTwo(
  unsigned int toggle,
  const CommandSequence &firstCode,
  const CommandSequence &secondCode)
{
  // Start with the value 0xF:
  unsigned int total = 0xF;

  // Add the other half-bytes in the second part of the frame:
  total += subDeviceOne;
  total += toggle;
  total += subDeviceTwo;

  unsigned int codeValue = 0;
  CommandSequence::const_iterator i = firstCode.begin();

  while (i != firstCode.end())
  {
    // Shift codeValue over and add the bit:
    codeValue = codeValue << 1;
    codeValue += *i;
    ++i;
  }

  total += codeValue >> 4;
  total += codeValue & 0xF;

  codeValue = 0;
  i = secondCode.begin();

  while (i != secondCode.end())
  {
    codeValue = codeValue << 1;
    codeValue += *i;
    ++i;
  }

  total += codeValue >> 4;
  total += codeValue & 0xF;

  // Next, invert:
  total = -total;

  // Finally, mod 0x10:
  total = total % 0x10;

  return total;
}
Exemplo n.º 8
0
CAssemblerCommand* Parser::parseCommandSequence(wchar_t indicator, std::initializer_list<wchar_t*> terminators)
{
	CommandSequence* sequence = new CommandSequence();

	while (atEnd() == false)
	{
		const Token &next = peekToken();
		if (next.stringValueStartsWith(indicator) && isPartOfList(next.getStringValue(), terminators))
			break;

		CAssemblerCommand* cmd = parseCommand();
		sequence->addCommand(cmd);
	}

	return sequence;
}
Exemplo n.º 9
0
int XMPProtocol::pushBits(
  const CommandSequence &bits,
  PIRInfraredLED &led)
{
  unsigned int duration = 0;

  // We can only sent 4-bit values in XMP, so need to collect bits up into
  // bundles of 4:

  unsigned int bitsValue = 0;
  int count = 0;
  CommandSequence::const_iterator i = bits.begin();

  while (i != bits.end())
  {
    if (count < 4)
    {
      bitsValue = bitsValue << 1;
      bitsValue += *i;
      ++count;
    }
    else
    {
      led.addPair(210, 760 + (136 * bitsValue));
      duration += 970 + (136 * bitsValue);

      count = 1;
      bitsValue = *i;
    }

    ++i;
  }

  if (count == 4)
  {
    led.addPair(210, 760 + (136 * bitsValue));
    duration += 970 + (136 * bitsValue);
  }

  return duration;
}
Exemplo n.º 10
0
Command* CommandSkill::createArc(SkillResult* result)
{
	CommandParallel * cmds = CommandParallel::create();
	for (int i = 0; i < result->numRecipients; i++)
	{
		CommandSequence* seq = CommandSequence::create();
		CommandSkill* skill = new CommandSkill();
		skill->addEffect(ArcEffect::create(result->skill.effect, result->giver, result->recipients[i]));
		seq->push(skill, false);
		CommandHeal* heal = CommandHeal::create(result->recipients[i]);
		seq->push(heal, false);
		if (result->value != 0)
		{
			Actor* victim = Engine::world->getActor(result->recipients[i]);
			CommandProgress* progress = CommandProgress::create(result->value[i], victim);
			seq->push(progress,false);
		}
		cmds->addCommand(seq);
	}
	return cmds;
}
Exemplo n.º 11
0
Command* CommandSkill::createHack(SkillResult* result)
{
	CommandSequence *seq = CommandSequence::create();
	CommandSkill* skill = new CommandSkill();
	skill->addEffect(HackEffect::create(result->skill.effect, result->giver, result->recipients[0]));
	seq->push(skill, false);
	CommandHit* hit = CommandHit::create(result->recipients[0]);
	seq->push(hit, false);
	Actor* victim = Engine::world->getActor(result->recipients[0]);
	if (result->value != 0)
	{
		CommandProgress* progress = CommandProgress::create(result->value[0], victim);
		seq->push(progress, false);
	}
	
	if (result->healthLeft[0] <= 0)
	{
		CommandDie* die = CommandDie::create(victim);
		seq->push(die, false);
	}
	
	return seq;
}
Exemplo n.º 12
0
void PanasonicProtocol::generateChecksum(
  const CommandSequence &device,
  const CommandSequence &subdevice,
  const CommandSequence &command,
  CommandSequence &checksum)
{
  checksum.clear(); // probably unnecessary sanity check.

  CommandSequence::const_iterator diter = device.begin();
  CommandSequence::const_iterator siter = subdevice.begin();
  CommandSequence::const_iterator citer = command.begin();

  while (diter !=device.end()
      && siter != subdevice.end()
      && citer != command.end())
  {
    checksum.push_back(*diter ^ *siter ^ *citer);
    ++diter;
    ++siter;
    ++citer;
  }
}
Exemplo n.º 13
0
Command* CommandSkill::createFixed(SkillResult* result)
{
	CommandParallel* cmds = CommandParallel::create();

	CommandSkill* skill = new CommandSkill();
	
	Actor* attacker = Engine::world->getActor(result->giver);

	for (int i = 0; i < result->skill.range2.numGSets; i++)
	{
		ID cid = result->skill.range2.gSets[i];
		GSet path;
		Config::skill->fill(&path, cid);
		FrisbeeEffect* fEffect = FrisbeeEffect::create(result->skill.effect, attacker->position());
		bool flag = false;
		CommandSequence* seq = NULL;
		float interval = 0;
		
		for (int j = 0; j < path.numElements; j++)
		{
			char ox = path.elements[j].x; 
			char oy = path.elements[j].y;
			
			bool needbreak = false;
			interval += .1f;
			Actor* actor = Engine::world->getActor(ccp(ox * GRID_SIZE + attacker->position()->x, oy * GRID_SIZE + attacker->position()->y));
			for (int k = 0; k < result->numRecipients; k++)
			{
				if (actor != NULL && result->recipients[k] == actor->iid() && result->set[k] == i)
				{
					flag = true;
					if (actor->isBarrier())
					{
						seq = CommandSequence::create();
						CommandWait* wait = CommandWait::create(interval);
						CommandHit* hit = CommandHit::create(actor->iid());
						seq->push(wait, false);
						seq->push(hit, false);
						fEffect->addNode(ox, oy);
						needbreak = true;
					}
					else
					{
						seq = CommandSequence::create();
						CommandWait* wait = CommandWait::create(interval);
						CommandHit* hit = CommandHit::create(actor->iid());
						seq->push(wait, false);
						seq->push(hit, false);
						CommandProgress* progress = CommandProgress::create(result->value[k], actor);
						seq->push(progress, false);
					}

					if (result->healthLeft[k] <= 0)
					{
						CommandDie* die = CommandDie::create(actor);
						seq->push(die, false);
					}

					cmds->addCommand(seq);
				}
			}
			if (attacker->getData()->positon.x + ox > NUM_GRIDS_ROW) needbreak = true;
			if (attacker->getData()->positon.x + ox < 0) needbreak = true;
			if (needbreak) break;
			fEffect->addNode(ox, oy);
		}
		skill->addEffect(fEffect);
	}
	cmds->addCommand(skill);
	return cmds;
}
Exemplo n.º 14
0
int main(int argc, char* argv[])
{

  try {

    // Get the filename
    string input;
    if(argc > 1){
      input = string(argv[1]);
    } else {
      input = "<stdin>";
    }

    // Create the expression manager
    Options options;
    options.setInputLanguage(language::input::LANG_SMTLIB_V2);
    cout << language::SetLanguage(language::output::LANG_SMTLIB_V2);
    // cout << Expr::dag(0);
    std::unique_ptr<api::Solver> solver =
        std::unique_ptr<api::Solver>(new api::Solver(&options));

    Mapper m(solver->getExprManager());

    // Create the parser
    ParserBuilder parserBuilder(solver.get(), input, options);
    if(input == "<stdin>") parserBuilder.withStreamInput(cin);
    Parser* parser = parserBuilder.build();

    // Variables and assertions
    vector<string> variables;
    vector<string> info_tags;
    vector<string> info_data;
    vector<Expr> assertions;

    Command* cmd = NULL;
    CommandSequence commandsSequence;
    bool logicisset = false;

    while ((cmd = parser->nextCommand())) {

      // till logic is set, don't do any modifications
      if(!parser->logicIsSet()) {
        cout << (*cmd) << endl;
        delete cmd;
        continue;
      }

      // transform set-logic command, if there is one
      SetBenchmarkLogicCommand* setlogic = dynamic_cast<SetBenchmarkLogicCommand*>(cmd);
      if(setlogic) {
	LogicInfo logicinfo(setlogic->getLogic());
	if(!logicinfo.isTheoryEnabled(theory::THEORY_SETS)) {
	  cerr << "Sets theory not enabled. Stopping translation." << endl;
	  return 0;
	}
        logicinfo = logicinfo.getUnlockedCopy();
        if(enableAxioms) {
          logicinfo.enableQuantifiers();
          logicinfo.lock();
          if(!logicinfo.hasEverything()) {
            (logicinfo = logicinfo.getUnlockedCopy()).disableTheory(theory::THEORY_SETS);
            logicinfo.lock();
            cout << SetBenchmarkLogicCommand(logicinfo.getLogicString()) << endl;
          }
        } else {
          logicinfo.enableTheory(theory::THEORY_ARRAYS);
          // we print logic string only for Quantifiers, for Z3 stuff
          // we don't set the logic
        }

        delete cmd;
        continue;
      }

      // if we reach here, logic is set by now, so can define our sort
      if( !logicisset ) {
        logicisset = true;
        m.defineSetSort();
      }

      // declare/define-sort commands are printed immediately
      DeclareTypeCommand* declaresort = dynamic_cast<DeclareTypeCommand*>(cmd);
      DefineTypeCommand* definesort = dynamic_cast<DefineTypeCommand*>(cmd);
      if(declaresort || definesort) {
        cout << *cmd << endl;
        delete cmd;
        continue;
      }

      // other commands are queued up, while replacing with new function symbols
      AssertCommand* assert = dynamic_cast<AssertCommand*>(cmd);
      DeclareFunctionCommand* declarefun = dynamic_cast<DeclareFunctionCommand*>(cmd);
      DefineFunctionCommand* definefun = dynamic_cast<DefineFunctionCommand*>(cmd);

      Command* new_cmd = NULL;
      if(assert) {
        Expr newexpr = m.collectSortsExpr(assert->getExpr());
        new_cmd = new AssertCommand(newexpr);
      } else if(declarefun) {
        Expr newfunc = m.collectSortsExpr(declarefun->getFunction());
        new_cmd = new DeclareFunctionCommand(declarefun->getSymbol(), newfunc, declarefun->getType());
      } else if(definefun) {
        Expr newfunc = m.collectSortsExpr(definefun->getFunction());
        Expr newformula = m.collectSortsExpr(definefun->getFormula());
        new_cmd = new DefineFunctionCommand(definefun->getSymbol(), newfunc, definefun->getFormals(), newformula);
      }

      if(new_cmd == NULL) {
        commandsSequence.addCommand(cmd);
      } else {
        commandsSequence.addCommand(new_cmd);
        delete cmd;
      }

    }

    m.dump();
    cout << commandsSequence;
    
  
    // Get rid of the parser
    //delete parser;
  } catch (Exception& e) {
    cerr << e << endl;
  }
}