Advertisement
pkramer

tictactoe.sce

Jul 19th, 2011
548
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 3.38 KB | None | 0 0
  1. board = ['-','-','-';'-','-','-';'-','-','-'];
  2. running = 1;
  3. round = 0;
  4.  
  5. mtlb_fprintf('Welcome to tictacto bitches!');
  6.  
  7. while(running == 1)
  8.  
  9.     //figure whos turn it is
  10.     if(pmodulo(round,2) == 0)
  11.         mtlb_fprintf('~= Xs Turn =~');
  12.         turn = 'X';
  13.     else
  14.         mtlb_fprintf('~= Os Turn =~');
  15.         turn = 'O';
  16.     end
  17.    
  18.     col = input('Column:');
  19.     row = input('Row:   ');
  20.  
  21.     // check if space if valid, if so then set acc|ding to turn
  22.     if (0)
  23.         mtlb_fprintf('!> Enter a number dumbass');
  24.     else
  25.         if ((col >= 0) & (col <= 3) & (row >= 0) & (row <= 3))
  26.             if(board(row,col) == '-')
  27.                 round = round + 1;
  28.                 board(row,col) = turn;
  29.             else
  30.                 mtlb_fprintf(' That space is taken jerkoff');
  31.             end
  32.         else
  33.             mtlb_fprintf(' This is tictactoe idiot, try a space that exists');
  34.         end
  35.     end
  36.    
  37.     mtlb_fprintf('');
  38.     disp(board);
  39.     mtlb_fprintf('');    
  40.    
  41.     //VICT|Y CONDITIONS
  42.     //row 1
  43.     if((board(1,1) == board(1,2)) & (board(1,2) == board(1,3)))
  44.         if (board(1,1)  ~= '-')
  45.             winner = board(1,1);
  46.             mtlb_fprintf('%s wins... congratualtions on beating yourself without porn', winner);
  47.             running = 0;
  48.         end
  49.     end
  50.    
  51.     // row 2
  52.     if((board(2,1) == board(2,2)) & (board(2,2) == board(2,3)))
  53.         if (board(2,1) ~= '-')
  54.             winner = board(2,1);
  55.             mtlb_fprintf('%s wins... congratualtions on beating yourself without porn', winner);
  56.             running = 0;
  57.         end
  58.     end
  59.    
  60.     // row 3
  61.     if((board(3,1) == board(3,2)) & (board(3,2) == board(3,3)))
  62.         if(board(3,1)  ~= '-')
  63.             winner = board(3,1);
  64.             mtlb_fprintf('%s wins... congratualtions on beating yourself without porn', winner);
  65.             running = 0;
  66.         end
  67.     end
  68.    
  69.     // column 1
  70.     if((board(1,1) == board(2,1)) & (board(2,1) == board(3,1)))
  71.         if (board(1,1)  ~= '-')
  72.             winner = board(1,1);
  73.             mtlb_fprintf('%s wins... congratualtions on beating yourself without porn', winner);
  74.             running = 0;
  75.         end
  76.     end
  77.    
  78.     // column 2
  79.     if((board(1,2) == board(2,2)) & (board(2,2) == board(3,2)))
  80.         if (board(1,2)  ~= '-')
  81.             winner = board(1,2);
  82.             mtlb_fprintf('%s wins... congratualtions on beating yourself without porn', winner);
  83.             running = 0;
  84.         end
  85.     end
  86.    
  87.     // column 3
  88.     if((board(1,3) == board(2,3)) & (board(2,3) == board(3,3)))
  89.         if (board(1,3)  ~= '-')
  90.             winner = board(1,3);
  91.             mtlb_fprintf('%s wins... congratualtions on beating yourself without porn', winner);
  92.             running = 0;
  93.         end
  94.     end
  95.    
  96.     // backward cross
  97.     if((board(1,1) == board(2,2)) & (board(2,2) == board(3,3)))
  98.         if (board(1,1) ~= '-')
  99.             winner = board(1,1);
  100.             mtlb_fprintf('%s wins... congratualtions on beating yourself without porn', winner);
  101.             running = 0;
  102.         end
  103.     end
  104.    
  105.     // foward cross
  106.     if((board(3,1) == board(2,2)) & (board(2,2) == board(1,3)))
  107.         if (board(3,1) ~= '-')
  108.             winner = board(3,1);
  109.             mtlb_fprintf('%s wins... congratualtions on beating yourself without porn', winner);
  110.             running = 0;
  111.         end
  112.     end
  113. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement