diff --git a/TicTacToe.hs b/TicTacToe.hs new file mode 100644 index 0000000..8b352a6 --- /dev/null +++ b/TicTacToe.hs @@ -0,0 +1,57 @@ +sm a x y c=do + let check1 =0 + let check2 =0 + let check3 =0 + let check4 =0 + let check5 =0 + let check6 =0 + let check7 =0 + let check8 =0 + if (a!!x!!y/=2) + then do + print "INVALID COORDINATES!! enter unfilled coordinates" + y<-getLine + x<-getLine + sm a (read x::Int) (read y::Int) c + else return() + + let row=a!!y + let p1=take x row + let p2= drop (x+1) row + let nrow=p1++[c `mod` 2]++p2 + let py1=take y a + let py2=drop (y+1) a + let f=py1++[nrow]++py2 + print (f!!0) + print (f!!1) + print (f!!2) + let b = c+1 + check1 <- if (f!!0!!0==f!!0!!1)&&(f!!0!!1==f!!0!!2)&&(f!!0!!2/=2) then return (1) else return (0) + check2 <- if (f!!1!!0==f!!1!!1)&&(f!!1!!1==f!!1!!2)&&(f!!1!!2/=2) then return (1) else return (0) + check3 <- if (f!!2!!0==f!!2!!1)&&(f!!2!!1==f!!2!!2)&&(f!!2!!2/=2) then return (1) else return (0) + check4 <- if (f!!0!!0==f!!1!!0)&&(f!!2!!0==f!!1!!0)&&(f!!1!!0/=2) then return (1) else return (0) + check5 <- if (f!!0!!1==f!!1!!1)&&(f!!1!!1==f!!2!!1)&&(f!!2!!1/=2) then return (1) else return (0) + check6 <- if (f!!0!!2==f!!1!!2)&&(f!!2!!2==f!!1!!2)&&(f!!1!!2/=2) then return (1) else return (0) + check7 <- if (f!!0!!0==f!!1!!1)&&(f!!1!!1==f!!2!!2)&&(f!!2!!2/=2) then return (1) else return (0) + check8 <- if (f!!0!!2==f!!1!!1)&&(f!!1!!1==f!!2!!0)&&(f!!2!!0/=2) then return (1) else return (0) + let check = check1+check2+check3+check4+check5+check6+check7+check8 + if (check/=0) + then do + print "Game Over" + print (c `mod` 2) + print "Wins" + else return() + print "Please enter x and y coordinates for next turn " + y<-getLine + x<-getLine + if (check==0) then sm f (read x::Int) (read y::Int) b else print ("GAME OVER ") + +main=do + let f=[[2,2,2],[2,2,2],[2,2,2]] + print (f!!0) + print (f!!1) + print (f!!2) + print "Please enter x and y coordinates for first turn " + x<-getLine + y<-getLine +sm f (read x::Int) (read y::Int) 0 diff --git a/tic.c b/tic.c new file mode 100644 index 0000000..f05323a --- /dev/null +++ b/tic.c @@ -0,0 +1,61 @@ +#include +char mat[3][3]={' ',' ',' ', +' ',' ',' ', +' ',' ',' '},i,arr[9]={0,0,0,0,0,0,0,0,0}; //arr is 0 where input is to be taken + +void printmat(){ + int i,j; + printf("\n"); + for(i=0;i<3;i++){ + for(j=0;j<3;j++) + printf("%c ",mat[i][j]); + printf("\n"); + } +} + +void printopt(){ + printf("\n"); + int i,j,p,c=1,t; + for(i=0;i<3;i++) + for(j=0;j<3;j++){ + //printf("%d",mat[i][j]); + if(mat[i][j]!=' '){ + t=3*i+j; + arr[t]=1; + } + } + + for(p=0;p<9;p++){ + if(arr[p]==0){ + printf("%d.(%d,%d)\n",c,(p)/3+1,(p)%3+1); + c++; + } + } +} + +int matammend(int ind,int in){ + int i; + for(i=0;i<9;i++){ + if(arr[i]==0){ + in--; + if(in==0){ + if(ind%2==0)mat[i/3][i%3]='X'; + else mat[i/3][i%3]='O'; + } + } + } +} +int main(){ +int in; +for(i=0;i<9;i++){ + +printopt(); +scanf("%d",&in); +matammend(i,in); +printmat(); + + +} + +} + diff --git a/try b/try new file mode 100644 index 0000000..9808d5e --- /dev/null +++ b/try @@ -0,0 +1,4 @@ +git remote add Ahsan https://github.com/ahsanbarkati/ACA_Haskell.git +git push serversbrnchname loclbrnchname +git pull +git push