-
Notifications
You must be signed in to change notification settings - Fork 115
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,58 @@ | |
M 3 vs 3 => blue win | ||
O 2 vs 1 => red win | ||
*/ | ||
|
||
#include <iostream> | ||
#include <algorithm> | ||
#include <cstdlib> | ||
using namespace std; | ||
|
||
|
||
int attacker_Dices[3]; | ||
int defender_Dices[3]; | ||
|
||
void compare(){ | ||
sort(attacker_Dices, attacker_Dices+ 3, greater<int>()); | ||
sort(defender_Dices, defender_Dices + 3, greater<int>()); | ||
for(int i=0; i<3; i++){ | ||
if(defender_Dices[i]>=attacker_Dices[i]) | ||
{ | ||
cout<<"N"<<attacker_Dices[i]<<" vs "<<defender_Dices[i]<< | ||
" ==> Blue Win"<<endl; | ||
} | ||
else | ||
{ | ||
cout<<"N"<<attacker_Dices[i]<<" vs "<<defender_Dices[i]<< | ||
" ==> Red Win"<<endl; | ||
} | ||
} | ||
|
||
} | ||
|
||
int main(){ | ||
srand(rand()%556745+1); | ||
|
||
|
||
cout<<"Red Dices:\n"; | ||
for(int i=0; i<3; i++){ | ||
attacker_Dices[i]= rand() % 5+1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potresti mettere |
||
cout<<attacker_Dices[i]<<endl; | ||
|
||
|
||
} | ||
|
||
|
||
cout<<"Blue Dices:\n"; | ||
for(int i=0; i<3; i++){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
defender_Dices[i]= rand() % 5+1; | ||
cout<<defender_Dices[i]<<endl; | ||
|
||
} | ||
|
||
compare(); | ||
|
||
|
||
|
||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consiglio di mettere l'istruzione di |
||
} |
There was a problem hiding this comment.
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:E ovviamente si dovrebbe adattare il codice con la costante definita DIM che incrementa la leggibilità del codice.