Giter VIP home page Giter VIP logo

Comments (7)

Crayder avatar Crayder commented on June 12, 2024

It's the first full-match... @maddinat0r you should implement a Levenshtein distance algorithm for matching play names. That would be a great way around this. The same would be great for k.

from sscanf.

Crayder avatar Crayder commented on June 12, 2024

Temporarily, I decided to provide @ykosovskyi a solution.

mathMin(inp1,inp2)
	return (inp1 > inp2 ? inp2 : inp1);

LevenshteinDistance(strs[], strt[])
{
	new n = strlen(strs), m = strlen(strt);
	
	new d[128][128];

	if (n == 0)
		return m;

	if (m == 0)
		return n;

	for (new i; i <= n; i++)
		d[i][0] = i;
	
	for (new j; j <= m; j++)
		d[0][j] = j;

	for (new j = 1; j <= m; j++)
	{
		for (new i = 1; i <= n; i++)
		{
			if (strs[i - 1] == strt[j - 1])
				d[i][j] = d[i - 1][j - 1];
			else
				d[i][j] = mathMin(mathMin(d[i - 1][j] + 1, d[i][j - 1] + 1), d[i - 1][j - 1] + 1);
		}
	}
	return d[n][m];
}

SSCANF:pname(string[])
{
	new Iterator:selected<MAX_PLAYERS>;
	new distance[MAX_PLAYERS], least = MAX_PLAYER_NAME;
	
	foreach(new i: Player)
	{
		new name[MAX_PLAYER_NAME];
		GetPlayerName(i, name, sizeof(name));
		
		if(strfind(name, string, true) != -1)
		{
			distance = LevenshteinDistance(string, name);
			
			if(least > distance)
			{
				Iter_Add(selected, i);
				least = distance;
			}
		}
	}
	
	return Iter_Last(selected);
}

As I suggested previously, this uses Levenshtein distance to calculate which player's name matches best. This example uses y_iterate, which vastly simplifies this entire snippet and makes it run pretty darn fast.

In case you don't know how to use "kustom" sscanf params, simply change u to k<pname>.

from sscanf.

ykosovskyi avatar ykosovskyi commented on June 12, 2024

Thank, @Crayder . I did that. While in the sscanf will not be fixed.

new Array_GetPlayerID[MAX_PLAYERS];
stock GetPlayerIDFromName(name[])
{
	new need_len = strlen(name);
	new count = 0;
	forPlayers(i)
	{
		if(strlen(PN(i)) == need_len) Array_GetPlayerID[count++] = i;
	}
	for(new i = 0; i < count; i++)
	{
		if(!strcmp(name, PN(Array_GetPlayerID[i]), false))
		{
			return Array_GetPlayerID[i];
		}
	}
	return INVALID_PLAYER_ID;
}

from sscanf.

Crayder avatar Crayder commented on June 12, 2024

It's not something that needs "fixed" in my opinion, it works as it should. It returns the first full matching player name. That's why I suggested the distance function separately.

from sscanf.

ykosovskyi avatar ykosovskyi commented on June 12, 2024

It would be nice to fix this way:
In the specifier "u" add a check for the length of the input nickname and the one that found, if not the same - continue the search.

from sscanf.

Crayder avatar Crayder commented on June 12, 2024

The input can be any length however, so that will not help

from sscanf.

Y-Less avatar Y-Less commented on June 12, 2024

Check the MATCH_NAME_PARTIAL and CELLMIN_ON_MATCHES options.

from sscanf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.