Difference between revisions of "Module:Glolfer"

From Glolf Wiki
Jump to navigation Jump to search
(Update emoji)
(Fix needlethreadableness rating)
 
Line 142: Line 142:
  
 
function precision_rating(p)
 
function precision_rating(p)
return (p.needlethreadableness*0.5 + p.finesse + p.estimation*0.2) * 5/(1+0.2+0.5) - math.abs(p.left_handedness)
+
return ((1-p.needlethreadableness)*0.5 + p.finesse + p.estimation*0.2) * 5/(1+0.2+0.5) - math.abs(p.left_handedness)
 
end
 
end
  

Latest revision as of 16:33, 30 August 2021

Documentation for this module may be created at Module:Glolfer/doc

local pyrandom = require "Module:Pyrandom"

function titlecase(str)
	local buf = {}
	local inWord = false
	for i = 1, #str do
		local c = string.sub(str, i, i)
		if inWord then
			table.insert(buf, string.lower(c))
		else
			table.insert(buf, string.upper(c))
		end
		inWord = (string.find(c, '%a') ~= nil)
	end
	return table.concat(buf)
end

function random_player_emoji(name)
	local humanoid = {
		"👶","👧","🧒","👦","👩","🧑","👨","👩‍🦱","🧑‍🦱","👨‍🦱","👩‍🦰","🧑‍🦰","👨‍🦰","👱‍♀️",
		"👱","👱‍♂️","👩‍🦳","🧑‍🦳","👨‍🦳","👩‍🦲","🧑‍🦲","👨‍🦲","🧔","👵","🧓","👴","👲","👳‍♀️",
		"👳","👳‍♂️","🧕","👮‍♀️","👮","👮‍♂️","👷‍♀️","👷","👷‍♂️","💂‍♀️","💂","💂‍♂️","🕵️‍♀️","🕵️",
		"🕵️‍♂️","👩‍⚕️","🧑‍⚕️","👨‍⚕️","👩‍🌾","🧑‍🌾","👨‍🌾","👩‍🍳","🧑‍🍳","👨‍🍳","👩‍🎓","🧑‍🎓","👨‍🎓","👩‍🎤",
		"🧑‍🎤","👨‍🎤","👩‍🏫","🧑‍🏫","👨‍🏫","👩‍🏭","🧑‍🏭","👨‍🏭","👩‍💻","🧑‍💻","👨‍💻","👩‍💼","🧑‍💼","👨‍💼",
		"👩‍🔧","🧑‍🔧","👨‍🔧","👩‍🔬","🧑‍🔬","👨‍🔬","👩‍🎨","🧑‍🎨","👨‍🎨","👩‍🚒","🧑‍🚒","👨‍🚒","👩‍✈️","🧑‍✈️",
		"👨‍✈️","👩‍🚀","🧑‍🚀","👨‍🚀","👩‍⚖️","🧑‍⚖️","👨‍⚖️","👰","🏋️","🤵","🤸","👸","🤴","🦸‍♀️","🦸",
		"🦸‍♂️","🦹‍♀️","🦹","🦹‍♂️","🤶","🚴","🎅","🧙‍♀️","🧙","🧙‍♂️","🧝‍♀️","🧝","🧝‍♂️","🧛‍♀️","🧛",
		"🧛‍♂️","🧟‍♀️","🧟","🧟‍♂️","🧞‍♀️","🧞","🧞‍♂️","🧜‍♀️","🧜","🧜‍♂️","🧚‍♀️","🧚","🧚‍♂️","👼","🤰",
		"🤱","🙇‍♀️","🙇","🙇‍♂️","💁‍♀️","💁","💁‍♂️","🙅‍♀️","🙅","🙅‍♂️","🙆‍♀️","🙆","🙆‍♂️","🙋‍♀️","🙋",
		"🙋‍♂️","🧏‍♀️","🧏","🧏‍♂️","🤦‍♀️","🤦","🤦‍♂️","🤷‍♀️","🤷","🤷‍♂️","🙎‍♀️","🙎","🙎‍♂️","🙍‍♀️","🙍",
		"🙍‍♂️","💇‍♀️","💇","💇‍♂️","💆‍♀️","💆","💆‍♂️","🧖‍♀️","🧖","🧖‍♂️","💅","🤳","💃","🕺","🕴","👩‍🦽",
		"🧑‍🦽","👨‍🦽","👩‍🦼","🧑‍🦼","👨‍🦼","🚶‍♀️","🚶","🚶‍♂️","👩‍🦯","🧑‍🦯","👨‍🦯","🧎‍♀️","🧎","🧎‍♂️","🏃‍♀️","🏃",
		"🏃‍♂️","🧍‍♀️","🧍","🧍‍♂️","👭","🧑‍🤝‍🧑","👬","👫","👩‍❤️‍👩","💑","👨‍❤️‍👨","👩‍❤️‍👨","👩‍❤️‍💋‍👩","💏","👨‍❤️‍💋‍👨","👩‍❤️‍💋‍👨",
		"👪","👨‍👩‍👦","👨‍👩‍👧","👨‍👩‍👧‍👦","👨‍👩‍👦‍👦","👨‍👩‍👧‍👧","👨‍👨‍👦","👨‍👨‍👧","👨‍👨‍👧‍👦","👨‍👨‍👦‍👦","👨‍👨‍👧‍👧","👩‍👩‍👦","👩‍👩‍👧","👩‍👩‍👧‍👦","👩‍👩‍👦‍👦","👩‍👩‍👧‍👧",
		"👨‍👦","👨‍👦‍👦","👨‍👧","👨‍👧‍👦","👨‍👧‍👧","👩‍👦","👩‍👦‍👦","👩‍👧","👩‍👧‍👦","👩‍👧‍👧","🗣","👤","👥"
	}

	local nonhumanoid={
		"🐶","🐱","🐭","🐹","🐰","🦊","🐻","🐼","🐨","🐯","🦁","🐮","🐷","🐽","🐸","🐵",
		"🙈","🙉","🙊","🐒","🐔","🐧","🐦","🐤","🐣","🐥","🦆","🦅","🦉","🦇","🐺","🐗","🐴","🦄",
		"🐝","🐛","🦋","🐌","🐞","🐞","🦟","🦗","🐞","🦂","🐢","🐍","🦎","🦖","🦕","🐙","🦑","🦐",
		"🦞","🦀","🐡","🐠","🐟","🐬","🐳","🐋","🦈","🐊","🐅","🐆","🦓","🦍","🦧","🐘","🦛","🦏",
		"🐪","🐫","🦒","🦘","🐃","🐂","🐄","🐎","🐖","🐏","🐑","🦙","🐐","🦌","🐕","🐩","🦮","🐕‍🦺",
		"🐈","🐓","🦃","🦚","🦜","🦢","🦩","🕊️","🐇","🦝","🦨","🦡","🦦","🦥","🐁","🐀","🐿","🦔",
		"🐉","🐲","🪐","💫","🌪","🌈","📠","📺"
	}

	local rand = pyrandom.new(titlecase(name))
	if rand:random() > 0.5 then
		return rand:choice(humanoid)
	else
		return rand:choice(nonhumanoid)
	end
end

function generate_random_stlats_from_name(name)
	local rand = pyrandom.new(titlecase(name))
	return {
		nyoomability = math.max(rand:gauss(0,0.3),1.4),
		tofu = rand:random(),
		wiggle = rand:random(),
		ritualism = rand:random(),
		musclitude = rand:random(),
		finesse = rand:random(),
		needlethreadableness = rand:random(), 
		left_handedness = rand:gauss(0,0.3),
		stance = rand:choice({"Tricky","Flashy","Aggro","Tanky","Twitchy","Powerful",
		"Wibble","Wobble","Reverse","Feint","Electric","Spicy","Pomegranate",
		"Explosive","Cottagecore","Corecore","Hardcore","Softcore",
		"Hand to Hand","Lefty","Pop-Punk","DPS","Repose"}),
		fav_tea = rand:choice({"Iced","Boba","White","Green","Oolong",
		"Pu'erh","Chai","Milk","Neon","Sweet","Void","Tea?","Caramel",
		"Lightspeed","Time-traveling","Bloody","Black","Miso","Concrete",
		"Hard-boiled egg","Hot Chocolate","Bubble"}),
		estimation = rand:random(),

		earliness = rand:random(),
		twirliness = rand:random(),
		churliness = rand:random(),
		aceness = rand:random(),
		marbles = rand:randrange(2,4),

		unworthiness = rand:random(),
		splortsmanship = rand:random(),
		tankitude = rand:random(),
		pettiness = rand:random(),
		owlishness = rand:random(),
		disco = rand:random(),
		pettability = rand:random(),
		softness = rand:random(),
		improv = rand:random(),
		tentacles = rand:randrange(0,10),
		capitalism = -rand:random(),
		polkadottedness = 0,
	}
end

function generate_random_player_from_name(name)
	local player = generate_random_stlats_from_name(name)
	player.name = name
	player.emoji = random_player_emoji(name)
	return player
end

function search_array(a, v)
	for i = 1, #a do
		if a[i] == v then
			return true
		end
	end
	return false
end

function sum(a)
	local r = 0
	for i = 1, #a do
		r = r + a[i]
	end
	return r
end

function unpredictability(p)
	local weights = {p.churliness,p.earliness,p.twirliness}
	if search_array({"Aggro","Powerful","Hand to Hand","DPS","Explosive","Hardcore", "Wibble","Electric"}, p.stance) then
		weights[1] = weights[1] + 0.5
	elseif search_array({"Tanky","Twitchy","Repose","Reverse","Softcore",  "Cottagecore","Pomegranate"}, p.stance) then
		weights[2] = weights[2] + 0.5
	elseif search_array("Feint","Tricky","Pop-Punk","Flashy","Spicy",       "Corecore","Wobble","Lefty", p.stance) then
		weights[3] = weights[3] + 0.5
	end

	local chanceOfBiggest = math.max(unpack(weights))/sum(weights)

	local minChance = 1/#weights

	return 1-(chanceOfBiggest-minChance)/(1-minChance)
end

function driving_rating(p)
	return (p.musclitude + p.tofu)*5/2
end

function precision_rating(p)
	return ((1-p.needlethreadableness)*0.5 + p.finesse + p.estimation*0.2) * 5/(1+0.2+0.5) - math.abs(p.left_handedness)
end

function aerodynamics_rating(p)
	return (p.ritualism + p.owlishness + p.softness) * 5/3
end

function self_awareness_rating(p)
	return (p.wiggle*0.5 + (p.marbles-2)/2 + unpredictability(p)*0.8) * 5/(0.5+1+0.8) + p.polkadottedness * 5
end

local known_players = {
	["Polkadot Patterson"] = {
		name="Polkadot Patterson",
		stance="Squiddish",
		fav_tea= "Iced",
		nyoomability = 1.5,
		musclitude=1,
		finesse=1,
		needlethreadableness=1,
		polkadottedness=1,  
		left_handedness= 0,
		estimation=1,
		twirliness=0.3,
		churliness=0.3,
		earliness=0.3,
		aceness=0.3,
		marbles=4,

		tofu=1,
		wiggle=1,
		ritualism=1,
		owlishness=1,
		disco=0.0,
		pettability=0.0,
		softness=1,
		improv=0.0,
		unworthiness=0,
		splortsmanship=1,
		tankitude=1.0,
		pettiness=0.0,
		tentacles=4,
		capitalism=-0.5,
		emoji="😅",
	},
}

function get_player_from_name(name)
	name = titlecase(name)
	return known_players[name] or generate_random_player_from_name(name)
end

local glolfer = {}

function glolfer.emoji(frame)
	local args
	if frame.args.name then
		args = frame.args
	else
		args = frame:getParent().args
	end
	local name = args.name
	return random_player_emoji(name)
end

function glolfer.infobox(frame)
	local args
	if frame.args.name then
		args = frame.args
	else
		args = frame:getParent().args
	end
	local name = args.name
	local p = get_player_from_name(name)
	local template_args = {}
	for k, v in pairs(args) do
		template_args[k] = v
	end
	for k, v in pairs({
		name = name,
		signature = p.emoji,
		stance = p.stance,
		tea = p.fav_tea,
		driving = driving_rating(p),
		grip = precision_rating(p),
		aerodynamics = aerodynamics_rating(p),
		["self-awareness"] = self_awareness_rating(p),
	}) do
		template_args[k] = v
	end

	return frame:expandTemplate{ title = "GlolferInfo", args = template_args}
end

return glolfer