Advertisement
hugol

Untitled

Dec 7th, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.44 KB | None | 0 0
  1. // Dev-C++ 5.4.2,    Marcin Komor AiR  149067,
  2.  
  3.  
  4. #include <iostream>
  5. #include <cstdlib>
  6. #include <iomanip>
  7. #include <time.h>
  8. #include <vector>
  9.  
  10. using namespace std;
  11.  
  12. const int n=6;
  13. const int m=6;
  14.  
  15.  
  16. void wyczysc (char plansza[n][m])
  17. {
  18.     int i,j;
  19.     for (i=0; i<n; i++){
  20.         for (j=0; j<m; j++){
  21.             plansza[i][j]=0;
  22.         }
  23.     }
  24. }
  25.  
  26. void wypisz (char plansza[n][m])
  27. {  
  28.     for(int i=0; i<n; i++){
  29.         for(int j=0; j<m; j++){
  30.             cout<<setw(6)<<"+-----";
  31.             plansza[i][j];
  32.         }
  33.         static int y=y++;// wtf?
  34.         // dodalem
  35.         cout<<"+"<< i <<endl;
  36.         // wypisywanie kolejnych komorek w poziomie
  37.         for(int x=0; x<2; x++){
  38.             for(int k=0; k<m; k++){
  39.                 if (plansza[i][k])
  40.                 {
  41.                     cout<<"| ### ";
  42.                 }
  43.                 else
  44.                 {
  45.                     cout<<"|     ";
  46.                 }
  47.  
  48.             }
  49.             cout<<"|" <<endl;
  50.         }
  51.  
  52.     } cout<<"+-----+-----+-----+-----+-----+-----+"<<endl;
  53.     for(int z=0; z<m; z++){
  54.         cout<<"   "<< z << setw(5);
  55.     }
  56.     cout<<endl<<endl;
  57.  
  58.  
  59. }
  60.  
  61. void ruch_komputera (char plansza[n][m]){
  62.     int i,j;
  63.     while(1){
  64.         i=rand()%n;
  65.         j=rand()%m;
  66.         if (plansza[i][j]== 0)
  67.         {
  68.             plansza[i][j]= 1;
  69.             return;
  70.         }
  71.     }//komputer ma wstawiac kamienie w losowe miejsca
  72. }
  73.  
  74.  
  75. // deklaracja
  76. int sprawdzenie (char plansza[n][m], char g);
  77.  
  78.  
  79. void ruch_gracza (char gracz, char plansza[n][m]) {
  80.     int wiersz;
  81.     int kolumna;
  82.     int wynik = 0;
  83.     int wynik_komputera = 0;
  84.     // nie wiem czy ta funkcja ma wczytywac w petli ? czy jak
  85.     while(1)
  86.     {  
  87.         cout << "Wynik: " << wynik << " Wynik komputera: " << wynik_komputera << "\n";
  88.         cout << "GraczA podaj wiersz i kolumne:\n";
  89.         cin >> wiersz >> kolumna;
  90.         // dodac sprawdzanie czy >0
  91.  
  92.         if (wiersz>=n || kolumna >=m)
  93.         {
  94.             cout << "NIe ma takiego pola\n";
  95.             // nalezy podjac jakies dzialania w tym przypadku ?
  96.             continue;
  97.         }
  98.         if (plansza[wiersz][kolumna])
  99.         {
  100.             cout << "Podane pole jest juz zajete\n";
  101.             // nalezy podjac jakies dzialania w tym przypadku ?
  102.             continue;
  103.         }
  104.  
  105.         // w przypadku prawidlowych pozycji
  106.         plansza[wiersz][kolumna]=1;
  107.  
  108.  
  109.         wynik =+ sprawdzenie(plansza, 0);
  110.         ruch_komputera(plansza);
  111.         wynik_komputera =+ sprawdzenie(plansza, 0);
  112.        
  113.  
  114.         // wypisywanie planszy od nowa
  115.         system("cls");
  116.         wypisz(plansza);
  117.     }
  118. }
  119.  
  120. int sprawdzenie (char plansza[n][m], char g)
  121. {
  122.     int idukladu= 0;
  123.     static vector<int> ruchy_wykonane;
  124.     // Sprawdzamy 3 w rzedzie
  125.     for(int i=0; i<n; i++) {
  126.         for(int j=0; j<m; j++){
  127.             // korzystanie z leniwej ewaluacji w celu unikniecia wyjscia poza indeks tablicy
  128.             if ((i>=0 && (i+2)<n  && j>=0 && j<m && (plansza[i][j] != 0) && (plansza[i+1][j] != 0) && (plansza[i+2][j] != 0)) ||
  129.                 (i>=0 && i<n  && j>=0 && (j+2)<m && (plansza[i][j] != 0) && (plansza[i][j+1] != 0) && (plansza[i][j+2] != 0)) ||
  130.                 (i>=0 && (i+1)<n  && j>=0 && (j+1)<m && (plansza[i][j] != 0) && (plansza[i+1][j+1] != 0) && (plansza[i+2][j+2] != 0)) ||
  131.                 (i>1 && i<n  && j>0 && (j+2)<m && (plansza[i][j] != 0) && (plansza[i-1][j+1] != 0) && (plansza[i-2][j+2] != 0)))
  132.             {
  133.  
  134.                 // dla szostek 0 zastapic 1
  135.                 int id_ruchu = 1 + j + i *256 + 0*256*256;
  136.                 bool ruch_juz_byl = false;
  137.                 for(int n=0; n<ruchy_wykonane.size(); n++)
  138.                 {
  139.                     if (ruchy_wykonane[n] == id_ruchu)
  140.                     {
  141.                         ruch_juz_byl = true;
  142.                         break;
  143.                     }
  144.                 }
  145.                 if (ruch_juz_byl)
  146.                     continue;
  147.  
  148.                 ruchy_wykonane.push_back(id_ruchu);
  149.                 return 1;
  150.             }
  151.         }
  152.     }
  153.  
  154.     return 0;
  155.  
  156.     // zrobic analogicznie do trojek
  157.     // Sprawdzamy 6 w rzedzie
  158.     for(int i=1; i<n; i++) {
  159.         for(int j=1; j<m; j++){
  160.             if (((plansza[i][j] != 0) && (plansza[i+1][j] != 0) && (plansza[i+2][j] != 0) && (plansza[i+3][j] != 0) && (plansza[i+4][j] != 0) && (plansza[i+5][j] != 0)) ||
  161.                 ((plansza[i][j] != 0) && (plansza[i][j+1] != 0) && (plansza[i][j+2] != 0) && (plansza[i][j+3] != 0) && (plansza[i][j+4] != 0) && (plansza[i][j+5] != 0)) ||
  162.                 ((plansza[i][j] != 0) && (plansza[i+1][j+1] != 0) && (plansza[i+2][j+2] != 0) && (plansza[i+3][j+3] != 0) && (plansza[i+4][j+4] != 0) && (plansza[i+5][j+5] != 0)) ||
  163.                 ((plansza[i][j] != 0) && (plansza[i-1][j+1] != 0) && (plansza[i-2][j+2] != 0) && (plansza[i-3][j+3] != 0) && (plansza[i-4][j+4] != 0) && (plansza[i-5][j+5] != 0))
  164.                 )
  165.             {
  166.                 // bla bla do doribenia
  167.  
  168.                 return 10;
  169.             }
  170.             //wynik2= wynik2+2;
  171.             //return wynik2;
  172.         }
  173.     }
  174.  
  175.     return 0;
  176. }
  177.  
  178.  
  179.  
  180. int main() {
  181.  
  182.     char plansza[n][m];
  183.  
  184.     char g;
  185.     srand(time(NULL));
  186.  
  187.     cout<<"Gra w Kamienie ;)"<<endl;
  188.     cout<<"=================="<<endl<<endl;
  189.  
  190.     wyczysc(plansza);
  191.  
  192.     wypisz(plansza);
  193.  
  194.     ruch_gracza(0, plansza);
  195.  
  196.  
  197.     return 0;
  198. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement