You are playing euchre and you want to know the new score after finishing a hand. There are two teams and each hand consists of 5 tricks. The team who wins the majority of the tricks will win points but the number of points varies. To determine the number of points, you must know which team called trump, how many tricks each team won, and if anyone went alone. Scoring is as follows:

For the team that called trump:

- if they win 2 or less tricks -> other team wins 2 points

- if they win 3 or 4 tricks -> 1 point

- if they don't go alone and win 5 tricks -> 2 points

- if they go alone and win 5 tricks -> 4 points

Only the team who called trump can go alone and you will notice that it only increases your points if you win all 5 tricks.


Your job is to create a method to calculate the new score. When reading the arguments, team 1 is represented by 1 and team 2 is represented by 2. All scores will be stored with this order: { team1, team2 }.

Difficulty: EASY
Tags: Data structures

Game theory
Skill types: Data structures

Starter code:
def update_score(current_score, called_trump, alone, tricks):
	

Solutions:
def update_score(score, trump, alone, tricks):
	done = tricks.count(trump)
	mul = 2 if done == 5 and alone else 1
	add = 1 if done in (3, 4) else 2
	winner = trump if done > 2 else 3 - trump
	return [pts + (add * mul if team == winner else 0) for (team, pts) in enumerate(score, 1)]


def update_score(score, trump, alone, tricks):
	(ts, sc) = (tricks.count(trump), score[:])
	if ts <= 2:
		sc[trump - 1 ^ 1] += 2
	else:
		sc[trump - 1] += [[1, 2][not alone and ts == 5], 4][alone and ts == 5]
	return sc


def update_score(current_score, called_trump, alone, tricks):
	n = tricks.count(called_trump)
	if n <= 2:
		called_trump = 3 - called_trump
		p = 2
	elif n <= 4:
		p = 1
	else:
		p = 4 if alone else 2
	current_score[called_trump > 1] += p
	return current_score


def update_score(current_score, called_trump, alone, tricks):
	new_score = current_score
	won = 0
	for score in tricks:
		if score == called_trump:
			won += 1
	if won <= 2:
		if called_trump == 1:
			new_score[1] += 2
		else:
			new_score[0] += 2
	elif won == 3 or won == 4:
		new_score[called_trump - 1] += 1
	elif won == 5 and alone == True:
		new_score[called_trump - 1] += 4
	else:
		new_score[called_trump - 1] += 2
	return new_score


POINTS = [[0, 2], [0, 2], [0, 2], [1, 0], [1, 0], [2, 0]]

def update_score(current_score, called_trump, alone, tricks):
	n_tricks = tricks.count(called_trump)
	inc = POINTS[n_tricks][:]
	if called_trump == 2:
		inc.reverse()
	return [v + inc[i] + 2 * (i == called_trump - 1 and n_tricks == 5 and alone) for (i, v) in enumerate(current_score)]


def update_score(current_score, called_trump, alone, tricks):
	a = current_score[:]
	w = tricks.count(called_trump)
	if w < 3:
		a[called_trump - 1 ^ 1] += 2
	else:
		a[called_trump - 1] += 1 if w < 5 else 4 if alone else 2
	return a


def update_score(current_score, called_trump, alone, tricks):
	w = tricks.count(called_trump)
	current_score[(w > 2) - called_trump] += 2 - (2 < w < 5) + 2 * (w == 5) * alone
	return current_score


_OUTCOMES = [2, 2, 2, 2, 1, 1, 2, 4]

def update_score(current_score, called_trump, alone, tricks):
	score = [0] + current_score
	winner = 1 + (tricks.count(2) > 2)
	i = 4 * (winner == called_trump) + 2 * (tricks.count(winner) == 5) + alone
	score[winner] += _OUTCOMES[i]
	return score[-2:]


def update_score(current_score, called_trump, alone, tricks):
	tricks_won = sum([int(val / called_trump) for val in tricks if val == called_trump])
	if alone and tricks_won == 5:
		points_won = 4
	elif tricks_won == 5:
		points_won = 2
	elif tricks_won == 5:
		points_won = 2
	elif tricks_won >= 3:
		points_won = 1
	else:
		points_won = 2
		if called_trump == 1:
			called_trump = 2
		else:
			called_trump = 1
	current_score[called_trump - 1] = current_score[called_trump - 1] + points_won
	return current_score


def update_score(current_score, called_trump, alone, tricks):
	score = current_score[:]
	c = tricks.count(called_trump)
	i = called_trump - 1
	if c <= 2:
		score[i ^ 1] += 2
	elif c < 5:
		score[i] += 1
	elif alone:
		score[i] += 4
	else:
		score[i] += 2
	return score