#include<conio.h>
#include<math.h>
#include<dos.h>
#include<stdlib.h>
#include<iostream.h>
#include<graphics.h>
void fire(int,int,int);
void plane(int,int,int,int);
void benzingah(int,int,int,int,int);
void enemy(int,int,int,int);
void remove();
void air(int);
//\\//\\//\\//\\//\\//\\//\\//\\//\\
int m=300;
int n=350;
int ch=0;
int v=0;
int l=0;
int l1=360;
int mogheiat[7][100];
//\\//\\//\\//\\//\\//\\//\\//\\//\\
void input()
{
int k;
randomize();
for(int m=0; m<7; m++)
{
k=(1+random (15));
if ( mogheiat[m][79]==0 && mogheiat[m][78]==0 && mogheiat[m][77]==0 &&
mogheiat[m][76]==0 && mogheiat[m][75]==0 && mogheiat[m][74]==0 )
mogheiat[m][80]=k;
}
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\
class move
{
private :
int col,x,y;
public:
move(){mogheiat[7][100]=0; col=x=y=0;}
void array();
void check(int);
void move_all();
void move_plane();
void repeat();
void clean(int,int);
};
//\\//\\//\\//\\//\\//\\//\\//\\//\\
void move::array()
{
for(int i=0; i<7; i++)
for(int j=0; j<100; j++)
mogheiat[i][j]=0;
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\
void move::check(int j)
{
for(int k=0; k<7; k++)
{
if(mogheiat[k][j]==1)
benzingah(200+30*k, 360-j*4, 0, 15, 0);
if(mogheiat[k][j]==2)
enemy(200+30*k, 381-j*4, 0, 12);
}
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\
void move::clean(int i,int j)
{
if(mogheiat[i][j]==1)
benzingah(200+30*i, 360-j*4, 9, 9, 9);
if(mogheiat[i][j]==2)
enemy(200+30*i, 381-j*4, 9, 9);
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\
void move::move_all()
{
v++;
if( v % 5 == 0)
for(int j=0; j<80; j++)
{
for(int i=0; i<7; i++)
{
clean(i,j+1);
clean(i,j);
mogheiat[i][j]=mogheiat[i][j+1];
mogheiat[i][j+1]=0;
}
check(j);
}
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\
void move::move_plane()
{
plane(m,n,7,0);
if(kbhit())
ch=getch();
if(ch==77) //right
{
if(m<380)
{
plane(m,n,9,9);
m=m+10;
plane(m,n,7,0);
ch=1;
}
}
if(ch==75) //left
{
if(m>210)
{
plane(m,n,9,9);
m=m-10;
plane(m,n,7,0);
ch=1;
}
}
if(ch==72) //up
{
if(n>100)
{
plane(m,n,9,9);
n=n-3;
plane(m,n,7,0);
ch=1;
}
}
if(ch==80) //down
{
if(n<370)
{
plane(m,n,9,9);
n=n+3;
plane(m,n,7,0);
ch=1;
}
}
if(ch==32) //space
{
int x,y;
int l=1;
for(int k=n-2; k>30; k--)
{
col=getpixel(m,k-11);
if(col==0 && l==1)
{
x=floor((m-200)/30);
y=floor((395-k)/4);
clean(x,y);
remove();
mogheiat[x][y]=0;
}
fire(m,k,l);
ch=1;
} //for
}
if(ch==27)
exit(4);
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\
void move::repeat()
{
for(int i=0;;i++)
{
move_all();
move_plane();
input();
if( i % 50 == 0 )
{
air(1);
plane(m,n,9,9);
n--;
plane(m,n,7,0);
}
delay(30);
}
}
//\\//\\//\\//\\//\\******************>>>> MIAN BODY
int main()
{
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "");
setbkcolor(0);
setcolor(15);
rectangle(180,5,410,400);
setfillstyle(1,9);
floodfill(300,200,15);
move t;
t.array();
input();
t.repeat();
getch();
closegraph();
return 0;
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\
void fire(int m,int k,int s)
{
if(s==1)
{
setcolor(15);
line(m,k,m,k-10);
delay(1);
setcolor(9);
line(m,k,m,k-10);
}
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\
void remove()
{
setcolor(9);
delay(10);
}
//\\//\\//\\//\\//\\/\\//\\//\\//\\
void air(int l)
{
if(l==1)
{
l1=l1-1;
}
if(l==2)
{
l1=l1+20;
}
setcolor(4);
rectangle(211,411,l1,419);
setfillstyle(1,2);
floodfill(212,415,4);
setcolor(1);
if(l1==215)
exit(1);
setcolor(15);
rectangle(210,410,363,420);
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\
void benzingah(int x,int y,int col1,int col2,int col3)
{
setcolor(col1);
rectangle(x,y,x+15,y+8);
setfillstyle(1,col2);
floodfill(x+1,y+1,col1);
rectangle(x,y+8,x+15,y+16);
setfillstyle(1,col3);
floodfill(x+1,y+11,col1);
rectangle(x,y+16,x+15,y+24);
setfillstyle(1,col2);
floodfill(x+1,y+17,col1);
}
//\\//\\//\\//\\//\\//\\//\\//\\
void enemy(int x,int y,int col1,int col2)
{
setcolor(col1);
rectangle(x,y,x+15,y+10);
setfillstyle(1,col2);
floodfill(x+10,y+5,col1);
}
//\\//\\//\\//\\//\\//\\//\\//\\
void plane(int x,int y,int col1,int col2)
{
setcolor(col2);
line(x,y,x-20,y+20);
line(x,y,x+20,y+20);
line(x-20,y+20,x,y+14);
line(x+20,y+20,x,y+14);
setfillstyle(1,col1);
floodfill(x,y+2,col2);
}
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
char s[5000];
void pp(int n);
void main()
{
clrscr();
long int i,k,m;
printf("enter number:\t");
scanf(" %ld",&m);
itoa(1, s, 10);
for(i=1;i<=m;++i){
pp(i);
}
k=strlen(s);
for(i=k;i>=0;--i)
printf("%c",s[i]);
getch();
}
////////////////
void pp(int n){
long int r,i,j,k,l;
r=0;
for(i=0;s[i]!='\0';++i){
k=(s[i]-48)*n+r;
l=k-(k/10)*10;
s[i]=l+48;
r=k/10;
}
for(j=i;r>0;++j){
l=r-(r/10)*10;
s[j]=l+48;
r=r/10;
}
s[j+1]='\0';
}
/******************** Ocarina.ws **********/
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <stdlib.h>
void main()
{
int random_y1,random_y2,random_x1,random_x2,w_x,w_y,x,y;
clrscr();
randomize();
do /***** Begin Loop *****/
{
w_x=wherex()-3;
w_y=wherey();
clrscr();
gotoxy(w_x+x,w_y+y);
textcolor(1+random(3));
printf("AMT");
/******** if text wherex=0 ********/
if (wherex()<=7)
{
sound(200);
random_x1=random(2);
if (random_x1==1)
{x=1;y=1;}
if (random_x1==0)
{x=1;y=-1;}
}
/******** if text wherex=80 ********/
if (wherex()>=78)
{
sound(500);
random_x2=random(2);
if (random_x2==1)
{x=-1;y=-1;}
if (random_x2==0)
{x=-1;y=-1;}
}
/******** if text wherey=0 ********/
if (wherey()==1)
{
sound(800);
random_y1=random(2);
if (random_y1==1)
{y=1;x=-1;}
if (random_y1==0)
{y=1;x=1;}
}
/******** if text wherey=25 ********/
if (wherey()==25)
{
sound(1200);
random_y2=random(2);
if (random_y2==1)
{y=-1;x=-1;}
if (random_y2==0)
{y=-1;x=1;}
}
delay(190);
nosound();
kbhit();
}
while(!kbhit());/***** End Loop *****/
}
/******************** Ocarina.ws **********/
#include <stdio.h>
#include <conio.h>
f_lines();
up_key();
down_key();
void main()
{
int i;
char c1,c2;
textbackground(0);
gotoxy(wherex(),11);
f_lines();
do
{
c1=getch();
/*******if insert ENTER key*******/
if (c1==13)
{
if (wherey()==19)
{
textbackground(2);
f_lines();
}
if (wherey()==15)
{
textbackground(1);
f_lines();
}
if (wherey()==11)
{
textbackground(4);
f_lines();
}
}
/*******if insert UP key*******/
if (c1==0)
{
c2=getch();
if (((c1==0) && (c2==72)))
{
up_key();
}
/*******if insert DOWN key*******/
if (((c1==0) && (c2==80)))
{
down_key();
}
}
}while(c1!=27);
}
/***********( FUNCTION )**********/
f_lines()
{
int w,i;
w=wherey();
textcolor(15);
clrscr();
printf("%c",201);
for (i=0; i<78; i++)
{
printf("%c",205);
}
printf("%c",187);
for (i=0; i<23; i++)
{ printf("%c\n",186); }
printf("%c",200);
for (i=0; i<77; i++)
{
printf("%c",205);
}
printf("%c",188);
for (i=2; i<25; i++)
{ gotoxy(80,i);
printf("%c",186); }
/*************** Drow KEY ****************/
/******* Red key *******/
gotoxy(34,9);
printf("%c%c%c%c%c%c%c%c%c%c%c%c",201,205,205,205,205,205,205,205,205,205,205,187);
gotoxy(34,10);
printf("%c RED %c",186,186);
gotoxy(34,11);
printf("%c%c%c%c%c%c%c%c%c%c%c%c",200,205,205,205,205,205,205,205,205,205,205,188);
/******* Blue key *******/
gotoxy(34,13);
printf("%c%c%c%c%c%c%c%c%c%c%c%c",201,205,205,205,205,205,205,205,205,205,205,187);
gotoxy(34,14);
printf("%c Blue %c",186,186);
gotoxy(34,15);
printf("%c%c%c%c%c%c%c%c%c%c%c%c",200,205,205,205,205,205,205,205,205,205,205,188);
/******* Green key *******/
gotoxy(34,17);
printf("%c%c%c%c%c%c%c%c%c%c%c%c",201,205,205,205,205,205,205,205,205,205,205,187);
gotoxy(34,18);
printf("%c Green %c",186,186);
gotoxy(34,19);
printf("%c%c%c%c%c%c%c%c%c%c%c%c",200,205,205,205,205,205,205,205,205,205,205,188);
gotoxy(wherex(),w);
}
up_key()
{
if ((wherey()==19) || (wherey()==15))
{
int k;
k=wherey()-4;
gotoxy(wherex(),k);
}
}
down_key()
{
if ((wherey()==15) || (wherey()==11))
{
int k;
k=wherey()+4;
gotoxy(wherex(),k);
}
}
[LEFT]#include <conio.h>
#include<stdio.h>
#include<graphics.h>
#include<dos.h>
#include<string.h>
#include <stdlib.h>
static int xb1=20, yb1=50, zb1=30, clb1=9;
static int xb2=120, yb2=yb1, zb2=zb1, clb2=15;
static int xb3=220,yb3=yb1, zb3=zb1, clb3=4;
static int xb4=320, yb4=yb1, zb4=zb1, clb4=5;
static int xb5=420, yb5=yb1, zb5=zb1, clb5=10;
static int x=30,y=450,z=10;
static int db=0,mi=2;
int ow=0,wo=0,to=0,ot=0,wot=0;
char a;
static char skol[50],sb_1[]={"hego"},sb_2[]={"hegoby"},sb_3[]={"hegobybus"},sb_4[]={"hegobybuseveryday"};
char sb1[]={"he"}, sb2[]={"go"}, sb3[]={"by"},sb4[]={"bus"},sb5[]={"everyday"};
void tank(int x,int y,int z);
void movetank(char a);
void shoottank(char a);
void balon(int a,int b,int c,int cl,char s[]);
void movebalon();
void start();
void finish();
void tank(int x,int y,int z)
{
circle(x,y,z);
rectangle(x-15,y,x+15,y+20);
circle(x-15,y,z/2);
circle(x+15,y,z/2);
rectangle(x-20,y-z,x-15,y);
rectangle(x+20,y-z,x+15,y);
rectangle(x-3,y-(z+8),x+3,y);
}
void movetank(char key)
{
if (key==77)
{
setcolor(0);
tank(x,y,z);
x+=5;
setcolor(15);
tank(x,y,z);
}
if (key==75)
{
setcolor(0);
tank(x,y,z);
x-=5;
setcolor(15);
tank(x,y,z);
}
else return;
}
void shoottank(char key)
{
int k;
k=y-20;
if (key==32){
while(k>0){
putpixel(x,k-=1,3);
delay(1);
putpixel(x,k,0);
if (getpixel(x,k-1)==9)
{ clb1=0;
balon(xb1,yb1,zb1,clb1,sb1);
strcat(skol,sb1);
printf(sb1);
ow=1;
}
if (getpixel(x,k-1)==15)
{ clb2=0;
balon(xb2,yb2,zb2,clb2,sb2);
strcat(skol,sb2);
printf(sb2);
wo=1;
}
if (getpixel(x,k-1)==4)
{ clb3=0;
balon(xb3,yb3,zb3,clb3,sb3);
strcat(skol,sb3);
printf(sb3);
to=1;
}
if (getpixel(x,k-1)==5)
{ clb4=0;
balon(xb4,yb4,zb4,clb4,sb4);
strcat(skol,sb4);
printf(sb4);
ot=1;
}
if (getpixel(x,k-1)==10)
{ clb5=0;
balon(xb5,yb5,zb5,clb5,sb5);
strcat(skol,sb5);
printf(sb5);
wot=1;
}
if (wo+ow==2&&mi==2)
{
setcolor(0);
cleardevice();
if (!strcmp(sb_1,skol)) {
settextstyle(3,0,50);
setcolor(15);
outtextxy(80,100,"YOU WIN ...");
delay(2000);
db=1;
return;
}
if(strcmp(sb_1,skol)) {
settextstyle(3,0,50);
setcolor(15);
outtextxy(50,100,"YOU LOSS ...");
delay(2000);
db=0;
return;
}
}
if (wo+ow+to==3&&mi==3)
{
setcolor(0);
cleardevice();
if (!strcmp(sb_2,skol)) {
settextstyle(3,0,50);
setcolor(15);
outtextxy(80,100,"YOU WIN ...");
delay(2000);
db=1;
return;
}
if(strcmp(sb_2,skol)) {
settextstyle(3,0,50);
setcolor(15);
outtextxy(50,100,"YOU LOSS ...");
delay(2000);
db=0;
return;
}
}
if (wo+ow+to+ot==4&&mi==4)
{
setcolor(0);
cleardevice();
if (!strcmp(sb_3,skol)) {
settextstyle(3,0,50);
setcolor(15);
outtextxy(80,100,"YOU WIN ...");
delay(2000);
db=1;
return;
}
if(strcmp(sb_3,skol)) {
settextstyle(3,0,50);
setcolor(15);
outtextxy(50,100,"YOU LOSS ...");
delay(2000);
db=0;
return;
}
}
if (wo+ow+to+ot+wot==5&&mi==5)
{
setcolor(0);
cleardevice();
if (!strcmp(sb_4,skol)) {
settextstyle(3,0,50);
setcolor(15);
outtextxy(80,100,"YOU WIN ...");
delay(2000);
db=1;
return;
}
if(strcmp(sb_4,skol)) {
settextstyle(3,0,50);
setcolor(15);
outtextxy(50,100,"YOU LOSS ...");
delay(2000);
db=0;
return;
}
}
}}}
void balon(int a,int b,int c,int cl,char s[])
{
setcolor(cl);
settextstyle(0,0,1);
circle(a,b,c);
rectangle(a-(c-5),b+(2*c),a+(c-5),b+(2*c)+50);
line(a-c,b,a-(c-5),b+(2*c));
line(a+c,b,a+(c-5),b+(2*c));
moveto(a-(c-5)+2,b+(2*c)+10);
outtext(s);
}
void movebalon(int a)
{
if (xb1==a)
{
if (xb1<640)
{
balon(xb1,yb1,zb1,0,sb1);
xb1+=1;
balon(xb1,yb1,zb1,clb1,sb1);
}
else {balon(xb1,yb1,zb1,0,sb1);
xb1=50;}
}
if (a==xb2)
{
if (xb2<640)
{
balon(xb2,yb2,zb2,0,sb2);
xb2+=1;
balon(xb2,yb2,zb2,clb2,sb2);
}
else {balon(xb2,yb2,zb2,0,sb2);
xb2=50;}
}
if (a==xb3)
if (mi==3||mi==4||mi==5)
{
if (xb3<640)
{
balon(xb3,yb3,zb3,0,sb3);
xb3+=1;
balon(xb3,yb3,zb3,clb3,sb3);
}
else {balon(xb3,yb3,zb3,0,sb3);
xb3=50;}
}
if (xb4==a)
if(mi==4||mi==5)
{
if (xb4<640)
{
balon(xb4,yb4,zb4,0,sb4);
xb4+=1;
balon(xb4,yb4,zb4,clb4,sb4);
}
else {balon(xb4,yb4,zb4,0,sb4);
xb4=50;}
}
if (xb5==a)
if (mi==5){
if (xb5<640)
{
balon(xb5,yb5,zb5,0,sb5);
xb5+=1;
balon(xb5,yb5,zb5,clb5,sb5);
}
else {balon(xb5,yb5,zb5,0,sb5);
xb5=50;}
}
}
void start()
{
int iop=1;
setcolor(15);
settextstyle(2,0,10);
outtextxy(100,100,"DESIGN BY:");
for(iop=1;iop<16;iop++) {
setcolor(iop);
settextstyle(3,0,8);
outtextxy(100,250,"OMID SISTANI");
delay(200);}
setcolor(0);
cleardevice();
setcolor(15);
while(!kbhit()){
settextstyle(2,0,8);
outtextxy(80,50,"INFORMATION ABOUT THIS GAME:");
outtextxy(80,100,"MOVE TO RIGHT: RIGHT key");
outtextxy(80,150,"MOVE TO LEFT: LEFT key");
outtextxy(80,200,"FIRE TANK: SPACE key");
outtextxy(80,250,"EXIT THE GAME: q key");
outtextxy(80,300,"YOU HAD MAKE THIS MESSAGE:");
settextstyle(3,0,5);
outtextxy(80,400,"HE GO BY BUS EVERYDAY");
}
setcolor(0);
cleardevice();
setcolor(15);
settextstyle(3,0,6);
outtextxy(1,150,"ARE YOU READY...");
delay(2000);
setcolor(0);
cleardevice();
setcolor(15);
}
void finish()
{
int op=1;
while (!kbhit())
{
setcolor(0);
cleardevice();
setcolor(op);
settextstyle(3,0,8);
outtextxy(100,100,"YOU FINISH");
outtextxy(100,300,"THIS GAME");
op++;
delay(100);
}}
void next()
{
strcpy(skol,"");
xb1=20, yb1=50, zb1=30, clb1=9;
xb2=120, yb2=yb1, zb2=zb1, clb2=15;
xb3=220,yb3=yb1, zb3=zb1, clb3=4;
xb4=320, yb4=yb1, zb4=zb1, clb4=5;
xb5=420, yb5=yb1, zb5=zb1, clb5=10;
setcolor(15);
x=30,y=450,z=10;
settextstyle(3,0,8);
setcolor(0);
cleardevice();
setcolor(15);
outtextxy(60,150,"NEXT MISSION");
delay(2000);
setcolor(0);
cleardevice();
setcolor(15);
tank(x,y,z);
}
void main()
{
int gd=DETECT,gm=0;
initgraph(&gd,&gm,"c:\\tc\\bgi");
start();
tank(x,y,z);
balon(xb1,yb1,zb1,clb1,sb1);
balon(xb2,yb2,zb2,clb2,sb2);
while(a!='q'){
while (!kbhit()){
delay(100);
movebalon(xb2);
movebalon(xb1); }
a=getch();
movetank(a);
shoottank(a);
if (wo+ow==2){if(db==1) {getch(); break;}
else{getch(); exit(1);} }
}
if (db==1){
ow=0;wo=0;to=0;
db=0;mi=3;
next();}
else exit(1);
while(a!='q'){
while (!kbhit()){
delay(100);
movebalon(xb3);
movebalon(xb2);
movebalon(xb1); }
a=getch();
movetank(a);
shoottank(a);
if (wo+ow+to==3){if(db==1) {getch(); break;}
else{getch(); exit(1);} }
}
if (db==1){ow=0;wo=0;to=0;
db=0;mi=4;
next();}
else exit(1);
while(a!='q'){
while (!kbhit()){
delay(100);
movebalon(xb4);
movebalon(xb3);
movebalon(xb2);
movebalon(xb1); }
a=getch();
movetank(a);
shoottank(a);
if (wo+ow+to+ot==4){if(db==1) {getch(); break;}
else{getch(); exit(1);} }
}
if (db==1){
ow=0;wo=0;to=0;ot=0;
db=0;mi=5;
next();}
else exit(1);
while(a!='q'){
while (!kbhit()){
delay(100);
movebalon(xb5);
movebalon(xb4);
movebalon(xb3);
movebalon(xb2);
movebalon(xb1); }
a=getch();
movetank(a);
shoottank(a);
if (wo+ow+to+ot+wot==5){if(db==1) {getch(); break;}
else{getch(); exit(1);} }
}
if (db==1) finish();
else exit(1);
closegraph();
}[/LEFT]
http://rapidshare.com/files/11980013/Library_Management.zip.html
public class compiler
{
public String[] t = {"keyword", "id" , "delimeter" , "operator" , "number"};
public int tc = 0;
public int [] token = new int [100];
////////////////////////////////////////////////////
public void scanner () throws Exception
{
char [] s = new char [100];
char ch = ' ';
int i= 0, l, j;
System.out.println("please enter your statments:");
while ((ch = (char)System.in.read()) != '#')
{
s[i] = ch;
i ++;
}
l = i - 1;
i = 0;
while (i <= l)
{
i = space (s, i);
if (i > l)
break;
if (s[i] == 13)
i+= 2;
if (letter (s, i))
i = id (s, i);
else if (digit (s, i))
i = number (s, i);
else if (s[i] == '+' || s[i] == '-' || s[i] == '*' || s[i] == '/' || s[i] == '%' || s[i] == '=')
i = cul (s, i);
else if (s[i] == ';'|| s[i] == '[' || s[i] == ']' || s[i] == '{' || s[i] == '}' || s[i] == 39 || s[i] == '(' || s[i] == ')' || s[i] == '"' ||s[i] == ',')
i = del (s, i);
else if (s[i] == '#')
System.exit(0);
}
System.out.println ("end of scan!");
token [tc] = 28;
pars(s);
}
///////////////////////////////////////////////////////////////////////
public int cul (char []s, int i)
{
int r=i;
switch (s[i])
{
case '=':
System.out.println ((tc +1) + ". =\t" + t[3]);
r = i + 1;
token[tc] = 5;
break;
case '+':
if (s[i + 1] == '=')
{
System.out.println ((tc +1) + ". +=\t" + t[3]);
r = i + 2;
token[tc] = 0;
}
else if (s[i + 1] == '+')
{
System.out.println ((tc + 1) + ". ++\t" + t [3]);
r = i + 2;
token[tc] = 15;
}
else
{
System.out.println ((tc +1) + ". +\t" + t[3]);
r = i + 1;
token[tc] = 13;
}
break;
case '-' :
if (s[i + 1] == '=')
{
System.out.println ((tc +1) + ". -=\t" + t[3]);
r = i + 2;
token[tc] = 1;
}
else if (s[i + 1] == '-')
{
System.out.println ((tc + 1) + ". --\t" + t [3]);
r = i + 2;
token[tc] = 16;
}
else
{
System.out.println ((tc +1) + ". -\t" + t[3]);
r = i + 1;
token[tc] = 14;
}
break;
case '*' :
if (s[i + 1] == '=')
{
System.out.println ((tc +1) + ". *=\t" + t[3]);
r = i + 2;
token[tc] = 2;
}
else
{
System.out.println ((tc +1) + ". *\t" + t[3]);
r = i + 1;
token[tc] = 6;
}
break;
case '/' :
if (s[i + 1] == '=')
{
System.out.println ((tc +1) + ". /=\t" + t[3]);
r = i + 2;
token[tc] = 3;
}
else
{
System.out.println ((tc +1) + ". /\t" + t[3]);
r = i + 1;
token[tc] = 7;
}
break;
case '%' :
if (s[i + 1] == '=')
{
System.out.println ((tc +1) + ". %=\t" + t[3]);
r = i + 2;
token[tc] = 4;
}
else
{
System.out.println ((tc +1) + ". %\t" + t[3]);
r = i + 1;
token[tc] = 8;
}
break;
}
tc ++;
return r;
}
///////////////////////////////////////////////////////////////////////
public int id (char []s, int i)
{
boolean flag = true;
int j = 1;
System.out.print ((tc + 1) + ". " + s[i]);
while (flag)
{
i ++;
if (letter (s, i) || digit (s, i))
{
System.out.print ( s[i]);
j++;
}
else
break;
}
token[tc] = 11;
switch (j)
{
case 3:
if (s[i - 3] == 'i' && s[i - 2] == 'n' && s[i -1] == 't')
{
token [tc] = 26;
System.out.println ("\t" + t[0]);
}
else
j = 0;
break;
case 4:
if (s [i - 4] == 'c' && s [i - 3] == 'h' && s [i - 2] == 'a' && s [i - 1] == 'r')
{
System.out.println ("\t" + t[0]);
token [tc] = 23;
}
else
j = 0;
break;
case 5:
if (s [i - 5] == 'f' && s [i - 4] == 'l' && s [i - 3] == 'o' && s [i - 2] == 'a' && s [i - 1] == 't')
{
System.out.println ("\t" + t[0]);
token [tc] = 24;
}
else
j = 0;
break;
case 6:
if (s [i - 6] == 's' && s [i - 5] == 't' && s [i - 4] == 'r' && s [i - 3] == 'i' && s [i - 2] == 'n' && s [i - 1] == 'g')
{
token[tc] = 20;
System.out.println ("\t" + t[0]);
}
else if (s[i - 6] == 'd' && s[i - 5] == 'o' && s[i - 4] == 'u' && s[i - 3] == 'b' && s[i - 2] == 'l' && s[i - 1] == 'e')
{
System.out.println ("\t" + t[0]);
token[tc] = 25;
}
else
j = 0;
break;
default:
System.out.println ("\t" + t[1]);
}
if (j == 0)
System.out.println ("\t" + t[1]);
tc ++;
return i;
}
///////////////////////////////////////////////////////////////////////////
public int number (char []s, int i)
{
boolean flag = true;
System.out.print ((tc + 1) + ". ");
while (flag)
{
if (digit (s, i))
System.out.print (s[i]);
else
break;
i++;
token[tc] = 9;
}
if (s[i] == '.')
{
System.out.print (s[i]);
while (flag)
{
i ++;
if (digit (s, i))
System.out.print (s [i]);
else
break;
}
token[tc] = 10;
}
System.out.println ("\t" + t[4]);
tc ++;
return i;
}
//////////////////////////////////////////////////////////////////////////
public int del (char []s, int i)
{
if (s[i] == '(' )
{
System.out.println((tc + 1) +". (\t" + t [2]);
i++;
token[tc] = 12;
}
if (s[i] == '"' )
{
System.out.println((tc + 1) +". "+ s[i]+"\t" + t [2]);
i++;
token[tc] = 17;
}
if (s[i] == ',' )
{
System.out.println((tc + 1) +". ,\t" + t [2]);
i++;
token[tc] = 18;
}
if (s[i] == '{' )
{
System.out.println((tc + 1) +". {\t" + t [2]);
i++;
token[tc] = 19;
}
if (s[i] == 39 )
{
System.out.println((tc + 1) +". '\t" + t [2]);
i++;
token[tc] = 21;
}
if (s[i] == '[' )
{
System.out.println((tc + 1) +". [\t" + t [2]);
i++;
token[tc] = 22;
}
if (s[i] == ';' )
{
System.out.println((tc + 1) +". ;\t" + t [2]);
i++;
token[tc] = 27;
}
if (s[i] == '}' )
{
System.out.println((tc + 1) +". }\t" + t [2]);
i++;
token[tc] = 29;
}
if (s[i] == ')' )
{
System.out.println((tc + 1) +". )\t" + t [2]);
i++;
token[tc] = 30;
}
if (s[i] == ']' )
{
System.out.println((tc + 1) +". ]\t" + t [2]);
i++;
token[tc] = 31;
}
tc++;
return i;
}
//////////////////////////////////////////////////////////////////////////
public boolean letter (char []s, int i)
{
if (('a' <= s[i] && s[i] <= 'z') || ('A' <= s[i] && s[i] <= 'Z'))
return true;
else
return false;
}
/////////////////////////////////////////////////////////////////////////
public boolean digit (char []s, int i)
{
if ('0' <= s[i] && s[i] <= '9')
return true;
else
return false;
}
////////////////////////////////////////////////////////////////////////
public int space (char []s, int i)
{
boolean flag = true;
while (flag)
{
if (s[i] == ' ' || s[i] == '\t' )
i ++;
else
break;
}
return i;
}
///////////////////////////////////////////////////////////////////////
public void pars (char []s)
{
int [][] table = new int [74][32];
int l=10, k, x, t;
stack stk = new stack();
for (l = 32; l< 74; l++)
for (t = 0; t <32; t++)
table [l][t] = 0;
table[32][11]=2;
table[32][15]=2;
table[32][16]=2;
table[32][20]=1;
table[32][23]=1;
table[32][24]=1;
table[32][25]=1;
table[32][26]=1;
table[32][28]=3;
table[33][20]=4;
table[33][23]=4;
table[33][24]=4;
table[33][26]=4;
table[34][20]=8;
table[34][23]=7;
table[34][24]=6;
table[34][26]=5;
table[35][26]=9;
table[36][5]=66;
table[36][22]=65;
table[36][27]=67;
table[37][22]=10;
table[38][22]=12;
table[38][27]=11;
table[39][9]=13;
table[39][12]=13;
table[40][18]=14;
table[40][29]=15;
table[41][9]=17;
table[41][11]=16;
table[42][24]=18;
table[42][25]=18;
table[43][24]=19;
table[43][25]=20;
table[44][22]=70;
table[45][9]=21;
table[45][10]=21;
table[45][11]=21;
table[46][18]=22;
table[46][29]=23;
table[47][9]=24;
table[47][10]=24;
table[47][11]=24;
table[48][23]=25;
table[49][5]=76;
table[49][21]=75;
table[49][27]=77;
table[50][20]=26;
table[51][20]=27;
table[52][18]=29;
table[52][29]=30;
table[53][20]=31;
table[54][20]=32;
table[55][5]=81;
table[55][22]=80;
table[55][27]=82;
table[56][17]=33;
table[57][17]=34;
table[58][18]=35;
table[58][29]=36;
table[59][9]=37;
table[59][10]=38;
table[59][11]=39;
table[60][17]=40;
table[61][11]=41;
table[61][15]=41;
table[61][16]=41;
table[62][11]=42;
table[62][15]=43;
table[62][16]=44;
table[63][0]=47;
table[63][1]=47;
table[63][2]=47;
table[63][3]=47;
table[63][4]=47;
table[63][5]=47;
table[63][15]=45;
table[63][16]=46;
table[64][0]=48;
table[64][1]=49;
table[64][2]=50;
table[64][3]=51;
table[64][4]=52;
table[64][5]=53;
table[65][9]=54;
table[65][10]=54;
table[65][11]=54;
table[65][12]=54;
table[66][13]=55;
table[66][14]=56;
table[66][28]=57;
table[66][30]=57;
table[67][9]=58;
table[67][10]=58;
table[67][11]=58;
table[67][12]=58;
table[68][6]=59;
table[68][7]=60;
table[68][9]=61;
table[68][28]=62;
table[68][30]=62;
table[69][9]=63;
table[69][10]=63;
table[69][11]=63;
table[69][12]=64;
table[70][5]=68;
table[70][27]=69;
table[71][5]=73;
table[71][27]=74;
table[72][5]=78;
table[72][27]=79;
table[73][5]=83;
table[73][27]=84;
stk.push(28);
stk.push(32);
tc = 0;
k = token[tc];
while(k > -1)
{
l = stk.pop();
if (l == k)
{
if (l == 28)
{
System.out.println ("accept");
System.exit(0);
}
else
{
// stk.pop();
tc++;
}
}
else if (k != l)
if ((l > -1 && l < 32) && (k > -1 && k < 32))
{
System.out.println ("ERROR in token " +(tc +1));
System.exit (0);
}
else if (l > 31)
{
stk.push(l);
x = table [l][k];
switch (x)
{
case 0:
System.out.println ("error in token " + (tc+1));
System.exit(0);
break;
case 1:
stk.pop();
stk.push(32);
stk.push(33);
break;
case 2:
stk.pop();
stk.push(32);
stk.push(61);
break;
case 3:
stk.pop();
break;
case 4:
stk.pop();
stk.push(27);
stk.push(34);
break;
case 5:
stk.pop();
stk.push(35);
break;
case 6:
stk.pop();
stk.push(42);
break;
case 7:
stk.pop();
stk.push(48);
break;
case 8:
stk.pop();
stk.push(54);
break;
case 9:
stk.pop();
stk.push(36);
stk.push(11);
stk.push(26);
break;
case 10:
stk.pop();
stk.push(38);
stk.push(31);
stk.push(9);
stk.push(22);
break;
case 11:
stk.pop();
break;
case 12:
stk.pop();
stk.push(31);
stk.push(9);
stk.push(22);
break;
case 13:
stk.pop();
stk.push(40);
stk.push(41);
break;
case 14:
stk.pop();
stk.push(40);
stk.push(41);
stk.push(18);
break;
case 15:
stk.pop();
break;
case 16:
stk.pop();
stk.push(11);
break;
case 17:
stk.pop();
stk.push(9);
break;
case 18:
stk.pop();
stk.push(44);
stk.push(11);
stk.push(43);
break;
case 19:
stk.pop();
stk.push(24);
break;
case 20:
stk.pop();
stk.push(25);
break;
case 21:
stk.pop();
stk.push(46);
stk.push(47);
break;
case 22:
stk.pop();
stk.push(45);
stk.push(18);
break;
case 23:
stk.pop();
break;
case 24:
stk.pop();
stk.push(59);
break;
case 25:
stk.pop();
stk.push(49);
stk.push(11);
stk.push(23);
break;
case 26:
stk.pop();
stk.push(21);
stk.push(59);
stk.push(21);
break;
case 27:
stk.pop();
stk.push(52);
stk.push(53);
break;
case 29:
stk.pop();
stk.push(53);
stk.push(18);
break;
case 30:
stk.pop();
break;
case 31:
stk.pop();
stk.push(50);
break;
case 32:
stk.pop();
stk.push(55);
stk.push(11);
stk.push(20);
break;
case 33:
stk.pop();
stk.push(17);
stk.push(59);
stk.push(17);
break;
case 34:
stk.pop();
stk.push(58);
stk.push(60);
break;
case 35:
stk.pop();
stk.push(60);
stk.push(18);
break;
case 36:
stk.pop();
break;
case 37:
stk.pop();
stk.push(9);
break;
case 38:
stk.pop();
stk.push(10);
break;
case 39:
stk.pop();
stk.push(11);
break;
case 40:
stk.pop();
stk.push(56);
break;
case 41:
stk.pop();
stk.push(27);
stk.push(62);
break;
case 42:
stk.pop();
stk.push(63);
stk.push(11);
break;
case 43:
stk.pop();
stk.push(11);
stk.push(15);
break;
case 44:
stk.pop();
stk.push(11);
stk.push(16);
break;
case 45:
stk.pop();
stk.push(15);
break;
case 46:
stk.pop();
stk.push(16);
break;
case 47:
stk.pop();
stk.push(65);
stk.push(64);
break;
case 48:
stk.pop();
stk.push(0);
break;
case 49:
stk.pop();
stk.push(1);
break;
case 50:
stk.pop();
stk.push(2);
break;
case 51:
stk.pop();
stk.push(3);
break;
case 52:
stk.pop();
stk.push(4);
break;
case 53:
stk.pop();
stk.push(5);
break;
case 54:
stk.pop();
stk.push(66);
stk.push(67);
break;
case 55:
stk.pop();
stk.push(66);
stk.push(67);
stk.push(13);
break;
case 56:
stk.pop();
stk.push(66);
stk.push(67);
stk.push(14);
break;
case 57:
stk.pop();
break;
case 58:
stk.pop();
stk.push(68);
stk.push(69);
break;
case 59:
stk.pop();
stk.push(68);
stk.push(69);
stk.push(6);
break;
case 60:
stk.pop();
stk.push(68);
stk.push(69);
stk.push(7);
break;
case 61:
stk.pop();
stk.push(68);
stk.push(69);
stk.push(8);
break;
case 62:
stk.pop();
break;
case 63:
stk.pop();
stk.push(59);
break;
case 64:
stk.pop();
stk.push(30);
stk.push(65);
stk.push(12);
break;
case 65:
stk.pop();
stk.push(70);
stk.push(37);
break;
case 66:
stk.pop();
stk.push(9);
stk.push(5);
break;
case 67:
stk.pop();
break;
case 68:
stk.pop();
stk.push(29);
stk.push(39);
stk.push(19);
stk.push(5);
break;
case 69:
stk.pop();
break;
case 70:
stk.pop();
stk.push(71);
stk.push(37);
break;
case 71:
stk.pop();
stk.push(59);
stk.push(5);
break;
case 72:
stk.pop();
break;
case 73:
stk.pop();
stk.push(29);
stk.push(45);
stk.push(19);
stk.push(5);
break;
case 74:
stk.pop();
break;
case 75:
stk.pop();
stk.push(72);
stk.push(37);
break;
case 76:
stk.pop();
stk.push(50);
stk.push(5);
break;
case 77:
stk.pop();
break;
case 78:
stk.pop();
stk.push(29);
stk.push(51);
stk.push(19);
stk.push(5);
break;
case 79:
stk.pop();
break;
case 80:
stk.pop();
stk.push(73);
stk.push(37);
break;
case 81:
stk.pop();
stk.push(56);
stk.push(5);
break;
case 82:
stk.pop();
break;
case 83:
stk.pop();
stk.push(29);
stk.push(57);
stk.push(19);
stk.push(5);
break;
case 84:
stk.pop();
break;
}//switch
}// else if
k = token[tc];
}//while
}
}
public class stack
{
private int top= 0;
private int size=100;
private int [] elem = new int [100];
///////////////////////////////////////////////
private boolean isfull ()
{
if (top >= size)
return true;
else
return false;
}
///////////////////////////////////////////////
private boolean isempty ()
{
if ( top < 0)
return true;
else
return false;
}
////////////////////////////////////////////////
public void push (int z)
{
if (isfull())
{
System.out.print ("stack is full!!");
System.exit (1);
}
elem [top] = z;
top++;
}
///////////////////////////////////////////////
public int pop ()
{
top--;
if (isempty())
{
System.out.println ("stack is empty!!!");
System.exit (2);
}
return elem[top];
}
}
public class project
{
public static void main(String []arg) throws Exception
{
compiler p = new compiler();
p.scanner();
}
}
//Coded By S.Farshad.Kazemi
#include <conio.h>
#include <iostream>
#include <Windows.h>
using namespace std;
//defining global variables
#define n 3
int Matris[n][n]={};//keep game's map
int uActions[(n*n)/2+1];
int counter=0;//a counter for user actions
//prototypes
void show_map();//show a matrix where games take place in it
void cls();//clear screen
void change_game(int,char);//change game when computer or user wanna make a choice
void make_choice(char);//a function which let you to define who should play also i run my algorithm to solve dooz in this function
short define_winner();//when the game changes,it checks matrix to find what is the game situation:user wins,computer wins,there isn't any winner
void end_the_game();//write a text at the end of the game depends on who won the game
void random_check();//it makes a random choose for computer when there isn't any difference between choices
int main(){
char fp;
do{
cls();
printf("shoroo konandeye bazi che kasi bashad?computer(=c) ya shoma(u)?");
fp = getche();
}while(fp!='u'&&fp!='c');
cls();
show_map();
make_choice(fp);
end_the_game();
printf("\nthank you for playing");
getche();
return 0;
}
void cls(){
system("cls");
}
void show_map(){
cls();
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(Matris[i][j]==0){
printf("\t%d",n*i+j+1);
}else if(Matris[i][j]==1){
printf("\tC");
}else if(Matris[i][j]==-1){
printf("\tU");
}
if(j!=n-1){
printf("\t|");
}
}
if(i!=n-1){
printf("\n ");
for(int k=0;k<n-1;k++){
printf("---------------|");
}
printf("---------------");
}
printf("\n");
}
}
void end_the_game(){
cls();
show_map();
printf("this round were finished..\n");
switch(define_winner()){
case 1:
printf("HaHaHa...you should try harder to lose me:P");break;
case -1:
printf("Finally you lose me..but what do u tghink about another round?");break;
case 2:
printf("No winner available..play again to know who can play better");break;
default:
printf("Error:please contact with programmer...");break;
}
}
void change_game(int num,char who){
if(who=='u'){
while(Matris[num/(int)n][num%n]!=0){
printf("khaneye morede nazar por ast...yek khaneye digar ebtekhab konid:");
scanf("%d",&num);
num--;
}
Matris[num/(int)n][num%n]=-1;
if(define_winner()==0){
make_choice('c');
}
}else{
Matris[num/(int)n][num%n]=1;
if(define_winner()==0){
show_map();
make_choice('u');
}
}
}
short define_winner(){
bool notFull=false;
for(int i=0;i<n-2;i++){
for(int j=0;j<n-2;j++){
if((Matris[i][j]==1&&Matris[i][j+1]==1&&Matris[i][j+2]==1)||(Matris[i][j]==1&&Matris[i+1][j]==1&&Matris[i+2][j]==1)||(Matris[i][j]==1&&Matris[i+1][j+1]==1&&Matris[i+2][j+2]==1)){
return 1;
}else if((Matris[i][j]==-1&&Matris[i][j+1]==-1&&Matris[i][j+2]==-1)||(Matris[i][j]==-1&&Matris[i+1][j]==-1&&Matris[i+2][j]==-1)||(Matris[i][j]==-1&&Matris[i+1][j+1]==-1&&Matris[i+2][j+2]==-1)){
return -1;
}
}
}
if(Matris[n-3][n-3]==1&&Matris[n-2][n-4]==1&&Matris[n-4][n-2]==1)
return 1;
else if(Matris[n-3][n-3]==-1&&Matris[n-2][n-4]==-1&&Matris[n-4][n-2]==-1)
return -1;
for(int i=0;i<n-2;i++){
if((Matris[n-2][i]==1&&Matris[n-2][i+1]==1&&Matris[n-2][i+2]==1)||(Matris[i][n-2]==1&&Matris[i+1][n-2]==1&&Matris[i+2][n-2]==1)||(Matris[n-1][i]==1&&Matris[n-1][i+1]==1&&Matris[n-1][i+2]==1)||(Matris[i][n-1]==1&&Matris[i+1][n-1]==1&&Matris[i+2][n-1]==1)||(Matris[n-1][i]==1&&Matris[n-2][i+1]==1&&Matris[n-3][i+2]==1)||(Matris[i][n-1]==1&&Matris[i+1][n-2]==1&&Matris[i+2][n-3]==1))
return 1;
else if((Matris[n-2][i]==-1&&Matris[n-2][i+1]==-1&&Matris[n-2][i+2]==-1)||(Matris[i][n-2]==-1&&Matris[i+1][n-2]==-1&&Matris[i+2][n-2]==-1)||(Matris[n-1][i]==-1&&Matris[n-1][i+1]==-1&&Matris[n-1][i+2]==-1)||(Matris[i][n-1]==-1&&Matris[i+1][n-1]==-1&&Matris[i+2][n-1]==-1)||(Matris[n-1][i]==-1&&Matris[n-2][i+1]==-1&&Matris[n-3][i+2]==-1)||(Matris[i][n-1]==-1&&Matris[i+1][n-2]==-1&&Matris[i+2][n-3]==-1))
return -1;
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(Matris[i][j]==0)
return 0;
}
}
return 2;
}
void make_choice(char who){
if(who=='u'){
printf("aknoon nobate shomast...kodam khane ra entekhab mikonid?");
int num;
scanf("%d",&num);
while(0>num&&num>9){
printf("\nadade vared shode eshtebah ast.lotfan mojaddadan talash konid:");
scanf("%d",&num);
}
uActions[counter++]=--num;
change_game(num,'u');
}else if(who=='c'){
bool choice_made=false;
int i,j;
printf("lotfan kami sabr konid nobate computer ast");Sleep(300);printf(".");Sleep(300);printf(".");Sleep(300);printf(".");Sleep(300);printf(".\n");
/*
for(int i=0;i<3;i++){
for(int j=0;j<2;j++){
if(Matris[i][j]==-1&&Matris[i][j+1]==-1){
if(j==0){
if(Matris[i][j+2]!=0)
continue;
change_game(3*i+j+2,'c');
}else{
if(Matris[i][j-1]!=0)
continue;
change_game(3*i+j-1,'c');
}
}else if(Matris[j][i]==-1&&Matris[i][j+1]==-1){
change_game(3*j+i,'c');
}else if(Matris[j][j]==-1&&Matris[j+1][j+1]==-1){
}
}*/
//check for positions that make us winner:D
/*
for(i=0;i<n-1;i++){
for(j=0;j<n-1;j++){
if(Matris[i][j]==1){
if(i<n-2&&j<n-2){
if(Matris[i][j+1]==1&&Matris[i][j+2]==0){
change_game(3*i+j+2,'c');break;
}else if(Matris[i][j+2]==1&&Matris[i][j+1]==0){
change_game(3*j+i+1,'c');break;
}else if(Matris[i+2][j]==1&&Matris[i+1][j]==0){
change_game(3*j+i+3,'c');break;
}else if(Matris[i+1][j+1]==1&&Matris[i+2][j+2]==0){
change_game(3*i+j+8,'c');break;
}else if(Matris[i+2][j+2]==1&&Matris[i+1][j+1]==0){
change_game(3*i+j+4,'c');break;
}else if(Matris[i+1][j+1]==1&&Matris[i+2][j+2]==0){
change_game(3*i+j+8,'c');break;
}
if(i>1){
if(Matris[i-1][j+1]==1&&Matris[i-2][j+2]==0){
change_game(3*i+j-4,'c');break;
}else if(Matris[i-2][j+2]==1&&Matris[i-1][j+1]==0){
change_game(3*i+j-2,'c');break;
}
}
}else{
if(Matris[i][j+1]==1&&Matris[i][j-1]==0){
change_game(3*i+j-1,'c');break;
}else if(Matris[i+1][j+1]==1&&Matris[i-1][j-1]==0){
change_game(3*i+j-4,'c');break;
}else if(Matris[i+1][j+1]==1){
change_game(3*i+j-4,'c');break;
}else if(Matris[i-1][j+1]==1){
change_game(3*i+j+2,'c');break;
}
}
}
}
if(j!=n-1){
//cout<<"here";
break;
}
}
*/
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if(Matris[i][j]==1){
if(i<n-2&&j<n-2){
//cout<<Matris[i][j+1]<<"==-1&&"<<Matris[i][j+2]<<endl;
if(Matris[i][j+1]==1&&Matris[i][j+2]==0){
change_game(n*i+j+2,'c');break;
}else if(Matris[i][j+2]==1&&Matris[i][j+1]==0){
change_game(n*i+j+1,'c');break;
}else if(Matris[i+2][j]==1&&Matris[i+1][j]==0){
change_game(n*(i+1)+j,'c');break;
}else if(Matris[i+1][j]==1&&Matris[i+2][j]==0){
change_game(n*(i+2)+j,'c');break;
}else if(Matris[i+2][j+2]==1&&Matris[i+1][j+1]==0){
change_game(n*(i+1)+j+1,'c');break;
}else if(Matris[i+1][j+1]==1&&Matris[i+2][j+2]==0){
change_game(n*(i+2)+j+2,'c');break;
}
if(i>1){
if(Matris[i-1][j+1]==1&&Matris[i-2][j+2]==0){
change_game(n*(i-2)+j+2,'c');break;
}else if(Matris[i-2][j+2]==1&&Matris[i-1][j+1]==0){
change_game(n*(i-1)+j+1,'c');break;
}
}
}else{
if(j>=n-2){
if(j==n-2&&Matris[i][j+1]==1&&Matris[i][j-1]==0){
change_game(n*(i)+j-1,'c');break;
}else if(i<n-2&&Matris[i+2][j]==1&&i>0&&Matris[i+1][j]==0){
change_game(n*(i+1)+j,'c');break;
}
}else{
if(Matris[i][j+1]==1&&Matris[i][j+2]==0){
change_game(n*(i)+j+2,'c');break;
}else if(Matris[i][j+2]==1&&Matris[i][j+1]==0){
change_game(n*(i)+j+1,'c');break;
}
}
if(i>=n-2){
if(i==n-2&&Matris[i+1][j]==1&&i>0&&Matris[i-1][j]==0){
change_game(n*(i-1)+j,'c');break;
}else if(j<n-2&&Matris[i][j+2]==1&&i>0&&Matris[i][j+1]==0){
change_game(n*(i)+j+1,'c');break;
}
}else{
if(Matris[i+2][j]==1&&Matris[i+1][j]==0){
change_game(n*(i+1)+j,'c');break;
}else if(Matris[i+1][j]==1&&Matris[i+2][j]==0){
change_game(n*(i+2)+j,'c');break;
}
}
if(Matris[i+1][j+1]==1&&Matris[i-1][j-1]==0){
change_game(n*(i-1)+j-1,'c');break;
}else if(i>1&&Matris[i-1][j+1]==1&&Matris[i+1][j-1]==0){
if(i!=1||j!=0){
change_game(n*(i+1)+j-1,'c');break;
}else{
change_game(n*(i+1)+j-1,'c');break;
}
}
}
}
}
if(j!=n){
choice_made=true;
break;
}
}
if(!choice_made){
//check for posisions prevent losing:(
/* for(i=0;i<n-1;i++){
for(j=0;j<n-1;j++){
if(Matris[i][j]==-1){
if(i<n-2&&j<n-2){
//cout<<Matris[i][j+1]<<"==-1&&"<<Matris[i][j+2]<<endl;
if(Matris[i][j+1]==-1&&Matris[i][j+2]==0){
change_game(n*i+j+2,'c');break;
}else if(Matris[i][j+2]==-1&&Matris[i][j+1]==0){
change_game(n*i+j+1,'c');break;
}else if(Matris[i+2][j]==-1&&Matris[i+1][j]==0){
change_game(n*(i+1)+j,'c');break;
}else if(Matris[i+1][j]==-1&&Matris[i+2][j]==0){
change_game(n*(i+2)+j,'c');break;
}else if(Matris[i+2][j+2]==-1&&Matris[i+1][j+1]==0){
change_game(n*(i+1)+j+1,'c');break;
}else if(Matris[i+1][j+1]==-1&&Matris[i+2][j+2]==0){
change_game(n*(i+2)+j+2,'c');break;
}
if(i>1){
if(Matris[i-1][j+1]==-1&&Matris[i-2][j+2]==0){
change_game(n*(i-2)+j+2,'c');break;
}else if(Matris[i-2][j+2]==-1&&Matris[i-1][j+1]==0){
change_game(n*(i-1)+j+1,'c');break;
}
}
}else{
if(j>=n-2){
if(Matris[i][j+1]==-1&&Matris[i][j-1]==0){
change_game(n*(i)+j-1,'c');break;
}
}else{
if(Matris[i][j+1]==-1&&Matris[i][j+2]==0){
change_game(n*(i)+j+2,'c');break;
}else if(Matris[i][j+2]==-1&&Matris[i][j+1]==0){
change_game(n*(i)+j+1,'c');break;
}
}
if(i>=n-2){
if(Matris[i+1][j]==-1&&i>0&&Matris[i-1][j]==0){
change_game(n*(i-1)+j,'c');break;
}
}else{
if(Matris[i+2][j]==-1&&Matris[i+1][j]==0){
change_game(n*(i+1)+j,'c');break;
}else if(Matris[i+1][j]==-1&&Matris[i+2][j]==0){
change_game(n*(i+2)+j,'c');break;
}
}
if(Matris[i+1][j+1]==-1&&Matris[i-1][j-1]==0){
change_game(n*(i-1)+j-1,'c');break;
}else if((i>1||j!=0)&&Matris[i-1][j+1]==-1){
if(i!=1||j!=0){
change_game(n*(i+1)+j-1,'c');break;
}else{
change_game(n*(i+1)+j-1,'c');break;
}
}
}
}
}
if(j!=n-1){
choice_made=true;
break;
}
}
*/
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if(Matris[i][j]==-1){
if(i<n-2&&j<n-2){
//cout<<Matris[i][j+1]<<"==-1&&"<<Matris[i][j+2]<<endl;
if(Matris[i][j+1]==-1&&Matris[i][j+2]==0){
change_game(n*i+j+2,'c');break;
}else if(Matris[i][j+2]==-1&&Matris[i][j+1]==0){
change_game(n*i+j+1,'c');break;
}else if(Matris[i+2][j]==-1&&Matris[i+1][j]==0){
change_game(n*(i+1)+j,'c');break;
}else if(Matris[i+1][j]==-1&&Matris[i+2][j]==0){
change_game(n*(i+2)+j,'c');break;
}else if(Matris[i+2][j+2]==-1&&Matris[i+1][j+1]==0){
change_game(n*(i+1)+j+1,'c');break;
}else if(Matris[i+1][j+1]==-1&&Matris[i+2][j+2]==0){
change_game(n*(i+2)+j+2,'c');break;
}
if(i>1){
if(Matris[i-1][j+1]==-1&&Matris[i-2][j+2]==0){
change_game(n*(i-2)+j+2,'c');break;
}else if(Matris[i-2][j+2]==-1&&Matris[i-1][j+1]==0){
change_game(n*(i-1)+j+1,'c');break;
}
}
}else{
if(j>=n-2){
if(Matris[i][j+1]==-1&&Matris[i][j-1]==0){
change_game(n*(i)+j-1,'c');break;
}
}else{
if(Matris[i][j+1]==-1&&Matris[i][j+2]==0){
change_game(n*(i)+j+2,'c');break;
}else if(Matris[i][j+2]==-1&&Matris[i][j+1]==0){
change_game(n*(i)+j+1,'c');break;
}
}
if(i>=n-2){
if(Matris[i+1][j]==-1&&i>0&&Matris[i-1][j]==0){
change_game(n*(i-1)+j,'c');break;
}
}else{
if(Matris[i+2][j]==-1&&Matris[i+1][j]==0){
change_game(n*(i+1)+j,'c');break;
}else if(Matris[i+1][j]==-1&&Matris[i+2][j]==0){
change_game(n*(i+2)+j,'c');break;
}
}
if(Matris[i+1][j+1]==-1&&Matris[i-1][j-1]==0){
change_game(n*(i-1)+j-1,'c');break;
}else if((i>1||j!=0)&&Matris[i-1][j+1]==-1&&Matris[i+1][j-1]==0){
if(i!=1||j!=0){
change_game(n*(i+1)+j-1,'c');break;
}else{
change_game(n*(i+1)+j-1,'c');break;
}
}
}
}
}
if(j!=n){
choice_made=true;
break;
}
}
if(!choice_made){
for(i=0;i<counter;i++){
for(j=i;j<counter;j++){
if(uActions[i]-uActions[j]==n-1){
if(Matris[(uActions[i]+1)/(int)n][(uActions[i]+1)%(int)n]==0&&(uActions[i]+1)%(int)n!=n-1&&(uActions[i]+1)/(int)n!=0){
change_game(uActions[i]+1,'c');choice_made=true;
}else if(Matris[(uActions[j]-1)/(int)n][(uActions[j]-1)%(int)n]==0&&(uActions[j]-1)%(int)n!=0){
change_game(uActions[j]-1,'c');choice_made=true;
}
}else if(uActions[j]-uActions[i]==n-1){
if(Matris[(uActions[j]+1)/(int)n][(uActions[j]+1)%(int)n]==0&&(uActions[j]+1)%(int)n!=n-1&&(uActions[j]+1)/(int)n!=0){
change_game(uActions[j]+1,'c');choice_made=true;
}else if(Matris[(uActions[i]-1)/(int)n][(uActions[i]-1)%(int)n]==0&&(uActions[i]-1)%(int)n!=0){
change_game(uActions[i]-1,'c');choice_made=true;
}
}
if(uActions[i]-uActions[j]==n+1){
if(Matris[(uActions[j]+1)/(int)n][(uActions[j]+1)%(int)n]==0&&(uActions[j]+1)%(int)n!=n-1&&(uActions[j]+1)/(int)n!=0){
change_game(uActions[j]+1,'c');choice_made=true;
}else if(Matris[(uActions[i]-1)/(int)n][(uActions[i]-1)%(int)n]==0&&(uActions[i]-1)%(int)n!=0){
change_game(uActions[i]-1,'c');choice_made=true;
}
}else if(uActions[j]-uActions[i]==n+1){
if(Matris[(uActions[i]+1)/(int)n][(uActions[i]+1)%(int)n]==0&&(uActions[i]+1)%(int)n!=n-1&&(uActions[i]+1)/(int)n!=0){
change_game(uActions[i]+1,'c');choice_made=true;
}else if(Matris[(uActions[j]-1)/(int)n][(uActions[j]-1)%(int)n]==0&&(uActions[j]-1)%(int)n!=0){
change_game(uActions[j]-1,'c');choice_made=true;
}
}
}
}
if(!choice_made){
if(Matris[(int)(n)/2][(int)(n)/2]==0){
change_game((n+1)*((int)(n)/2),'c');
}else{
if(Matris[2][2]==0){
change_game(n*2+2,'c');
}else if(Matris[2][2]==1){
if(Matris[3][3]!=-1&&n>4&&Matris[4][4]==0){
change_game(n*4+4,'c');
}else if(Matris[0][0]==0){
change_game(0,'c');
}else if(Matris[2][2]==1&&Matris[0][0]==1&&Matris[0][2]==0){
if(Matris[0][2]==0)
change_game(2,'c');
else if(Matris[2][0]==0)
change_game(n*2,'c');
else{
random_check();
}
}else if(Matris[2][2]==1&&n>4&&Matris[4][4]==1){
if(Matris[2][4]==0)
change_game(n*2+4,'c');
else if(Matris[4][2]==0)
change_game(n*4+2,'c');
else
random_check();
}else{
random_check();
}
}else{
random_check();
}
}
}
}
}
}
}
void random_check(){
cout<<"random";
/*
if(i==n-1&&j==n-1){
i=(int)(rand()*3);
j=(int)(rand()*3);
while(Matris[i][j]!=0){
i=(int)(rand()*3);
j=(int)(rand()*3);
}
change_game(3*i+j,'c');
}
*/
int i,j;
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if(Matris[i][j]==0){
change_game(3*i+j,'c');break;
}
}
if(j!=n){
break;
}
}
}