Esempio n. 1
0
/* We don't bother modeling all the nuances of the game's rules in these functions */
static void
move_pawn(char *board, int x, int y)
{
    if (isupper(get_piece(board, x - 1, y)))
        set_move(x, y, x - 1, y);
    else if (isupper(get_piece(board, x + 1, y)))
        set_move(x, y, x + 1, y);
    else if (get_piece(board, x, y + 2) == ' ')
        set_move(x, y, x, y + 2);
    else if (get_piece(board, x, y + 1) == ' ')
        set_move(x, y, x, y + 1);
}
Esempio n. 2
0
static void
move_rook(char *board, int x, int y)
{
    if (isupper(get_piece(board, x, y + 1)) || get_piece(board, x, y + 1) == ' ')
        set_move(x, y, x, y + 1);
    else if (isupper(get_piece(board, x - 1, y)) || get_piece(board, x - 1, y) == ' ')
        set_move(x, y, x - 1, y);
    else if (isupper(get_piece(board, x + 1, y)) || get_piece(board, x + 1, y) == ' ')
        set_move(x, y, x + 1, y);
    else if (isupper(get_piece(board, x, y - 1)) || get_piece(board, x, y - 1) == ' ')
        set_move(x, y, x, y - 1);
}
Esempio n. 3
0
void turretDrive(){
	int left  = 0;
	int right = 0;

	int VLeft = *(int*)(&receive_buffer[2]);
	int HLeft = ((*(int*)(&receive_buffer[6])) * 3)/2; 

	int VRight = (*(int*)(&receive_buffer[4])); 
	int HRight = ((*(int*)(&receive_buffer[8])) * 3 )/ 2; 

	char TU;
	if 	(VRight> 200) 	{ TU =  1;}
	else if (VRight<-200) 	{ TU = -1;}
	else 			{ TU=0;}

	char TH;
	if 	(HRight> 200) 	{ TH =  1;}
	else if (HRight<-200) 	{ TH = -1;}
	else 			{ TH=0;}



	if 	(VLeft >  500 )	{ VLeft  =  999;}
	else if (VLeft < -500 )	{ VLeft  = -999;}
	else 		 	{ VLeft  = 2*VLeft;}


	if ( VLeft > 0){	// going forward 
		if (HLeft > 0 ){ 	// joystick right
			right = VLeft - HLeft;
			left = VLeft;
		}else {			// joystick left (HLeft < 0 )
			left = VLeft + HLeft;
			right = VLeft;
		}
	}else if (VLeft < -50) { 	// going back (VLeft < 0)
		if ( HLeft > 0){ 	// joystick right ()
			right =VLeft + HLeft;
			left  = VLeft;
		}else{			// joystick left (HLeft < 0 )
			left = VLeft - HLeft;
			right = VLeft;
		}
	}else {
		if ( HLeft > 0){ 	// joystick right ()
			right =VLeft ;
			left  = VLeft + HLeft;
		}else{			// joystick left (HLeft < 0 )
			right = VLeft - HLeft;
			left = VLeft;
		}
	}
	set_move(left, right,  TH, TU );
}
Esempio n. 4
0
static void
move_knight(char *board, int x, int y)
{
    if (isupper(get_piece(board, x + 1, y + 2)) || get_piece(board, x + 1, y + 2) == ' ')
        set_move(x, y, x + 1, y + 2);
    else if (isupper(get_piece(board, x + 2, y + 1)) || get_piece(board, x + 2, y + 1) == ' ')
        set_move(x, y, x + 2, y + 1);
    else if (isupper(get_piece(board, x + 2, y - 1)) || get_piece(board, x + 2, y - 1) == ' ')
        set_move(x, y, x + 2, y - 1);
    else if (isupper(get_piece(board, x + 1, y - 2)) || get_piece(board, x + 1, y - 2) == ' ')
        set_move(x, y, x + 1, y - 2);
    else if (isupper(get_piece(board, x - 1, y + 2)) || get_piece(board, x - 1, y + 2) == ' ')
        set_move(x, y, x - 1, y + 2);
    else if (isupper(get_piece(board, x - 2, y + 1)) || get_piece(board, x - 2, y + 1) == ' ')
        set_move(x, y, x - 2, y + 1);
    else if (isupper(get_piece(board, x - 2, y - 1)) || get_piece(board, x - 2, y - 1) == ' ')
        set_move(x, y, x - 2, y - 1);
    else if (isupper(get_piece(board, x - 1, y - 2)) || get_piece(board, x - 1, y - 2) == ' ')
        set_move(x, y, x - 1, y - 2);
}
Esempio n. 5
0
//--------- Begin of function Unit::process_ship_to_beach ---------//
// process unit action SHIP_TO_BEACH
//
void Unit::process_ship_to_beach()
{
	//----- action_mode never clear, in_beach to skip idle checking
	if(cur_action==SPRITE_IDLE)
	{
		int shipXLoc = next_x_loc();
		int shipYLoc = next_y_loc();
		if(shipXLoc==move_to_x_loc && shipYLoc==move_to_y_loc)
		{
			if(abs(move_to_x_loc-action_x_loc2)<=2 && abs(move_to_y_loc-action_y_loc2)<=2)
			{
				UnitMarine *shipPtr = (UnitMarine*) this;
				//------------------------------------------------------------------------------//
				// determine whether extra_move is required
				//------------------------------------------------------------------------------//
				switch(shipPtr->extra_move_in_beach)
				{
					case NO_EXTRA_MOVE:
							if(abs(shipXLoc-action_x_loc2)>1 || abs(shipYLoc-action_y_loc2)>1)
							{
								err_when(abs(shipXLoc-action_x_loc2)>2 || abs(shipYLoc-action_y_loc2)>2);
								err_when(result_node_array);

								shipPtr->extra_move();
							}
							else
							{
								//shipPtr->in_beach = 1;
								shipPtr->extra_move_in_beach = NO_EXTRA_MOVE;
								
							//#### trevor 23/10 #####//
								if(ai_action_id)
									nation_array[nation_recno]->action_finished(ai_action_id, sprite_recno);
							//#### trevor 23/10 #####//
							}
							break;

					case EXTRA_MOVING_IN:
					case EXTRA_MOVING_OUT:
							//err_when(cur_action!=SPRITE_SHIP_EXTRA_MOVE);
							break;

							//#### trevor 23/10 #####//

					case EXTRA_MOVE_FINISH:
							if(ai_action_id)
								nation_array[nation_recno]->action_finished(ai_action_id, sprite_recno);
							break;

							//#### trevor 23/10 #####//

					default: err_here();
								break;
				}
			}
		}			
		else
			reset_action_para();
	}
	else if(cur_action==SPRITE_TURN && is_dir_correct())
		set_move();
}