Advertisement
Guest User

Tic Tac Toe in Pawn

a guest
Apr 30th, 2010
918
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 23.05 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. #define kmd(%1) if(!strcmp(%1,cmd,true))
  4.  
  5. #define X 0
  6. #define O 1
  7. #define easy 0
  8. #define hard 1
  9.  
  10. new
  11.     started,
  12.     startpos,
  13.     diff,
  14.     side,
  15.     hole[9],
  16.     win,
  17.     ai;
  18.  
  19. public OnFilterScriptInit()
  20. {
  21.     print("Welcome to PAWN-tic-tac-toe");
  22.     print("Choose your side:(type X or O [and all other commands] in console without the \"/\" character)");
  23.     print("+------------+-----------+");
  24.     print("|     X      |     O     |");
  25.     print("+-------+----+---+-------+");
  26.     print("|   XX  |   OO   |  XX   |");
  27.     print("|   XX  |   OO   |  XX   |");
  28.     print("+-------+--------+-------+");
  29.     print("|   OO  |   XX   |  OO   |");
  30.     print("|   OO  |   XX   |  OO   |");
  31.     print("+-------+--------+-------+");
  32.     print("|   XX  |   OO   |  XX   |");
  33.     print("|   XX  |   OO   |  XX   |");
  34.     print("+-------+--------+-------+");
  35.     started =  0;
  36.     diff    =  0;
  37.     hole[0] = -1;
  38.     hole[1] = -1;
  39.     hole[2] = -1;
  40.     hole[3] = -1;
  41.     hole[4] = -1;
  42.     hole[5] = -1;
  43.     hole[6] = -1;
  44.     hole[7] = -1;
  45.     hole[8] = -1;
  46.     win     = -1;
  47.     ai      =  1;
  48.     side    =  X;
  49.     return 1;
  50. }
  51.  
  52. public OnRconCommand(cmd[]){
  53.     kmd("human"){
  54.         if(started == 1){
  55.             print("The game is already runing, type \"exitgame\" to start a new game later");
  56.             return 1;
  57.         }
  58.         ai = 0;
  59.         side = X;
  60.         print("You have chosen the Human VS Human Mode, type \"startgame\" to start the game");
  61.         return 1;
  62.     }
  63.     kmd("ai"){
  64.         if(started == 1){
  65.             print("The game is already runing, type \"exitgame\" to start a new game later");
  66.             return 1;
  67.         }
  68.         ai = 1;
  69.         print("You have chosen the Human VS AI Mode, type \"startgame\" to start the game");
  70.         return 1;
  71.     }
  72.     kmd("X"){
  73.         if(started == 1){
  74.             print("The game is already runing, type \"exitgame\" to start a new game later");
  75.             return 1;
  76.         }
  77.         side = X;
  78.         print("You have chosen \"X\" as your side, type \"startgame\" to start the game");
  79.         return 1;
  80.     }
  81.     kmd("O"){
  82.         if(started == 1){
  83.             print("The game is already runing, type \"exitgame\" to start a new game later");
  84.             return 1;
  85.         }
  86.         side = O;
  87.         print("You have chosen \"O\" as your side, type \"startgame\" to start the game");
  88.         print("WARNING: Chosing O as first side enables Human VS AI mode! Human VS Human disabled.");
  89.         ai = 1;
  90.         return 1;
  91.     }
  92.     kmd("easy"){
  93.         if(started == 1){
  94.             print("The game is already runing, type \"exitgame\" to start a new game later");
  95.             return 1;
  96.         }
  97.         diff = 0;
  98.         print("You have chosen \"EASY\" , type \"startgame\" to start the game");
  99.         return 1;
  100.     }
  101.     kmd("hard"){
  102.         if(started == 1){
  103.             print("The game is already runing, type \"exitgame\" to start a new game later");
  104.             return 1;
  105.         }
  106.         diff = 1;
  107.         print("You have chosen \"HARD\" , type \"startgame\" to start the game");
  108.         return 1;
  109.     }
  110.     kmd("startgame"){
  111.         if(side == -1)return print("Choose a side first! (\"X\" or \"O\")");
  112.         if(started == 1){
  113.             print("The game is already runing, type \"exitgame\" to start a new game later");
  114.             return 1;
  115.         }
  116.         started = 1;
  117.         if(side == X){
  118.             print("+-------+");
  119.             print("| 1 2 3 |");
  120.             print("| 4 5 6 |");
  121.             print("| 7 8 9 |");
  122.             print("+-------+");
  123.             print("Choose a number to place your X");
  124.         }else
  125.         if(side == O){
  126.             if(diff == easy){
  127.                 startpos = random(9);
  128.                 if(startpos == 0){
  129.                     print("+-------+");
  130.                     print("| 1 2 3 |");
  131.                     print("| 4 X 6 |");
  132.                     print("| 7 8 9 |");
  133.                     print("+-------+");
  134.                     hole[4] = X;
  135.                 }else
  136.                 if(startpos == 1){
  137.                     print("+-------+");
  138.                     print("| 1 2 3 |");
  139.                     print("| 4 5 6 |");
  140.                     print("| 7 X 9 |");
  141.                     print("+-------+");
  142.                     hole[7] = X;
  143.                 }else
  144.                 if(startpos == 2){
  145.                     print("+-------+");
  146.                     print("| 1 2 3 |");
  147.                     print("| 4 5 6 |");
  148.                     print("| 7 8 X |");
  149.                     print("+-------+");
  150.                     hole[8] = X;
  151.                 }else
  152.                 if(startpos == 3){
  153.                     print("+-------+");
  154.                     print("| 1 X 3 |");
  155.                     print("| 4 5 6 |");
  156.                     print("| 7 8 9 |");
  157.                     print("+-------+");
  158.                     hole[1] = X;
  159.                 }else
  160.                 if(startpos == 4){
  161.                     print("+-------+");
  162.                     print("| X 2 3 |");
  163.                     print("| 4 5 6 |");
  164.                     print("| 7 8 9 |");
  165.                     print("+-------+");
  166.                     hole[0] = X;
  167.                 }else
  168.                 if(startpos == 5){
  169.                     print("+-------+");
  170.                     print("| 1 2 3 |");
  171.                     print("| X 5 6 |");
  172.                     print("| 7 8 9 |");
  173.                     print("+-------+");
  174.                     hole[3] = X;
  175.                 }else
  176.                 if(startpos == 6){
  177.                     print("+-------+");
  178.                     print("| 1 2 X |");
  179.                     print("| 4 5 6 |");
  180.                     print("| 7 8 9 |");
  181.                     print("+-------+");
  182.                     hole[2] = X;
  183.                 }else
  184.                 if(startpos == 7){
  185.                     print("+-------+");
  186.                     print("| 1 2 3 |");
  187.                     print("| 4 5 X |");
  188.                     print("| 7 8 9 |");
  189.                     print("+-------+");
  190.                     hole[5] = X;
  191.                 }else
  192.                 if(startpos == 8){
  193.                     print("+-------+");
  194.                     print("| 1 2 3 |");
  195.                     print("| 4 5 6 |");
  196.                     print("| X 8 9 |");
  197.                     print("+-------+");
  198.                     hole[6] = X;
  199.                 }
  200.             }else
  201.             if(diff == hard){
  202.                     print("+-------+");
  203.                     print("| 1 2 3 |");
  204.                     print("| 4 X 6 |");
  205.                     print("| 7 8 9 |");
  206.                     print("+-------+");
  207.                     hole[4] = X;
  208.             }
  209.             print("Choose a number to place your O");
  210.         }
  211.         return 1;
  212.     }
  213.     kmd("exitgame"){
  214.         OnFilterScriptInit();
  215.         return 1;
  216.     }
  217.     for(new i; i < 9; i++){
  218.         new command[256];
  219.         format(command,256,"%d",i+1);
  220.         kmd(command){
  221.             if(started == 0){
  222.                 print("The game is not running, type \"startgame\" to start a new game");
  223.                 return 1;
  224.             }
  225.             PlaceMe(i);
  226.             return 1;
  227.         }
  228.     }
  229.     return 1;
  230. }
  231.  
  232. forward PlaceMe(field);
  233. public PlaceMe(field){
  234.     if(hole[field] != (-1))return print("The chosen field is already taken, choose another one");
  235.     if(side == X){
  236.         hole[field] = X;
  237.     }else
  238.     if(side == O){
  239.         hole[field] = O;
  240.     }
  241.     printf("You have chosen \"%d\" , object has been placed",field+1);
  242.     DrawBoard();
  243.     win = CheckWinner();
  244.     if(win == X){
  245.         print("---X--- HAS WON THE GAME!! :)");
  246.         OnFilterScriptInit();
  247.         print("---X--- HAS WON THE GAME!! :), resetting all... Please start a new game :)");
  248.     }else
  249.     if(win == O){
  250.         print("---O--- HAS WON THE GAME!! :)");
  251.         OnFilterScriptInit();
  252.         print("---O--- HAS WON THE GAME!! :), resetting all... Please start a new game :)");
  253.     }else
  254.     if(win == 10){//draw game
  255.         print("Nobody has won... :P");
  256.         OnFilterScriptInit();
  257.         print("Nobody has won... :P, resetting all... Please start a new game :)");
  258.     }else{
  259.         if(ai == 1){
  260.             PlaceEnemy();
  261.         }else{
  262.             print("Next side turn, please choose a number");
  263.             if(side == X){
  264.                 side = O;
  265.                 return O;
  266.             }else{
  267.                 side = X;
  268.                 return X;
  269.             }
  270.         }
  271.     }
  272.     return 1;
  273. }
  274.  
  275. forward PlaceEnemy();
  276. public PlaceEnemy(){
  277.     print("Enemy turn...");
  278.     if(side == X){
  279.         if(diff == easy){
  280.             new rand;
  281.             rand = random(9);
  282.             if(rand == 0){
  283.                 rand = random(9);
  284.                 rand = random(9);
  285.             }
  286.             if(rand == 1){
  287.                 rand = random(9);
  288.                 rand = random(9);
  289.                 rand = random(9);
  290.                 rand = random(9);
  291.                 rand = random(9);
  292.                 rand = random(9);
  293.             }
  294.             if(rand == 2){
  295.                 rand = random(9);
  296.                 rand = random(9);
  297.                 rand = random(9);
  298.             }
  299.             if(rand == 3){
  300.                 rand = random(9);
  301.                 rand = random(9);
  302.                 rand = random(9);
  303.                 rand = random(9);
  304.                 rand = random(9);
  305.                 rand = random(9);
  306.                 rand = random(9);
  307.                 rand = random(9);
  308.                 rand = random(9);
  309.             }
  310.             if(rand == 4){
  311.                 rand = random(9);
  312.                 rand = random(9);
  313.                 rand = random(9);
  314.                 rand = random(9);
  315.             }
  316.             if(rand == 5){
  317.                 rand = random(9);
  318.                 rand = random(9);
  319.                 rand = random(9);
  320.                 rand = random(9);
  321.                 rand = random(9);
  322.                 rand = random(9);
  323.                 rand = random(9);
  324.                 rand = random(9);
  325.                 rand = random(9);
  326.                 rand = random(9);
  327.                 rand = random(9);
  328.                 rand = random(9);
  329.             }
  330.             if(rand == 6){
  331.                 rand = random(9);
  332.                 rand = random(9);
  333.                 rand = random(9);
  334.                 rand = random(9);
  335.                 rand = random(9);
  336.                 rand = random(9);
  337.             }
  338.             if(rand == 7){
  339.                 rand = random(9);
  340.                 rand = random(9);
  341.                 rand = random(9);
  342.                 rand = random(9);
  343.                 rand = random(9);
  344.                 rand = random(9);
  345.                 rand = random(9);
  346.                 rand = random(9);
  347.                 rand = random(9);
  348.                 rand = random(9);
  349.                 rand = random(9);
  350.                 rand = random(9);
  351.                 rand = random(9);
  352.                 rand = random(9);
  353.                 rand = random(9);
  354.                 rand = random(9);
  355.                 rand = random(9);
  356.             }
  357.             if(rand == 8){
  358.                 rand = random(9);
  359.                 rand = random(9);
  360.                 rand = random(9);
  361.                 rand = random(9);
  362.                 rand = random(9);
  363.                 rand = random(9);
  364.                 rand = random(9);
  365.                 rand = random(9);
  366.                 rand = random(9);
  367.                 rand = random(9);
  368.                 rand = random(9);
  369.             }
  370.  
  371.             if(rand == 4){
  372.                 if(hole[4] == -1)hole[4] = O;else
  373.                 if(hole[8] == -1)hole[8] = O;else
  374.                 if(hole[3] == -1)hole[3] = O;else
  375.                 if(hole[5] == -1)hole[5] = O;else
  376.                 if(hole[2] == -1)hole[2] = O;else
  377.                 if(hole[1] == -1)hole[1] = O;else
  378.                 if(hole[0] == -1)hole[0] = O;else
  379.                 if(hole[6] == -1)hole[6] = O;else
  380.                 if(hole[7] == -1)hole[7] = O;
  381.             }else
  382.             if(rand == 7){
  383.                 if(hole[7] == -1)hole[7] = O;else
  384.                 if(hole[5] == -1)hole[5] = O;else
  385.                 if(hole[3] == -1)hole[3] = O;else
  386.                 if(hole[1] == -1)hole[1] = O;else
  387.                 if(hole[0] == -1)hole[0] = O;else
  388.                 if(hole[8] == -1)hole[8] = O;else
  389.                 if(hole[6] == -1)hole[6] = O;else
  390.                 if(hole[2] == -1)hole[2] = O;else
  391.                 if(hole[4] == -1)hole[4] = O;
  392.             }else{
  393.                 if(hole[5] == -1)hole[5] = O;else
  394.                 if(hole[3] == -1)hole[3] = O;else
  395.                 if(hole[7] == -1)hole[7] = O;else
  396.                 if(hole[8] == -1)hole[8] = O;else
  397.                 if(hole[0] == -1)hole[0] = O;else
  398.                 if(hole[1] == -1)hole[1] = O;else
  399.                 if(hole[2] == -1)hole[2] = O;else
  400.                 if(hole[4] == -1)hole[4] = O;else
  401.                 if(hole[6] == -1)hole[6] = O;
  402.             }
  403.         }else{
  404.        
  405.         }
  406.     }else
  407.     if(side == O){
  408.         if(diff == easy){
  409.             new rand;
  410.             rand = random(9);
  411.             if(rand == 0){
  412.                 rand = random(9);
  413.                 rand = random(9);
  414.             }
  415.             if(rand == 1){
  416.                 rand = random(9);
  417.                 rand = random(9);
  418.                 rand = random(9);
  419.                 rand = random(9);
  420.                 rand = random(9);
  421.                 rand = random(9);
  422.             }
  423.             if(rand == 2){
  424.                 rand = random(9);
  425.                 rand = random(9);
  426.                 rand = random(9);
  427.             }
  428.             if(rand == 3){
  429.                 rand = random(9);
  430.                 rand = random(9);
  431.                 rand = random(9);
  432.                 rand = random(9);
  433.                 rand = random(9);
  434.                 rand = random(9);
  435.                 rand = random(9);
  436.                 rand = random(9);
  437.                 rand = random(9);
  438.             }
  439.             if(rand == 4){
  440.                 rand = random(9);
  441.                 rand = random(9);
  442.                 rand = random(9);
  443.                 rand = random(9);
  444.             }
  445.             if(rand == 5){
  446.                 rand = random(9);
  447.                 rand = random(9);
  448.                 rand = random(9);
  449.                 rand = random(9);
  450.                 rand = random(9);
  451.                 rand = random(9);
  452.                 rand = random(9);
  453.                 rand = random(9);
  454.                 rand = random(9);
  455.                 rand = random(9);
  456.                 rand = random(9);
  457.                 rand = random(9);
  458.             }
  459.             if(rand == 6){
  460.                 rand = random(9);
  461.                 rand = random(9);
  462.                 rand = random(9);
  463.                 rand = random(9);
  464.                 rand = random(9);
  465.                 rand = random(9);
  466.             }
  467.             if(rand == 7){
  468.                 rand = random(9);
  469.                 rand = random(9);
  470.                 rand = random(9);
  471.                 rand = random(9);
  472.                 rand = random(9);
  473.                 rand = random(9);
  474.                 rand = random(9);
  475.                 rand = random(9);
  476.                 rand = random(9);
  477.                 rand = random(9);
  478.                 rand = random(9);
  479.                 rand = random(9);
  480.                 rand = random(9);
  481.                 rand = random(9);
  482.                 rand = random(9);
  483.                 rand = random(9);
  484.                 rand = random(9);
  485.             }
  486.             if(rand == 8){
  487.                 rand = random(9);
  488.                 rand = random(9);
  489.                 rand = random(9);
  490.                 rand = random(9);
  491.                 rand = random(9);
  492.                 rand = random(9);
  493.                 rand = random(9);
  494.                 rand = random(9);
  495.                 rand = random(9);
  496.                 rand = random(9);
  497.                 rand = random(9);
  498.             }
  499.            
  500.             if(rand == 4){
  501.                 if(hole[4] == -1)hole[4] = X;else
  502.                 if(hole[8] == -1)hole[8] = X;else
  503.                 if(hole[3] == -1)hole[3] = X;else
  504.                 if(hole[5] == -1)hole[5] = X;else
  505.                 if(hole[2] == -1)hole[2] = X;else
  506.                 if(hole[1] == -1)hole[1] = X;else
  507.                 if(hole[0] == -1)hole[0] = X;else
  508.                 if(hole[6] == -1)hole[6] = X;else
  509.                 if(hole[7] == -1)hole[7] = X;
  510.             }else
  511.             if(rand == 7){
  512.                 if(hole[7] == -1)hole[7] = X;else
  513.                 if(hole[5] == -1)hole[5] = X;else
  514.                 if(hole[3] == -1)hole[3] = X;else
  515.                 if(hole[1] == -1)hole[1] = X;else
  516.                 if(hole[0] == -1)hole[0] = X;else
  517.                 if(hole[8] == -1)hole[8] = X;else
  518.                 if(hole[6] == -1)hole[6] = X;else
  519.                 if(hole[2] == -1)hole[2] = X;else
  520.                 if(hole[4] == -1)hole[4] = X;
  521.             }else{
  522.                 if(hole[5] == -1)hole[5] = X;else
  523.                 if(hole[3] == -1)hole[3] = X;else
  524.                 if(hole[7] == -1)hole[7] = X;else
  525.                 if(hole[8] == -1)hole[8] = X;else
  526.                 if(hole[0] == -1)hole[0] = X;else
  527.                 if(hole[1] == -1)hole[1] = X;else
  528.                 if(hole[2] == -1)hole[2] = X;else
  529.                 if(hole[4] == -1)hole[4] = X;else
  530.                 if(hole[6] == -1)hole[6] = X;
  531.             }
  532.         }else{
  533.  
  534.         }
  535.     }
  536.     DrawBoard();
  537.     win = CheckWinner();
  538.     if(win == X){
  539.         print("---X--- HAS WON THE GAME!! :)");
  540.         OnFilterScriptInit();
  541.         print("---X--- HAS WON THE GAME!! :), resetting all... Please start a new game :)");
  542.     }else
  543.     if(win == O){
  544.         print("---O--- HAS WON THE GAME!! :)");
  545.         OnFilterScriptInit();
  546.         print("---O--- HAS WON THE GAME!! :), resetting all... Please start a new game :)");
  547.     }else
  548.     if(win == 10){//draw game
  549.         print("Nobody has won... :P");
  550.         OnFilterScriptInit();
  551.         print("Nobody has won... :P, resetting all... Please start a new game :)");
  552.     }
  553.     return 1;
  554. }
  555.  
  556. forward DrawBoard();
  557. public DrawBoard(){
  558.     //start
  559.     print("+-------+");
  560.     //sector 0
  561.     if(hole[0] == -1){
  562.         if(hole[1] == -1){
  563.             if(hole[2] == -1){
  564.                 print("| 1 2 3 |");
  565.             }else
  566.             if(hole[2] == X){
  567.                 print("| 1 2 X |");
  568.             }else
  569.             if(hole[2] == O){
  570.                 print("| 1 2 O |");
  571.             }
  572.         }else
  573.         if(hole[1] == X){
  574.             if(hole[2] == -1){
  575.                 print("| 1 X 3 |");
  576.             }else
  577.             if(hole[2] == X){
  578.                 print("| 1 X X |");
  579.             }else
  580.             if(hole[2] == O){
  581.                 print("| 1 X O |");
  582.             }
  583.         }else
  584.         if(hole[1] == O){
  585.             if(hole[2] == -1){
  586.                 print("| 1 O 3 |");
  587.             }else
  588.             if(hole[2] == X){
  589.                 print("| 1 O X |");
  590.             }else
  591.             if(hole[2] == O){
  592.                 print("| 1 O O |");
  593.             }
  594.         }
  595.     }else
  596.     if(hole[0] == X){
  597.         if(hole[1] == -1){
  598.             if(hole[2] == -1){
  599.                 print("| X 2 3 |");
  600.             }else
  601.             if(hole[2] == X){
  602.                 print("| X 2 X |");
  603.             }else
  604.             if(hole[2] == O){
  605.                 print("| X 2 O |");
  606.             }
  607.         }else
  608.         if(hole[1] == X){
  609.             if(hole[2] == -1){
  610.                 print("| X X 3 |");
  611.             }else
  612.             if(hole[2] == X){
  613.                 print("| X X X |");
  614.             }else
  615.             if(hole[2] == O){
  616.                 print("| X X O |");
  617.             }
  618.         }else
  619.         if(hole[1] == O){
  620.             if(hole[2] == -1){
  621.                 print("| X O 3 |");
  622.             }else
  623.             if(hole[2] == X){
  624.                 print("| X O X |");
  625.             }else
  626.             if(hole[2] == O){
  627.                 print("| X O O |");
  628.             }
  629.         }
  630.     }else
  631.     if(hole[0] == O){
  632.         if(hole[1] == -1){
  633.             if(hole[2] == -1){
  634.                 print("| O 2 3 |");
  635.             }else
  636.             if(hole[2] == X){
  637.                 print("| O 2 X |");
  638.             }else
  639.             if(hole[2] == O){
  640.                 print("| O 2 O |");
  641.             }
  642.         }else
  643.         if(hole[1] == X){
  644.             if(hole[2] == -1){
  645.                 print("| O X 3 |");
  646.             }else
  647.             if(hole[2] == X){
  648.                 print("| O X X |");
  649.             }else
  650.             if(hole[2] == O){
  651.                 print("| O X O |");
  652.             }
  653.         }else
  654.         if(hole[1] == O){
  655.             if(hole[2] == -1){
  656.                 print("| O O 3 |");
  657.             }else
  658.             if(hole[2] == X){
  659.                 print("| O O X |");
  660.             }else
  661.             if(hole[2] == O){
  662.                 print("| O O O |");
  663.             }
  664.         }
  665.     }
  666.     //sector 1
  667.     if(hole[3] == -1){
  668.         if(hole[4] == -1){
  669.             if(hole[5] == -1){
  670.                 print("| 4 5 6 |");
  671.             }else
  672.             if(hole[5] == X){
  673.                 print("| 4 5 X |");
  674.             }else
  675.             if(hole[5] == O){
  676.                 print("| 4 5 O |");
  677.             }
  678.         }else
  679.         if(hole[4] == X){
  680.             if(hole[5] == -1){
  681.                 print("| 4 X 6 |");
  682.             }else
  683.             if(hole[5] == X){
  684.                 print("| 4 X X |");
  685.             }else
  686.             if(hole[5] == O){
  687.                 print("| 4 X O |");
  688.             }
  689.         }else
  690.         if(hole[4] == O){
  691.             if(hole[5] == -1){
  692.                 print("| 4 O 6 |");
  693.             }else
  694.             if(hole[5] == X){
  695.                 print("| 4 O X |");
  696.             }else
  697.             if(hole[5] == O){
  698.                 print("| 4 O O |");
  699.             }
  700.         }
  701.     }else
  702.     if(hole[3] == X){
  703.         if(hole[4] == -1){
  704.             if(hole[5] == -1){
  705.                 print("| X 5 6 |");
  706.             }else
  707.             if(hole[5] == X){
  708.                 print("| X 5 X |");
  709.             }else
  710.             if(hole[5] == O){
  711.                 print("| X 5 O |");
  712.             }
  713.         }else
  714.         if(hole[4] == X){
  715.             if(hole[5] == -1){
  716.                 print("| X X 6 |");
  717.             }else
  718.             if(hole[5] == X){
  719.                 print("| X X X |");
  720.             }else
  721.             if(hole[5] == O){
  722.                 print("| X X O |");
  723.             }
  724.         }else
  725.         if(hole[4] == O){
  726.             if(hole[5] == -1){
  727.                 print("| X O 6 |");
  728.             }else
  729.             if(hole[5] == X){
  730.                 print("| X O X |");
  731.             }else
  732.             if(hole[5] == O){
  733.                 print("| X O O |");
  734.             }
  735.         }
  736.     }else
  737.     if(hole[3] == O){
  738.         if(hole[4] == -1){
  739.             if(hole[5] == -1){
  740.                 print("| O 5 6 |");
  741.             }else
  742.             if(hole[5] == X){
  743.                 print("| O 5 X |");
  744.             }else
  745.             if(hole[5] == O){
  746.                 print("| O 5 O |");
  747.             }
  748.         }else
  749.         if(hole[4] == X){
  750.             if(hole[5] == -1){
  751.                 print("| O X 6 |");
  752.             }else
  753.             if(hole[5] == X){
  754.                 print("| O X X |");
  755.             }else
  756.             if(hole[5] == O){
  757.                 print("| O X O |");
  758.             }
  759.         }else
  760.         if(hole[4] == O){
  761.             if(hole[5] == -1){
  762.                 print("| O O 6 |");
  763.             }else
  764.             if(hole[5] == X){
  765.                 print("| O O X |");
  766.             }else
  767.             if(hole[5] == O){
  768.                 print("| O O O |");
  769.             }
  770.         }
  771.     }
  772.     //sector 2
  773.     if(hole[6] == -1){
  774.         if(hole[7] == -1){
  775.             if(hole[8] == -1){
  776.                 print("| 7 8 9 |");
  777.             }else
  778.             if(hole[8] == X){
  779.                 print("| 7 8 X |");
  780.             }else
  781.             if(hole[8] == O){
  782.                 print("| 7 8 O |");
  783.             }
  784.         }else
  785.         if(hole[7] == X){
  786.             if(hole[8] == -1){
  787.                 print("| 7 X 9 |");
  788.             }else
  789.             if(hole[8] == X){
  790.                 print("| 7 X X |");
  791.             }else
  792.             if(hole[8] == O){
  793.                 print("| 7 X O |");
  794.             }
  795.         }else
  796.         if(hole[7] == O){
  797.             if(hole[8] == -1){
  798.                 print("| 7 O 9 |");
  799.             }else
  800.             if(hole[8] == X){
  801.                 print("| 7 O X |");
  802.             }else
  803.             if(hole[8] == O){
  804.                 print("| 7 O O |");
  805.             }
  806.         }
  807.     }else
  808.     if(hole[6] == X){
  809.         if(hole[7] == -1){
  810.             if(hole[8] == -1){
  811.                 print("| X 8 9 |");
  812.             }else
  813.             if(hole[8] == X){
  814.                 print("| X 8 X |");
  815.             }else
  816.             if(hole[8] == O){
  817.                 print("| X 8 O |");
  818.             }
  819.         }else
  820.         if(hole[7] == X){
  821.             if(hole[8] == -1){
  822.                 print("| X X 9 |");
  823.             }else
  824.             if(hole[8] == X){
  825.                 print("| X X X |");
  826.             }else
  827.             if(hole[8] == O){
  828.                 print("| X X O |");
  829.             }
  830.         }else
  831.         if(hole[7] == O){
  832.             if(hole[8] == -1){
  833.                 print("| X O 9 |");
  834.             }else
  835.             if(hole[8] == X){
  836.                 print("| X O X |");
  837.             }else
  838.             if(hole[8] == O){
  839.                 print("| X O O |");
  840.             }
  841.         }
  842.     }else
  843.     if(hole[6] == O){
  844.         if(hole[7] == -1){
  845.             if(hole[8] == -1){
  846.                 print("| O 8 9 |");
  847.             }else
  848.             if(hole[8] == X){
  849.                 print("| O 8 X |");
  850.             }else
  851.             if(hole[8] == O){
  852.                 print("| O 8 O |");
  853.             }
  854.         }else
  855.         if(hole[7] == X){
  856.             if(hole[8] == -1){
  857.                 print("| O X 9 |");
  858.             }else
  859.             if(hole[8] == X){
  860.                 print("| O X X |");
  861.             }else
  862.             if(hole[8] == O){
  863.                 print("| O X O |");
  864.             }
  865.         }else
  866.         if(hole[7] == O){
  867.             if(hole[8] == -1){
  868.                 print("| O O 9 |");
  869.             }else
  870.             if(hole[8] == X){
  871.                 print("| O O X |");
  872.             }else
  873.             if(hole[8] == O){
  874.                 print("| O O O |");
  875.             }
  876.         }
  877.     }
  878.     print("+-------+");
  879.     //end
  880. }
  881.  
  882. forward CheckWinner();
  883. public CheckWinner(){
  884.  
  885.     if(hole[0] == X && hole[1] == X && hole[2] == X)return X;
  886.     if(hole[3] == X && hole[4] == X && hole[5] == X)return X;
  887.     if(hole[6] == X && hole[7] == X && hole[8] == X)return X;
  888.     if(hole[0] == X && hole[3] == X && hole[6] == X)return X;
  889.     if(hole[1] == X && hole[4] == X && hole[7] == X)return X;
  890.     if(hole[2] == X && hole[5] == X && hole[8] == X)return X;
  891.     if(hole[2] == X && hole[4] == X && hole[6] == X)return X;
  892.     if(hole[0] == X && hole[4] == X && hole[8] == X)return X;
  893.    
  894.    
  895.     if(hole[0] == O && hole[1] == O && hole[2] == O)return O;
  896.     if(hole[3] == O && hole[4] == O && hole[5] == O)return O;
  897.     if(hole[6] == O && hole[7] == O && hole[8] == O)return O;
  898.     if(hole[0] == O && hole[3] == O && hole[6] == O)return O;
  899.     if(hole[1] == O && hole[4] == O && hole[7] == O)return O;
  900.     if(hole[2] == O && hole[5] == O && hole[8] == O)return O;
  901.     if(hole[2] == O && hole[4] == O && hole[6] == O)return O;
  902.     if(hole[0] == O && hole[4] == O && hole[8] == O)return O;
  903.  
  904.     if(
  905.         (hole[0] != (-1)) &&
  906.         (hole[1] != (-1)) &&
  907.         (hole[2] != (-1)) &&
  908.         (hole[3] != (-1)) &&
  909.         (hole[4] != (-1)) &&
  910.         (hole[5] != (-1)) &&
  911.         (hole[6] != (-1)) &&
  912.         (hole[7] != (-1)) &&
  913.         (hole[8] != (-1))
  914.     )return 10;//draw game, nobody won
  915.    
  916.     return -1;
  917. }
  918. /*
  919. print("| 0 1 2 |");
  920. print("| 3 4 5 |");
  921. print("| 6 7 8 |");
  922.  
  923. print("| 1 2 3 |");
  924. print("| 4 5 6 |");
  925. print("| 7 8 9 |");
  926.  
  927. print("| - - - |");
  928. print("| - - X |");
  929. print("| - - O |");
  930. print("| - X - |");
  931. print("| - X X |");
  932. print("| - X O |");
  933. print("| - O - |");
  934. print("| - O X |");
  935. print("| - O O |");
  936. print("| X - - |");
  937. print("| X - X |");
  938. print("| X - O |");
  939. print("| X X - |");
  940. print("| X X X |");
  941. print("| X X O |");
  942. print("| X O - |");
  943. print("| X O X |");
  944. print("| X O O |");
  945. print("| O - - |");
  946. print("| O - X |");
  947. print("| O - O |");
  948. print("| O X - |");
  949. print("| O X X |");
  950. print("| O X O |");
  951. print("| O O - |");
  952. print("| O O X |");
  953. print("| O O O |");
  954. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement