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

📄 basics.cpp

📁 RoboCup 2D 仿真组老牌强队Mersad 2005的完整源代码
💻 CPP
字号:
/* *  Copyright 2002-2005, Mersad Team, Allameh Helli High School (NODET). * *  This program is free software, you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *  GNU Library General Public License for more details. * *  This file is created by: Ahmad Boorghany *  and is modified by: Mohammad Salehe, Sassan Haradji * *  Released on Monday 1 August 2005, 10 Mordad 1384 by Mersad RoboCup Team. *  For more information please read README file.*/#include <Basics.h>#include <cmath>#include <stdio.h>#include <string.h>using namespace std;namespace Basics{	bool isInPlayers(const unsigned num, const char *str)	{		char charNum = num + '0';		if (num >= 10) charNum = num - 10 + 'A';		for (unsigned i = 0; i < strlen(str); i++)			if (str[i] == charNum) return 1;		return 0;	}	unsigned charToUniNum(const char str)	{		unsigned uniNum = str - '0';		if (str >= 'A') uniNum = str + 10 - 'A';		return uniNum;	}	char uniNumToChar(const unsigned num)	{		char charNum = num + '0';		if (num >= 10) charNum = num - 10 + 'A';		return charNum;	}		unsigned firstPlayerInList(const string list, const string blackList)	{		for (unsigned i = 0; i < list.size(); i++)			if (blackList.find(list[i]) == string::npos)				return charToUniNum(list[i]);		return 0;	}	float reRate(float value, float a, float b, float c,			float d, ReRateMode mode)	{		if (a == b)			return c;		if (mode == RRM_DIRECT)		{			if (value < a)				return c;			if (value > b)				return d;			return (value - a) / (b - a) * (d - c) + c;		}		else		{			if (value < a)				return d;			if (value > b)				return c;			return (value - a) / (b - a) * (c - d) + d;		}	}	float sigmoid(float x)	{		return (float)(1 / (1 + exp(-x)));	}	unsigned changeIntBase(int number, int base, string &str)	{		unsigned i = 0;		for (i = 0; number >= base; i++)		{			str += (char)(number % base) ;			number = (int)((float)number / base);		}		str += (char)number ;		return i + 1;	}	unsigned baghimande(int number, unsigned base)	{		if (number < (int)base)		{			while (number <= (int)base)				number += base;			return (unsigned)(number - base);		}		while (number >= (int)base)			number -= base;		return (unsigned)number;	}		int sign(float number)	{		if (number > 0) return 1;		else if (number < 0) return -1;		return 0;	}}

⌨️ 快捷键说明

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