Profilo di
delion bart
| Nome | delion bart |
|---|---|
| Indirizzo email | delionbart3681@gmail.com |
| Avatar | ![]() |
| Messaggi | 2 |
-
- 2025-12-15 14:11:03
- Re: Pseudo codice per prime armi.
- Forum >> Principianti
- Alexander92319 said @ 2020-11-01 04:13:22:Give me some advice so I can optimize this code. Just pseudo code please, thanks
"'
We have four players competing in Scrabble+. In every hand
of Scrabble+, players, in turn, must insert a word into the
scoreboard and get a score, calculated based on the value
of the letters that make up the inserted word.
Each player creates their own word by choosing it from a
hand of 8 letters, which are replaced once the word
it was played, until they are sold out. The total number of
letters is 130. The game ends when a player manages to
finish all the letters in his hand and there are no more letters to
provision to replace those he has just played (i.e.,
the 130 letters are sold out, because they are played or because they are in the hand
to other players).
At the end of the plays, the player who has accumulated the most wins
points, considering that for each letter that remains unplayed
(i.e. remains in the hands of a player when the game ends)
3 points are subtracted.
The scores are calculated as follows:
1 point: E, A, I, O, N, R, T, L, S, U
2 points: D, G
3 points: B, C, M, P
4 points: F, H, V, W, Y
5 points: K
8 points: J, X
10 points: Q, Z
Design a function ex1(g1, g2, g3, g4, dim_hand, num_letters) that calculates the
scores from a Scrabble+ game played between the 4 players, with
the variant that the number of initial letters is num_letters, rather than
130 and the number of letters available to each player is dim_hand.
g1, g2, g3 and g4 are lists of strings representing the
plays of players g1, g2, g3 and g4, respectively,
in each shift.
ES: dim_hand=5, num_letters=40
g1 = ['silk','peeks','deter']
g2 = ['reo','pumas']
g3 = ['xx','xx']
g4 = ['frs','bern']
Note that at the beginning of the game 5 letters are given to each of the
players, so the num_letters counter decreases accordingly.
dim_hand - num_letters - word - dots
5 5 5 5 20 silk 4 0 0 0
5 5 5 5 16 guilty 4 3 0 0
5 5 5 5 13 xx 4 3 16 0
5 5 5 5 11 frs 4 3 16 6
5 5 5 5 8 peeks 15 3 16 6
5 5 5 5 3 pumas 15 12 16 6
5 3 5 5 0 xx 15 12 32 6
5 3 3 5 0 bern 15 12 32 12
5 3 3 1 0 deter 21 12 32 12
0 3 3 1 0 GAME OVER
-------------------------------------
Final 21 3 23 9
"'
def calculate_value(word):
value = 0
dictionary_scores = {
"a":1,"e":1,"i":1,"o":1,"n":1,"r":1,"t":1,"l":1,"s":1,"u":1,
"d":2,"g":2,
"b":3,"c":3,"m":3,"p":3,
"f":4,"h":4,"v":4,"w":4,"y":4,
"k":5,
"j":8,"x":8,
"q":10,"z":10,
}
for letter in word:
value += dictionary_scoresletter
return value
def ex1(g1, g2, g3, g4, dim_hand, num_letters):
lung_g1 = 0
lung_g2 = 0
lung_g3 = 0
lung_g4 = 0
hand_letters_G1 = dim_hand
letters_hand_G2 = dim_hand
letters_hand_G3 = dim_hand
hand_letters_G4 = dim_hand
score_list = [0,0,0,0]
num_letters -= dim_hand * 4
while letters_hand_G1 > 0 and letters_hand_G2 > 0 and letters_hand_G3 > 0 and letters_hand_G4 > 0 or num_letters > 0:
if lung_g1 <= len(g1) - 1:
word_G1 = g1lung g1
score_G1 = calculate_value(word_G1)
score_list0 += score_G1
lung_g1 += 1
#Calcolo the values of G1 with the cycle
letters_hand_G1 -= len(word_G1)
#Scarico G1's hand
if num_letters > 0:
if letters_hand_G1 + num_letters > dim_hand:
letters_hand_G1 += len(word_G1)
elif letters_hand_G1 + num_letters <= dim_hand:
letters_hand_G1 += num_letters
#carico G1's hand
num_letters -= len(word_G1)
#Scarico the deck
#turno 1
if lung_g2 <= len(g2) - 1:
word_G2 = g2lung g2
score_G2 = calculate_value(word_G2)
score_list1 += score_G2
lung_g2 += 1
#Calcolo the values of G2 with the cycle
letters_hand_G2 -= len(word_G2)
#Scarico G2's hand
if num_letters > 0:
if letters_hand_G2 + num_letters > dim_hand:
letters_hand_G2 += len(word_G2)
elif letters_hand_G2 + num_letters <= dim_hand:
letters_hand_G2 += num_letters
#carico G2's hand
num_letters -= len(word_G2)
#Scarico the deck
#turno 2
if lung_g3 <= len(g3) - 1:
word_G3 = g3lung g3
score_G3 = calculate_value(word_G3)
score_list2 += score_G3
lung_g3 += 1
#Calcolo the values of G3 with the cycle
letters_hand_G3 -= len(word_G3)
#Scarico G3's hand
if num_letters > 0:
if letters_hand_G3 + num_letters > dim_hand:
letters_hand_G3 += len(word_G3)
elif letters_hand_G3 + num_letters <= dim_hand:
letters_hand_G3 += num_letters
#carico G3's hand
num_letters -= len(word_G3)
#Scarico the deck
#turno 3
if lung_g4 <= len(g4) - 1:
word_G4 = g4lung g4
score_G4 = calculate_value(word_G4)
score_list3 += score_G4
lung_g4 += 1
#Calcolo the values of G4 with the cycle
letters_hand_G4 -= len(word_G4)
#Scarico G2's hand
if num_letters > 0:
if letters_hand_G4 + num_letters > dim_hand:
letters_hand_G4 += len(word_G4)
elif letters_hand_G4 + num_letters <= dim_hand:
letters_hand_G4 += num_letters
#carico G4's hand
num_letters -= len(word_G4)
#Scarico the deck
#turno 4
score_list0 -= hand_letters_G1 * 3
score_list1 -= hand_letters_G2 * 3
score_list2 -= hand_letters_G3 * 3
score_list3 -= hand_letters_G4 * 3
return list_scores
passNice breakdown 👍
To optimize this, try treating all players uniformly using arrays/objects, run the game in round-based loops, and move repeated logic (word play, refill, scoring) into small helper functions. This will remove duplication, reduce bugs, and make the game flow much easier to manage and extend.
-
- 2025-11-22 08:12:51
- Re: Problema Raspberry PI con NavigationToolbar2Tk
- Forum >> Programmazione Python >> GUI
- This error usually happens because your Raspberry Pi is running an older version of matplotlib. In itNavigationToolbar2Tk didn't exist yet — it was called NavigationToolbar2TkAgg.
Try
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
Unselfishness
If you want to use the new name (NavigationToolbar2Tk), update matplotlib:
pip3 install --upgrade matplotlib
But on a Pi 3 with Python 3.5, upgrading may be limited, so using NavigationToolbar2TkAgg is usually the simplest fix.
--- Ultima modifica di delion bart in data 2025-11-22 08:13:28 ---
--- Ultima modifica di delion bart in data 2025-11-22 08:13:55 ---

