Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #define kmd(%1) if(!strcmp(%1,cmd,true))
- #define X 0
- #define O 1
- #define easy 0
- #define hard 1
- new
- started,
- startpos,
- diff,
- side,
- hole[9],
- win,
- ai;
- public OnFilterScriptInit()
- {
- print("Welcome to PAWN-tic-tac-toe");
- print("Choose your side:(type X or O [and all other commands] in console without the \"/\" character)");
- print("+------------+-----------+");
- print("| X | O |");
- print("+-------+----+---+-------+");
- print("| XX | OO | XX |");
- print("| XX | OO | XX |");
- print("+-------+--------+-------+");
- print("| OO | XX | OO |");
- print("| OO | XX | OO |");
- print("+-------+--------+-------+");
- print("| XX | OO | XX |");
- print("| XX | OO | XX |");
- print("+-------+--------+-------+");
- started = 0;
- diff = 0;
- hole[0] = -1;
- hole[1] = -1;
- hole[2] = -1;
- hole[3] = -1;
- hole[4] = -1;
- hole[5] = -1;
- hole[6] = -1;
- hole[7] = -1;
- hole[8] = -1;
- win = -1;
- ai = 1;
- side = X;
- return 1;
- }
- public OnRconCommand(cmd[]){
- kmd("human"){
- if(started == 1){
- print("The game is already runing, type \"exitgame\" to start a new game later");
- return 1;
- }
- ai = 0;
- side = X;
- print("You have chosen the Human VS Human Mode, type \"startgame\" to start the game");
- return 1;
- }
- kmd("ai"){
- if(started == 1){
- print("The game is already runing, type \"exitgame\" to start a new game later");
- return 1;
- }
- ai = 1;
- print("You have chosen the Human VS AI Mode, type \"startgame\" to start the game");
- return 1;
- }
- kmd("X"){
- if(started == 1){
- print("The game is already runing, type \"exitgame\" to start a new game later");
- return 1;
- }
- side = X;
- print("You have chosen \"X\" as your side, type \"startgame\" to start the game");
- return 1;
- }
- kmd("O"){
- if(started == 1){
- print("The game is already runing, type \"exitgame\" to start a new game later");
- return 1;
- }
- side = O;
- print("You have chosen \"O\" as your side, type \"startgame\" to start the game");
- print("WARNING: Chosing O as first side enables Human VS AI mode! Human VS Human disabled.");
- ai = 1;
- return 1;
- }
- kmd("easy"){
- if(started == 1){
- print("The game is already runing, type \"exitgame\" to start a new game later");
- return 1;
- }
- diff = 0;
- print("You have chosen \"EASY\" , type \"startgame\" to start the game");
- return 1;
- }
- kmd("hard"){
- if(started == 1){
- print("The game is already runing, type \"exitgame\" to start a new game later");
- return 1;
- }
- diff = 1;
- print("You have chosen \"HARD\" , type \"startgame\" to start the game");
- return 1;
- }
- kmd("startgame"){
- if(side == -1)return print("Choose a side first! (\"X\" or \"O\")");
- if(started == 1){
- print("The game is already runing, type \"exitgame\" to start a new game later");
- return 1;
- }
- started = 1;
- if(side == X){
- print("+-------+");
- print("| 1 2 3 |");
- print("| 4 5 6 |");
- print("| 7 8 9 |");
- print("+-------+");
- print("Choose a number to place your X");
- }else
- if(side == O){
- if(diff == easy){
- startpos = random(9);
- if(startpos == 0){
- print("+-------+");
- print("| 1 2 3 |");
- print("| 4 X 6 |");
- print("| 7 8 9 |");
- print("+-------+");
- hole[4] = X;
- }else
- if(startpos == 1){
- print("+-------+");
- print("| 1 2 3 |");
- print("| 4 5 6 |");
- print("| 7 X 9 |");
- print("+-------+");
- hole[7] = X;
- }else
- if(startpos == 2){
- print("+-------+");
- print("| 1 2 3 |");
- print("| 4 5 6 |");
- print("| 7 8 X |");
- print("+-------+");
- hole[8] = X;
- }else
- if(startpos == 3){
- print("+-------+");
- print("| 1 X 3 |");
- print("| 4 5 6 |");
- print("| 7 8 9 |");
- print("+-------+");
- hole[1] = X;
- }else
- if(startpos == 4){
- print("+-------+");
- print("| X 2 3 |");
- print("| 4 5 6 |");
- print("| 7 8 9 |");
- print("+-------+");
- hole[0] = X;
- }else
- if(startpos == 5){
- print("+-------+");
- print("| 1 2 3 |");
- print("| X 5 6 |");
- print("| 7 8 9 |");
- print("+-------+");
- hole[3] = X;
- }else
- if(startpos == 6){
- print("+-------+");
- print("| 1 2 X |");
- print("| 4 5 6 |");
- print("| 7 8 9 |");
- print("+-------+");
- hole[2] = X;
- }else
- if(startpos == 7){
- print("+-------+");
- print("| 1 2 3 |");
- print("| 4 5 X |");
- print("| 7 8 9 |");
- print("+-------+");
- hole[5] = X;
- }else
- if(startpos == 8){
- print("+-------+");
- print("| 1 2 3 |");
- print("| 4 5 6 |");
- print("| X 8 9 |");
- print("+-------+");
- hole[6] = X;
- }
- }else
- if(diff == hard){
- print("+-------+");
- print("| 1 2 3 |");
- print("| 4 X 6 |");
- print("| 7 8 9 |");
- print("+-------+");
- hole[4] = X;
- }
- print("Choose a number to place your O");
- }
- return 1;
- }
- kmd("exitgame"){
- OnFilterScriptInit();
- return 1;
- }
- for(new i; i < 9; i++){
- new command[256];
- format(command,256,"%d",i+1);
- kmd(command){
- if(started == 0){
- print("The game is not running, type \"startgame\" to start a new game");
- return 1;
- }
- PlaceMe(i);
- return 1;
- }
- }
- return 1;
- }
- forward PlaceMe(field);
- public PlaceMe(field){
- if(hole[field] != (-1))return print("The chosen field is already taken, choose another one");
- if(side == X){
- hole[field] = X;
- }else
- if(side == O){
- hole[field] = O;
- }
- printf("You have chosen \"%d\" , object has been placed",field+1);
- DrawBoard();
- win = CheckWinner();
- if(win == X){
- print("---X--- HAS WON THE GAME!! :)");
- OnFilterScriptInit();
- print("---X--- HAS WON THE GAME!! :), resetting all... Please start a new game :)");
- }else
- if(win == O){
- print("---O--- HAS WON THE GAME!! :)");
- OnFilterScriptInit();
- print("---O--- HAS WON THE GAME!! :), resetting all... Please start a new game :)");
- }else
- if(win == 10){//draw game
- print("Nobody has won... :P");
- OnFilterScriptInit();
- print("Nobody has won... :P, resetting all... Please start a new game :)");
- }else{
- if(ai == 1){
- PlaceEnemy();
- }else{
- print("Next side turn, please choose a number");
- if(side == X){
- side = O;
- return O;
- }else{
- side = X;
- return X;
- }
- }
- }
- return 1;
- }
- forward PlaceEnemy();
- public PlaceEnemy(){
- print("Enemy turn...");
- if(side == X){
- if(diff == easy){
- new rand;
- rand = random(9);
- if(rand == 0){
- rand = random(9);
- rand = random(9);
- }
- if(rand == 1){
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- }
- if(rand == 2){
- rand = random(9);
- rand = random(9);
- rand = random(9);
- }
- if(rand == 3){
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- }
- if(rand == 4){
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- }
- if(rand == 5){
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- }
- if(rand == 6){
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- }
- if(rand == 7){
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- }
- if(rand == 8){
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- }
- if(rand == 4){
- if(hole[4] == -1)hole[4] = O;else
- if(hole[8] == -1)hole[8] = O;else
- if(hole[3] == -1)hole[3] = O;else
- if(hole[5] == -1)hole[5] = O;else
- if(hole[2] == -1)hole[2] = O;else
- if(hole[1] == -1)hole[1] = O;else
- if(hole[0] == -1)hole[0] = O;else
- if(hole[6] == -1)hole[6] = O;else
- if(hole[7] == -1)hole[7] = O;
- }else
- if(rand == 7){
- if(hole[7] == -1)hole[7] = O;else
- if(hole[5] == -1)hole[5] = O;else
- if(hole[3] == -1)hole[3] = O;else
- if(hole[1] == -1)hole[1] = O;else
- if(hole[0] == -1)hole[0] = O;else
- if(hole[8] == -1)hole[8] = O;else
- if(hole[6] == -1)hole[6] = O;else
- if(hole[2] == -1)hole[2] = O;else
- if(hole[4] == -1)hole[4] = O;
- }else{
- if(hole[5] == -1)hole[5] = O;else
- if(hole[3] == -1)hole[3] = O;else
- if(hole[7] == -1)hole[7] = O;else
- if(hole[8] == -1)hole[8] = O;else
- if(hole[0] == -1)hole[0] = O;else
- if(hole[1] == -1)hole[1] = O;else
- if(hole[2] == -1)hole[2] = O;else
- if(hole[4] == -1)hole[4] = O;else
- if(hole[6] == -1)hole[6] = O;
- }
- }else{
- }
- }else
- if(side == O){
- if(diff == easy){
- new rand;
- rand = random(9);
- if(rand == 0){
- rand = random(9);
- rand = random(9);
- }
- if(rand == 1){
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- }
- if(rand == 2){
- rand = random(9);
- rand = random(9);
- rand = random(9);
- }
- if(rand == 3){
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- }
- if(rand == 4){
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- }
- if(rand == 5){
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- }
- if(rand == 6){
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- }
- if(rand == 7){
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- }
- if(rand == 8){
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- rand = random(9);
- }
- if(rand == 4){
- if(hole[4] == -1)hole[4] = X;else
- if(hole[8] == -1)hole[8] = X;else
- if(hole[3] == -1)hole[3] = X;else
- if(hole[5] == -1)hole[5] = X;else
- if(hole[2] == -1)hole[2] = X;else
- if(hole[1] == -1)hole[1] = X;else
- if(hole[0] == -1)hole[0] = X;else
- if(hole[6] == -1)hole[6] = X;else
- if(hole[7] == -1)hole[7] = X;
- }else
- if(rand == 7){
- if(hole[7] == -1)hole[7] = X;else
- if(hole[5] == -1)hole[5] = X;else
- if(hole[3] == -1)hole[3] = X;else
- if(hole[1] == -1)hole[1] = X;else
- if(hole[0] == -1)hole[0] = X;else
- if(hole[8] == -1)hole[8] = X;else
- if(hole[6] == -1)hole[6] = X;else
- if(hole[2] == -1)hole[2] = X;else
- if(hole[4] == -1)hole[4] = X;
- }else{
- if(hole[5] == -1)hole[5] = X;else
- if(hole[3] == -1)hole[3] = X;else
- if(hole[7] == -1)hole[7] = X;else
- if(hole[8] == -1)hole[8] = X;else
- if(hole[0] == -1)hole[0] = X;else
- if(hole[1] == -1)hole[1] = X;else
- if(hole[2] == -1)hole[2] = X;else
- if(hole[4] == -1)hole[4] = X;else
- if(hole[6] == -1)hole[6] = X;
- }
- }else{
- }
- }
- DrawBoard();
- win = CheckWinner();
- if(win == X){
- print("---X--- HAS WON THE GAME!! :)");
- OnFilterScriptInit();
- print("---X--- HAS WON THE GAME!! :), resetting all... Please start a new game :)");
- }else
- if(win == O){
- print("---O--- HAS WON THE GAME!! :)");
- OnFilterScriptInit();
- print("---O--- HAS WON THE GAME!! :), resetting all... Please start a new game :)");
- }else
- if(win == 10){//draw game
- print("Nobody has won... :P");
- OnFilterScriptInit();
- print("Nobody has won... :P, resetting all... Please start a new game :)");
- }
- return 1;
- }
- forward DrawBoard();
- public DrawBoard(){
- //start
- print("+-------+");
- //sector 0
- if(hole[0] == -1){
- if(hole[1] == -1){
- if(hole[2] == -1){
- print("| 1 2 3 |");
- }else
- if(hole[2] == X){
- print("| 1 2 X |");
- }else
- if(hole[2] == O){
- print("| 1 2 O |");
- }
- }else
- if(hole[1] == X){
- if(hole[2] == -1){
- print("| 1 X 3 |");
- }else
- if(hole[2] == X){
- print("| 1 X X |");
- }else
- if(hole[2] == O){
- print("| 1 X O |");
- }
- }else
- if(hole[1] == O){
- if(hole[2] == -1){
- print("| 1 O 3 |");
- }else
- if(hole[2] == X){
- print("| 1 O X |");
- }else
- if(hole[2] == O){
- print("| 1 O O |");
- }
- }
- }else
- if(hole[0] == X){
- if(hole[1] == -1){
- if(hole[2] == -1){
- print("| X 2 3 |");
- }else
- if(hole[2] == X){
- print("| X 2 X |");
- }else
- if(hole[2] == O){
- print("| X 2 O |");
- }
- }else
- if(hole[1] == X){
- if(hole[2] == -1){
- print("| X X 3 |");
- }else
- if(hole[2] == X){
- print("| X X X |");
- }else
- if(hole[2] == O){
- print("| X X O |");
- }
- }else
- if(hole[1] == O){
- if(hole[2] == -1){
- print("| X O 3 |");
- }else
- if(hole[2] == X){
- print("| X O X |");
- }else
- if(hole[2] == O){
- print("| X O O |");
- }
- }
- }else
- if(hole[0] == O){
- if(hole[1] == -1){
- if(hole[2] == -1){
- print("| O 2 3 |");
- }else
- if(hole[2] == X){
- print("| O 2 X |");
- }else
- if(hole[2] == O){
- print("| O 2 O |");
- }
- }else
- if(hole[1] == X){
- if(hole[2] == -1){
- print("| O X 3 |");
- }else
- if(hole[2] == X){
- print("| O X X |");
- }else
- if(hole[2] == O){
- print("| O X O |");
- }
- }else
- if(hole[1] == O){
- if(hole[2] == -1){
- print("| O O 3 |");
- }else
- if(hole[2] == X){
- print("| O O X |");
- }else
- if(hole[2] == O){
- print("| O O O |");
- }
- }
- }
- //sector 1
- if(hole[3] == -1){
- if(hole[4] == -1){
- if(hole[5] == -1){
- print("| 4 5 6 |");
- }else
- if(hole[5] == X){
- print("| 4 5 X |");
- }else
- if(hole[5] == O){
- print("| 4 5 O |");
- }
- }else
- if(hole[4] == X){
- if(hole[5] == -1){
- print("| 4 X 6 |");
- }else
- if(hole[5] == X){
- print("| 4 X X |");
- }else
- if(hole[5] == O){
- print("| 4 X O |");
- }
- }else
- if(hole[4] == O){
- if(hole[5] == -1){
- print("| 4 O 6 |");
- }else
- if(hole[5] == X){
- print("| 4 O X |");
- }else
- if(hole[5] == O){
- print("| 4 O O |");
- }
- }
- }else
- if(hole[3] == X){
- if(hole[4] == -1){
- if(hole[5] == -1){
- print("| X 5 6 |");
- }else
- if(hole[5] == X){
- print("| X 5 X |");
- }else
- if(hole[5] == O){
- print("| X 5 O |");
- }
- }else
- if(hole[4] == X){
- if(hole[5] == -1){
- print("| X X 6 |");
- }else
- if(hole[5] == X){
- print("| X X X |");
- }else
- if(hole[5] == O){
- print("| X X O |");
- }
- }else
- if(hole[4] == O){
- if(hole[5] == -1){
- print("| X O 6 |");
- }else
- if(hole[5] == X){
- print("| X O X |");
- }else
- if(hole[5] == O){
- print("| X O O |");
- }
- }
- }else
- if(hole[3] == O){
- if(hole[4] == -1){
- if(hole[5] == -1){
- print("| O 5 6 |");
- }else
- if(hole[5] == X){
- print("| O 5 X |");
- }else
- if(hole[5] == O){
- print("| O 5 O |");
- }
- }else
- if(hole[4] == X){
- if(hole[5] == -1){
- print("| O X 6 |");
- }else
- if(hole[5] == X){
- print("| O X X |");
- }else
- if(hole[5] == O){
- print("| O X O |");
- }
- }else
- if(hole[4] == O){
- if(hole[5] == -1){
- print("| O O 6 |");
- }else
- if(hole[5] == X){
- print("| O O X |");
- }else
- if(hole[5] == O){
- print("| O O O |");
- }
- }
- }
- //sector 2
- if(hole[6] == -1){
- if(hole[7] == -1){
- if(hole[8] == -1){
- print("| 7 8 9 |");
- }else
- if(hole[8] == X){
- print("| 7 8 X |");
- }else
- if(hole[8] == O){
- print("| 7 8 O |");
- }
- }else
- if(hole[7] == X){
- if(hole[8] == -1){
- print("| 7 X 9 |");
- }else
- if(hole[8] == X){
- print("| 7 X X |");
- }else
- if(hole[8] == O){
- print("| 7 X O |");
- }
- }else
- if(hole[7] == O){
- if(hole[8] == -1){
- print("| 7 O 9 |");
- }else
- if(hole[8] == X){
- print("| 7 O X |");
- }else
- if(hole[8] == O){
- print("| 7 O O |");
- }
- }
- }else
- if(hole[6] == X){
- if(hole[7] == -1){
- if(hole[8] == -1){
- print("| X 8 9 |");
- }else
- if(hole[8] == X){
- print("| X 8 X |");
- }else
- if(hole[8] == O){
- print("| X 8 O |");
- }
- }else
- if(hole[7] == X){
- if(hole[8] == -1){
- print("| X X 9 |");
- }else
- if(hole[8] == X){
- print("| X X X |");
- }else
- if(hole[8] == O){
- print("| X X O |");
- }
- }else
- if(hole[7] == O){
- if(hole[8] == -1){
- print("| X O 9 |");
- }else
- if(hole[8] == X){
- print("| X O X |");
- }else
- if(hole[8] == O){
- print("| X O O |");
- }
- }
- }else
- if(hole[6] == O){
- if(hole[7] == -1){
- if(hole[8] == -1){
- print("| O 8 9 |");
- }else
- if(hole[8] == X){
- print("| O 8 X |");
- }else
- if(hole[8] == O){
- print("| O 8 O |");
- }
- }else
- if(hole[7] == X){
- if(hole[8] == -1){
- print("| O X 9 |");
- }else
- if(hole[8] == X){
- print("| O X X |");
- }else
- if(hole[8] == O){
- print("| O X O |");
- }
- }else
- if(hole[7] == O){
- if(hole[8] == -1){
- print("| O O 9 |");
- }else
- if(hole[8] == X){
- print("| O O X |");
- }else
- if(hole[8] == O){
- print("| O O O |");
- }
- }
- }
- print("+-------+");
- //end
- }
- forward CheckWinner();
- public CheckWinner(){
- if(hole[0] == X && hole[1] == X && hole[2] == X)return X;
- if(hole[3] == X && hole[4] == X && hole[5] == X)return X;
- if(hole[6] == X && hole[7] == X && hole[8] == X)return X;
- if(hole[0] == X && hole[3] == X && hole[6] == X)return X;
- if(hole[1] == X && hole[4] == X && hole[7] == X)return X;
- if(hole[2] == X && hole[5] == X && hole[8] == X)return X;
- if(hole[2] == X && hole[4] == X && hole[6] == X)return X;
- if(hole[0] == X && hole[4] == X && hole[8] == X)return X;
- if(hole[0] == O && hole[1] == O && hole[2] == O)return O;
- if(hole[3] == O && hole[4] == O && hole[5] == O)return O;
- if(hole[6] == O && hole[7] == O && hole[8] == O)return O;
- if(hole[0] == O && hole[3] == O && hole[6] == O)return O;
- if(hole[1] == O && hole[4] == O && hole[7] == O)return O;
- if(hole[2] == O && hole[5] == O && hole[8] == O)return O;
- if(hole[2] == O && hole[4] == O && hole[6] == O)return O;
- if(hole[0] == O && hole[4] == O && hole[8] == O)return O;
- if(
- (hole[0] != (-1)) &&
- (hole[1] != (-1)) &&
- (hole[2] != (-1)) &&
- (hole[3] != (-1)) &&
- (hole[4] != (-1)) &&
- (hole[5] != (-1)) &&
- (hole[6] != (-1)) &&
- (hole[7] != (-1)) &&
- (hole[8] != (-1))
- )return 10;//draw game, nobody won
- return -1;
- }
- /*
- print("| 0 1 2 |");
- print("| 3 4 5 |");
- print("| 6 7 8 |");
- print("| 1 2 3 |");
- print("| 4 5 6 |");
- print("| 7 8 9 |");
- print("| - - - |");
- print("| - - X |");
- print("| - - O |");
- print("| - X - |");
- print("| - X X |");
- print("| - X O |");
- print("| - O - |");
- print("| - O X |");
- print("| - O O |");
- print("| X - - |");
- print("| X - X |");
- print("| X - O |");
- print("| X X - |");
- print("| X X X |");
- print("| X X O |");
- print("| X O - |");
- print("| X O X |");
- print("| X O O |");
- print("| O - - |");
- print("| O - X |");
- print("| O - O |");
- print("| O X - |");
- print("| O X X |");
- print("| O X O |");
- print("| O O - |");
- print("| O O X |");
- print("| O O O |");
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement