pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

binaryfire private pastebin - collaborative debugging tool What's a private pastebin?


Posted by Binary_Fire on Tue 13 May 21:19
report spam | download | new post

  1. //X si 0 versiunea veche
  2.  
  3. #include<gl/gl.h>
  4. #include<gl/glut.h>
  5. #include<iostream>
  6.  
  7. int arena[3][3];
  8. int winer=0,term=0;
  9. static float coord_x,coord_y;
  10. static int m_w,m_h;
  11. //declar font-ul folosit
  12. GLubyte space[] =
  13. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  14. GLubyte letters[][13] = {
  15. {0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0xff, 0xc3, 0xc3, 0xc3, 0x66, 0x3c, 0x18},
  16. {0x00, 0x00, 0xfe, 0xc7, 0xc3, 0xc3, 0xc7, 0xfe, 0xc7, 0xc3, 0xc3, 0xc7, 0xfe},
  17. {0x00, 0x00, 0x7e, 0xe7, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xe7, 0x7e},
  18. {0x00, 0x00, 0xfc, 0xce, 0xc7, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc7, 0xce, 0xfc},
  19. {0x00, 0x00, 0xff, 0xc0, 0xc0, 0xc0, 0xc0, 0xfc, 0xc0, 0xc0, 0xc0, 0xc0, 0xff},
  20. {0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xfc, 0xc0, 0xc0, 0xc0, 0xff},
  21. {0x00, 0x00, 0x7e, 0xe7, 0xc3, 0xc3, 0xcf, 0xc0, 0xc0, 0xc0, 0xc0, 0xe7, 0x7e},
  22. {0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xff, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3},
  23. {0x00, 0x00, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7e},
  24. {0x00, 0x00, 0x7c, 0xee, 0xc6, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06},
  25. {0x00, 0x00, 0xc3, 0xc6, 0xcc, 0xd8, 0xf0, 0xe0, 0xf0, 0xd8, 0xcc, 0xc6, 0xc3},
  26. {0x00, 0x00, 0xff, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0},
  27. {0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xdb, 0xff, 0xff, 0xe7, 0xc3},
  28. {0x00, 0x00, 0xc7, 0xc7, 0xcf, 0xcf, 0xdf, 0xdb, 0xfb, 0xf3, 0xf3, 0xe3, 0xe3},
  29. {0x00, 0x00, 0x7e, 0xe7, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xe7, 0x7e},
  30. {0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xfe, 0xc7, 0xc3, 0xc3, 0xc7, 0xfe},
  31. {0x00, 0x00, 0x3f, 0x6e, 0xdf, 0xdb, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0x66, 0x3c},
  32. {0x00, 0x00, 0xc3, 0xc6, 0xcc, 0xd8, 0xf0, 0xfe, 0xc7, 0xc3, 0xc3, 0xc7, 0xfe},
  33. {0x00, 0x00, 0x7e, 0xe7, 0x03, 0x03, 0x07, 0x7e, 0xe0, 0xc0, 0xc0, 0xe7, 0x7e},
  34. {0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xff},
  35. {0x00, 0x00, 0x7e, 0xe7, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3},
  36. {0x00, 0x00, 0x18, 0x3c, 0x3c, 0x66, 0x66, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3},
  37. {0x00, 0x00, 0xc3, 0xe7, 0xff, 0xff, 0xdb, 0xdb, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3},
  38. {0x00, 0x00, 0xc3, 0x66, 0x66, 0x3c, 0x3c, 0x18, 0x3c, 0x3c, 0x66, 0x66, 0xc3},
  39. {0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x3c, 0x66, 0x66, 0xc3},
  40. {0x00, 0x00, 0xff, 0xc0, 0xc0, 0x60, 0x30, 0x7e, 0x0c, 0x06, 0x03, 0x03, 0xff}
  41. };
  42. GLuint fontOffset;
  43. void makeRasterFont(void)
  44. {
  45. GLuint i, j;
  46. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  47. fontOffset = glGenLists (128);
  48. for (i = 0,j = 'A'; i < 26; i++,j++) {
  49. glNewList(fontOffset + j, GL_COMPILE);
  50. glBitmap(8, 13, 0.0, 2.0, 10.0, 0.0, letters[i]);
  51. glEndList();
  52. }
  53. glNewList(fontOffset + ' ', GL_COMPILE);
  54. glBitmap(8, 13, 0.0, 2.0, 10.0, 0.0, space);
  55. glEndList();
  56. }
  57. void init(void)
  58. {
  59. glShadeModel (GL_FLAT);
  60. makeRasterFont();
  61. }
  62. void printString(char *s)
  63. {
  64. glPushAttrib (GL_LIST_BIT);
  65. glListBase(fontOffset);
  66. glCallLists(strlen(s), GL_UNSIGNED_BYTE, (GLubyte *) s);
  67. glPopAttrib ();
  68. }
  69. //terminarea functiei de afisare a textului
  70.  
  71. int castigator() //verific daca exista un castigator
  72. {int i,j,i2,j2,linie,egal=1;
  73.  for (i=0;i<=2;i++)
  74.    for (j=0;j<=2;j++)
  75.      {if (arena[i][j]==1)
  76.            {linie=1;
  77.             for (i2=0;i2<=2;i2++)
  78.               if (arena[i2][j]!=1) linie=0;
  79.             if (linie==1) winer=1;
  80.             else {linie=1;
  81.                   for (j2=0;j2<=2;j2++)
  82.                     if (arena[i][j2]!=1) linie=0;
  83.                   if (linie==1) winer=1;
  84.                   else {linie=1;
  85.                         if (i==j)
  86.                               {j2=0;
  87.                                for (i2=0;i2<=2;i2++)
  88.                                 {if (arena[i2][j2]!=1) linie=0;
  89.                                  j2++;}}
  90.                         else if (i==(j+2) || j==(i+2))
  91.                               {j2=2;
  92.                                for (i2=0;i2<=2;i2++)
  93.                                 {if (arena[i2][j2]!=1) linie=0;
  94.                                  j2--;}}
  95.                              else linie=0;
  96.                         if (linie==1) winer=1;    
  97.                         }
  98.                   }
  99.             }
  100.       else if (arena[i][j]==2)
  101.              {linie=1;
  102.               for (i2=0;i2<=2;i2++)
  103.                 if (arena[i2][j]!=2) linie=0;
  104.               if (linie==1) winer=2;
  105.               else {linie=1;
  106.                   for (j2=0;j2<=2;j2++)
  107.                     if (arena[i][j2]!=2) linie=0;
  108.                   if (linie==1) winer=2;
  109.                   else {linie=1;
  110.                         if (i==j)
  111.                               {j2=0;
  112.                                for (i2=0;i2<=2;i2++)
  113.                                 {if (arena[i2][j2]!=2) linie=0;
  114.                                  j2++;}}
  115.                         else if (i==(j+2) || j==(i+2))
  116.                               {j2=2;
  117.                                for (i2=0;i2<=2;i2++)
  118.                                 {if (arena[i2][j2]!=2) linie=0;
  119.                                  j2--;}}
  120.                              else linie=0;
  121.                         if (linie==1) winer=2;    
  122.                         }
  123.                   }
  124.             }
  125.       if (arena[i][j]==0 || winer!=0) egal=0;
  126.       }
  127.  if (egal) winer=3;
  128.  return winer;
  129. }
  130.  
  131. void display_arena(void)
  132. {int i,j;
  133.  float c_x,c_y,c_z,c_t;
  134.  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  135.  glColor3f(0.0,0.0,1.0);
  136.  glRasterPos2f(0,9.5);
  137.  printString("PRESS ESCAPE TO EXIT");
  138.  glColor3f(0.0,1.0,0.0);
  139.  glBegin(GL_LINE_LOOP);
  140.     glVertex2i(2,2);
  141.     glVertex2i(2,8);
  142.     glVertex2i(8,8);
  143.     glVertex2i(8,2);
  144.  glEnd();
  145.  glBegin(GL_LINES);
  146.     glVertex2i(2,4);
  147.     glVertex2i(8,4);
  148.     glVertex2i(2,6);
  149.     glVertex2i(8,6);
  150.     glVertex2i(4,8);
  151.     glVertex2i(4,2);
  152.     glVertex2i(6,8);
  153.     glVertex2i(6,2);
  154.  glEnd();
  155.  glBegin(GL_LINES);
  156.     for (i=2;i>=0;i--)
  157.       for (j=0;j<=2;j++)
  158.         {if (j==0) c_x=2.5;
  159.          else if (j==1) c_x=4.5;
  160.               else c_x=6.5;
  161.          if (i==0) c_y=2.5;
  162.          else if (i==1) c_y=4.5;
  163.               else c_y=6.5;
  164.          c_z=c_x+1;
  165.          c_t=c_y+1;
  166.          if (arena[i][j]==1) {glColor3f(1.0,0.0,0.0);  //desenez mutarea user-ului
  167.                               glVertex2f(c_x,c_y);
  168.                               glVertex2f(c_z,c_t);
  169.                               glVertex2f(c_x,c_t);
  170.                               glVertex2f(c_z,c_y);
  171.                               }
  172.          else
  173.          if (arena[i][j]==2) {glColor3f(1.0,1.0,1.0); //desenez mutarea pc-ului
  174.                               glVertex2f(c_x,c_y);
  175.                               glVertex2f(c_x,c_t);
  176.                               glVertex2f(c_x,c_t);
  177.                               glVertex2f(c_z,c_t);
  178.                               glVertex2f(c_z,c_t);
  179.                               glVertex2f(c_z,c_y);
  180.                               glVertex2f(c_z,c_y);
  181.                               glVertex2f(c_x,c_y);
  182.                              }
  183.          }
  184.  glEnd();
  185.  glColor3f(0.6,1.0,1.0);
  186.  if (winer==1) {glRasterPos2i(4,1);
  187.                 printString("YOU WON");
  188.                 glRasterPos2f(1.3,0.5);
  189.                 printString("PRESS Y FOR ANOTHER GAME");
  190.                 term=1;}
  191.  else if (winer==2) {glRasterPos2i(4,1);
  192.                      printString("YOU LOSE");
  193.                      glRasterPos2f(1.3,0.5);
  194.                      printString("PRESS Y FOR ANOTHER GAME");
  195.                      term=1;}
  196.       else if (winer==3)  {glRasterPos2i(4,1);
  197.                            printString("DRAW");
  198.                            glRasterPos2f(1.3,0.5);
  199.                            printString("PRESS Y FOR ANOTHER GAME");
  200.                            term=1;}
  201.  glFlush();
  202.  }
  203.  
  204. void resize(int w, int h)
  205. {glViewport(0, 0, (GLsizei)w, (GLsizei)h);
  206.  m_w=w;
  207.  m_h=h;
  208.  glMatrixMode(GL_PROJECTION);
  209.  glLoadIdentity();
  210.  glOrtho(0.0, 10.0, 0.0, 10.0, -1.0, 1.0);
  211.  glMatrixMode(GL_MODELVIEW);
  212.  glLoadIdentity();
  213.  }
  214.  
  215. int cautare_mutare(int seeker,int i,int j)
  216. {int nr_el,loc_liber,i2,j2,mutare=0;
  217.  nr_el=0;loc_liber=-1;
  218.  for (i2=0;i2<=2;i2++)
  219.       if (arena[i2][j]==seeker) nr_el++;
  220.       else if(arena[i2][j]==0) loc_liber=i2;
  221.       if (nr_el==2 && loc_liber!=-1 && mutare==0) {arena[loc_liber][j]=2;mutare=1;}
  222.       if (mutare==0)
  223.             {nr_el=0;loc_liber=-1;
  224.              for (j2=0;j2<=2;j2++)
  225.              if (arena[i][j2]==seeker) nr_el++;
  226.              else if(arena[i][j2]==0) loc_liber=j2;
  227.             }
  228.       if (nr_el==2 && loc_liber!=-1 && mutare==0) {arena[i][loc_liber]=2;mutare=1;}
  229.       if (mutare==0 && i==j)
  230.             {nr_el=0;loc_liber=-1;j2=0;
  231.              for (i2=0;i2<=2;i2++)
  232.              {if (arena[i2][j2]==seeker) nr_el++;
  233.               else if (arena[i2][j2]==0) loc_liber=i2;
  234.               j2++;}
  235.              if (nr_el==2 && loc_liber!=-1 && mutare==0) {arena[loc_liber][loc_liber]=2;
  236.                                                           mutare=1;}
  237.              }
  238.       if (mutare==0 && (i==j+2 || j==i+2))
  239.            {nr_el=0;loc_liber=-1;j2=2;
  240.             for (i2=0;i2<=2;i2++)
  241.               {if (arena[i2][j2]==seeker) nr_el++;
  242.                else if (arena[i2][j2]==0) loc_liber=i2;
  243.                j2--;}
  244.             if (nr_el==2 && loc_liber!=-1 && mutare==0)
  245.                {if (loc_liber==0) arena[loc_liber][2]=2;
  246.                 else if (loc_liber==1) arena[loc_liber][1]=2;
  247.                      else arena[loc_liber][0]=2;
  248.                 mutare=1;}
  249.                }
  250.  return mutare;
  251. }
  252.  
  253. void pc_move() //muta pc-ul
  254. {int i,j,mutare=0,i_lib,j_lib;
  255.  for (i=0;i<=2;i++)
  256.    for (j=0;j<=2;j++)
  257.      if (arena[i][j]==2 && mutare==0) mutare=cautare_mutare(2,i,j);
  258.  if (mutare==0)
  259.    for (i=0;i<=2;i++)
  260.      for (j=0;j<=2;j++)
  261.        if (arena[i][j]==1 && mutare==0) mutare=cautare_mutare(1,i,j);
  262.        else if(arena[i][j]==0) {i_lib=i;j_lib=j;}  
  263.  if (mutare==0) arena[i_lib][j_lib]=2;
  264. }
  265.  
  266. void keyboard(unsigned char key,int x,int y)
  267. {int i,j;
  268.      
  269.  if (key==27) exit(0);
  270.  else if (key=='y' && winer!=0)
  271.       {for (i=0;i<=2;i++)
  272.          for (j=0;j<=2;j++)
  273.              arena[i][j]=0;
  274.        winer=0;term=0;
  275.        glutPostRedisplay();}  
  276. }
  277.  
  278. void mouse (int button,int state,int x,int y)
  279. {int i,j;
  280.  
  281.  if (button==GLUT_LEFT_BUTTON)
  282.    if (state==GLUT_DOWN )                           //voi transforma coord x si y (a pointerului)
  283.             {coord_x=((float)x*100/m_w)*10/100;     //in sist. ortogonal definit de mine (10x10)
  284.              coord_y=10-((float)y*100/m_h)*10/100;  //folosesc float pentru a avea o precizie mare
  285.              if (coord_x>2 && coord_x<8 && coord_y>2 && coord_y<8)
  286.              {if (coord_x<4) j=0;
  287.               else if (coord_x>4 && coord_x<6) j=1;
  288.                    else j=2;
  289.               if (coord_y<4) i=0;
  290.               else if (coord_y>4 && coord_y<6) i=1;
  291.                    else i=2;
  292.               if (arena[i][j]==0) {arena[i][j]=1;castigator();
  293.                                    if (winer==0) pc_move();
  294.                                    castigator();}
  295.               if (winer==0 || term==0) glutPostRedisplay();
  296.              }
  297.             }
  298. }
  299.  
  300. int main(int argc,char** argv)
  301. {int i,j;
  302.  for (i=0;i<=2;i++)
  303.   for (j=0;j<=2;j++)
  304.     arena[i][j]=0;
  305.  glutInit(&argc,argv);
  306.  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  307.  glutInitWindowSize(300,300);
  308.  glutInitWindowPosition(350,350);
  309.  glutCreateWindow("Tic-Tac-Toe");
  310.  init();
  311.  glutReshapeFunc(resize);
  312.  glutKeyboardFunc(keyboard);
  313.  glutMouseFunc(mouse);
  314.  glutDisplayFunc(display_arena); //desenez terenul
  315.  glutMainLoop();
  316.  return 0;
  317.  }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me