Exemplo n.º 1
0
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();
		}
}
Exemplo n.º 2
0
void Animation::increaseDelta()
{
	if (m_currentDelta++ >= m_delta)
	{
		m_currentDelta = 0;
		increaseStep();
	}
}
Exemplo n.º 3
0
void Player::move() {//make a move based on the move made by the opponent
		lastMe_ = me;
		sab.setStep(step);
        cout << "Computing. Be patient, it takes time to become intelligent" << endl;
		me = sab.searchAB(curState);		
		if (!checkLose(me))
				curState.update(MAX, me);
		else 
				gameOver = MIN;
		increaseStep();
}
Exemplo n.º 4
0
void stepMotor::step(int steps_to_move){
      
        // declare scan object
        scan scan1;
        // Get current time
        // Get distance from Lidar
        //unsigned long startTime = micros();
        //int distance = scan1.getDistance();
        //unsigned long endTime = micros();
        // compensate for the time it takes to read from lidar
        //step_delay -= (endTime - startTime);

	int steps_left = abs(steps_to_move);
	// int steps_left = 0;

	if(steps_to_move > 0){
		direction = 1;
	}
	else{
		direction = 0;
	}
	while(steps_left > 0){
                
		unsigned long current_step_time = micros();
		if(current_step_time - last_step_time >= step_delay){
                        // reset the speed
                        setSpeed(originalRPM);
			last_step_time = current_step_time;
			if(direction == 1){
				step_number++;
				
				if(step_number == number_of_steps)
					step_number = 0;
			
			}
			else{
				if(step_number == 0)
					step_number = number_of_steps;
				step_number--;
			}

                        unsigned long startTime = micros();
                        int distance = 0;
                        distance = scan1.getDistance();
                        unsigned long endTime = micros();
                        // compensate for the time it takes to read from lidar
                        //Serial.print("Offset Calculations");
                        //Serial.println(endTime - startTime);
                        if( (endTime - startTime) > step_delay)
                          step_delay = 0;
                        else
                          step_delay -= (endTime - startTime);
                        //Serial.print("This is delay updated ");
                        //Serial.println(step_delay);
                        if(step_delay < 0)
                          step_delay = 0;
                        // Serial Print data
                        Serial.print(degree);
                        Serial.print(", ");
                        //Serial.print("Distance: ");
                        Serial.println(distance);
			steps_left--;
                        // reset step_delay
			increaseStep(step_number % 4);
		}

	}
        

}