static CharT decode_octal (state &state_)
    {
        std::size_t accumulator_ = 0;
        CharT ch_ = *state_._curr;
        unsigned short count_ = 3;
        bool eos_ = false;

        for (;;)
        {
            accumulator_ *= 8;
            accumulator_ += ch_ - '0';
            --count_;
            state_.increment ();
            eos_ = state_.eos ();

            if (!count_ || eos_) break;

            ch_ = *state_._curr;

            // Don't consume invalid chars!
            if (ch_ < '0' || ch_ > '7')
            {
                break;
            }
        }

        return static_cast<CharT> (accumulator_);
    }
Example #2
0
bool process(state* astate, queue<state*>& bfsq)
{
	if(astate->clocks == ten9)
	{
		return print(astate);
	}
	
	for(int i=0; i<9; i++)
	{
		newstate.set(astate);
		newstate.inc(config[i]);
		//cout<<"trying state: "<<newstates[i].getnum()<<", foundsz="<<answers.size()<<endl;

		if(visited.find(newstate.clocks) == visited.end())
		{
			state *ns = new state();
			ns->clocks = newstate.clocks;
			ns->prevop = i+1;
		    ns->prevstate = astate;
			bfsq.push(ns);
			visited[ns->clocks] = true;
			nobj++;
		}
	}
	return true;
}
Example #3
0
void statement::generate_nested(state & state, ostream & stream)
{
    state.increase_indentation();
    state.new_line(stream);
    generate(state, stream);
    state.decrease_indentation();
}
Example #4
0
int main() {
    ifstream in("/home/joshua/Downloads/s4.4.in");
    while(1) {
        done=0;
        int N;
        in>>N;
        if(!N) break;
        for(int i=0;i<32609;i++) MHASH[i].clear();
        _.clear();
        m.clear();
        int X;
        for(int i=0;i<N;i++) {
            place p,v;
            in>>X;
            p.push_back(X);
            _.push_back(p);
            v.push_back(i+1);
            m.push_back(v);
        }
        superhash=hash(m);
        recurse(_,0);
        while(Q.size()) {
            state l=Q.front().first;
            int m=Q.front().second;
            Q.pop_front();
            recurse(l,m);
        }
        bool ok=0;
        for(set<gstate>::iterator it=MHASH[superhash].begin();it!=MHASH[superhash].end();++it) {
            if((*it).first==m) { ok=1; cout<< ((*it).second)<<endl; break; }
        }
        if(!ok) cout<<"IMPOSSIBLE"<<endl;
    }
}
Example #5
0
bool table::need_calculate(const state & state) const
{
	return this->street != state.get_street()
		|| this->get_dealer_pos() != state.get_dealer_pos()
		|| this->get_my_player().get_hand() != state.get_pocket()
		|| this->active_players_count() != state.get_active_players_count();
}
Example #6
0
/// Opens a library
///
/// \param s The Lua state.
/// \param name The name of the module to create.
/// \param members The list of member functions to add to the module.
void lutok::registerLib(state& s, const std::map< std::string, cxx_function >& members){
	assert(s.is_table());

    for (std::map< std::string, cxx_function >::const_iterator
         iter = members.begin(); iter != members.end(); iter++) {
        s.push_string((*iter).first);
        s.push_cxx_function((*iter).second);
        s.set_table(-3);
    }
}
Example #7
0
static typename lutok::LObject<T>::Index lutok::LObject<T>::push(state& s, T* instance, bool gc) {
	if (!instance) {
		s.push_nil();
		return 0;
	}

	luaL_getmetatable(s._pimpl->lua_state, T::s_lunaClassName);
	if (s.is_nil()) {
		luaL_error(s._pimpl->lua_state, "[Luna::%s] Class %s has not been commited!", __func__, T::s_lunaClassName);
		return 0;
	}
	lutok::LObject<T>::Index metatable = s.get_top();

	subtable(s, metatable, "userdata", "v");
	lutok::LObject<T>::Userdata * userdata = allocUserdata(s, metatable, instance);
	if (userdata) {
		userdata->pT = instance;
		s.push_value(metatable);
		s.set_metatable();
		if (!gc) {
			lua_checkstack(s._pimpl->lua_state, 3);
			subtable(s, metatable, "unmanaged", "k");

			s.push_value(-2);
			s.push_boolean(1);
			s.set_table();
			s.pop(1);
		}
	}
	lua_replace(s._pimpl->lua_state, metatable);
	lua_settop(s._pimpl->lua_state, metatable);
	return metatable;
}
Example #8
0
void complex_statement::generate_nested(state & state, ostream & stream)
{
    state.new_line(stream);
    stream << "{";
    state.increase_indentation();
    state.new_line(stream);
    generate(state, stream);
    state.decrease_indentation();
    state.new_line(stream);
    stream << "}";
}
Example #9
0
void input()
{
    G.assign(2 * x, vector<int>()), s.assign(x, ""), t.assign(x, "");

    rep(i, y) {
        int p, q; char P, Q;
        cin >> p >> P >> q >> Q;
        int a = P == 'W' ? p : p + x;
        int b = Q == 'W' ? q : q + x;
        G[a].pb(b), G[b].pb(a);        
    }
Example #10
0
bool simulation::match(const state &left, const state &right)
{
  assert(left.size() == right.size());
  for (size_t i = 0; i < left.size(); i++)
  {
    if (!is_variable(left[i]) && !is_variable(right[i]) && left[i] != right[i])
    {
      return false;
    }
  }
  return true;
}
Example #11
0
/**
 * @brief setter
 * Der aktuelle Zustand wird geaendert. Das Signal stateChanged(newState.getID()) wird ausgeloest.
 * @param newState neuer Zustand 
 * @return void
 */
void automaton::setState(state newState){
    currentState = newState;
    emit stateChanged(newState.getId());

    // Testfunktion
    QMessageBox msgBox;
    msgBox.setText("Die Id des States auf den zu setzen ist, ist: "+ QString::number(newState.getId()));
    msgBox.exec();

    msgBox.setText("Die Id des neuen States ist: "+ QString::number(currentState.getId()));
    msgBox.exec();
}
/**
FUNCTION: overload == operator
DESCRIPTION: Overloads the == operator so that it can be used to test wheather or not 'this' state is equal to otherState.
RETURN bool - True if in fact 'this' state is equal to otherState
*/
bool state::operator== (const state& otherState) const{
	if(otherState.boardMemoryAllocated == false) return false;
	if(this->getBoard()[0][0] != otherState.getBoard()[0][0])return false;
	if(this->getBoard()[0][1] != otherState.getBoard()[0][1])return false;
	if(this->getBoard()[0][2] != otherState.getBoard()[0][2])return false;
	if(this->getBoard()[1][0] != otherState.getBoard()[1][0])return false;
	if(this->getBoard()[1][1] != otherState.getBoard()[1][1])return false;
	if(this->getBoard()[1][2] != otherState.getBoard()[1][2])return false;
	if(this->getBoard()[2][0] != otherState.getBoard()[2][0])return false;
	if(this->getBoard()[2][1] != otherState.getBoard()[2][1])return false;
	if(this->getBoard()[2][2] != otherState.getBoard()[2][2])return false;
	return true;
}
Example #13
0
static int lutok::LObject<T>::gcT(state& s) {
	if (luaL_getmetafield(s._pimpl->lua_state, 1, "unmanaged")) {
		s.push_value(1);
		s.get_table();
		if (!s.is_nil()) {
			return 0;
		}
	}

	Userdata* ud = s.to_userdata<UserData>(1);
	T* obj = ud->pT;
	delete obj;
	return 0;
}
Example #14
0
/// Creates a module: i.e. a table with a set of methods in it.
///
/// \param s The Lua state.
/// \param name The name of the module to create.
/// \param members The list of member functions to add to the module.
void
lutok::create_module(state& s, const std::string& name,
                     const std::map< std::string, cxx_function >& members)
{
    stack_cleaner cleaner(s);
    s.new_table();
    for (std::map< std::string, cxx_function >::const_iterator
         iter = members.begin(); iter != members.end(); iter++) {
        s.push_string((*iter).first);
        s.push_cxx_function((*iter).second);
        s.set_table(-3);
    }
    s.set_global(name);
}
Example #15
0
action2ValuePair min_Value(int clr,int alpha, int beta){
	action2 a2;
	if(terminal_Test()){
		double util=currentState->utility(count);
		int d=currentState->depth;
		action2ValuePair a2v(chance[d]*util,a2);
		return a2v;
	}
	double v=10000;
	vector<colorNode> cn=generateColors(clr);
	vector<action2> actions=chaosActions(cn);
	int l=actions.size();
	for(int i=0;i<l;i++){
		nodecount++;
		action2 a=actions.at(i);
		chaosMove(a);
		double val=max_Value(alpha,beta).value;
		chaosDeMove(a);
		if(v>val){
			v=val;
			a2=a;
		}
		if(v<alpha){
			action2ValuePair a2v(v,a2);
			return a2v;
		}
		if(beta>v){
			beta=v;
		}
	}
	action2ValuePair a2v(v,a2);
	return a2v;
}
Example #16
0
actionValuePair max_Value(double alpha, double beta){
	action a2;
	if(terminal_Test()){
		double util=currentState->utility(count);
		int d=currentState->depth;
		actionValuePair av(chance[d]*util,a2);
		return av;
	}
	double v=-10000;
	vector<action> actions=orderActions();
	int l=actions.size();
	for(int i=0;i<l;i++){
		nodecount++;
		action a=actions.at(i);
		orderMove(a);//depth++
		double val=min_Value(-1,alpha,beta).value;
		orderDeMove(a);//depth--

		if(v<val){
			v=val;
			a2=a;
		}
		if(v>beta){
			actionValuePair av(v,a2);
			return av;
		}
		if(alpha<v){
			alpha=v;
		}
	}
	actionValuePair av(v,a2);
	return av;
}
Example #17
0
int bfs(state init) {
	state u, v;
	queue<state> Q;
	map<state, int> R;
	int f;
	
	init = eraseGoal(init);
	Q.push(init), R[init] = 0;
//	print(init);
	if (init.isComplete())
		return 0;
	
	while (!Q.empty()) {
		u = Q.front(), Q.pop();
		int step = R[u];
		
//		print(u);
//		printf("step %d\n", step);
		for (int i = 0; i < 4; i++) {
			v = rotateMap(u, i, f);
			v = eraseGoal(v);
			if (!f || R.count(v))		continue;
			if (v.isComplete())
				return step + 1;
			R[v] = step + 1;
//			print(v);
			Q.push(v);
		}
//		puts("--------------");
//		getchar();
	}
	return -1;
}
Example #18
0
double GTPWrapper::countBlack(state bboard){
  double ret=0;
  for(unsigned int i=0;i<(bboard.size()/2);i++)
    if(bboard[2*i]==0 && bboard[(2*i)+1]==1)
      ret++;
  return ret;
}
Example #19
0
state next_state(const state &s)
{
    auto state_size = s.size();
    state ret;
    ret.reserve(state_size);

    if (!state_size) {
        throw std::runtime_error("empty state");
    }

    // trivial case
    if (state_size == 1) {
        ret.push_back(false);
        return ret;
    }

    // Left border
    ret.push_back(s[1] != s[state_size - 1]);

    for (std::vector<bool>::size_type i = 1; i < state_size - 1; ++i) {
        ret.push_back(s[i - 1] != s[i + 1]);
    }

    // Right border
    ret.push_back(s[state_size - 2] != s[0]);

    return ret;
}
Example #20
0
int hash(state& s) {
    int l=0;
    for(int i=0;i<s.size();i++) {
        l+=primes[i]*hash(s[i]);
        l%=32609;
    }
    return l;
}
Example #21
0
void PTS::set_frequency_ttls(state& the_state) {

  // find the frequency informations...
  // and exchange the phase informations
  analogout* pts_aout=NULL;
  /* find a analogout section with suitable id */
  state::iterator i=the_state.begin();
  while(i!=the_state.end()) {
    analogout* aout=dynamic_cast<analogout*>(*i);
    if (aout!=NULL && aout->id==id) {
      if (pts_aout==NULL) {
	/* save the informations */
	pts_aout=aout;
      }
      else {
	fprintf(stderr, "found another pts decade section, ignoring\n");
	delete aout;
      }
      /* remove the analog out section */
      the_state.erase(i++);
    }
    else
      ++i;
  } /* state members loop */

  /* now, add the ttl information*/
  if (pts_aout!=NULL) {
    phase_add_ttls(the_state, pts_aout->phase);
    if (pts_aout->frequency!=0) {
      if (frequency==0) {
	set_frequency(pts_aout->frequency);
      }
      /* different frequencies are forbidden */
      else if (frequency!=pts_aout->frequency) {
	fprintf(stderr, "ignoring frequency %g at analogout %d\n",pts_aout->frequency,id);
      }
    }
    delete pts_aout;
  }
  else {
    /* because we use transparent mode, we have to set phase everywhere */
    phase_add_ttls(the_state, phase);
  }

}
Example #22
0
static int lutok::LObject<T>::newT(state& s) {
	lua_remove(s._pimpl->lua_state, 1);

	T* obj = new T(s);
	Userdata* ud = s.new_userdata<Userdata>();
	ud->pT = obj;
	luaL_getmetatable(s._pimpl->lua_state, T::s_lunaClassName);
	s.set_metatable();
	return 1;
}
Example #23
0
double gasinfo::heat_capacity_volume(const state &st) const {
    double Cv = 0;

    for (int i = 0; i < nc; i++) {
        double x = st.rho[i] * Rspecific[i] * beta[i];
        Cv += x;
    }

    return Cv / st.density();
}
Example #24
0
/// Loads and processes a Lua file.
///
/// This is a replacement for luaL_dofile but with proper error reporting
/// and stack control.
///
/// \param s The Lua state.
/// \param file The file to load.
/// \param nresults The number of results to expect; -1 for any.
///
/// \return The number of results left on the stack.
///
/// \throw error If there is a problem processing the file.
unsigned int
lutok::do_file(state& s, const std::string& file, const int nresults)
{
    assert(nresults >= -1);
    const int height = s.get_top();

    stack_cleaner cleaner(s);
    try {
        s.load_file(file);
        s.pcall(0, nresults == -1 ? LUA_MULTRET : nresults, 0);
    } catch (const lutok::api_error& e) {
        throw lutok::error("Failed to load Lua file '" + file + "': " +
                           e.what());
    }
    cleaner.forget();

    const int actual_results = s.get_top() - height;
    assert(nresults == -1 || actual_results == nresults);
    assert(actual_results >= 0);
    return static_cast< unsigned int >(actual_results);
}
	/**
	COPY CONSTRUCTOR:  state(const state& obj)
	DESCRIPTION:  Deep copyes obj to this object
	PARAMS:
	obj - The obj that this object is about to become.
	*/
state::state(const state& obj){
	this->g = obj.g;
	this->parent = obj.parent;
	if(obj.boardMemoryAllocated == true){
		this->board = new int*[NUM_ROWS_ON_BOARD];
		for(int i = 0 ; i < NUM_ROWS_ON_BOARD; i++)
		{
			this->board[i] = new int[NUM_COLS_ON_BOARD];
		}
		this->board[0][0] = obj.getBoard()[0][0];
		this->board[0][1] = obj.getBoard()[0][1];
		this->board[0][2] = obj.getBoard()[0][2];
		this->board[1][0] = obj.getBoard()[1][0];
		this->board[1][1] = obj.getBoard()[1][1];
		this->board[1][2] = obj.getBoard()[1][2];
		this->board[2][0] = obj.getBoard()[2][0];
		this->board[2][1] = obj.getBoard()[2][1];
		this->board[2][2] = obj.getBoard()[2][2];
		this->move = obj.move;
	}
}
Example #26
0
void PTS::phase_add_ttls(state& the_state, double p) const {
  unsigned int binary_code=phase_ttl_values(p);
  std::vector<ttlout>::const_iterator mask=ttl_masks.begin();
  while (mask!=ttl_masks.end()) {
    /* obeye negative logic */
    if ((binary_code & 1<<11)==0 ^ negative_logic==0) the_state.push_back(mask->copy_new());
    binary_code<<=1;
    binary_code&=0xFFF;
    ++mask;
  }
  if (binary_code!=0) fprintf(stderr,"Warning! Insufficient phase precision for %f\n",p);
}
    static CharT decode_control_char (state &state_)
    {
        // Skip over 'c'
        state_.increment ();

        CharT ch_ = 0;
        bool eos_ = state_.next (ch_);

        if (eos_)
        {
            // Pointless returning index if at end of string
            throw runtime_error ("Unexpected end of regex following \\c.");
        }
        else
        {
            if (ch_ >= 'a' && ch_ <= 'z')
            {
                ch_ -= 'a' - 1;
            }
            else if (ch_ >= 'A' && ch_ <= 'Z')
            {
                ch_ -= 'A' - 1;
            }
            else if (ch_ == '@')
            {
                // Apparently...
                ch_ = 0;
            }
            else
            {
                std::ostringstream ss_;

                ss_ << "Invalid control char at index " <<
                    state_.index () - 1 << '.';
                throw runtime_error (ss_.str ().c_str ());
            }
        }

        return ch_;
    }
Example #28
0
/// update state using a rotation speed (in rad/s) and acceleration (in m/s^2)
void update(state & s, double timestep, vector3d const& rotspeed, vector3d const& acc)
{
	double thalf = 0.5*timestep;
	matrix3d const rhalf = rotation_vec_to_matrix(rotspeed*thalf);
	matrix3d const ohalf = s.orientation * rhalf;
	vector3d const racc  = ohalf * acc;
	vector3d const racchp = racc - s.rot_acc_lpf(racc);
	vector3d const shinc = thalf * racchp;
	vector3d const shalf = s.speed + shinc;
	s.location.noalias() += shalf * timestep;
	s.speed.noalias() = shalf + shinc;
	s.orientation.noalias() = ohalf * rhalf;
}
Example #29
0
static void lutok::LObject<T>::weaktable(state& s,  const std::string& mode) {
	s.new_table();
	s.push_value();
	s.set_metatable();

	s.push_literal("__mode");
	s.push_string(mode);
	s.set_table();
}
Example #30
0
/// Opens a library
///
/// \param s The Lua state.
/// \param name The name of the module to create.
/// \param members The list of member functions to add to the module.
void lutok::registerLib(state& s, const std::string& name, const std::map< std::string, cxx_function >& members, const int nup){
	s.findLib(name, members.size(), nup);
	assert(s.is_table());
    for (std::map< std::string, cxx_function >::const_iterator
         iter = members.begin(); iter != members.end(); iter++) {
        s.push_string((*iter).first);
        s.push_cxx_function((*iter).second);
        s.set_table(-3);
    }
	s.pop(nup);
}