⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 worldmodel.cpp

📁 mersad源码 03年robocup 季军 可以研究一下大家
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	unsigned i;	bool isGoalieInList = false;		for (int i = 0; i < FULL_PLAYERS_NUM; i++)		if (getFullPlayer(TID_OPPONENT,i).isValid() &&			getFullPlayer(TID_OPPONENT,i).isGoalie())			isGoalieInList = true;	for (int i = 0; i < HALF_PLAYERS_NUM; i++)		if (getHalfPlayer(TID_OPPONENT,i).isValid() &&			getHalfPlayer(TID_OPPONENT,i).isGoalie())			isGoalieInList = true;								if (isGoalieInList)	{		offsideLine = -0xFFFF;		for (i = 0; i < FULL_PLAYERS_NUM; i++)			if (getFullPlayer(TID_OPPONENT,i).isValid() &&				getFullPlayer(TID_OPPONENT,i).getPos().getX() > offsideLine &&				!getFullPlayer(TID_OPPONENT,i).isGoalie()) 				offsideLine = getFullPlayer(TID_OPPONENT,i).getPos().getX();		for (i = 0; i < HALF_PLAYERS_NUM; i++)			if (getHalfPlayer(TID_OPPONENT,i).isValid() &&				getHalfPlayer(TID_OPPONENT,i).getPos().getX() > offsideLine &&				!getHalfPlayer(TID_OPPONENT,i).isGoalie())				offsideLine = getHalfPlayer(TID_OPPONENT,i).getPos().getX();	}	else	{		float firstMaxX = -0xFFFF, secMaxX = -0xFFFF;		for (i = 0; i < FULL_PLAYERS_NUM; i++)			if (getFullPlayer(TID_OPPONENT,i).isValid() &&				getFullPlayer(TID_OPPONENT,i).getPos().getX() > secMaxX)				{					secMaxX = getFullPlayer(TID_OPPONENT,i).getPos().getX();					if (secMaxX > firstMaxX)						swap(firstMaxX, secMaxX);				}		for (i = 0; i < HALF_PLAYERS_NUM; i++)			if (getHalfPlayer(TID_OPPONENT,i).isValid() &&				getHalfPlayer(TID_OPPONENT,i).getPos().getX() > secMaxX)				{					secMaxX = getHalfPlayer(TID_OPPONENT,i).getPos().getX();					if (secMaxX > firstMaxX)						swap(firstMaxX, secMaxX);				}		offsideLine = secMaxX;				}	if (isBallFlag)		if (offsideLine < getBall().getPos().getX())			offsideLine = getBall().getPos().getX();	if (offsideLine < 0)		offsideLine = 0;			return offsideLine;}float WorldModel::getTmmOffsideLine(bool isBallFlag) const{	float offsideLine;	unsigned i;	bool isGoalieInList = false;		for (int i = 0; i < FULL_PLAYERS_NUM; i++)		if (getFullPlayer(TID_TEAMMATE,i).isValid() &&			getFullPlayer(TID_TEAMMATE,i).isGoalie())			isGoalieInList = true;	for (int i = 0; i < HALF_PLAYERS_NUM; i++)		if (getHalfPlayer(TID_TEAMMATE,i).isValid() &&			getHalfPlayer(TID_TEAMMATE,i).isGoalie())			isGoalieInList = true;								if (isGoalieInList)	{		offsideLine = 0xFFFF;		for (i = 0; i < FULL_PLAYERS_NUM; i++)			if (getFullPlayer(TID_TEAMMATE,i).isValid() &&				getFullPlayer(TID_TEAMMATE,i).getPos().getX() < offsideLine &&				!getFullPlayer(TID_TEAMMATE,i).isGoalie()) 				offsideLine = getFullPlayer(TID_TEAMMATE,i).getPos().getX();		for (i = 0; i < HALF_PLAYERS_NUM; i++)			if (getHalfPlayer(TID_TEAMMATE,i).isValid() &&				getHalfPlayer(TID_TEAMMATE,i).getPos().getX() < offsideLine &&				!getHalfPlayer(TID_TEAMMATE,i).isGoalie())				offsideLine = getHalfPlayer(TID_TEAMMATE,i).getPos().getX();	}	else	{		float firstMaxX = 0xFFFF, secMaxX = 0xFFFF;		for (i = 0; i < FULL_PLAYERS_NUM; i++)			if (getFullPlayer(TID_TEAMMATE,i).isValid() &&				getFullPlayer(TID_TEAMMATE,i).getPos().getX() < secMaxX)				{					secMaxX = getFullPlayer(TID_TEAMMATE,i).getPos().getX();					if (secMaxX < firstMaxX)						swap(firstMaxX, secMaxX);				}		for (i = 0; i < HALF_PLAYERS_NUM; i++)			if (getHalfPlayer(TID_TEAMMATE,i).isValid() &&				getHalfPlayer(TID_TEAMMATE,i).getPos().getX() < secMaxX)				{					secMaxX = getHalfPlayer(TID_TEAMMATE,i).getPos().getX();					if (secMaxX < firstMaxX)						swap(firstMaxX, secMaxX);				}		offsideLine = secMaxX;				}	if (isBallFlag)		if (offsideLine > getBall().getPos().getX())			offsideLine = getBall().getPos().getX();	if (offsideLine > 0)		offsideLine = 0;			return offsideLine;}int WorldModel::getOppPlayersBeforeLine(float lineX) const{	int counter = 0;	register int i;	for (i = 0; i < FULL_PLAYERS_NUM; i++)		if (getFullPlayer(TID_OPPONENT,i).isValid() &&			getFullPlayer(TID_OPPONENT,i).getPos().getX() <= lineX)		{			if (!getFullPlayer(TID_OPPONENT,i).isGoalie())				counter++;			else				counter += 3;		}	for (i = 0; i < HALF_PLAYERS_NUM; i++)		if (getHalfPlayer(TID_OPPONENT,i).isValid() &&			getHalfPlayer(TID_OPPONENT,i).getPos().getX() <= lineX)		{			if (!getHalfPlayer(TID_OPPONENT,i).isGoalie())				counter++;			else				counter += 3;		}		return counter;}int WorldModel::getOppPlayersBetweenLines(float line1X, float line2X) const{	return getOppPlayersBeforeLine(line2X) - getOppPlayersBeforeLine(line1X);}const Player *WorldModel::getTmmGoalie() const{	for (unsigned i = 0; i < FULL_PLAYERS_NUM; i++)		if (getFullPlayer(TID_TEAMMATE, i).isValid() &&			getFullPlayer(TID_TEAMMATE, i).isGoalie())			return fullPlayers[TID_TEAMMATE][i];	for (unsigned i = 0; i < HALF_PLAYERS_NUM; i++)		if (getHalfPlayer(TID_TEAMMATE, i).isValid() &&			getHalfPlayer(TID_TEAMMATE, i).isGoalie())			return halfPlayers[TID_TEAMMATE][i];	return NULL;}const Player *WorldModel::getOppGoalie() const{	for (unsigned i = 0; i < FULL_PLAYERS_NUM; i++)		if (getFullPlayer(TID_OPPONENT, i).isValid() &&			getFullPlayer(TID_OPPONENT, i).isGoalie())			return fullPlayers[TID_OPPONENT][i];	for (unsigned i = 0; i < HALF_PLAYERS_NUM; i++)		if (getHalfPlayer(TID_OPPONENT, i).isValid() &&			getHalfPlayer(TID_OPPONENT, i).isGoalie())			return halfPlayers[TID_OPPONENT][i];	return NULL;}void WorldModel::parseHear(const SExpression &exp){	float hearDir;	unsigned hearCycle;	unsigned senderNum;	SExpAtomic *at;	SExpression *exp2;	resetHearedNums();	at = dynamic_cast<SExpAtomic *>(exp[1]);	assert(at);	hearCycle = at->asInt();	at = dynamic_cast<SExpAtomic *>(exp[2]);	assert(at);	if (at->toString() == "referee")	{		parseRefereeHear(exp);		refereeHearTime = curTime;	}	else if (at->toString().substr(0, 12) == "online_coach")	{		if ((fieldSide == SI_LEFT && at->toString().substr(13, 4) == "left") ||			(fieldSide == SI_RIGHT && at->toString().substr(13, 5) == "right"))		{ // teammate coach.			exp2 = dynamic_cast<SExpression *>(exp[3]);			assert(exp2);			parseTeammateCoachHear(*exp2);		}		else		{ // opponent coach.		}	}	else if (at->toString() == "self")	{		at = dynamic_cast<SExpAtomic *>(exp[3]);		assert(at);		selfHear(at->toString());	}	else // a player has said that.	{		at = dynamic_cast<SExpAtomic *>(exp[2]);		assert(at);		hearDir = at->asInt();		at = dynamic_cast<SExpAtomic *>(exp[3]);		assert(at);		if (at->toString() == "our")		{			at = dynamic_cast<SExpAtomic *>(exp[4]);			assert(at);			senderNum = at->asInt();			at = dynamic_cast<SExpAtomic *>(exp[5]);			assert(at);			teammateHear(hearDir, senderNum, at->toString());		}		else		{			assert(at->toString() == "opp");			at = dynamic_cast<SExpAtomic *>(exp[4]);			assert(at);			opponentHear(hearDir, at->toString());		}	}}void WorldModel::parseRefereeHear(const SExpression &exp){	SExpAtomic *at;	at = dynamic_cast<SExpAtomic *>(exp[3]);	assert(at);	playModeRemainCycle = 0;	// normal PlayModes	if (at->toString() == "before_kick_off")		playMode = PM_BEFORE_KICK_OFF;	else if (at->toString() == "play_on")	{		playMode = PM_PLAY_ON;		virtualPlayMode = VPM_NONE;		playOnStartCycle = curTime;	}	else if (at->toString() == "kick_off_l")	{		if (fieldSide == SI_LEFT)			playMode = PM_KICK_OFF;		else			playMode = PM_KICK_OFF_OPP;		playModeRemainCycle = 200;		ball->updateByHear(0, 0, 0, 0, *body);	}	else if (at->toString() == "kick_off_r")	{		if (fieldSide == SI_RIGHT)			playMode = PM_KICK_OFF;		else			playMode = PM_KICK_OFF_OPP;		playModeRemainCycle = 200;		ball->updateByHear(0, 0, 0, 0, *body);	}	else if (at->toString() == "free_kick_l")	{		if (fieldSide == SI_LEFT)			playMode = PM_FREE_KICK;		else			playMode = PM_FREE_KICK_OPP;		playModeRemainCycle = 200;	}	else if (at->toString() == "free_kick_r")	{		if (fieldSide == SI_RIGHT)			playMode = PM_FREE_KICK;		else			playMode = PM_FREE_KICK_OPP;		playModeRemainCycle = 200;	}	else if (at->toString() == "indirect_free_kick_l")	{		if (fieldSide == SI_LEFT)		{			playMode = PM_FREE_KICK;			virtualPlayMode = VPM_INDIRECT_FREE_KICK;		}		else		{			playMode = PM_FREE_KICK_OPP;			virtualPlayMode = VPM_INDIRECT_FREE_KICK_OPP;		}		playModeRemainCycle = 200;	}	else if (at->toString() == "indirect_free_kick_r")	{		if (fieldSide == SI_RIGHT)		{			playMode = PM_FREE_KICK;			virtualPlayMode = VPM_INDIRECT_FREE_KICK;		}		else		{			playMode = PM_FREE_KICK_OPP;			virtualPlayMode = VPM_INDIRECT_FREE_KICK_OPP;		}		playModeRemainCycle = 200;	}	else if (at->toString() == "kick_in_l")	{		if (fieldSide == SI_LEFT)			playMode = PM_KICK_IN;		else			playMode = PM_KICK_IN_OPP;		playModeRemainCycle = 200;	}	else if (at->toString() == "kick_in_r")	{		if (fieldSide == SI_RIGHT)			playMode = PM_KICK_IN;		else			playMode = PM_KICK_IN_OPP;		playModeRemainCycle = 200;	}	else if (at->toString() == "offside_l")	{		if (fieldSide == SI_LEFT)			playMode = PM_OFFSIDE;		else			playMode = PM_OFFSIDE_OPP;		playModeRemainCycle = 30;	}	else if (at->toString() == "offside_r")	{		if (fieldSide == SI_RIGHT)			playMode = PM_OFFSIDE;		else			playMode = PM_OFFSIDE_OPP;		playModeRemainCycle = 30;	}	else if (at->toString() == "goal_kick_l")	{		if (fieldSide == SI_LEFT)			playMode = PM_GOAL_KICK;		else			playMode = PM_GOAL_KICK_OPP;		virtualPlayMode = VPM_NONE;		playModeRemainCycle = 200;	}	else if (at->toString() == "goal_kick_r")	{		if (fieldSide == SI_RIGHT)			playMode = PM_GOAL_KICK;		else			playMode = PM_GOAL_KICK_OPP;		virtualPlayMode = VPM_NONE;		playModeRemainCycle = 200;	}	else if (at->toString() == "corner_kick_l")	{		if (fieldSide == SI_LEFT)			playMode = PM_CORNER_KICK;		else			playMode = PM_CORNER_KICK_OPP;		playModeRemainCycle = 200;	}	else if (at->toString() == "corner_kick_r")	{		if (fieldSide == SI_RIGHT)			playMode = PM_CORNER_KICK;		else			playMode = PM_CORNER_KICK_OPP;		playModeRemainCycle = 200;	}	else if (at->toString() == "free_kick_fault_l")	{		if (fieldSide == SI_LEFT)			playMode = PM_FREE_KICK_FAULT;		else			playMode = PM_FREE_KICK_FAULT_OPP;		playModeRemainCycle = 30;	}	else if (at->toString() == "free_kick_fault_r")	{		if (fieldSide == SI_RIGHT)			playMode = PM_FREE_KICK_FAULT;		else			playMode = PM_FREE_KICK_FAULT_OPP;		playModeRemainCycle = 30;	}	else if (at->toString() == "catch_fault_l")	{		if (fieldSide == SI_LEFT)			playMode = PM_CATCH_FAULT;		else			playMode = PM_CATCH_FAULT_OPP;		playModeRemainCycle = 30;	}	else if (at->toString() == "catch_fault_r")	{		if (fieldSide == SI_RIGHT)			playMode = PM_CATCH_FAULT;		else			playMode = PM_CATCH_FAULT_OPP;		playModeRemainCycle = 30;	}	else if (at->toString() == "penalty_setup_l")	{		if (fieldSide == SI_LEFT)			playMode = PM_PENALTY_SETUP;		else			playMode = PM_PENALTY_SETUP_OPP;		playModeRemainCycle = 100;		virtualPlayMode = VPM_NONE;	}	else if (at->toString() == "penalty_setup_r")	{		if (fieldSide == SI_RIGHT)			playMode = PM_PENALTY_SETUP;		else			playMode = PM_PENALTY_SETUP_OPP;		playModeRemainCycle = 100;		virtualPlayMode = VPM_NONE;	}	else if (at->toString() == "penalty_ready_l")	{		if (fieldSide == SI_LEFT)			playMode = PM_PENALTY_READY;		else			playMode = PM_PENALTY_READY_OPP;		playModeRemainCycle = 50;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -