tic tac toe de c a c++ quien me ayuda?????

=[zero]=
27 de Mayo del 2004
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include "global.h"
#include "ai_tic.h"

void Intro();
void Zero();
void One1();
void One2();
void Two();
void ClearBoard();
void ClearText();
void DrawBoard();
void UpdateBoard();
void PlayerMove(int PlayerNumber);
void ComputerMove(int PlayerNumber);
int Win();
int Draw();
void Result();
void Winner(int WinChar2);

void main()
{
randomize();
_setcursortype(0);
Start:;
Intro();
switch(Choice)
{
case 'a' : Zero(); Result(); goto Start;
case 'b' :
cout << endl << "tQuien juega primero ?" << endl;
cout << "t (a) Humano" << endl;
cout << "t (b) Computadora" << endl;
do
{
Choice2 = getch();
} while ( Choice2 != 'a' && Choice2 != 'b' );
switch(Choice2)
{
case 'a' : One1(); break;
case 'b' : One2(); break;
}
Result(); goto Start;
case 'c' : Two(); Result(); goto Start;
case 'd' : ;
}
}

void Intro()
{
clrscr();
cout << "+------------------------------------------------------------------------------+";
cout << "| Tic Tac Toe |";
cout << "+------------------------------------------------------------------------------+" << endl;
cout << endl;
cout << " Este es un Tic Tac Toe, simple y divertido juego (por un momento). Puede ser" << endl;
cout << " jugado por una o 2 personas (2 necesarios en el mundo real). Un jugador es X" << endl;
cout << " y el otro es O. Los jugadores hacen un movimiento a la vez y tratan de obtener" << endl;
cout << " un 3 en raya con los caracteres formando una linea. Si el tablero esta lleno," << endl;
cout << " nadie gana lo que es llamado un empate." << endl;
cout << endl;
cout << "tSelecciona un modo de juego:" << endl;
cout << "t (a) 0 Jugadores (computadora vs computadora)" << endl;
cout << "t (b) 1 Jugador (humano [X] vs computadora [O])" << endl;
cout << "t (c) 2 Jugadores (humano vs humano)" << endl;
cout << "t (d) Salir" << endl;
do
{
Choice = getch();
} while ( Choice != 'a' && Choice != 'b' && Choice != 'c' && Choice != 'd' );
}

void ClearBoard()
{
for ( int i = 0; i < 3; i++ )
for ( int j = 0; j < 3; j++ )
Board[i][j] = ' ';
}

void DrawBoard()
{
clrscr();
cout << "+------------------------------------------------------------------------------+";
cout << "| Tic Tac Toe |";
cout << "+------------------------------------------------------------------------------+" << endl;
cout << " C O L U M N A S" << endl;
cout << " |1| |2| |3|" << endl;
cout << " +-----+-----+-----+" << endl;
cout << " F | | | |" << endl;
cout << " -1-| | | |" << endl;
cout << " I | | | |" << endl;
cout << " +-----+-----+-----+" << endl;
cout << " L | | | |" << endl;
cout << " -2-| | | |" << endl;
cout << " A | | | |" << endl;
cout << " +-----+-----+-----+" << endl;
cout << " S | | | |" << endl;
cout << " -3-| | | |" << endl;
cout << " | | | |" << endl;
cout << " +-----+-----+-----+" << endl;
cout << "+------------------------------------------------------------------------------+";
cout << "| |";
cout << "| |";
cout << "| |";
cout << "+------------------------------------------------------------------------------+";
}

void UpdateBoard()
{
gotoxy(34,9);
cout << Board[0][0];
gotoxy(40,9);
cout << Board[1][0];
gotoxy(46,9);
cout << Board[2][0];
gotoxy(34,13);
cout << Board[0][1];
gotoxy(40,13);
cout << Board[1][1];
gotoxy(46,13);
cout << Board[2][1];
gotoxy(34,17);
cout << Board[0][2];
gotoxy(40,17);
cout << Board[1][2];
gotoxy(46,17);
cout << Board[2][2];
gotoxy(2,21);
cout << " ";
gotoxy(2,22);
cout << " ";
gotoxy(2,23);
cout << " ";
}

void ClearText()
{
gotoxy(2,21);
cout << " ";
gotoxy(2,22);
cout << " ";
gotoxy(2,23);
cout << " ";
}

int Win()
{
int Winner = 1;
if ( Board[0][0] != ' ' && Board[0][1] != ' ' && Board[0][2] != ' ' )
if ( Board[0][0] == Board[0][1] && Board[0][1] == Board[0][2] )
Winner = 0;
if ( Board[1][0] != ' ' && Board[1][1] != ' ' && Board[1][2] != ' ' )
if ( Board[1][0] == Board[1][1] && Board[1][1] == Board[1][2] )
Winner = 0;
if ( Board[2][0] != ' ' && Board[2][1] != ' ' && Board[2][2] != ' ' )
if ( Board[2][0] == Board[2][1] && Board[2][1] == Board[2][2] )
Winner = 0;
if ( Board[0][0] != ' ' && Board[1][0] != ' ' && Board[2][0] != ' ' )
if ( Board[0][0] == Board[1][0] && Board[1][0] == Board[2][0] )
Winner = 0;
if ( Board[0][1] != ' ' && Board[1][1] != ' ' && Board[2][1] != ' ' )
if ( Board[0][1] == Board[1][1] && Board[1][1] == Board[2][1] )
Winner = 0;
if ( Board[0][2] != ' ' && Board[1][2] != ' ' && Board[2][2] != ' ' )
if ( Board[0][2] == Board[1][2] && Board[1][2] == Board[2][2] )
Winner = 0;
if ( Board[0][0] != ' ' && Board[1][1] != ' ' && Board[2][2] != ' ' )
if ( Board[0][0] == Board[1][1] && Board[1][1] == Board[2][2] )
Winner = 0;
if ( Board[0][2] != ' ' && Board[1][1] != ' ' && Board[2][0] != ' ' )
if ( Board[0][2] == Board[1][1] && Board[1][1] == Board[2][0] )
Winner = 0;
return Winner;
}

int Draw()
{
int Draw = 0;
for ( int i = 0; i < 3; i++ )
for ( int j = 0; j < 3; j++ )
if ( Board[i][j] == ' ' )
Draw = 1;
return Draw;
}


void PlayerMove(int PlayerNumber)
{
int Row, Col;
char cRow, cCol;
_setcursortype(1);
Start:;
ClearText();
gotoxy(3,21);
cout << "Jugador: " << PlayerNumber << ", ingresa movimiento...";
gotoxy(3,22);
cout << "Ingresa numero de fila: ";
do
{
cRow = getch();
} while ( cRow != '1' && cRow != '2' && cRow != '3' );
cout << cRow;
gotoxy(3,23);
cout << "Ingresa numero de columna: ";
do
{
cCol = getch();
} while ( cCol != '1' && cCol != '2' && cCol != '3' );
cout << cCol;
switch(cRow)
{
case '1' : Row = 0; break;
case '2' : Row = 1; break;
case '3' : Row = 2; break;
}
switch(cCol)
{
case '1' : Col = 0; break;
case '2' : Col = 1; break;
case '3' : Col = 2; break;
}
if ( Board[Col][Row] == ' ' )
Board[Col][Row] = Icon[--PlayerNumber];
else goto Start;
_setcursortype(0);
}

void Zero()
{
ClearBoard();
DrawBoard();
do
{
ComputerMove(1);
UpdateBoard();
if ( Draw() == 0 || Win() == 0 )
break;
gotoxy(3,22);
cout << "Presiona una tecla para el siguiente movimiento...";
getch();
ComputerMove(2);
UpdateBoard();
if ( Draw() == 0 || Win() == 0 )
break;
gotoxy(3,22);
cout << "Presiona una tecla para el siguiente movimiento...";
getch();
} while ( 1 );
}

void One1()
{
ClearBoard();
DrawBoard();
do
{
PlayerMove(1);
UpdateBoard();
if ( Draw() == 0 || Win() == 0 )
break;
ComputerMove(2);
UpdateBoard();
if ( Draw() == 0 || Win() == 0 )
break;
} while ( 1 );
}

void One2()
{
ClearBoard();
DrawBoard();
do
{
ComputerMove(2);
UpdateBoard();
if ( Draw() == 0 || Win() == 0 )
break;
PlayerMove(1);
UpdateBoard();
if ( Draw() == 0 || Win() == 0 )
break;
} while ( 1 );
}

void Two()
{
clrscr();
ClearBoard();
DrawBoard();
do
{
PlayerMove(1);
UpdateBoard();
if ( Draw() == 0 || Win() == 0 )
break;
PlayerMove(2);
UpdateBoard();
if ( Draw() == 0 || Win() == 0 )
break;
} while ( 1 );
}

void Result()
{
int Winner;
char WinChar;
textbackground(RED);
gotoxy(32,8);
cprintf(" ");
gotoxy(32,9);
cprintf(" ");
gotoxy(32,10);
cprintf(" ");
gotoxy(32,12);
cprintf(" ");
gotoxy(32,13);
cprintf(" ");
gotoxy(32,14);
cprintf(" ");
gotoxy(32,16);
cprintf(" ");
gotoxy(32,17);
cprintf(" ");
gotoxy(32,18);
cprintf(" ");
gotoxy(38,8);
cprintf(" ");
gotoxy(38,9);
cprintf(" ");
gotoxy(38,10);
cprintf(" ");
gotoxy(38,12);
cprintf(" ");
gotoxy(38,13);
cprintf(" ");
gotoxy(38,14);
cprintf(" ");
gotoxy(38,16);
cprintf(" ");
gotoxy(38,17);
cprintf(" ");
gotoxy(38,18);
cprintf(" ");
gotoxy(44,8);
cprintf(" ");
gotoxy(44,9);
cprintf(" ");
gotoxy(44,10);
cprintf(" ");
gotoxy(44,12);
cprintf(" ");
gotoxy(44,13);
cprintf(" ");
gotoxy(44,14);
cprintf(" ");
gotoxy(44,16);
cprintf(" ");
gotoxy(44,17);
cprintf(" ");
gotoxy(44,18);
cprintf(" ");
textcolor(BLACK);
gotoxy(34,9);
putch(Board[0][0]);
gotoxy(40,9);
putch(Board[1][0]);
gotoxy(46,9);
putch(Board[2][0]);
gotoxy(34,13);
putch(Board[0][1]);
gotoxy(40,13);
putch(Board[1][1]);
gotoxy(46,13);
putch(Board[2][1]);
gotoxy(34,17);
putch(Board[0][2]);
gotoxy(40,17);
putch(Board[1][2]);
gotoxy(46,17);
putch(Board[2][2]);
textcolor(LIGHTGRAY);
textbackground(BLACK);
if ( Win() == 0 )
{
if ( Board[0][0] != ' ' && Board[0][1] != ' ' && Board[0][2] != ' ' )
if ( Board[0][0] == Board[0][1] && Board[0][1] == Board[0][2] )
{
Winner = 1;
textbackground(GREEN);
gotoxy(32,8);
cprintf(" ");
gotoxy(32,9);
cprintf(" ");
gotoxy(32,10);
cprintf(" ");
gotoxy(32,12);
cprintf(" ");
gotoxy(32,13);
cprintf(" ");
gotoxy(32,14);
cprintf(" ");
gotoxy(32,16);
cprintf(" ");
gotoxy(32,17);
cprintf(" ");
gotoxy(32,18);
cprintf(" ");
textcolor(BLACK);
gotoxy(34,9);
putch(Board[0][0]);
gotoxy(34,13);
putch(Board[0][1]);
gotoxy(34,17);
putch(Board[0][2]);
textcolor(LIGHTGRAY);
textbackground(BLACK);
}
if ( Board[1][0] != ' ' && Board[1][1] != ' ' && Board[1][2] != ' ' )
if ( Board[1][0] == Board[1][1] && Board[1][1] == Board[1][2] )
{
Winner = 2;
textbackground(GREEN);
gotoxy(38,8);
cprintf(" ");
gotoxy(38,9);
cprintf(" ");
gotoxy(38,10);
cprintf(" ");
gotoxy(38,12);
cprintf(" ");
gotoxy(38,13);
cprintf(" ");
gotoxy(38,14);
cprintf(" ");
gotoxy(38,16);
cprintf(" ");
gotoxy(38,17);
cprintf(" ");
gotoxy(38,18);
cprintf(" ");
textcolor(BLACK);
gotoxy(40,9);
putch(Board[1][0]);
gotoxy(40,13);
putch(Board[1][1]);
gotoxy(40,17);
putch(Board[1][2]);
textcolor(LIGHTGRAY);
textbackground(BLACK);
}
if ( Board[2][0] != ' ' && Board[2][1] != ' ' && Board[2][2] != ' ' )
if ( Board[2][0] == Board[2][1] && Board[2][1] == Board[2][2] )
{
Winner = 3;
textbackground(GREEN);
gotoxy(44,8);
cprintf(" ");
gotoxy(44,9);
cprintf(" ");
gotoxy(44,10);
cprintf(" ");
gotoxy(44,12);
cprintf(" ");
gotoxy(44,13);
cprintf(" ");
gotoxy(44,14);
cprintf(" ");
gotoxy(44,16);
cprintf(" ");
gotoxy(44,17);
cprintf(" ");
gotoxy(44,18);
cprintf(" ");
textcolor(BLACK);
gotoxy(46,9);
putch(Board[2][0]);
gotoxy(46,13);
putch(Board[2][1]);
gotoxy(46,17);
putch(Board[2][2]);
textcolor(LIGHTGRAY);
textbackground(BLACK);
}
if ( Board[0][0] != ' ' && Board[1][0] != ' ' && Board[2][0] != ' ' )
if ( Board[0][0] == Board[1][0] && Board[1][0] == Board[2][0] )
{
Winner = 4;
textbackground(GREEN);
gotoxy(32,8);
cprintf(" ");
gotoxy(32,9);
cprintf(" ");
gotoxy(32,10);
cprintf(" ");
gotoxy(38,8);
cprintf(" ");
gotoxy(38,9);
cprintf(" ");
gotoxy(38,10);
cprintf(" ");
gotoxy(44,8);
cprintf(" ");
gotoxy(44,9);
cprintf(" ");
gotoxy(44,10);
cprintf(" ");
textcolor(BLACK);
gotoxy(34,9);
putch(Board[0][0]);
gotoxy(40,9);
putch(Board[1][0]);
gotoxy(46,9);
putch(Board[2][0]);
gotoxy(34,13);
textcolor(LIGHTGRAY);
textbackground(BLACK);
}
if ( Board[0][1] != ' ' && Board[1][1] != ' ' && Board[2][1] != ' ' )
if ( Board[0][1] == Board[1][1] && Board[1][1] == Board[2][1] )
{
Winner = 5;
textbackground(GREEN);
gotoxy(32,12);
cprintf(" ");
gotoxy(32,13);
cprintf(" ");
gotoxy(32,14);
cprintf(" ");
gotoxy(38,12);
cprintf(" ");
gotoxy(38,13);
cprintf(" ");
gotoxy(38,14);
cprintf(" ");
gotoxy(44,12);
cprintf(" ");
gotoxy(44,13);
cprintf(" ");
gotoxy(44,14);
cprintf(" ");
textcolor(BLACK);
gotoxy(34,9);
gotoxy(34,13);
putch(Board[0][1]);
gotoxy(40,13);
putch(Board[1][1]);
gotoxy(46,13);
putch(Board[2][1]);
textbackground(BLACK);
}
if ( Board[0][2] != ' ' && Board[1][2] != ' ' && Board[2][2] != ' ' )
if ( Board[0][2] == Board[1][2] && Board[1][2] == Board[2][2] )
{
Winner = 6;
textbackground(GREEN);
gotoxy(32,16);
cprintf(" ");
gotoxy(32,17);
cprintf(" ");
gotoxy(32,18);
cprintf(" ");
gotoxy(38,16);
cprintf(" ");
gotoxy(38,17);
cprintf(" ");
gotoxy(38,18);
cprintf(" ");
gotoxy(44,16);
cprintf(" ");
gotoxy(44,17);
cprintf(" ");
gotoxy(44,18);
cprintf(" ");
textcolor(BLACK);
gotoxy(34,17);
putch(Board[0][2]);
gotoxy(40,17);
putch(Board[1][2]);
gotoxy(46,17);
putch(Board[2][2]);
textcolor(LIGHTGRAY);
textbackground(BLACK);
}
if ( Board[0][0] != ' ' && Board[1][1] != ' ' && Board[2][2] != ' ' )
if ( Board[0][0] == Board[1][1] && Board[1][1] == Board[2][2] )
{
Winner = 7;
textbackground(GREEN);
gotoxy(32,8);
cprintf(" ");
gotoxy(32,9);
cprintf(" ");
gotoxy(32,10);
cprintf(" ");
gotoxy(38,12);
cprintf(" ");
gotoxy(38,13);
cprintf(" ");
gotoxy(38,14);
cprintf(" ");
gotoxy(44,16);
cprintf(" ");
gotoxy(44,17);
cprintf(" ");
gotoxy(44,18);
cprintf(" ");
textcolor(BLACK);
gotoxy(34,9);
putch(Board[0][0]);
gotoxy(40,13);
putch(Board[1][1]);
gotoxy(46,17);
putch(Board[2][2]);
textcolor(LIGHTGRAY);
textbackground(BLACK);
}
if ( Board[0][2] != ' ' && Board[1][1] != ' ' && Board[2][0] != ' ' )
if ( Board[0][2] == Board[1][1] && Board[1][1] == Board[2][0] )
{
Winner = 8;
textbackground(GREEN);
gotoxy(32,16);
cprintf(" ");
gotoxy(32,17);
cprintf(" ");
gotoxy(32,18);
cprintf(" ");
gotoxy(38,12);
cprintf(" ");
gotoxy(38,13);
cprintf(" ");
gotoxy(38,14);
cprintf(" ");
gotoxy(44,8);
cprintf(" ");
gotoxy(44,9);
cprintf(" ");
gotoxy(44,10);
cprintf(" ");
textcolor(BLACK);
gotoxy(46,9);
putch(Board[2][0]);
gotoxy(40,13);
putch(Board[1][1]);
gotoxy(34,17);
putch(Board[0][2]);
textcolor(LIGHTGRAY);
textbackground(BLACK);
}
switch(Winner)
{
case 1 : WinChar = Board[0][0]; break;
case 2 : WinChar = Board[1][0]; break;
case 3 : WinChar = Board[2][0]; break;
case 4 : WinChar = Board[0][0]; break;
case 5 : WinChar = Board[0][1]; break;
case 6 : WinChar = Board[0][2]; break;
case 7 : WinChar = Board[0][0]; break;
case 8 : WinChar = Board[0][2]; break;
}
gotoxy(3,22);
float Number = -1000;
do
{
gotoxy(16,22);
if ( Number == 999 )
textcolor(LIGHTGRAY);
else textcolor(random(120));
cprintf("Congratulaciones Jugador ");
if ( WinChar == 'X' )
cprintf("1 (X)");
else cprintf("2 (O)");
cprintf(" tu eres el ganador!");
Number++;
} while ( Number < 1000 );
textcolor(LIGHTGRAY);
}
else
{
gotoxy(3,22);
cout << "El juego termino empatado.";
}
getch();
}

noel solw
27 de Mayo del 2004
No esta claro que es lo que quieres. Tu pides pasar un tic tac toe de C a C++.
Pero si lo que mandaste en tu nota esta en C++,
#include <iostream.h> y cout, seguro no pertenecen a C ! ! !
Explica mejor que es lo que quieres.