Torna indietro   Hardware Upgrade Forum > Software > Programmazione

Dark Perk Ergo e Sym provati tra wireless, software via browser e peso ridotto
Dark Perk Ergo e Sym provati tra wireless, software via browser e peso ridotto
be quiet! debutta nel settore mouse da gaming con Dark Perk Ergo e Dark Perk Sym: due modelli gemelli per specifiche, con polling rate di 8.000 Hz anche in wireless, sensore PixArt PAW3950 da 32.000 DPI e autonomia dichiarata fino a 110 ore. Nel test, a 8.000 Hz si arriva a circa 30 ore reali, con ricarica completa in un'ora e mezza
DJI RS 5: stabilizzazione e tracking intelligente per ogni videomaker
DJI RS 5: stabilizzazione e tracking intelligente per ogni videomaker
Analizziamo nel dettaglio DJI RS 5, l'ultimo arrivato della famiglia Ronin progettato per videomaker solisti e piccoli studi. Tra tracciamento intelligente migliorato e ricarica ultra rapida, scopriamo come questo gimbal eleva la qualità delle produzioni.
AMD Ryzen 7 9850X3D: Zen 5, 3D V-Cache e frequenze al top per il gaming
AMD Ryzen 7 9850X3D: Zen 5, 3D V-Cache e frequenze al top per il gaming
AMD Ryzen 7 9850X3D è la nuova CPU gaming di riferimento grazie alla 3D V-Cache di seconda generazione e frequenze fino a 5,6 GHz. Nei test offre prestazioni superiori a 9800X3D e 7800X3D, confermando la leadership AMD nel gaming su PC.
Tutti gli articoli Tutte le news

Vai al Forum
Rispondi
 
Strumenti
Old 05-02-2013, 23:58   #1
jokers85
Member
 
Iscritto dal: Jun 2010
Messaggi: 48
[c++] Gioco del tris (correzione e\o suggerimenti)

ho scritto questo programmino per giocare a tris contro il pc, funziona sembra andare bene, ma volevo qualche consiglio su come cercare di migliorarlo

codice:

#include <stdlib.h>
#include <iostream>
#include<math.h>
#include <time.h>

using namespace std;


void campo(char mat[][3]);

void scelta_G(char mat[][3]);

void scelta_C(char mat[][3]);

void scelta_Crand(char mat[][3]);

void randScelta(int& i, int& j);

bool Tris(char mat[][3]);

bool pieno(char mat[][3]);

void tris(char mat[][3], bool& fatto);


int main()

{
system("color 02");
system("CLS");
char scelta;
do{
system("CLS");


char mat[3][3];
for(int i=0; i<3; i++)
for(int j=0; j<3; j++)
mat[i][j]=' ';
bool fatto=false;

campo(mat);

do{
scelta_G(mat);
if(Tris(mat)){
system("CLS");

campo(mat);
cout<<"Hai vinto!!!"<<endl;
break;
}
tris(mat,fatto);
if(!fatto)
scelta_C(mat);

if(Tris(mat))
{
system("CLS");

campo(mat);
cout<<"Hai perso..."<<endl;
break;
}
system("CLS");

campo(mat);

}while(!pieno(mat));

cout<<"Vuoi giocare ancora? (s/n)"<<endl;
do{
cin>>scelta;
}while(scelta!='s' && scelta!='n');

}while(scelta=='s');

//system("PAUSE");
return 0;

}



void campo(char mat[][3])

{

cout<<"1\t |2 \t |3 \n "<<mat[0][0]<<" \t | "
<<mat[0][1]<<" \t | "<<mat[0][2]<<" \n\t | \t | \n";


cout<<" ---------------------------\n";

cout<<"4\t |5 \t |6 \n "<<mat[1][0]<<" \t | "
<<mat[1][1]<<" \t | "<<mat[1][2]<<" \n\t | \t | \n";


cout<<" ---------------------------\n";

cout<<"7\t |8 \t |9 \n "<<mat[2][0]<<" \t | "
<<mat[2][1]<<" \t | "<<mat[2][2]<<" \n\t | \t | \n";



}



void scelta_G(char mat[][3])

{

int scelta;

cin>>scelta;

switch(scelta){

case 1: if(mat[0][0]==' ') mat[0][0]='X';
else return scelta_G(mat); break;


case 2: if(mat[0][1]==' ') mat[0][1]='X';
else return scelta_G(mat); break;


case 3: if(mat[0][2]==' ') mat[0][2]='X';
else return scelta_G(mat); break;


case 4: if(mat[1][0]==' ') mat[1][0]='X';
else return scelta_G(mat); break;


case 5: if(mat[1][1]==' ') mat[1][1]='X';
else return scelta_G(mat); break;


case 6: if(mat[1][2]==' ') mat[1][2]='X';
else return scelta_G(mat); break;


case 7: if(mat[2][0]==' ') mat[2][0]='X';
else return scelta_G(mat); break;


case 8: if(mat[2][1]==' ') mat[2][1]='X';
else return scelta_G(mat); break;


case 9: if(mat[2][2]==' ') mat[2][2]='X';
else return scelta_G(mat); break;

}

}



void scelta_Crand(char mat[][3])

{

int i=0;

int j=0;

randScelta(i,j);
while(mat[i][j]!= ' ' && !pieno(mat))

randScelta(i,j);



if(mat[i][j]==' ')

mat[i][j]='O';
}
void randScelta(int& i, int& j)
{
srand(time(NULL));
i=rand()%3;
j=rand()%3;
}
void scelta_C(char mat[][3])

{
bool fatto=false;
int countC=0;
int countL=0;
int countD1=0;
int countD2=0;
int count=0;
bool freeC=false;
bool freeL=false;
bool freeD1=false;
bool freeD2=false;
int cC,rC,cL,rL,cD1,rD1,cD2,rD2;

for(int i=0; i<3; i++){
countC=0;
countL=0;
count=0;
for(int j=0; j<3; j++){
//Controllo la diagonale principale
if(i==j){
if(mat[i][j]=='X')
countD1++;
else if(mat[i][j]==' '){
freeD1=true;
cD1=i;
rD1=j;
}
}

//Controllo la diagonale secondaria
if(mat[i][3-i-1]=='X' && count==0)
{
countD2++;
count++;
}
else if(mat[i][3-i-1]==' '){
freeD2=true;
cD2=i;
rD2=3-i-1;
}

//Controllo le colonne
if(mat[j][i]=='X')
countC++;
else if(mat[j][i]==' '){
freeC=true;
cC=j;
rC=i;
}

//Controllo le righe
if(mat[i][j]=='X')
countL++;
else if(mat[i][j]==' '){
freeL=true;
cL=i;
rL=j;
}
}

if(countD1==2 && freeD1){
mat[cD1][rD1]='O';
fatto=true;
break;
}
else if(countD2==2 && freeD2){
mat[cD2][rD2]='O';
fatto=true;
break;
}
else if(countC==2 && freeC){
mat[cC][rC]='O';
fatto=true;
break;
}
else if(countL==2 && freeL){
mat[cL][rL]='O';
fatto=true;
break;
}
}
if(!fatto)
scelta_Crand(mat);
}
bool Tris(char mat[][3])

{

int contX=0, contO=0;


for(int i=0; i<3; i++){
contX=0;
contO=0;
for(int j=0; j<3; j++){
if(mat[i][j]=='X')
contX++;

if(mat[i][j]=='O')
contO++;
}

if(contX==3)
return true;

if(contO==3)
return true;
}
contX=0; contO=0;

for(int i=0; i<3; i++){
contX=0;
contO=0;
for(int j=0; j<3; j++){
if(mat[j][i]=='X')
contX++;
if(mat[j][i]=='O')
contO++;

}
if(contX==3)
return true;

if(contO==3)
return true;
}

contX=0; contO=0;

for(int i=0; i<3; i++)
for(int j=0; j<3; j++){
if(i==j && mat[i][j]=='X')
contX++;
if(i==j && mat[i][j]=='O')
contO++;
}

if(contX==3)
return true;

if(contO==3)
return true;

contX=0; contO=0;

for(int i=0; i<3; i++){
if(mat[i][3-i-1]=='X')
contX++;

if(mat[i][3-i-1]=='O')
contO++;
}


if(contX==3)
return true;

if(contO==3)
return true;

return false;

}



bool pieno(char mat[][3])

{



for(int i=0; i<3; i++)

for(int j=0; j<3; j++)

if(mat[i][j]==' ')

return false;

return true;



}
void tris(char mat[][3], bool& fatto)
{

fatto=false;
int countC=0;
int countL=0;
int countD1=0;
int countD2=0;
int count=0;
bool freeC=false;
bool freeL=false;
bool freeD1=false;
bool freeD2=false;
int cC,rC,cL,rL,cD1,rD1,cD2,rD2;

for(int i=0; i<3; i++){
countC=0;
countL=0;
count=0;
for(int j=0; j<3; j++){

if(i==j){
if(mat[i][j]=='O')
countD1++;
else if(mat[i][j]==' '){
freeD1=true;
cD1=i;
rD1=j;
}
}

if(mat[i][3-i-1]=='O' && count==0){
countD2++;
count++;
}
else if(mat[i][3-i-1]==' '){
freeD2=true;
cD2=i;
rD2=3-i-1;
}

if(mat[j][i]=='O')
countC++;
else if(mat[j][i]==' '){
freeC=true;
cC=j;
rC=i;
}

if(mat[i][j]=='O')
countL++;
else if(mat[i][j]==' '){
freeL=true;
cL=i;
rL=j;
}
}

if(countD1==2 && freeD1){
mat[cD1][rD1]='O';
fatto=true;
break;
}
else if(countD2==2 && freeD2){
mat[cD2][rD2]='O';
fatto=true;
break;
}
else if(countC==2 && freeC){
mat[cC][rC]='O';
fatto=true;
break;
}
else if(countL==2 && freeL){
mat[cL][rL]='O';
fatto=true;
break;
}
}


}
jokers85 è offline   Rispondi citando il messaggio o parte di esso
 Rispondi


Dark Perk Ergo e Sym provati tra wireless, software via browser e peso ridotto Dark Perk Ergo e Sym provati tra wireless, softw...
DJI RS 5: stabilizzazione e tracking intelligente per ogni videomaker DJI RS 5: stabilizzazione e tracking intelligent...
AMD Ryzen 7 9850X3D: Zen 5, 3D V-Cache e frequenze al top per il gaming AMD Ryzen 7 9850X3D: Zen 5, 3D V-Cache e frequen...
Le soluzioni FSP per il 2026: potenza e IA al centro Le soluzioni FSP per il 2026: potenza e IA al ce...
AWS annuncia European Sovereign Cloud, il cloud sovrano per convincere l'Europa AWS annuncia European Sovereign Cloud, il cloud ...
3 TV da 55" crollano di prezzo: c'&...
Segway Navimow presenta la nuova gamma d...
Xiaomi SU7 Pro: l'ispezione dopo 265.000...
Nimbus Innovation Awards 2026: le miglio...
SSD Samsung contraffatto, ma Windows e C...
Enrique Lores, CEO e presidente di HP, l...
SoftBank e Intel preparano la 'memoria d...
Il blocco dei porno per i minori è...
AMD: i nuovi processori Zen 6 saranno (i...
Ancora aumenti per le schede video Radeo...
Sonos presenta Amp Multi a ISE 2026: il ...
Una funzione esclusiva dei Pixel potrebb...
La Cina vieta ufficialmente le maniglie ...
HP e lavoro ibrido: le nuove cuffie Poly...
MSI sta lavorando a un dissipatore ottim...
Chromium
GPU-Z
OCCT
LibreOffice Portable
Opera One Portable
Opera One 106
CCleaner Portable
CCleaner Standard
Cpu-Z
Driver NVIDIA GeForce 546.65 WHQL
SmartFTP
Trillian
Google Chrome Portable
Google Chrome 120
VirtualBox
Tutti gli articoli Tutte le news Tutti i download

Strumenti

Regole
Non Puoi aprire nuove discussioni
Non Puoi rispondere ai messaggi
Non Puoi allegare file
Non Puoi modificare i tuoi messaggi

Il codice vB è On
Le Faccine sono On
Il codice [IMG] è On
Il codice HTML è Off
Vai al Forum


Tutti gli orari sono GMT +1. Ora sono le: 07:53.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Served by www3v