Beispiel #1
0
unsigned int DisjointSets<T, hasher>::merge_classes( 
    unsigned int c1, 
    unsigned int c2 
    ) {
  //get class representatives
  const unsigned int c1_rep = get_rep(c1) ;
  const unsigned int c2_rep = get_rep(c2) ;
  //if the classes are already merged, do nothing
  if(c1_rep == c2_rep) return c1_rep ;

  //merge
  //get the class ranks
  const unsigned int c1_rank = get_rank(c1_rep) ;
  const unsigned int c2_rank = get_rank(c2_rep) ;
  if(c1_rank < c2_rank) {
    //tree for c2 is deeper, use c2 as root
    set_rep(c1_rep, c2_rep) ;
    return c2_rep ;
  } else if(c2_rank < c1_rank) {
    //tree for c1 is deeper, use c1 as root
    set_rep(c2_rep, c1_rep) ;
    return c1_rep ;
  } else {
    //trees have the same depth, use c1 as root and increase its depth
    set_rep(c2_rep, c1_rep) ;
    set_rank(c1_rep, c1_rank+1) ;
    return c1_rep ;
  }
}
Beispiel #2
0
Card *create_card(char *rank, char *suit)
{
    Card *cp;
    init_card(&cp);
    set_rank(cp, rank);
    set_suit(cp, suit);
    return cp;
}
Beispiel #3
0
void gameover()
{
	if(cp==1)
	   endscore=score;
	if(cp==2)
		endscore=score+40;
	if(cp==3)
		endscore=score+70;
	Sleep(100);
	initgraph(700,600);
	setbkcolor(BLUE);
	cleardevice();
	setcolor(RED);
	setfont(100,0,"华文行楷");
	outtextxy(160,80,"游戏结束");
	setcolor(YELLOW);
	setfont(70,0,"华文行楷");
	outtextxy(160,210,"最后得分:");
	char str[10];
	setcolor(YELLOW);
	setfont(70,0,"华文行楷");
    sprintf(str,"%d",score);
    outtextxy(460,210,str);
	setcolor(CYAN);
	setfont(60,0,"楷体");
	outtextxy(20,320,"点击右下角返回到主页面");
	setcolor(LIGHTGREEN);
	setfont(60,0,"华文隶书");
	outtextxy(440,500,"→主页面");
    set_rank();
	MOUSEMSG m; 
	while(true)
	{
	  m=GetMouseMsg();
	  switch(m.uMsg)
	  {
	  case WM_LBUTTONDOWN:
	   if(m.x>=440&&m.y>=500&&m.y<=560&&m.x<=680)
		   main();
	  }
	}
}
Beispiel #4
0
int Unit::think_general_action()
{
	if( think_leader_action() )
		return 1;

	//--- if the general is not assigned to a camp due to its low competency ----//

	Nation* ownNation = nation_array[nation_recno];
	int 	  rc = 0;

	if( team_info->member_count <= 1 )
	{
		rc = 1;
	}

	//--- if the skill of the general and the number of soldiers he commands is not large enough to justify building a new camp ---//

	else if( skill.skill_level + team_info->member_count*4
				< 40 + ownNation->pref_keep_general/5 )					// 40 to 60
	{
		rc = 1;
	}

	//-- think about splitting the team and assign them into other forts --//

	else if( ownNation->ai_has_too_many_camp() )
	{
		rc = 1;
	}

	//--------- demote the general to soldier and disband the troop -------//

	if( rc )
	{
		set_rank(RANK_SOLDIER);
		return think_normal_human_action();
	}

	return 0;
}
Beispiel #5
0
//--------- Begin of function Unit::spy_change_nation ---------//
//
// Change the deceiving nation recno of a spy unit which you control.
//
// <int>  newNationRecno - the new nation the spy changes its cloack to 
// <char> remoteAction   - remote action type 
//
void Unit::spy_change_nation(int newNationRecno, char remoteAction)
{
	if( newNationRecno == nation_recno )
		return;

	if( newNationRecno && nation_array.is_deleted(newNationRecno) )      // this can happen in a multiplayer message
		return;

	//------- if this is a remote action -------//

	if( !remoteAction && remote.is_enable() )
	{
		// packet structure <unit recno> <new nation Recno>
		short *shortPtr = (short *)remote.new_send_queue_msg(MSG_UNIT_SPY_NATION, 2*sizeof(short) );
		*shortPtr = sprite_recno;
		shortPtr[1] = newNationRecno;
		return;
	}

	//----- update the var in Spy ------//

	Spy* spyPtr = spy_array[spy_recno];

	//--- when a spy change cloak to another nation, he can't cloak as a general, he must become a soldier first ---//

	if( is_visible() &&					// if the spy is a commander in a camp, don't set its rank to soldier
		 rank_id == RANK_GENERAL &&
		 newNationRecno != spyPtr->true_nation_recno )
	{
		set_rank(RANK_SOLDIER);
	}

	//---------------------------------------------------//
	//
	// If this spy unit is a general or an overseer of the
	// cloaked nation, when he changes nation, that will
	// inevitably be noticed by the cloaked nation.
	//
	//---------------------------------------------------//

	if( spyPtr->true_nation_recno != nation_array.player_recno )	// only send news message if he is not the player's own spy
	{
		if( rank_id == RANK_GENERAL || unit_mode == UNIT_MODE_OVERSEE ||
			 spyPtr->notify_cloaked_nation_flag )
		{
			//-- if this spy's cloaked nation is the player's nation, the player will be notified --//

			if( nation_recno == nation_array.player_recno )
				news_array.unit_betray(sprite_recno, newNationRecno);
		}

		//---- send news to the cloaked nation if notify flag is on ---//

		if( spyPtr->notify_cloaked_nation_flag )
		{
			if( newNationRecno == nation_array.player_recno )    			// cloaked as the player's nation
				news_array.unit_betray(sprite_recno, newNationRecno);
		}
	}

	//--------- change nation recno now --------//

	spyPtr->cloaked_nation_recno = newNationRecno;

	betray(newNationRecno);		// call the betray function to change natino. There is no difference between a spy changing nation and a unit truly betrays
}
Beispiel #6
0
//--------- Begin of function Unit::detect_button ---------//
//
void Unit::detect_button()
{
	//---- if currently in the mode of selecting a unit to succeed the king ----//

	if( nation_array.player_recno &&
		 nation_recno == nation_array.player_recno &&
		 (~nation_array)->king_unit_recno == 0 )
	{
		if( race_id && button_succeed_king.detect() )
		{
			if( !remote.is_enable() )
			{
				(~nation_array)->succeed_king(sprite_recno);
				info.disp();
			}
			else
			{
				// packet structure : <unit recno> <nation recno>
				short *shortPtr = (short *)remote.new_send_queue_msg(MSG_UNIT_SUCCEED_KING, 2*sizeof(short));
				*shortPtr = sprite_recno;
				shortPtr[1] = nation_array.player_recno;
			}
		}

		return;
	}

	//--------- "return camp" button ---------//

	if( home_camp_firm_recno && button_return_camp.detect('R') )
	{
		// sound effect
		se_res.far_sound(next_x_loc(), next_y_loc(), 1, 'S', sprite_id, "ACK");

		unit_array.return_camp(COMMAND_PLAYER);
		return;
	}

	//------- toggle unit aggressive mode button ------//

	if( button_aggressive_mode.detect() )
	{
		group_change_aggressive_mode();
	}

	//-------- build button --------//

	if( button_build.detect('B') )
	{
		unit_menu_mode = UNIT_MENU_BUILD;
		info.disp();
	}

	//-------- settle button ---------//

	if( button_settle.detect('T') )
	{
		power.issue_command(COMMAND_SETTLE, sprite_recno);
		info.disp();
		return;
	}

	//-------- detect promote/demote button --------//

	if( rank_id == RANK_SOLDIER )
	{
		if( button_promote.detect() )
		{
			if(!remote.is_enable() )
			{
				set_rank(RANK_GENERAL);
			}
			else
			{
				// packet structure : <unit recno> <new rank>
				short *shortPtr = (short *)remote.new_send_queue_msg(MSG_UNIT_SET_RANK, 2*sizeof(short));
				*shortPtr = sprite_recno;
				shortPtr[1] = RANK_GENERAL;
			}

			se_ctrl.immediate_sound("TURN_ON");
		}
	}
	else if( rank_id == RANK_GENERAL )
	{
		if( button_demote.detect() )
		{
			if( !remote.is_enable() )
			{
				set_rank(RANK_SOLDIER);
			}
			else
			{
				// packet structure : <unit recno> <new rank>
				short *shortPtr = (short *)remote.new_send_queue_msg(MSG_UNIT_SET_RANK, 2*sizeof(short));
				*shortPtr = sprite_recno;
				shortPtr[1] = RANK_SOLDIER;
			}

			se_ctrl.immediate_sound("TURN_OFF");
		}
	}

	//------------ detect assign to firm button ------------//

	if( button_assign.detect() )
	{
		power.issue_command(COMMAND_ASSIGN, sprite_recno);
	}

	//------------ "reward" button ---------//

	if( button_reward.detect() )
	{
		group_reward();
	}

	//------- spy notify button ------//

	if( spy_recno && button_spy_notify.detect() )
	{
		group_change_spy_notify_flag();
	}

	//------- drop spy identity button ------//

	if( spy_recno && button_spy_drop_identity.detect() )
	{
		group_drop_spy_identity();
	}

/*
	//--------- detect button for changing nation color -------//

	if( button_change_color.detect() )
	{
		Nation* nationPtr = nation_array[nation_recno];

		if( ++nationPtr->color_scheme_id > MAX_COLOR_SCHEME )
			nationPtr->color_scheme_id = 1;

		nationPtr->nation_color	= game.color_remap_array[nationPtr->color_scheme_id-1].main_color;
	}
*/
}