function calculateScore(tableOfCards)
	local score=0
	for i=1,tableLength(tableOfCards) do
		score=score+tableOfCards[i].power*cardsMultipliers[i]
	end
	return score
end

function calculateHandScore(hand)
	local score=0
	for i=1,tableLength(hand) do
		score=score+hand[i].power
	end
	return score
end

function initCardsMultipliers()
	local multipliers={}
	multipliers[1]=1
	for i=2,16 do
		multipliers[i]=1+(i/10)
	end
	return multipliers
end

function calculateSocialAscensionScore(rankBefore, rankAfter)
	--"president", "vice president", "vice asshole", "asshole", "neutral"
	-- ass-pres: 200, 50 pts per step
	if rankBefore=="neutral" then
		if rankAfter=="president" then
			return 100
		elseif rankAfter=="vice president" then
			return 50
		elseif rankAfter=="vice asshole" then
			return -50
		elseif rankAfter=="asshole" then
			return -100
		end
	elseif rankBefore=="asshole" then
		if rankAfter=="vice asshole" then
			return 50
		elseif rankAfter=="vice president" then
			return 150
		elseif rankAfter=="president" then
			return 200
		end
	elseif rankBefore=="vice asshole" then
		if rankAfter=="asshole" then
			return -50
		elseif rankAfter=="vice president" then
			return 100
		elseif rankAfter=="president" then
			return 150
		end
	elseif rankBefore=="vice president" then
		if rankAfter=="asshole" then
			return -150
		elseif rankAfter=="vice asshole" then
			return -100
		elseif rankAfter=="president" then
			return 50
		end
	elseif rankBefore=="president" then
		if rankAfter=="asshole" then
			return -200
		elseif rankAfter=="vice asshole" then
			return -150
		elseif rankAfter=="vice president" then
			return -50
		end
	end
	return 0
end

function getRankMultiplier(rank)
	if rank=="president" then
		return 1.15
	elseif rank=="vice president" then
		return 1.07
	elseif rank=="neutral" then
		return 1
	elseif rank=="vice asshole" then
		return 0.93
	else
		return 0.85
	end
end


--global vars
--says how many points the 2nd, 3rd... cards have in a combo
cardsMultipliers=initCardsMultipliers()
--says by how much the score is multiplied given the rank
--ranksMultipliers=initRanksMultipliers()




function getPlaceInHighscores(score)
	local place=nil
	for i=10, 1, -1 do
		if score<SCORES["hs"..i] then
			return place
		else
			place=i
		end
	end
	return place
end

function getPlaceInReigns(reign)
	local place=nil
	for i=10, 1, -1 do
		if reign<SCORES["r"..i] then
			return place
		else
			place=i
		end
	end
	return place
end

function insertInHighscore(score, name)
	local place=getPlaceInHighscores(score)
	fdebug("insert in highscores:")
	if place~=nil then
		fdebug("place ~= nil")
		fdebug("for i=10, "..(place+1)..", -1 do")
		for i=10,place+1,-1 do
			fdebug("i="..i)
			SCORES["hs"..i]=SCORES["hs"..(i-1)]
			fdebug("SCORES[\"hs"..i.."\"]=SCORES[\"hs"..(i-1).."\"]")
			SCORES["hsname"..i]=SCORES["hsname"..(i-1)]
		end
		SCORES["hs"..place]=score
		SCORES["hsname"..place]=name
	end
end

function insertInReign(reign, name)
	local place=getPlaceInReigns(reign)
	fdebug("reign="..reign..", place="..place)
	if place~=nil then
		for i=10,place+1,-1 do
			SCORES["r"..i]=SCORES["r"..(i-1)]
			SCORES["rname"..i]=SCORES["rname"..(i-1)]
		end
		SCORES["r"..place]=reign
		SCORES["rname"..place]=name
	end
end























