Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implementation Risiko #300

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

NuccioDe1
Copy link

No description provided.



int attacker_Dices[3];
int defender_Dices[3];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Evita di usare variabili globali perchè sono "rischiose" e ci si può accedere da qualsiasi punto del codice. Piuttosto potresti creare questi array nel main e passarli alla funzione compare, tipo:

// Definisco la costante della dimensione degli array
#define DIM 3
void compare (int* attacker_Dices, int* defender_Dices){
    //...
}

//...

int main(){
    int* attacker_Dices = new int[DIM];
    int* defender_Dices = new int[DIM];
    //...
    compare(attacker_Dices, defender_Dices);
}

E ovviamente si dovrebbe adattare il codice con la costante definita DIM che incrementa la leggibilità del codice.



cout<<"Blue Dices:\n";
for(int i=0; i<3; i++){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potresti eliminare questo for e utilizzare il precedente per fare le operazioni sul secondo array visto che esse sono indipendenti fra loro, quindi evitare una serie di cicli.





Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consiglio di mettere l'istruzione di return del main e di rimuovere eventuali spazi bianchi (o ritorni a capo) che allungano il codice, quindi migliorare l'indentazione per migliorare la leggibilità del codice.


cout<<"Red Dices:\n";
for(int i=0; i<3; i++){
attacker_Dices[i]= rand() % 5+1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potresti mettere attacker_Dices[i] = rand() % 6; piuttosto che lasciare esplicitamente 5+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants