void Player::play(){   //play the game		
		// Player would increase step every time one makes a movement,
		// And modify it depthlimit every 5 steps
		gameOver = 0; // nobody wins the game
		step = 0;
		depthLimit_ = 7;
		sab.setDepthLimit(depthLimit_);
		if (role == MIN) {
				takeIn();
				curState.print();				
		}				
		move();		putOut();
		curState.print();		
		takeIn();	
		curState.print();		
		while (gameOver == 0) {
				move();		putOut();
				curState.print();				
				if (gameOver == 0) {
						takeIn();			
						curState.print();						
				}
		}
		checkGame();		
}
Exemple #2
0
char *twohundred(char *filename, struct stat statresult){
    char firstline[] = "HTTP/1.1 200 OK\r\n";
    char secondline[]= "Content-type: text/plain\r\n";
    char l3temp [50];
    strcpy(l3temp, "Content length: %d\r\n");//template to be added later
    char line4[] = "\r\n"; 
    FILE * fd = 0;
    fd = fopen(filename,"r");
    char fileholder[32000];
    takeIn(fileholder, fd);//get the file in our hands
    fclose(fd);
    char content[64000];//if every char is \n, then the file will double
    //fprintf(stderr,"%s",fileholder);
    addRs(content,fileholder);//and the /r charaters
    char line3[50];
    sprintf(line3,l3temp,(strlen(content)));
    char *returnval;
    returnval = (char*) malloc(sizeof(char)*64250);
	//put it all together
    strcpy(returnval,firstline);
    strcat(returnval,secondline);
    strcat(returnval,line3);
    strcat(returnval,line4);
    strcat(returnval,content);
    strcat(returnval, "\r\n");
    return returnval;
}
void Player::takeIn(){ // take in the opponent's move, and deal with roll back
		int i, j;
		cin >> i >> j;
		if (i == -1 && j == -1) {
				rollBack();				
				cout << "Insert you move again" << endl;
				takeIn();
		}
		else {
				lastYou_ = you;				
				you[0] = i; you[1] = j;
				you[0]--; you[1]--;				
				char c;
				while (!checkLegal(you) ) {
						cout << "Are u sure that u input something illegal y/n?" << endl;						
						cin >> c;
						if (c == 'y') {
								gameOver = MAX;	
								return;
						}
						cin >> i >> j;
						you[0] = i; you[1] = j;
						you[0]--; you[1]--;
				}
				curState.update(MIN, you);				
				increaseStep();
		}
}