コード例 #1
0
ファイル: brain.c プロジェクト: mikaelangman/grupp2robot
/*
 * Recursive help function for DFS. 
 * Returns 1 if area is NOT closed.
 * Returns 0 if area is closed.
 */
uint8_t dfs_help(uint8_t startx, uint8_t starty){
	if(visited[startx][starty] == 0){

		if(rmem(startx,starty) == OUTSIDE){
			return 1;
		}
		if(rmem(startx,starty) == WALL){
			return 0;
		}
		visited[startx][starty] = 1;
		
		if(dfs_help(startx,starty-1) == 1){
			return 1;
		}
		if(dfs_help(startx+1,starty) == 1){
			return 1;
		}
		if(dfs_help(startx,starty+1) == 1){
			return 1;
		}
		if(dfs_help(startx-1,starty) == 1){
			return 1;
		}
	}
	return 0;
}
コード例 #2
0
ファイル: brain.c プロジェクト: mikaelangman/grupp2robot
void purge_iwalls(){

	uint8_t i;
	uint8_t j;

	for(i = 0; i < 32; i++){
		for(j = 0; j < 32; j++){


			if(rmem(i,j) == IWALL){

				uint8_t alone_iwall = 1;

				// check the 8 surronding tiles 
				if(rmem(i+1, j) == UNEXP){
					alone_iwall = 0;
				}
				if(rmem(i-1, j) == UNEXP){
					alone_iwall = 0;
				}
				if(rmem(i, j+1) == UNEXP){
					alone_iwall = 0;
				}
				if(rmem(i, j-1) == UNEXP){
					alone_iwall = 0;
				}
				if(rmem(i+1, j+1) == UNEXP){
					alone_iwall = 0;
				}
				if(rmem(i-1, j-1) == UNEXP){
					alone_iwall = 0;
				}
				if(rmem(i-1, j+1) == UNEXP){
					alone_iwall = 0;
				}
				if(rmem(i+1, j-1) == UNEXP){
					alone_iwall = 0;
				}

				// if none unexp, mark as wall
				if(alone_iwall == 1){
					wmem_auto(WALL,i,j);
				}


			}
		}
	}
}
コード例 #3
0
ファイル: debug_core.c プロジェクト: dancrossnyc/harvey
/*
 * Weak aliases for breakpoint management,
 * can be overriden by architectures when needed:
 */
char *
arch_set_breakpoint(GdbState *ks, struct bkpt *bpt)
{
	char *err;

	err = rmem(bpt->saved_instr, ks->threadid, bpt->bpt_addr, machdata->bpsize);
	if (err)
		return err;

	err = wmem(bpt->bpt_addr, ks->threadid, machdata->bpinst, machdata->bpsize);
	return err;
}
コード例 #4
0
ファイル: brain.c プロジェクト: mikaelangman/grupp2robot
/*
 * Returns 0 if there are any IWALL tiles on the map.
 * Otherwise returns 0.
 */
uint8_t done_iwall(){

	uint8_t answer = 1;
	uint8_t i;
	uint8_t j;

	for(i = 0; i < 32; i++){
		for(j = 0; j < 32; j++){
			if(rmem(i,j) == IWALL){
				answer = 0;
			}			
		}
	}
	return answer;
}
コード例 #5
0
ファイル: brain.c プロジェクト: mikaelangman/grupp2robot
/*
 * Returns 0 if there are any UNEXP tiles on the map.
 * Otherwise returns 1.
 */
uint8_t done_unexp(){

	uint8_t answer = 1;
	uint8_t i;
	uint8_t j;

	for(i = 0; i < 32; i++){
		for(j = 0; j < 32; j++){
			if(rmem(i,j) == UNEXP){
				answer = 0;
			}			
		}
	}
	return answer;
}
コード例 #6
0
ファイル: brain.c プロジェクト: mikaelangman/grupp2robot
/*
 * Generate next action
 */
void think(){
	if((curr_action == EMPTY) && (map_complete == 0)){	

		if(follow_wall == 1){ //If in follow wall mode

			if((s_ir_front < 11) && (s_ir_front > 2)){ //If to close to the wall, back up a bit
					curr_action = BACKWARD;
			}
		
			else if(((t_vagg_h_f == 0) && (t_vagg_h_b == 0)) || ((t_vagg_h_f == 1) && (t_vagg_h_b == 1))){ //If there is no wall to the right of the robot
					curr_action = SPIN_R;
				
				if((s_ir_front > 12) && (s_ir_front < 30)){  //If we're close to wall, nudge to it.
					curr_action = NUDGE_TO_WALL;
				}

				else if((t_vagg_v_f == 1) && (t_vagg_v_b == 1)){	// parallelize against a wall far to the left
					if(t_p_v != 0){
						curr_action = P_WEAK_L;
					}
				}

			}

			else if( (t_vagg_h_f != 2) && (t_vagg_h_b == 2) ){ //If there is no wall to the right of the robot
				curr_action = NUDGE_FORWARD;
			}

			else if(t_vagg_front == 2){ //If the robot has a wall right in front of it, turn where there is an empty tile, right is prefered
				if(t_p_h != 0){
					curr_action = P_WEAK;
				}
				else{

					if((s_ir_front > 13) && (s_ir_front < 30)){
						curr_action = NUDGE_TO_WALL;
					}

					else{ //If there is a wall front and right, turn left
						curr_action = SPIN_L;
					}
				}
			}
			else{
				curr_action = FORWARD;
			}

			if(map_enclosed == 1){	//outer wall is connected, enclosing the inner area.

				uint8_t temp_x, temp_y;

				switch(dir){
					case(0):
						temp_x = 0;
						temp_y = -1;
					break;

					case(1):
						temp_x = 1;
						temp_y = 0;
					break;

					case(2):
						temp_x = 0;
						temp_y = 1;
					break;

					case(3):
						temp_x = -1;
						temp_y = 0;
					break;
				} 

				if((lets_go_home == 0) && (follow_island == 0)){
					if ((rmem(robot_pos_x + temp_y, robot_pos_y - temp_x) == IWALL) || 
						(rmem(robot_pos_x + temp_y * 2, robot_pos_y - temp_x * 2) == IWALL)){ 
							land_o_hoy = 0;
							first_time_on_island = 1;
							curr_action = PARALLELIZE;
							next_action = SPIN_L;
					}
				}
			}
		} 
		think_hard();
	}	

	return;
}
コード例 #7
0
ファイル: VirtualCPU.cpp プロジェクト: validus77/Synacor_VM
std::uint16_t VirtualCPU::executeInstructionAtAddress(std::uint16_t address) {
  debugger_.pc_  = address; //HACK FOR NOW
    switch (memoryController_.readAtAddress(address)) {
        case 0:
            return address + halt();
        case 1:
            return address + set(memoryController_.readAtAddress(address + 1), memoryController_.readAtAddress(address + 2));
        case 2:
            return address + push(memoryController_.readAtAddress(address + 1));
        case 3:
            return address + pop(memoryController_.readAtAddress(address + 1));
        case 4:
            return address +
                    eq(memoryController_.readAtAddress(address + 1),
                       memoryController_.readAtAddress(address + 2),
                       memoryController_.readAtAddress(address + 3));
        case 5:
            return address + gt(memoryController_.readAtAddress(address + 1),
                                memoryController_.readAtAddress(address +2),
                                memoryController_.readAtAddress(address + 3));
        case 6:
            return jump(memoryController_.readAtAddress(address + 1), address);
        case 7:
            return jt(memoryController_.readAtAddress(address + 1),
                                memoryController_.readAtAddress(address + 2),
                                address);
        case 8:
            return jf(memoryController_.readAtAddress(address + 1),
                                memoryController_.readAtAddress(address + 2),
                                address);
        case 9:
            return address + add(memoryController_.readAtAddress(address + 1),
                                 memoryController_.readAtAddress(address + 2),
                                 memoryController_.readAtAddress(address + 3));
        case 10:
            return address + mult(memoryController_.readAtAddress(address + 1),
                                 memoryController_.readAtAddress(address + 2),
                                 memoryController_.readAtAddress(address + 3));
        case 11:
            return address + mod(memoryController_.readAtAddress(address + 1),
                                  memoryController_.readAtAddress(address + 2),
                                  memoryController_.readAtAddress(address + 3));
        case 12:
            return address + and_i(memoryController_.readAtAddress(address + 1),
                                 memoryController_.readAtAddress(address + 2),
                                 memoryController_.readAtAddress(address + 3));
        case 13:
            return address + or_i(memoryController_.readAtAddress(address + 1),
                                 memoryController_.readAtAddress(address + 2),
                                 memoryController_.readAtAddress(address + 3));
        case 14:
            return address + not_i(memoryController_.readAtAddress(address + 1),
                                 memoryController_.readAtAddress(address + 2));
        case 15:
            return address + rmem(memoryController_.readAtAddress(address + 1),
                                 memoryController_.readAtAddress(address + 2));
        case 16:
            return address + wmem(memoryController_.readAtAddress(address + 1),
                                  memoryController_.readAtAddress(address + 2));
        case 17:
            return call(memoryController_.readAtAddress(address + 1), address);
        case 18:
            return ret();
        case 19:
            return address + out(memoryController_.readAtAddress(address + 1));
        case 21:
            return address + noop();
        case 20:
            return address + in(memoryController_.readAtAddress(address + 1));
        default:
            std::cout << "CPU ERROR illegal op code: " << memoryController_.readAtAddress(address) << std::endl;
            return address + 1;
    }
}