示例#1
0
文件: roff.c 项目: ysei/h-compiler
int suck()		// OK
{
    while(1) {
        c = cachec;
        cachec=0;	/* Get the cached char first */
        if (c=='\0') c = getchar();
        if (islegal(c)) return(c);
    }
}
示例#2
0
static long
floppyread(Chan *c, void *a, long n, vlong off)
{
	FDrive *dp;
	long rv;
	int sec, head, cyl;
	long len;
	uchar *aa;
	ulong offset = off;

	if(c->qid.type & QTDIR)
		return devdirread(c, a, n, floppydir, 1+fl.ndrive*NFDIR, devgen);

	rv = 0;
	dp = &fl.d[c->qid.path & ~Qmask];
	switch ((int)(c->qid.path & Qmask)) {
	case Qdata:
		islegal(offset, n, dp);
		aa = a;

		qlock(&fl);
		if(waserror()){
			qunlock(&fl);
			nexterror();
		}
		floppyon(dp);
		changed(c, dp);
		for(rv = 0; rv < n; rv += len){
			/*
			 *  all xfers come out of the track cache
			 */
			dp->len = n - rv;
			floppypos(dp, offset+rv);
			cyl = dp->tcyl;
			head = dp->thead;
			len = dp->len;
			sec = dp->tsec;
			if(readtrack(dp, cyl, head) < 0)
				break;
			memmove(aa+rv, dp->cache + (sec-1)*dp->t->bytes, len);
		}
		qunlock(&fl);
		poperror();

		break;
	case Qctl:
		return readstr(offset, a, n, dp->t->name);
	default:
		panic("floppyread: bad qid");
	}

	return rv;
}
示例#3
0
文件: 2311.c 项目: Crmiv/AlgoSolution
int main()
{
	int i,j,k,x,y,z,t,mind;
	int p,head,tail;

	while(scanf("%*s%d ",&n)!=EOF){
		for(k=0;k<n;k++)
			for(j=0;j<n;j++){
				for(i=0;i<n;i++)
					mp[i][j][k]=getchar();
				getchar();
			}
		scanf("%d%d%d",&q[0][0],&q[0][1],&q[0][2]);
		scanf("%d%d%d",&i,&j,&k);
		mp[i][j][k]='E';
		scanf("%*s");
		p=0;mind=0;tail=1;
		while(p<tail){
			head=tail;
			while(p<head){
				if(mp[i=q[p][0]][j=q[p][1]][k=q[p][2]]=='E') break;
				for(t=0;t<6;t++){
					if(islegal(x=i+d[t][0],y=j+d[t][1],z=k+d[t][2])){
						if(mp[x][y][z]=='E'){mind++;break;}
						mp[x][y][z]='X';
						q[tail][0]=x;
						q[tail][1]=y;
						q[tail][2]=z;
						tail++;
					}
				}
				if(t<6) break;
				p++;
			}
			if(p<head) break;
			mind++;
		}
		if(p<tail) printf("%d %d\n",n,mind);
		else printf("NO ROUTE\n");
	}

	return 0;
}
示例#4
0
int createrulelink_f(char *file){ //解析文件
	char path[120]={0};
	char line[1024] = { 0 };
	char *data[10]={0};
	struct ruledata rd={0};
	FILE *fp;
	int status=0;
	culine=0;
	getpath(path,file);
	cufile=path;
	if(!(fp=fopen(path,"r"))){
		printf("指定规则文件%s不存在\n",path);
		exit(1);
	}
	while (1){ //遍历规则文件,以行模式
		int i = 0;
		int j = 1;
		if(!fgets(line, 1023, fp))
			break;
		culine++;
		if(isignore(line[0])) //判断行首字符是不是注释符
			break;
		data[0] = line;
		while (line[i]){ //以空格分割规则成10部分
			if (line[i] == ' '){
				line[i] = '\0';
				data[j] = (char *)(line + i+1);
				j++;
			}
			i++;
			if (j == 10)
				break;
		}
		if(islegal(data,culine)){ //验证规则合法性
			exit(0);
		}
		
		datatostruct(data,&rd); //从规则中提取出数据,获得ruledata结构
		linetorules(&rd);//使用ruledata数据结构中数据转化成规则体,挂载到rks规则链中
	}
	return 0;
}
示例#5
0
文件: 1940.c 项目: Crmiv/AlgoSolution
int main()
{
    int i,j,k;
    int t,p,tail;

    while(scanf("%d%d%d ",&x,&y,&z)!=EOF && x||y||z){
        for(i=0;i<x;i++){
            for(j=0;j<y;j++){
                for(k=0;k<z;k++){
                    mind[i][j][k]=-1;
                    mp[i][j][k]=getchar();
                    if(mp[i][j][k]=='S'){q[0][0]=i;q[0][1]=j;q[0][2]=k;mind[i][j][k]=0;}
                }
                getchar();
            }
            getchar();
        }
        p=0;
        tail=1;
        while(p<tail){
            if(mp[q[p][0]][q[p][1]][q[p][2]]=='E') break;
            for(t=0;t<6;t++){
                i=q[p][0]+d[t][0];
                j=q[p][1]+d[t][1];
                k=q[p][2]+d[t][2];
                if(islegal(i,j,k)&&mind[i][j][k]==-1&&mp[i][j][k]!='#'){
                    mind[i][j][k]=mind[q[p][0]][q[p][1]][q[p][2]]+1;
                    q[tail][0]=i;q[tail][1]=j;q[tail][2]=k;
                    tail++;
                }
            }
            p++;
        }
        if(p==tail) printf("Trapped!\n");
        else printf("Escaped in %d minute(s).\n",mind[q[p][0]][q[p][1]][q[p][2]]);
    }

    return 0;   /* NZEC */
}
示例#6
0
unsigned int findlegal(struct gameinfo *gi) {
	unsigned int i, l, legaln;
	char oppcolor;
	legaln = 0; //number of legal moves
	if (gi->gs->nowplaying == 'W') oppcolor = 'B'; //find opponent's color
	else oppcolor = 'W';
	for (i = 0; i<gi->r_size; i++)
		for (l = 0; l<gi->r_size; l++)
			if (gi->gs->board[i][l] == oppcolor) {//if there is an empty position next to one of the opponent's pieces, check if it's a legal move
				if (i>0) {//prevent array overflows
					if (gi->gs->board[i-1][l] == ' ' && islegal(gi, i-1, l, i, l, oppcolor) == 1) {gi->gs->board[i-1][l] = '*'; legaln++; }
					if (l>0 && gi->gs->board[i-1][l-1] == ' ' && islegal(gi, i-1, l-1, i, l, oppcolor) == 1) {gi->gs->board[i-1][l-1] = '*'; legaln++; }
					if (l<(gi->r_size-1) && gi->gs->board[i-1][l+1] == ' ' && islegal(gi, i-1, l+1, i, l, oppcolor) == 1) {gi->gs->board[i-1][l+1] = '*'; legaln++; }
				}
				if (i<(gi->r_size-1)) {
					if (gi->gs->board[i+1][l] == ' ' && islegal(gi, i+1, l, i, l, oppcolor) == 1) {gi->gs->board[i+1][l] = '*'; legaln++; }
					if (l>0 && gi->gs->board[i+1][l-1] == ' ' && islegal(gi, i+1, l-1, i, l, oppcolor) == 1) {gi->gs->board[i+1][l-1] = '*'; legaln++; }
					if (l<(gi->r_size-1) && gi->gs->board[i+1][l+1] == ' ' && islegal(gi, i+1, l+1, i, l, oppcolor) == 1) {gi->gs->board[i+1][l+1] = '*'; legaln++; }
				}
				if (l>0 && gi->gs->board[i][l-1] == ' ' && islegal(gi, i, l-1, i, l, oppcolor)) {gi->gs->board[i][l-1] = '*'; legaln++; }
				if (l<(gi->r_size-1) && gi->gs->board[i][l+1] == ' ' && islegal(gi, i, l+1, i, l, oppcolor)) {gi->gs->board[i][l+1] = '*'; legaln++; }
			}
	return legaln; //return number of legal moves
}
示例#7
0
AString *AString::getlegal()
{
	char * temp = new char[len+1];
	char * temp2 = temp;
	int j = 0;
	for (int i=0; i<len; i++) {
		if (islegal(str[i])) {
			*temp2 = str[i];
			if (str[i] != ' ') j=1;
			temp2++;
		}
	}

	if (!j) {
		delete temp;
		return 0;
	}

	*temp2 = '\0';
	AString * retval = new AString(temp);
	delete temp;
	return retval;
}
示例#8
0
vector<double> GTPWrapper::getSensoryInput(bool first)
{
  //int * fpos = getpos(first);
  //cout << "fpos: " << fpos[0] << " , " << fpos[1] << endl;
  //get all the data..
  boost::dynamic_bitset<> * oslook = sqlook(first);
  vector<double> lrange = getLongrange(first);

  int * pos = getpos(first);
  int l = islegal(first);//(board.at(((bsize-(pos[0]+1))*bsize)+pos[1]) == 0 ) ? true : false;// islegal(first); TODO make this back ... or not?
  //cout << "pos: " << pos[0] << " , " << pos[1] << endl;
  //now convert the look to black and white bools..
  vector<double> slook;
  //int c2=0;
  vector<double> ret;
  for(unsigned int i=0;i<(*oslook).size();i++)
    ret.push_back((*oslook)[i]);
  delete oslook;
//   int c=0;
//   for(unsigned int i=0;i<slook.size();i++)
//     if(slook.at(i)!=0.0)
//       c++;
//   if(c!=0)
//     cout << c << " not null points in slook vector" << endl;
  //concat the vectors...that is for a later time
  //cause now my battery is running empty and I
  //am on a bus heading home for crhistmas! :D
  //...and also, dunno this syntax, need web :p
  //vector<double> ret(slook.begin(),slook.end());
  //  ret.insert(ret.end(),lrange.begin(),lrange.end());
  for(unsigned int i=0;i<lrange.size();i++)
    ret.push_back(ret.at(i));
  ret.push_back((double)pos[0]/(double)bsize);
  ret.push_back((double)pos[1]/(double)bsize);
  ret.push_back(l);
  return ret;
}
示例#9
0
文件: board2.c 项目: ferrin22/EDA132
int main(int argc, char const *argv[])
{
	newgame();
	inst();
	printf("\nHow Many Milliseconds Per Move Would You Like Your Opponent To Take?\n");
	scanf("%d",inp);
	int mils = *inp;
	
	while(game==0) {

		checkMove();
		if(moves==0){
			cantMove[0]=1;
			legal=1;
		}
		screen();
		scanf("%s",pos);
		row=pos[0]-'1';
		col=letToNum(pos[2])-1;
		islegal(row,col);
		if(legal==1){
			retZero();
			putPiece(row,col);
		}
	nextTurn:
		retZero();
		if (legal == 1) {
			player = 2;
			checkMove();
			if(moves==0){
				cantMove[1]=1;
				legal=0;
				goto nextTurn1;
			}
			clock_t begin = clock(), runningTime;
			int ai = minimax(player, board, 6, turn, begin, runningTime, mils)[0];
			if (ai != 0) {
				yy = ai % 10;
			 	yy = yy - 1;
			 	xx = ai / 10;
			 	xx = xx - 1;
		 		printf("\n");
				printf("Opponent Moved To %d,%d\n", (xx + 1), (yy + 1));
				putPiece(xx, yy);
				retZero();
				player = 1;
			}
			legal=0;
		}
	nextTurn1:
		if(cantMove[0]==1 && cantMove[1]==1){
			game=1;
			if(cantMove[0]==0){
				printf("\nPlayer 1 Wins");
			}else{
				printf("\n AI Wins");
			}
		}else{
			game=0;
			cantMove[0]=0;
			cantMove[1]=0;
		}
	}
	return 0;
}
示例#10
0
static long
floppywrite(Chan *c, void *a, long n, vlong off)
{
	FDrive *dp;
	long rv, i;
	char *aa = a;
	Cmdbuf *cb;
	Cmdtab *ct;
	ulong offset = off;

	rv = 0;
	dp = &fl.d[c->qid.path & ~Qmask];
	switch ((int)(c->qid.path & Qmask)) {
	case Qdata:
		islegal(offset, n, dp);
		qlock(&fl);
		if(waserror()){
			qunlock(&fl);
			nexterror();
		}
		floppyon(dp);
		changed(c, dp);
		for(rv = 0; rv < n; rv += i){
			floppypos(dp, offset+rv);
			if(dp->tcyl == dp->ccyl)
				dp->ccyl = -1;
			i = floppyxfer(dp, Fwrite, aa+rv, offset+rv, n-rv);
			if(i < 0)
				break;
			if(i == 0)
				error(Eio);
		}
		qunlock(&fl);
		poperror();
		break;
	case Qctl:
		rv = n;
		cb = parsecmd(a, n);
		if(waserror()){
			free(cb);
			nexterror();
		}
		qlock(&fl);
		if(waserror()){
			qunlock(&fl);
			nexterror();
		}
		ct = lookupcmd(cb, floppyctlmsg, nelem(floppyctlmsg));
		switch(ct->index){
		case CMeject:
			floppyeject(dp);
			break;
		case CMformat:
			floppyformat(dp, cb);
			break;
		case CMreset:
			fl.confused = 1;
			floppyon(dp);
			break;
		case CMdebug:
			floppydebug = 1;
			break;
		case CMnodebug:
			floppydebug = 0;
			break;
		}
		poperror();
		qunlock(&fl);
		poperror();
		free(cb);
		break;
	default:
		panic("floppywrite: bad qid");
	}

	return rv;
}