예제 #1
0
MoveList* MaxMove3 (Disc board [BOARD_SIZE][BOARD_SIZE],int current_player) {
    Disc copy [BOARD_SIZE][BOARD_SIZE];
    int temp_score =0, max_score=-50;
    MoveList* best_move = NULL;
    MoveList* curr_suggested_move =NULL;
    MoveListList* moves_for_all_discs_this_turn = NULL, *curr =NULL;

    moves_for_all_discs_this_turn = collect_all_moves_for_player(board, current_player);

    curr = moves_for_all_discs_this_turn;
    while (curr  !=NULL)
    {
        copy_board2(board, copy);
        curr_suggested_move = curr->data;


        make_turn(copy,curr_suggested_move);
        

        temp_score = calculate_score_for_board2(copy, 1, current_player*(-1));
        if ((-1)*temp_score > max_score)
        {
            max_score = (-1)*temp_score;
            best_move =curr_suggested_move;
        }
        curr = curr->next;
    }
    curr= NULL;
    return best_move;
    
}
예제 #2
0
int calculate_score_for_board2(Disc board [BOARD_SIZE][BOARD_SIZE],int depth, int current_player) {
    int is_max=0;
    Disc copy [BOARD_SIZE][BOARD_SIZE];
    int temp_score =0, max_score=-50;
    MoveList* curr_suggested_move =NULL;
    MoveListList* moves_for_all_discs_this_turn = NULL, *curr =NULL;
    
    is_max = (current_player == global_current_player) ? 1 :-1;
    
    if (depth >global_max_depth)
    {
        int temp =0;
        temp = get_discs_board_score_for_player(board, current_player);
        return is_max*temp;
    }
    
    moves_for_all_discs_this_turn = collect_all_moves_for_player(board, current_player);
   
    if (moves_for_all_discs_this_turn==NULL)
    {
        return (-40)*(is_max);
    }
    
    
    curr = moves_for_all_discs_this_turn;
    while (curr  !=NULL)
    {
        copy_board2(board, copy);
        curr_suggested_move = curr->data;
        make_turn(copy,curr_suggested_move);
        depth++;
        temp_score = calculate_score_for_board2(copy, depth, current_player*(-1));
        if ((is_max)*temp_score > max_score)
        {
            max_score = (is_max)*temp_score;
        }
        curr = curr->next;
    }

    return max_score;
}
예제 #3
0
int main(void)
{
	//Sväng inte
	turn = 0;
	
	//Initiera spi, pwm och display
	spi_init();
	pwm_init();
	init_display();
	update();
	
	claw_out();
	_delay_ms(500);
	claw_in();	
	
	//Aktivera global interrupts
	sei();
	
	//Initiera regulator
	clear_pid();	
	init_pid(80, -80);
	//update_k_values(40, 12, 22);
	update_k_values(40, 170, 20);
	
	// Pekare till aktuell position i bufferten
	tmp_sensor_buffer_p = 0x00;
	
	// Flagga som avgör huruvida vi är i början av meddelande	
	sensor_start = 1;
	
	// Anger aktuell längd av meddelandet				
	tmp_sensor_buffer_len = 0x00;
	
	//Initiera standardsträng på display		
	init_default_printf_string();
	clear_screen();
	update();
	
	
	while(1)
	{
		uint8_t has_comm_data, has_sensor_data, comm_data, sensor_data;
	
		do_spi(&has_comm_data, &has_sensor_data, &comm_data, &sensor_data);
		
		//Undersök och hantera meddelanden från slavarna
		if(has_comm_data) decode_comm(comm_data);
		if(has_sensor_data) decode_sensor(sensor_data);
		
		//Vid manuell sväng eller 180 grader måste make_turn anropas 		
		if(!autonomous || turning_180)
		{
			if(turn_dir) 
			{
				make_turn_flag = 1;
				make_turn(turn_dir);
				
				if(!make_turn_flag) 
				{
					turn_dir = 0;
					stop_motors();
				}				
			}
		}			
		
		//Kör regulatorn
		if (regulator_enable)
		{
			regulator(sensor_buffer[IR_RIGHT_FRONT] - sensor_buffer[IR_RIGHT_BACK], 
					  sensor_buffer[IR_LEFT_FRONT] - sensor_buffer[IR_LEFT_BACK], 
					  sensor_buffer[IR_RIGHT_FRONT] - sensor_buffer[IR_LEFT_FRONT], 
					  sensor_buffer[IR_RIGHT_BACK] - sensor_buffer[IR_LEFT_BACK]);
			regulator_enable = 0;
		}	
	}
}