SlideShare una empresa de Scribd logo
1 de 18
Descargar para leer sin conexión
#include <stdio.h>

#include <iostream>

#include <time.h>

#include <stdlib.h>

#include <fstream>

#include <pthread.h>

#include <unistd.h>

#include <signal.h>



using namespace std;



#define CLEAR_ROW 1

#define CLEAR_COLUMN 2

#define CLEAR_FIRST_NEIGHBOURS 3

#define DUAL_COLOUR 4

#define NORMAL 5

#define PLAYER_1 1

#define PLAYER_2 2



/* global decalarations */

int turn = 0;/* this number will record whose turn is it */

int moves1=0,moves2=0;/* for tracking the number of moves pklayed yet by participants*/

int
spmove11=0,spmove21=0,spmove31=0,spmove41=0,spmove12=0,spmove22=0,spmove32=0,spmov
e42=0;/* flags to keep track the special moves of players */

int move_type=0,move=0;

int board[7][6] = {0};
/* functions used */

int legal_move();

int add_disk();

int check_win(int team);

int right_up(int x,int y);

int left_up(int x,int y);

int vertical(int x,int y);

int horizontal(int x,int y);

int write_board();

int draw_board();

int first_turn();

int board_full();

int call_code();

int move_counter();



int main()

{

    first_turn();/* decides first turn */

    write_board();/* writes board to txt file */

    draw_board();/* call graphics function to draw the board */

    int match_over = 0;/* flag telling match is over or not */

    while(1)/*starting the infinite loop*/

    {

        write_board();

        match_over = board_full();/*checking if board is full*/

        if(match_over==1)

        break;
/*calling the participant code*/

match_over = call_code();

if(match_over == 1)

break;



else/* match_over == 0 *//* match is not over */

{

    move_counter();

    turn++;

    draw_board();

    int check1 = check_win(1);/* checking winner */

    int check2 = check_win(2);

    if(check1 == 1 && check2 == 1)

    {

        printf("its a drawn");

        break;

    }

    else if(check1 == 1)

    {

        printf("player 1 winsn");

        break;

    }

    else if(check2 == 1)

    {

        printf("player 2 winsn");

        break;

    }
}

    }

    return 0;

}



int legal_move()

{

    if(move > 7 || move < 1)/*invalid column */

    return 0;

    else if(board[move-1][0] != 0)/* top most position of column is not empty*/

    return 0;

    if(turn%2 == 0)/* for player 2 */

    {

        if(move_type == CLEAR_ROW && spmove12 == 1)

        return 0;

        else if(move_type == CLEAR_COLUMN && spmove22 == 1)

        return 0;

        else if(move_type == CLEAR_FIRST_NEIGHBOURS && spmove32 == 1)

        return 0;

        else if(move_type == DUAL_COLOUR && spmove42 == 1)

        return 0;

    else if(move_type != DUAL_COLOUR && moves2 == 9 && spmove42 == 0)/* move type 4 means
dual color block */

        return 0;

    }

    else

    {

        if(move_type == CLEAR_ROW && spmove11 == 1)
return 0;

        else if(move_type == CLEAR_COLUMN && spmove21 == 1)

        return 0;

        else if(move_type == CLEAR_FIRST_NEIGHBOURS && spmove31 == 1)

        return 0;

        else if(move_type == DUAL_COLOUR && spmove41 == 1)

        return 0;

        else if(move_type != DUAL_COLOUR && moves1 == 9 && spmove41 == 0)

        return 0;

    }

    return 1;

}



int add_disk()

{

    for(int y = 0;y<6;y++)

    {

        if(board[move-1][y+1] != 0 || y+1>5)/* bottommost position in that column */

        {

            if(move_type == CLEAR_ROW)/* 1 means detroying complete row */

            {

                for(int x=0;x<7;x++)

                {

                    for(int temp = y;temp>=0;temp--)

                    board[x][temp] = board[x][temp-1];

                    board[x][0] = 0;

                }
}

      else if(move_type == CLEAR_COLUMN)/* destroying complete column */

      {

          for(int temp = 0;temp<7;temp++)

          board[move-1][temp] = 0;

      }

       else if(move_type == CLEAR_FIRST_NEIGHBOURS)/* destroying neighbour block in every
direction */

      {

          for(int temp = move-2;temp <= move;temp++)

          {

              if(temp<0 || temp>6)

              continue;

              if(y+1<6)

              board[temp][y+1]=0;

              board[temp][y]=0;

              if(y-1>=0)

              board[temp][y-1]=0;

              /* now need to shift zeroes */

              for(int count=0;count < 3;count++)

              {

                  for(int change = 5;change > 0;change--)

                  {

                      if(board[temp][change]==0)

                      {

                          board[temp][change] = board[temp][change-1];

                          board[temp][change-1] = 0;

                      }
}

                    }

                }

            }

            else if(move_type == DUAL_COLOUR)/* dual color block */

            {

            board[move-1][y] = 12;

            }

            else/* normal block */

            {

                if(turn % 2 == 1)

                board[move-1][y] = 1;

                else

                board[move-1][y] = 2;

            }

            break;

        }

    }

    return 0;

}



int check_win(int team)

{

    int result=0,temp=0;

    for(int y=5;y>=0;y--)

    for(int x=0;x<7;x++)

    {
if(board[x][y] == 0)/* block is empty */

        continue;

        if(board[x][y] == team || board[x][y] == 12)

        {

            result = right_up(x,y);

            if(result!=1)

            result = left_up(x,y);

            if(result!=1)

            result = vertical(x,y);

            if(result!=1)

            result = horizontal(x,y);

        }

        if(result == 1)

        return 1;

    }

    return 0;

}



int right_up(int x,int y)

{

    if(y<3 || x>3)/* not possible */

    return 0;

    else if(x-1>=0 && y+1<6 && (board[x-1][y+1] == board[x][y] || board[x-1][y+1] == 12))

    return 0;/* condition was checked at x-1 and y+1 already */

    else

    {

        int count=1;
for(int temp = 1;temp<4;temp++)

        {

            if(board[x+temp][y-temp] == board[x][y] || board[x+temp][y-temp] == 12)

            count++;

        }

        if(count == 4)

        return 1;

    }

    return 0;

}



int left_up(int x,int y)

{

    if(y<3 || x<3)/* not possible */

    return 0;

    else if(x+1<7 && y+1<6 && (board[x+1][y+1] == board[x][y] || board[x+1][y+1] == 12))

    return 0;/* condition was checked at x+1 and y+1 already */

    else

    {

        int count=1;

        for(int temp = 1;temp<4;temp++)

        {

            if(board[x-temp][y-temp] == board[x][y])

            count++;

        }

        if(count == 4)

        return 1;
}

    return 0;

}



int vertical(int x,int y)

{

    if(y<3)

    return 0;

    else if( y+1 < 6 && (board[x][y+1] == board[x][y] || board[x][y+1] == 12))

    return 0;

    int count = 1;

    for(int temp=1;temp<4;temp++)

    {

        if(board[x][y-temp] == board[x][y] || board[x][y-temp] == 12 )

        count++;

    }

    if(count == 4)

    return 1;

    return 0;

}



int horizontal(int x,int y)

{

    if(x>3)

    return 0;

    else if( x-1>=0 && (board[x-1][y] == board[x][y] || board[x-1][y]==12))

    return 0;
int count=1;

    for(int temp=1;temp<4;temp++)

    {

        if(board[x+temp][y] == board[x][y] || board[x+temp][y] == 12 )

        count++;

    }

    if(count == 4)

    return 1;

    return 0;

}



int write_board()

{

    ofstream pt ("board.txt");

    for(int y = 5 ; y>=0 ; y--)

    {

        for(int x = 0 ; x < 7 ;x++)

        {

            pt<<board[x][y]<<" ";

        }

    }

    pt.close();

    return 0;

}



int draw_board()

{
printf("n");

    for(int y = 0 ; y<6;y++)

    {

        for(int x = 0 ; x < 7 ; x++)



        printf("%d ",board[x][y]);

        printf("n");

    }

    printf("nn");

    return 0;

}



int first_turn()

{

    srand ( time(NULL) );

    /* initialization to generate a random number*/

    /* deciding the first player whose turn is it */

    ifstream pt ("turn.txt");

    /* opening the file in which the player who got the first turn is written */

    if(pt == NULL)/* no such file exists*/

    {

        turn = rand()%2 + 1;

        /* generating a random number to decide the first player to play */

        ofstream ptr ("turn.txt");

        ptr<<turn;

        ptr.close();

    }
else/* file exists */

    {

        pt>>turn;

        pt.close();

        if(turn%2==0)

                turn = 1;

                else

                turn = 2;

        ofstream file ("turn.txt");

        file<<turn;

        file.close();

    }

}



int board_full()

{

    for(int y=0;y<6;y++)

        {

            int empty=0;/* flag for board empty */

            for(int x=0;x<7;x++)

            {

            if(board[x][y]==0)

                {

                empty = 1;

                break;

                }

            }
if(empty==1)

          return 0;

          else/*board is full*/

             {

             printf("this match is a drawn");

             return 1;

             }

      }

}

int call_code()

{

    for(int temp=0;temp<=3;temp++)/* at max 3 times */

     {

                 remove("output.txt");/* deleting the output.txt file */

          ofstream ptr ("moves.txt");/* writing moves played yet and powers used by player*/

          ifstream abc ("turn.txt");

                 int record;

                 abc>>record;

                 if(record%2==1)

          ptr<<(turn-1)/2<<" ";

                 else

                 ptr<<turn/2-1<<" ";

          if(turn%2==0)

          ptr<<spmove12<<" "<<spmove22<<" "<<spmove32<<" "<<spmove42;

          else

          ptr<<spmove11<<" "<<spmove21<<" "<<spmove31<<" "<<spmove41;

          ptr.close();
ofstream file ("team_no.txt");/* creating the team_no.txt file */



    if(turn%2==0)

    file<<"2";

    else

    file<<"1";

    file.close();



    ofstream pt ("opponent_move.txt");



    if(turn%2==0)

    pt<<spmove11<<" "<<spmove21<<" "<<spmove31<<" "<<spmove41;

    else

    pt<<spmove12<<" "<<spmove22<<" "<<spmove32<<" "<<spmove42;

    pt.close();



int legal = 1;

if(temp == 3)

{

    printf("game overn");

    if(turn%2 == 1)

    printf("player 2 winsn");

    else

    printf("player 1 winsn");

    return 1;

}
pid_t pid;

              pid = fork();/* to start a child process*/

              if(pid == 0)/* child process */

              {

                     // team codes will be called from here

                     // respective commands according to the language of the code will be used

                 // for eg to run c++ program named "abc.cpp" first copy the code in the same
directory as this code then write

                     // system("g++ abc.cpp -o abc");

                     // system("./abc");

          if(turn%2 == 1)

          {

                        /*call first player code */

                     // write command (system function) here to call code

          }

          else

          {

              /* call second participant code*/

                     // write command (system function) here to call code

          }

                  exit(0);/* exit the child process */

      }

              else

              {/* main program sleeps for 2s*/

              sleep(2);/* execution time limit */

              kill(pid,SIGKILL);

              }

      ifstream out ("output.txt");/*reading output*/
if(out == NULL)

        continue;

        else

        {

            out>>move_type;

            out>>move;

            out.close();

        }

        int check = legal_move();/* check if move is legal */

        if(check == 0)/* move is illegal */

        continue;

        if(legal == 1)/* this means code reaches succesfully i.e. move is legal */

        break;

    }

    return 0;

}



int move_counter()

{

        add_disk();

        if(turn%2 == 0)

        moves2++;

        else

        moves1++;

        if(move_type==1)

        {

            if(turn%2==0)
spmove12++;

        else

        spmove11++;

    }

    else if(move_type==2)

    {

        if(turn%2==0)

        spmove22++;

        else

        spmove21++;

    }

    else if(move_type==3)

    {

        if(turn%2==0)

        spmove32++;

        else

        spmove31++;

    }

    else if(move_type==4)

    {

        if(turn%2==0)

        spmove42++;

        else

        spmove41++;

    }

}

Más contenido relacionado

La actualidad más candente

The Ring programming language version 1.10 book - Part 38 of 212
The Ring programming language version 1.10 book - Part 38 of 212The Ring programming language version 1.10 book - Part 38 of 212
The Ring programming language version 1.10 book - Part 38 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 79 of 184
The Ring programming language version 1.5.3 book - Part 79 of 184The Ring programming language version 1.5.3 book - Part 79 of 184
The Ring programming language version 1.5.3 book - Part 79 of 184Mahmoud Samir Fayed
 
The Ring programming language version 1.5 book - Part 5 of 31
The Ring programming language version 1.5 book - Part 5 of 31The Ring programming language version 1.5 book - Part 5 of 31
The Ring programming language version 1.5 book - Part 5 of 31Mahmoud Samir Fayed
 
[WELC] 21. I’m Changing the Same Code All Over the Place
[WELC] 21. I’m Changing the Same Code All Over the Place[WELC] 21. I’m Changing the Same Code All Over the Place
[WELC] 21. I’m Changing the Same Code All Over the Place종빈 오
 
統計的学習の基礎 4章 前半
統計的学習の基礎 4章 前半統計的学習の基礎 4章 前半
統計的学習の基礎 4章 前半Ken'ichi Matsui
 
The Ring programming language version 1.10 book - Part 81 of 212
The Ring programming language version 1.10 book - Part 81 of 212The Ring programming language version 1.10 book - Part 81 of 212
The Ring programming language version 1.10 book - Part 81 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 62 of 189
The Ring programming language version 1.6 book - Part 62 of 189The Ring programming language version 1.6 book - Part 62 of 189
The Ring programming language version 1.6 book - Part 62 of 189Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 51 of 180
The Ring programming language version 1.5.1 book - Part 51 of 180The Ring programming language version 1.5.1 book - Part 51 of 180
The Ring programming language version 1.5.1 book - Part 51 of 180Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 71 of 212
The Ring programming language version 1.10 book - Part 71 of 212The Ring programming language version 1.10 book - Part 71 of 212
The Ring programming language version 1.10 book - Part 71 of 212Mahmoud Samir Fayed
 
AST: threats and opportunities
AST: threats and opportunitiesAST: threats and opportunities
AST: threats and opportunitiesAlexander Lifanov
 
The Ring programming language version 1.4 book - Part 7 of 30
The Ring programming language version 1.4 book - Part 7 of 30The Ring programming language version 1.4 book - Part 7 of 30
The Ring programming language version 1.4 book - Part 7 of 30Mahmoud Samir Fayed
 
Bowling Game Kata by Robert C. Martin
Bowling Game Kata by Robert C. MartinBowling Game Kata by Robert C. Martin
Bowling Game Kata by Robert C. MartinLalit Kale
 
Bowling Game Kata in C# Adapted
Bowling Game Kata in C# AdaptedBowling Game Kata in C# Adapted
Bowling Game Kata in C# AdaptedMike Clement
 
Bowling Game Kata C#
Bowling Game Kata C#Bowling Game Kata C#
Bowling Game Kata C#Dan Stewart
 
The Ring programming language version 1.9 book - Part 37 of 210
The Ring programming language version 1.9 book - Part 37 of 210The Ring programming language version 1.9 book - Part 37 of 210
The Ring programming language version 1.9 book - Part 37 of 210Mahmoud Samir Fayed
 
Games, AI, and Research - Part 2 Training (FightingICE AI Programming)
Games, AI, and Research - Part 2 Training (FightingICE AI Programming)Games, AI, and Research - Part 2 Training (FightingICE AI Programming)
Games, AI, and Research - Part 2 Training (FightingICE AI Programming)Pujana Paliyawan
 
「ベータ分布の謎に迫る」第6回 プログラマのための数学勉強会 LT資料
「ベータ分布の謎に迫る」第6回 プログラマのための数学勉強会 LT資料「ベータ分布の謎に迫る」第6回 プログラマのための数学勉強会 LT資料
「ベータ分布の謎に迫る」第6回 プログラマのための数学勉強会 LT資料Ken'ichi Matsui
 

La actualidad más candente (20)

The Ring programming language version 1.10 book - Part 38 of 212
The Ring programming language version 1.10 book - Part 38 of 212The Ring programming language version 1.10 book - Part 38 of 212
The Ring programming language version 1.10 book - Part 38 of 212
 
The Ring programming language version 1.5.3 book - Part 79 of 184
The Ring programming language version 1.5.3 book - Part 79 of 184The Ring programming language version 1.5.3 book - Part 79 of 184
The Ring programming language version 1.5.3 book - Part 79 of 184
 
The Ring programming language version 1.5 book - Part 5 of 31
The Ring programming language version 1.5 book - Part 5 of 31The Ring programming language version 1.5 book - Part 5 of 31
The Ring programming language version 1.5 book - Part 5 of 31
 
[WELC] 21. I’m Changing the Same Code All Over the Place
[WELC] 21. I’m Changing the Same Code All Over the Place[WELC] 21. I’m Changing the Same Code All Over the Place
[WELC] 21. I’m Changing the Same Code All Over the Place
 
統計的学習の基礎 4章 前半
統計的学習の基礎 4章 前半統計的学習の基礎 4章 前半
統計的学習の基礎 4章 前半
 
The Ring programming language version 1.10 book - Part 81 of 212
The Ring programming language version 1.10 book - Part 81 of 212The Ring programming language version 1.10 book - Part 81 of 212
The Ring programming language version 1.10 book - Part 81 of 212
 
ES6, WTF?
ES6, WTF?ES6, WTF?
ES6, WTF?
 
The Ring programming language version 1.6 book - Part 62 of 189
The Ring programming language version 1.6 book - Part 62 of 189The Ring programming language version 1.6 book - Part 62 of 189
The Ring programming language version 1.6 book - Part 62 of 189
 
The Ring programming language version 1.5.1 book - Part 51 of 180
The Ring programming language version 1.5.1 book - Part 51 of 180The Ring programming language version 1.5.1 book - Part 51 of 180
The Ring programming language version 1.5.1 book - Part 51 of 180
 
The Ring programming language version 1.10 book - Part 71 of 212
The Ring programming language version 1.10 book - Part 71 of 212The Ring programming language version 1.10 book - Part 71 of 212
The Ring programming language version 1.10 book - Part 71 of 212
 
AST: threats and opportunities
AST: threats and opportunitiesAST: threats and opportunities
AST: threats and opportunities
 
The Ring programming language version 1.4 book - Part 7 of 30
The Ring programming language version 1.4 book - Part 7 of 30The Ring programming language version 1.4 book - Part 7 of 30
The Ring programming language version 1.4 book - Part 7 of 30
 
Bowling Game Kata by Robert C. Martin
Bowling Game Kata by Robert C. MartinBowling Game Kata by Robert C. Martin
Bowling Game Kata by Robert C. Martin
 
Bowling Game Kata in C# Adapted
Bowling Game Kata in C# AdaptedBowling Game Kata in C# Adapted
Bowling Game Kata in C# Adapted
 
Bowling Game Kata C#
Bowling Game Kata C#Bowling Game Kata C#
Bowling Game Kata C#
 
The Ring programming language version 1.9 book - Part 37 of 210
The Ring programming language version 1.9 book - Part 37 of 210The Ring programming language version 1.9 book - Part 37 of 210
The Ring programming language version 1.9 book - Part 37 of 210
 
Games, AI, and Research - Part 2 Training (FightingICE AI Programming)
Games, AI, and Research - Part 2 Training (FightingICE AI Programming)Games, AI, and Research - Part 2 Training (FightingICE AI Programming)
Games, AI, and Research - Part 2 Training (FightingICE AI Programming)
 
Pemrograman visual
Pemrograman visualPemrograman visual
Pemrograman visual
 
Lập trình Python cơ bản
Lập trình Python cơ bảnLập trình Python cơ bản
Lập trình Python cơ bản
 
「ベータ分布の謎に迫る」第6回 プログラマのための数学勉強会 LT資料
「ベータ分布の謎に迫る」第6回 プログラマのための数学勉強会 LT資料「ベータ分布の謎に迫る」第6回 プログラマのための数学勉強会 LT資料
「ベータ分布の謎に迫る」第6回 プログラマのための数学勉強会 LT資料
 

Similar a AI CHALLENGE ADMIN

In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdfIn Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdfanjandavid
 
#include stdio.h #include string.h #include stdlib.h #in.pdf
#include stdio.h #include string.h #include stdlib.h #in.pdf#include stdio.h #include string.h #include stdlib.h #in.pdf
#include stdio.h #include string.h #include stdlib.h #in.pdfsinghanubhav1234
 
19012011102_Nayan Oza_Practical-7_AI.pdf
19012011102_Nayan Oza_Practical-7_AI.pdf19012011102_Nayan Oza_Practical-7_AI.pdf
19012011102_Nayan Oza_Practical-7_AI.pdfNayanOza
 
The main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdfThe main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdfasif1401
 
Need to make a ReversiOthello Board game in JAVAThe board size ca.pdf
Need to make a ReversiOthello Board game in JAVAThe board size ca.pdfNeed to make a ReversiOthello Board game in JAVAThe board size ca.pdf
Need to make a ReversiOthello Board game in JAVAThe board size ca.pdfflashfashioncasualwe
 
package Assignment;import java.util.;public class assignment .pdf
package Assignment;import java.util.;public class assignment .pdfpackage Assignment;import java.util.;public class assignment .pdf
package Assignment;import java.util.;public class assignment .pdfnoelbuddy
 
The following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdfThe following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdffonecomp
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語ikdysfm
 
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docxPiersRCoThomsonw
 
write the TODO part of the program.docx
write the TODO part of the program.docxwrite the TODO part of the program.docx
write the TODO part of the program.docxannetnash8266
 
i have a code that runs, but it only lets the player to guess where .pdf
i have a code that runs, but it only lets the player to guess where .pdfi have a code that runs, but it only lets the player to guess where .pdf
i have a code that runs, but it only lets the player to guess where .pdfpoblettesedanoree498
 
ARM 7 LPC 2148 lecture
ARM 7 LPC 2148 lectureARM 7 LPC 2148 lecture
ARM 7 LPC 2148 lectureanishgoel
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsKandarp Tiwari
 
Sorting programs
Sorting programsSorting programs
Sorting programsVarun Garg
 
#includeiostream #includefstreamusing namespace std; glo.pdf
#includeiostream #includefstreamusing namespace std; glo.pdf#includeiostream #includefstreamusing namespace std; glo.pdf
#includeiostream #includefstreamusing namespace std; glo.pdfkrram1989
 
Create a C program that implements The Game of Life cellular auto.pdf
Create a C program that implements The Game of Life cellular auto.pdfCreate a C program that implements The Game of Life cellular auto.pdf
Create a C program that implements The Game of Life cellular auto.pdfarihantsherwani
 
Here is the code for youimport java.util.Scanner; import java.u.pdf
Here is the code for youimport java.util.Scanner; import java.u.pdfHere is the code for youimport java.util.Scanner; import java.u.pdf
Here is the code for youimport java.util.Scanner; import java.u.pdfanithareadymade
 
import tio.;class TicTacToe {static final int EMPTY = 0;stati.pdf
import tio.;class TicTacToe {static final int EMPTY = 0;stati.pdfimport tio.;class TicTacToe {static final int EMPTY = 0;stati.pdf
import tio.;class TicTacToe {static final int EMPTY = 0;stati.pdfpreetajain
 

Similar a AI CHALLENGE ADMIN (20)

Include
IncludeInclude
Include
 
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdfIn Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
 
#include stdio.h #include string.h #include stdlib.h #in.pdf
#include stdio.h #include string.h #include stdlib.h #in.pdf#include stdio.h #include string.h #include stdlib.h #in.pdf
#include stdio.h #include string.h #include stdlib.h #in.pdf
 
19012011102_Nayan Oza_Practical-7_AI.pdf
19012011102_Nayan Oza_Practical-7_AI.pdf19012011102_Nayan Oza_Practical-7_AI.pdf
19012011102_Nayan Oza_Practical-7_AI.pdf
 
The main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdfThe main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdf
 
Need to make a ReversiOthello Board game in JAVAThe board size ca.pdf
Need to make a ReversiOthello Board game in JAVAThe board size ca.pdfNeed to make a ReversiOthello Board game in JAVAThe board size ca.pdf
Need to make a ReversiOthello Board game in JAVAThe board size ca.pdf
 
tetris
tetristetris
tetris
 
package Assignment;import java.util.;public class assignment .pdf
package Assignment;import java.util.;public class assignment .pdfpackage Assignment;import java.util.;public class assignment .pdf
package Assignment;import java.util.;public class assignment .pdf
 
The following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdfThe following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdf
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語
 
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
 
write the TODO part of the program.docx
write the TODO part of the program.docxwrite the TODO part of the program.docx
write the TODO part of the program.docx
 
i have a code that runs, but it only lets the player to guess where .pdf
i have a code that runs, but it only lets the player to guess where .pdfi have a code that runs, but it only lets the player to guess where .pdf
i have a code that runs, but it only lets the player to guess where .pdf
 
ARM 7 LPC 2148 lecture
ARM 7 LPC 2148 lectureARM 7 LPC 2148 lecture
ARM 7 LPC 2148 lecture
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C Programs
 
Sorting programs
Sorting programsSorting programs
Sorting programs
 
#includeiostream #includefstreamusing namespace std; glo.pdf
#includeiostream #includefstreamusing namespace std; glo.pdf#includeiostream #includefstreamusing namespace std; glo.pdf
#includeiostream #includefstreamusing namespace std; glo.pdf
 
Create a C program that implements The Game of Life cellular auto.pdf
Create a C program that implements The Game of Life cellular auto.pdfCreate a C program that implements The Game of Life cellular auto.pdf
Create a C program that implements The Game of Life cellular auto.pdf
 
Here is the code for youimport java.util.Scanner; import java.u.pdf
Here is the code for youimport java.util.Scanner; import java.u.pdfHere is the code for youimport java.util.Scanner; import java.u.pdf
Here is the code for youimport java.util.Scanner; import java.u.pdf
 
import tio.;class TicTacToe {static final int EMPTY = 0;stati.pdf
import tio.;class TicTacToe {static final int EMPTY = 0;stati.pdfimport tio.;class TicTacToe {static final int EMPTY = 0;stati.pdf
import tio.;class TicTacToe {static final int EMPTY = 0;stati.pdf
 

Último

Jewish Resources in the Family Resource Centre
Jewish Resources in the Family Resource CentreJewish Resources in the Family Resource Centre
Jewish Resources in the Family Resource CentreNZSG
 
20220816-EthicsGrade_Scorecard-JP_Morgan_Chase-Q2-63_57.pdf
20220816-EthicsGrade_Scorecard-JP_Morgan_Chase-Q2-63_57.pdf20220816-EthicsGrade_Scorecard-JP_Morgan_Chase-Q2-63_57.pdf
20220816-EthicsGrade_Scorecard-JP_Morgan_Chase-Q2-63_57.pdfChris Skinner
 
Onemonitar Android Spy App Features: Explore Advanced Monitoring Capabilities
Onemonitar Android Spy App Features: Explore Advanced Monitoring CapabilitiesOnemonitar Android Spy App Features: Explore Advanced Monitoring Capabilities
Onemonitar Android Spy App Features: Explore Advanced Monitoring CapabilitiesOne Monitar
 
14680-51-4.pdf Good quality CAS Good quality CAS
14680-51-4.pdf  Good  quality CAS Good  quality CAS14680-51-4.pdf  Good  quality CAS Good  quality CAS
14680-51-4.pdf Good quality CAS Good quality CAScathy664059
 
20200128 Ethical by Design - Whitepaper.pdf
20200128 Ethical by Design - Whitepaper.pdf20200128 Ethical by Design - Whitepaper.pdf
20200128 Ethical by Design - Whitepaper.pdfChris Skinner
 
WSMM Media and Entertainment Feb_March_Final.pdf
WSMM Media and Entertainment Feb_March_Final.pdfWSMM Media and Entertainment Feb_March_Final.pdf
WSMM Media and Entertainment Feb_March_Final.pdfJamesConcepcion7
 
PSCC - Capability Statement Presentation
PSCC - Capability Statement PresentationPSCC - Capability Statement Presentation
PSCC - Capability Statement PresentationAnamaria Contreras
 
Planetary and Vedic Yagyas Bring Positive Impacts in Life
Planetary and Vedic Yagyas Bring Positive Impacts in LifePlanetary and Vedic Yagyas Bring Positive Impacts in Life
Planetary and Vedic Yagyas Bring Positive Impacts in LifeBhavana Pujan Kendra
 
Excvation Safety for safety officers reference
Excvation Safety for safety officers referenceExcvation Safety for safety officers reference
Excvation Safety for safety officers referencessuser2c065e
 
Environmental Impact Of Rotary Screw Compressors
Environmental Impact Of Rotary Screw CompressorsEnvironmental Impact Of Rotary Screw Compressors
Environmental Impact Of Rotary Screw Compressorselgieurope
 
Interoperability and ecosystems: Assembling the industrial metaverse
Interoperability and ecosystems:  Assembling the industrial metaverseInteroperability and ecosystems:  Assembling the industrial metaverse
Interoperability and ecosystems: Assembling the industrial metaverseSiemens
 
TriStar Gold Corporate Presentation - April 2024
TriStar Gold Corporate Presentation - April 2024TriStar Gold Corporate Presentation - April 2024
TriStar Gold Corporate Presentation - April 2024Adnet Communications
 
WSMM Technology February.March Newsletter_vF.pdf
WSMM Technology February.March Newsletter_vF.pdfWSMM Technology February.March Newsletter_vF.pdf
WSMM Technology February.March Newsletter_vF.pdfJamesConcepcion7
 
GUIDELINES ON USEFUL FORMS IN FREIGHT FORWARDING (F) Danny Diep Toh MBA.pdf
GUIDELINES ON USEFUL FORMS IN FREIGHT FORWARDING (F) Danny Diep Toh MBA.pdfGUIDELINES ON USEFUL FORMS IN FREIGHT FORWARDING (F) Danny Diep Toh MBA.pdf
GUIDELINES ON USEFUL FORMS IN FREIGHT FORWARDING (F) Danny Diep Toh MBA.pdfDanny Diep To
 
1911 Gold Corporate Presentation Apr 2024.pdf
1911 Gold Corporate Presentation Apr 2024.pdf1911 Gold Corporate Presentation Apr 2024.pdf
1911 Gold Corporate Presentation Apr 2024.pdfShaun Heinrichs
 
digital marketing , introduction of digital marketing
digital marketing , introduction of digital marketingdigital marketing , introduction of digital marketing
digital marketing , introduction of digital marketingrajputmeenakshi733
 
How To Simplify Your Scheduling with AI Calendarfly The Hassle-Free Online Bo...
How To Simplify Your Scheduling with AI Calendarfly The Hassle-Free Online Bo...How To Simplify Your Scheduling with AI Calendarfly The Hassle-Free Online Bo...
How To Simplify Your Scheduling with AI Calendarfly The Hassle-Free Online Bo...SOFTTECHHUB
 
Go for Rakhi Bazaar and Pick the Latest Bhaiya Bhabhi Rakhi.pptx
Go for Rakhi Bazaar and Pick the Latest Bhaiya Bhabhi Rakhi.pptxGo for Rakhi Bazaar and Pick the Latest Bhaiya Bhabhi Rakhi.pptx
Go for Rakhi Bazaar and Pick the Latest Bhaiya Bhabhi Rakhi.pptxRakhi Bazaar
 
Church Building Grants To Assist With New Construction, Additions, And Restor...
Church Building Grants To Assist With New Construction, Additions, And Restor...Church Building Grants To Assist With New Construction, Additions, And Restor...
Church Building Grants To Assist With New Construction, Additions, And Restor...Americas Got Grants
 

Último (20)

Jewish Resources in the Family Resource Centre
Jewish Resources in the Family Resource CentreJewish Resources in the Family Resource Centre
Jewish Resources in the Family Resource Centre
 
WAM Corporate Presentation April 12 2024.pdf
WAM Corporate Presentation April 12 2024.pdfWAM Corporate Presentation April 12 2024.pdf
WAM Corporate Presentation April 12 2024.pdf
 
20220816-EthicsGrade_Scorecard-JP_Morgan_Chase-Q2-63_57.pdf
20220816-EthicsGrade_Scorecard-JP_Morgan_Chase-Q2-63_57.pdf20220816-EthicsGrade_Scorecard-JP_Morgan_Chase-Q2-63_57.pdf
20220816-EthicsGrade_Scorecard-JP_Morgan_Chase-Q2-63_57.pdf
 
Onemonitar Android Spy App Features: Explore Advanced Monitoring Capabilities
Onemonitar Android Spy App Features: Explore Advanced Monitoring CapabilitiesOnemonitar Android Spy App Features: Explore Advanced Monitoring Capabilities
Onemonitar Android Spy App Features: Explore Advanced Monitoring Capabilities
 
14680-51-4.pdf Good quality CAS Good quality CAS
14680-51-4.pdf  Good  quality CAS Good  quality CAS14680-51-4.pdf  Good  quality CAS Good  quality CAS
14680-51-4.pdf Good quality CAS Good quality CAS
 
20200128 Ethical by Design - Whitepaper.pdf
20200128 Ethical by Design - Whitepaper.pdf20200128 Ethical by Design - Whitepaper.pdf
20200128 Ethical by Design - Whitepaper.pdf
 
WSMM Media and Entertainment Feb_March_Final.pdf
WSMM Media and Entertainment Feb_March_Final.pdfWSMM Media and Entertainment Feb_March_Final.pdf
WSMM Media and Entertainment Feb_March_Final.pdf
 
PSCC - Capability Statement Presentation
PSCC - Capability Statement PresentationPSCC - Capability Statement Presentation
PSCC - Capability Statement Presentation
 
Planetary and Vedic Yagyas Bring Positive Impacts in Life
Planetary and Vedic Yagyas Bring Positive Impacts in LifePlanetary and Vedic Yagyas Bring Positive Impacts in Life
Planetary and Vedic Yagyas Bring Positive Impacts in Life
 
Excvation Safety for safety officers reference
Excvation Safety for safety officers referenceExcvation Safety for safety officers reference
Excvation Safety for safety officers reference
 
Environmental Impact Of Rotary Screw Compressors
Environmental Impact Of Rotary Screw CompressorsEnvironmental Impact Of Rotary Screw Compressors
Environmental Impact Of Rotary Screw Compressors
 
Interoperability and ecosystems: Assembling the industrial metaverse
Interoperability and ecosystems:  Assembling the industrial metaverseInteroperability and ecosystems:  Assembling the industrial metaverse
Interoperability and ecosystems: Assembling the industrial metaverse
 
TriStar Gold Corporate Presentation - April 2024
TriStar Gold Corporate Presentation - April 2024TriStar Gold Corporate Presentation - April 2024
TriStar Gold Corporate Presentation - April 2024
 
WSMM Technology February.March Newsletter_vF.pdf
WSMM Technology February.March Newsletter_vF.pdfWSMM Technology February.March Newsletter_vF.pdf
WSMM Technology February.March Newsletter_vF.pdf
 
GUIDELINES ON USEFUL FORMS IN FREIGHT FORWARDING (F) Danny Diep Toh MBA.pdf
GUIDELINES ON USEFUL FORMS IN FREIGHT FORWARDING (F) Danny Diep Toh MBA.pdfGUIDELINES ON USEFUL FORMS IN FREIGHT FORWARDING (F) Danny Diep Toh MBA.pdf
GUIDELINES ON USEFUL FORMS IN FREIGHT FORWARDING (F) Danny Diep Toh MBA.pdf
 
1911 Gold Corporate Presentation Apr 2024.pdf
1911 Gold Corporate Presentation Apr 2024.pdf1911 Gold Corporate Presentation Apr 2024.pdf
1911 Gold Corporate Presentation Apr 2024.pdf
 
digital marketing , introduction of digital marketing
digital marketing , introduction of digital marketingdigital marketing , introduction of digital marketing
digital marketing , introduction of digital marketing
 
How To Simplify Your Scheduling with AI Calendarfly The Hassle-Free Online Bo...
How To Simplify Your Scheduling with AI Calendarfly The Hassle-Free Online Bo...How To Simplify Your Scheduling with AI Calendarfly The Hassle-Free Online Bo...
How To Simplify Your Scheduling with AI Calendarfly The Hassle-Free Online Bo...
 
Go for Rakhi Bazaar and Pick the Latest Bhaiya Bhabhi Rakhi.pptx
Go for Rakhi Bazaar and Pick the Latest Bhaiya Bhabhi Rakhi.pptxGo for Rakhi Bazaar and Pick the Latest Bhaiya Bhabhi Rakhi.pptx
Go for Rakhi Bazaar and Pick the Latest Bhaiya Bhabhi Rakhi.pptx
 
Church Building Grants To Assist With New Construction, Additions, And Restor...
Church Building Grants To Assist With New Construction, Additions, And Restor...Church Building Grants To Assist With New Construction, Additions, And Restor...
Church Building Grants To Assist With New Construction, Additions, And Restor...
 

AI CHALLENGE ADMIN

  • 1. #include <stdio.h> #include <iostream> #include <time.h> #include <stdlib.h> #include <fstream> #include <pthread.h> #include <unistd.h> #include <signal.h> using namespace std; #define CLEAR_ROW 1 #define CLEAR_COLUMN 2 #define CLEAR_FIRST_NEIGHBOURS 3 #define DUAL_COLOUR 4 #define NORMAL 5 #define PLAYER_1 1 #define PLAYER_2 2 /* global decalarations */ int turn = 0;/* this number will record whose turn is it */ int moves1=0,moves2=0;/* for tracking the number of moves pklayed yet by participants*/ int spmove11=0,spmove21=0,spmove31=0,spmove41=0,spmove12=0,spmove22=0,spmove32=0,spmov e42=0;/* flags to keep track the special moves of players */ int move_type=0,move=0; int board[7][6] = {0};
  • 2. /* functions used */ int legal_move(); int add_disk(); int check_win(int team); int right_up(int x,int y); int left_up(int x,int y); int vertical(int x,int y); int horizontal(int x,int y); int write_board(); int draw_board(); int first_turn(); int board_full(); int call_code(); int move_counter(); int main() { first_turn();/* decides first turn */ write_board();/* writes board to txt file */ draw_board();/* call graphics function to draw the board */ int match_over = 0;/* flag telling match is over or not */ while(1)/*starting the infinite loop*/ { write_board(); match_over = board_full();/*checking if board is full*/ if(match_over==1) break;
  • 3. /*calling the participant code*/ match_over = call_code(); if(match_over == 1) break; else/* match_over == 0 *//* match is not over */ { move_counter(); turn++; draw_board(); int check1 = check_win(1);/* checking winner */ int check2 = check_win(2); if(check1 == 1 && check2 == 1) { printf("its a drawn"); break; } else if(check1 == 1) { printf("player 1 winsn"); break; } else if(check2 == 1) { printf("player 2 winsn"); break; }
  • 4. } } return 0; } int legal_move() { if(move > 7 || move < 1)/*invalid column */ return 0; else if(board[move-1][0] != 0)/* top most position of column is not empty*/ return 0; if(turn%2 == 0)/* for player 2 */ { if(move_type == CLEAR_ROW && spmove12 == 1) return 0; else if(move_type == CLEAR_COLUMN && spmove22 == 1) return 0; else if(move_type == CLEAR_FIRST_NEIGHBOURS && spmove32 == 1) return 0; else if(move_type == DUAL_COLOUR && spmove42 == 1) return 0; else if(move_type != DUAL_COLOUR && moves2 == 9 && spmove42 == 0)/* move type 4 means dual color block */ return 0; } else { if(move_type == CLEAR_ROW && spmove11 == 1)
  • 5. return 0; else if(move_type == CLEAR_COLUMN && spmove21 == 1) return 0; else if(move_type == CLEAR_FIRST_NEIGHBOURS && spmove31 == 1) return 0; else if(move_type == DUAL_COLOUR && spmove41 == 1) return 0; else if(move_type != DUAL_COLOUR && moves1 == 9 && spmove41 == 0) return 0; } return 1; } int add_disk() { for(int y = 0;y<6;y++) { if(board[move-1][y+1] != 0 || y+1>5)/* bottommost position in that column */ { if(move_type == CLEAR_ROW)/* 1 means detroying complete row */ { for(int x=0;x<7;x++) { for(int temp = y;temp>=0;temp--) board[x][temp] = board[x][temp-1]; board[x][0] = 0; }
  • 6. } else if(move_type == CLEAR_COLUMN)/* destroying complete column */ { for(int temp = 0;temp<7;temp++) board[move-1][temp] = 0; } else if(move_type == CLEAR_FIRST_NEIGHBOURS)/* destroying neighbour block in every direction */ { for(int temp = move-2;temp <= move;temp++) { if(temp<0 || temp>6) continue; if(y+1<6) board[temp][y+1]=0; board[temp][y]=0; if(y-1>=0) board[temp][y-1]=0; /* now need to shift zeroes */ for(int count=0;count < 3;count++) { for(int change = 5;change > 0;change--) { if(board[temp][change]==0) { board[temp][change] = board[temp][change-1]; board[temp][change-1] = 0; }
  • 7. } } } } else if(move_type == DUAL_COLOUR)/* dual color block */ { board[move-1][y] = 12; } else/* normal block */ { if(turn % 2 == 1) board[move-1][y] = 1; else board[move-1][y] = 2; } break; } } return 0; } int check_win(int team) { int result=0,temp=0; for(int y=5;y>=0;y--) for(int x=0;x<7;x++) {
  • 8. if(board[x][y] == 0)/* block is empty */ continue; if(board[x][y] == team || board[x][y] == 12) { result = right_up(x,y); if(result!=1) result = left_up(x,y); if(result!=1) result = vertical(x,y); if(result!=1) result = horizontal(x,y); } if(result == 1) return 1; } return 0; } int right_up(int x,int y) { if(y<3 || x>3)/* not possible */ return 0; else if(x-1>=0 && y+1<6 && (board[x-1][y+1] == board[x][y] || board[x-1][y+1] == 12)) return 0;/* condition was checked at x-1 and y+1 already */ else { int count=1;
  • 9. for(int temp = 1;temp<4;temp++) { if(board[x+temp][y-temp] == board[x][y] || board[x+temp][y-temp] == 12) count++; } if(count == 4) return 1; } return 0; } int left_up(int x,int y) { if(y<3 || x<3)/* not possible */ return 0; else if(x+1<7 && y+1<6 && (board[x+1][y+1] == board[x][y] || board[x+1][y+1] == 12)) return 0;/* condition was checked at x+1 and y+1 already */ else { int count=1; for(int temp = 1;temp<4;temp++) { if(board[x-temp][y-temp] == board[x][y]) count++; } if(count == 4) return 1;
  • 10. } return 0; } int vertical(int x,int y) { if(y<3) return 0; else if( y+1 < 6 && (board[x][y+1] == board[x][y] || board[x][y+1] == 12)) return 0; int count = 1; for(int temp=1;temp<4;temp++) { if(board[x][y-temp] == board[x][y] || board[x][y-temp] == 12 ) count++; } if(count == 4) return 1; return 0; } int horizontal(int x,int y) { if(x>3) return 0; else if( x-1>=0 && (board[x-1][y] == board[x][y] || board[x-1][y]==12)) return 0;
  • 11. int count=1; for(int temp=1;temp<4;temp++) { if(board[x+temp][y] == board[x][y] || board[x+temp][y] == 12 ) count++; } if(count == 4) return 1; return 0; } int write_board() { ofstream pt ("board.txt"); for(int y = 5 ; y>=0 ; y--) { for(int x = 0 ; x < 7 ;x++) { pt<<board[x][y]<<" "; } } pt.close(); return 0; } int draw_board() {
  • 12. printf("n"); for(int y = 0 ; y<6;y++) { for(int x = 0 ; x < 7 ; x++) printf("%d ",board[x][y]); printf("n"); } printf("nn"); return 0; } int first_turn() { srand ( time(NULL) ); /* initialization to generate a random number*/ /* deciding the first player whose turn is it */ ifstream pt ("turn.txt"); /* opening the file in which the player who got the first turn is written */ if(pt == NULL)/* no such file exists*/ { turn = rand()%2 + 1; /* generating a random number to decide the first player to play */ ofstream ptr ("turn.txt"); ptr<<turn; ptr.close(); }
  • 13. else/* file exists */ { pt>>turn; pt.close(); if(turn%2==0) turn = 1; else turn = 2; ofstream file ("turn.txt"); file<<turn; file.close(); } } int board_full() { for(int y=0;y<6;y++) { int empty=0;/* flag for board empty */ for(int x=0;x<7;x++) { if(board[x][y]==0) { empty = 1; break; } }
  • 14. if(empty==1) return 0; else/*board is full*/ { printf("this match is a drawn"); return 1; } } } int call_code() { for(int temp=0;temp<=3;temp++)/* at max 3 times */ { remove("output.txt");/* deleting the output.txt file */ ofstream ptr ("moves.txt");/* writing moves played yet and powers used by player*/ ifstream abc ("turn.txt"); int record; abc>>record; if(record%2==1) ptr<<(turn-1)/2<<" "; else ptr<<turn/2-1<<" "; if(turn%2==0) ptr<<spmove12<<" "<<spmove22<<" "<<spmove32<<" "<<spmove42; else ptr<<spmove11<<" "<<spmove21<<" "<<spmove31<<" "<<spmove41; ptr.close();
  • 15. ofstream file ("team_no.txt");/* creating the team_no.txt file */ if(turn%2==0) file<<"2"; else file<<"1"; file.close(); ofstream pt ("opponent_move.txt"); if(turn%2==0) pt<<spmove11<<" "<<spmove21<<" "<<spmove31<<" "<<spmove41; else pt<<spmove12<<" "<<spmove22<<" "<<spmove32<<" "<<spmove42; pt.close(); int legal = 1; if(temp == 3) { printf("game overn"); if(turn%2 == 1) printf("player 2 winsn"); else printf("player 1 winsn"); return 1; }
  • 16. pid_t pid; pid = fork();/* to start a child process*/ if(pid == 0)/* child process */ { // team codes will be called from here // respective commands according to the language of the code will be used // for eg to run c++ program named "abc.cpp" first copy the code in the same directory as this code then write // system("g++ abc.cpp -o abc"); // system("./abc"); if(turn%2 == 1) { /*call first player code */ // write command (system function) here to call code } else { /* call second participant code*/ // write command (system function) here to call code } exit(0);/* exit the child process */ } else {/* main program sleeps for 2s*/ sleep(2);/* execution time limit */ kill(pid,SIGKILL); } ifstream out ("output.txt");/*reading output*/
  • 17. if(out == NULL) continue; else { out>>move_type; out>>move; out.close(); } int check = legal_move();/* check if move is legal */ if(check == 0)/* move is illegal */ continue; if(legal == 1)/* this means code reaches succesfully i.e. move is legal */ break; } return 0; } int move_counter() { add_disk(); if(turn%2 == 0) moves2++; else moves1++; if(move_type==1) { if(turn%2==0)
  • 18. spmove12++; else spmove11++; } else if(move_type==2) { if(turn%2==0) spmove22++; else spmove21++; } else if(move_type==3) { if(turn%2==0) spmove32++; else spmove31++; } else if(move_type==4) { if(turn%2==0) spmove42++; else spmove41++; } }