Necesito codigo fuente de un juego en C,C++. URGENTE
necesito que me mandeis el codigo fuente de cualquier juego como ajedrez, damas, othello, 3 en raya... es para las practicas de Inteligencia Artificial. Pero lo necesito ya.
te envio un programa que soluciona el problema del laberinto.
un elemento sabe encontrar el camino afuera.
creo que es adaptable al tema de inteligencia artificial.
// program k5a7.CPP - page 79
// labyrinth.
// c++ exercices book - dr. gershon kagan (first edition : 2001)
// written in Borland CPP ver 3.1
#include <conio.h>
#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>
#include <dos.h>
#define M 12
#define N 10
#define B (80-3*N)/2
#define H (24-M)/2
#define CLOCK 1
#define ANTICLOCK -1
#define north 0
#define east 1
#define south 2
#define west 3
const char *sym[] = {"²²²"," ù "," þ "};
const color[] = {LIGHTBLUE,YELLOW,LIGHTRED};
void ShowLabyrinth(char a[M+2][N+2])
{
gotoxy(B+10,3);
cout << "Labyrinth Maze";
textcolor(color[0]);
for(int i = 0; i < M+2; i++)
{
gotoxy(B,H+i);
for(int j = 0; j < N+2; j++)
cprintf(sym[a[i][j]]);
cout << endl;
}
cout << endl;
} // SHOW LABYRINTH
int OutSide(int i,int j)
{
return (i == 0) || (i == M+1) || (j == 0) || (j == N+1);
} // OUTSIDE
void Show(int i,int j,int sw)
{
gotoxy(B+j*3,H+i);
textcolor(color[sw]);
cprintf(sym[sw]);
} // SHOW
int LeftEmpty(char a[M+2][N+2],int i,int j,int dir)
{
int ret;
switch(dir)
{
case north : ret = a[i][j-1];
break;
case east : ret = a[i-1][j];
break;
case south : ret = a[i][j+1];
break;
case west : ret = a[i+1][j];
break;
}
return ret;
} // LEFT EMPTY
int FrontEmpty(char a[M+2][N+2],int i,int j,int dir)
{
int ret;
switch(dir)
{
case north : ret = a[i-1][j];
break;
case east : ret = a[i][j+1];
break;
case south : ret = a[i+1][j];
break;
case west : ret = a[i][j-1];
break;
}
return ret;
} // FRONT EMPTY
int Rotate(int dir,int clock)
{
dir += clock + 4;
return dir % 4;
} // ROTATE
void Process(char a[M+2][N+2])
{
int i = 2, j = 0,di,dj;
int dir = east;
char choice = 100;
Show(i,j++,1);
Show(i,j,2);
while(!OutSide(i,j) && choice != 27)
{
delay(150);
Show(i,j,1);
if(LeftEmpty(a,i,j,dir))
{
dir = Rotate(dir,ANTICLOCK);
if(!FrontEmpty(a,i,j,dir))
dir = Rotate(dir,CLOCK);
}
if(!FrontEmpty(a,i,j,dir))
{
dir = Rotate(dir,CLOCK);
if(!FrontEmpty(a,i,j,dir))
dir = Rotate(dir,CLOCK);
}
switch(dir)
{
case north : di = -1;
dj = 0;
break;
case east : di = 0;
dj = 1;
break;
case south : di = 1;
dj = 0;
break;
case west : di = 0;
dj = -1;
break;
}
i += di;
j += dj;
Show(i,j,2);
if(kbhit())
choice = getch();
}
} // PROCESS
void main()
{
char a[M+2][N+2] = {{1,1,1,1,1,1,1,1,1,1,1,1},
{1,0,0,0,0,0,0,0,0,0,0,1},
{1,1,1,0,1,1,1,1,1,1,0,1},
{1,0,1,0,0,1,0,0,0,1,0,1},
{1,0,1,1,0,1,0,1,1,1,0,1},
{1,0,1,0,0,1,0,0,0,0,0,1},
{1,0,1,0,1,1,1,1,1,1,0,1},
{1,0,1,0,1,0,1,0,0,1,0,1},
{1,0,1,0,0,0,1,0,0,1,0,1},
{1,0,1,1,1,0,1,1,1,1,0,1},
{1,0,0,0,1,1,1,0,0,0,0,1},
{1,0,1,1,1,0,1,1,1,1,0,1},
{1,0,0,0,0,0,0,0,0,0,0,1},
{1,1,1,1,1,1,1,1,1,1,1,1}};
randomize();
int x = random(3),i = random(M-2)+2;
switch(x)
{
case 0 :
case 1 : int j = 1;
if(a[i][j+1])
a[i][j] = 1;
break;
case 2 : j = N;
if(a[i][j-1])
a[i][j] = 1;
}
clrscr();
_setcursortype(_NOCURSOR);
ShowLabyrinth(a);
Process(a);
gotoxy(B+3,23);
cout << "end of program - good bye ! ! !n";
getch();
_setcursortype(_NORMALCURSOR);
} // MAIN
/*
Labyrinth Maze
ù ù ù ù ù ù ù ù ù ù ù ù
ù ²²²²²²²²²²²²²²²²²²²²²²²²²²²²²² ù
ù ù ù ²²² ù ù ù ù ù ù ²²² ù
ù ²²² ù ²²²²²² ù ²²²²²²²²² ù ²²² ù
ù ²²² ù ù ²²² ù ²²² ù ù ù ²²² ù
ù ²²² ù ²²²²²² ù ²²²²²²²²²²²²²²² ù
ù ²²² ù ²²² ù ù ù ù ù ù ²²² ù
ù ²²² ù ²²² ù ²²² ù ²²²²²² ù ²²² ù
ù ²²² ù ²²²²²²²²² ù ²²²²²² ù ²²² ù
ù ²²² ù ù ù ²²² ù ù ù ù ù þ
ù ²²²²²²²²² ù ù ù ²²²²²²²²²²²² ù
ù ²²² ù ù ù ²²² ù ù ù ù ²²² ù
ù ²²²²²²²²²²²²²²²²²²²²²²²²²²²²²² ù
ù ù ù ù ù ù ù ù ù ù ù ù
end of program - good bye ! ! !
*/
un elemento sabe encontrar el camino afuera.
creo que es adaptable al tema de inteligencia artificial.
// program k5a7.CPP - page 79
// labyrinth.
// c++ exercices book - dr. gershon kagan (first edition : 2001)
// written in Borland CPP ver 3.1
#include <conio.h>
#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>
#include <dos.h>
#define M 12
#define N 10
#define B (80-3*N)/2
#define H (24-M)/2
#define CLOCK 1
#define ANTICLOCK -1
#define north 0
#define east 1
#define south 2
#define west 3
const char *sym[] = {"²²²"," ù "," þ "};
const color[] = {LIGHTBLUE,YELLOW,LIGHTRED};
void ShowLabyrinth(char a[M+2][N+2])
{
gotoxy(B+10,3);
cout << "Labyrinth Maze";
textcolor(color[0]);
for(int i = 0; i < M+2; i++)
{
gotoxy(B,H+i);
for(int j = 0; j < N+2; j++)
cprintf(sym[a[i][j]]);
cout << endl;
}
cout << endl;
} // SHOW LABYRINTH
int OutSide(int i,int j)
{
return (i == 0) || (i == M+1) || (j == 0) || (j == N+1);
} // OUTSIDE
void Show(int i,int j,int sw)
{
gotoxy(B+j*3,H+i);
textcolor(color[sw]);
cprintf(sym[sw]);
} // SHOW
int LeftEmpty(char a[M+2][N+2],int i,int j,int dir)
{
int ret;
switch(dir)
{
case north : ret = a[i][j-1];
break;
case east : ret = a[i-1][j];
break;
case south : ret = a[i][j+1];
break;
case west : ret = a[i+1][j];
break;
}
return ret;
} // LEFT EMPTY
int FrontEmpty(char a[M+2][N+2],int i,int j,int dir)
{
int ret;
switch(dir)
{
case north : ret = a[i-1][j];
break;
case east : ret = a[i][j+1];
break;
case south : ret = a[i+1][j];
break;
case west : ret = a[i][j-1];
break;
}
return ret;
} // FRONT EMPTY
int Rotate(int dir,int clock)
{
dir += clock + 4;
return dir % 4;
} // ROTATE
void Process(char a[M+2][N+2])
{
int i = 2, j = 0,di,dj;
int dir = east;
char choice = 100;
Show(i,j++,1);
Show(i,j,2);
while(!OutSide(i,j) && choice != 27)
{
delay(150);
Show(i,j,1);
if(LeftEmpty(a,i,j,dir))
{
dir = Rotate(dir,ANTICLOCK);
if(!FrontEmpty(a,i,j,dir))
dir = Rotate(dir,CLOCK);
}
if(!FrontEmpty(a,i,j,dir))
{
dir = Rotate(dir,CLOCK);
if(!FrontEmpty(a,i,j,dir))
dir = Rotate(dir,CLOCK);
}
switch(dir)
{
case north : di = -1;
dj = 0;
break;
case east : di = 0;
dj = 1;
break;
case south : di = 1;
dj = 0;
break;
case west : di = 0;
dj = -1;
break;
}
i += di;
j += dj;
Show(i,j,2);
if(kbhit())
choice = getch();
}
} // PROCESS
void main()
{
char a[M+2][N+2] = {{1,1,1,1,1,1,1,1,1,1,1,1},
{1,0,0,0,0,0,0,0,0,0,0,1},
{1,1,1,0,1,1,1,1,1,1,0,1},
{1,0,1,0,0,1,0,0,0,1,0,1},
{1,0,1,1,0,1,0,1,1,1,0,1},
{1,0,1,0,0,1,0,0,0,0,0,1},
{1,0,1,0,1,1,1,1,1,1,0,1},
{1,0,1,0,1,0,1,0,0,1,0,1},
{1,0,1,0,0,0,1,0,0,1,0,1},
{1,0,1,1,1,0,1,1,1,1,0,1},
{1,0,0,0,1,1,1,0,0,0,0,1},
{1,0,1,1,1,0,1,1,1,1,0,1},
{1,0,0,0,0,0,0,0,0,0,0,1},
{1,1,1,1,1,1,1,1,1,1,1,1}};
randomize();
int x = random(3),i = random(M-2)+2;
switch(x)
{
case 0 :
case 1 : int j = 1;
if(a[i][j+1])
a[i][j] = 1;
break;
case 2 : j = N;
if(a[i][j-1])
a[i][j] = 1;
}
clrscr();
_setcursortype(_NOCURSOR);
ShowLabyrinth(a);
Process(a);
gotoxy(B+3,23);
cout << "end of program - good bye ! ! !n";
getch();
_setcursortype(_NORMALCURSOR);
} // MAIN
/*
Labyrinth Maze
ù ù ù ù ù ù ù ù ù ù ù ù
ù ²²²²²²²²²²²²²²²²²²²²²²²²²²²²²² ù
ù ù ù ²²² ù ù ù ù ù ù ²²² ù
ù ²²² ù ²²²²²² ù ²²²²²²²²² ù ²²² ù
ù ²²² ù ù ²²² ù ²²² ù ù ù ²²² ù
ù ²²² ù ²²²²²² ù ²²²²²²²²²²²²²²² ù
ù ²²² ù ²²² ù ù ù ù ù ù ²²² ù
ù ²²² ù ²²² ù ²²² ù ²²²²²² ù ²²² ù
ù ²²² ù ²²²²²²²²² ù ²²²²²² ù ²²² ù
ù ²²² ù ù ù ²²² ù ù ù ù ù þ
ù ²²²²²²²²² ù ù ù ²²²²²²²²²²²² ù
ù ²²² ù ù ù ²²² ù ù ù ù ²²² ù
ù ²²²²²²²²²²²²²²²²²²²²²²²²²²²²²² ù
ù ù ù ù ù ù ù ù ù ù ù ù
end of program - good bye ! ! !
*/
