Professional Documents
Culture Documents
_ _ _ _ _ _ _ _
| | | | | | | | |
| | | | | | | | |
| | | | | | | | |
| | | |o|x| | | |
| | | |x|o| | | |
| | | | | | | | |
| | | | | | | | |
|_|_|_|_|_|_|_|_|
}
Program otelo_dos_jugadores;
Uses Crt;
Const
{valores con los cuales llenar la matriz}
VACIO = 0;
BLANCO = 1;
NEGRO = 2; {COMPUTADORA- aleatorio}
{s¡mbolos que representan cada ficha}
FICHA : array[BLANCO..NEGRO] of Char = ('o','x'); {eleg¡ blanco: color blanco
negro : color azul }
{mensajes de error}
ERRORES: array[0..2] of string = ('Esa posici¢n no est en el tablero',
'Casillero ocupado ',
'Esa posici¢n no es vlida');
Var
casillero : array[1..8, 1..8] of byte; {tablero}
coordxchar: char; {coordenadas para posicionar la ficha}
coordx,coordy: byte;
turno: byte; {de qui‚n es el turno}
v,b,n,c: byte; {contadores: vac¡os, blancas, negras y posibles}
msj_error: string;
{##############################################################}
{# INICIALIZACIàN DE LA MATRIZ #}
{##############################################################}
Procedure Inicializar_Tablero;
Var i,j: byte;
Begin
{Limpia el tablero}
For i:=1 to 8 Do
For j:=1 to 8 Do
begin
casillero[i,j] := 0;
end;
{Posiciona las fichas de apertura}
casillero[4,4]:= BLANCO; casillero[5,5]:= BLANCO;
casillero[4,5]:= NEGRO; casillero[5,4]:= NEGRO;
End;
{##############################################################}
{# RUTINAS DE GRµFICAS e INICIALES #}
{##############################################################}
Procedure Dibujar_Tablero;
Var i: byte;
Begin
Writeln;
Writeln(' A B C D E F G H ');
Writeln(' ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»');
For i:=1 to 7 Do
Begin
Writeln(' ',i,' º ³ ³ ³ ³ ³ ³ ³ º');
Writeln(' ºÄÄÅÄÄÅÄÄÅÄÄÅÄÄÅÄÄÅÄÄÅÄĺ');
End;
Writeln(' ',8,' º ³ ³ ³ ³ ³ ³ ³ º');
Writeln(' ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ');
End;
Procedure Dibujar_Fichas;
Var i,j: byte;
Begin
For i:=1 to 8 Do
For j:=1 to 8 Do
Begin
GotoXY(IZQ+i*3, 2+j*2); {(trat‚ de pasar la matriz a las coordenadas
de la pantalla en modo texto)}
Case casillero[i,j] of
BLANCO : Begin
TextColor(White);
Write(ficha[BLANCO]);
End;
NEGRO : Begin
TextColor(Blue);
Write(ficha[NEGRO]);
End;
End;
TextColor(lightgray);
End;
End;
{##############################################################}
{# RUTINAS DE DETECCIàN DE ERRORES #}
{##############################################################}
{###############################################################}
{# RUTINA DE CONVERSIàN DE FICHAS #}
{###############################################################}
End;
(*##############################################################)
(##############################################################*)
Procedure Leer_Datos;
Begin
{Limpiar errores}
msj_error:='';
GotoXY(6,24); DelLine;
GotoXY(6,24); Write('Ubicar ficha en: ');
Readln(coordxchar,coordy);
{cambia valor ASCII a n£mero}
coordx:= Ord(Upcase(coordxchar))-64;
{si no est en el tablero}
If (coordx>8)OR(coordx<1)OR(coordy>8)OR(coordy<1) then
msj_error:= ERRORES[0]
{si el lugar no est vac¡o}
Else If Not(EstaVacio(coordx,coordy)) then
msj_error:= ERRORES[1]
{si no es un movimiento legal}
Else If Not(EsLegal(coordx,coordy)) then
msj_error:= ERRORES[2];
GotoXY(6,22); Write(' ');
TextColor(magenta);
GotoXY(6,22); Write(msj_error);
TextColor(lightgray);
End;
Procedure Leer_Datos_Maquina;
Var error: Boolean;
Begin
error:= TRUE;
Randomize;
While error=TRUE Do
Begin
coordx:= Random(8)+1;
coordy:= Random(8)+1;
error:=FALSE;
If (coordx>8)OR(coordx<1)OR(coordy>8)OR(coordy<1) then
error:= TRUE
Else If Not(EstaVacio(coordx,coordy)) then
error:= TRUE
Else If Not(EsLegal(coordx,coordy)) then
error:= TRUE;
End;
End;
Procedure Mostrar_Posibles;
Var ip,jp: byte;
Begin
c:=0;
{para cada casillero y el jugador de turno, eval£a si no hay errores}
For ip:=1 to 8 Do
For jp:=1 to 8 Do
If EstaVacio(ip,jp) then
If EsLegal(ip,jp) then
Begin
GotoXY(IZQ+ip*3, 2+jp*2);
Write('°°');
c:=c+1;
End
Else continue;
End;
(*************************************************************)
(*************************************************************)
{ PROGRAMA PRINCIPAL }
(*************************************************************)
(*************************************************************)
Begin
Clrscr;
Inicializar_Tablero;
Dibujar_Tablero;
Dibujar_Fichas;
turno:= BLANCO;
Tabla_de_Fichas;
Repeat
{Muestra los lugares posibles}
Mostrar_Posibles; If c=0 then {si no los hay, pasa el turno}
Begin
Case turno of
BLANCO: turno:= NEGRO;
NEGRO : turno:= BLANCO;
End;
Tabla_de_Fichas;
Mostrar_Posibles;
End;
{Lee d¢nde quiere ubicar la ficha}
If turno=BLANCO then
Begin
Leer_Datos;
While Length(msj_error)>0 Do
Leer_Datos;
End
Else if turno=NEGRO then {<========MAQUINA}
Begin
Delay(25000);
Leer_Datos_Maquina;
End;
{cambia de turno}
Case turno of
BLANCO: turno:= NEGRO;
NEGRO : turno:= BLANCO;
End;
{muestra "puntuaci¢n" de cada uno"}
Tabla_de_Fichas;
Until v=0;
GotoXY(6,24); TextColor(White);
If b=n Then Writeln('Empate');
If b>n Then Writeln('Ganador: ',FICHA[BLANCO]);
If b<n Then Writeln('Ganador: ',FICHA[NEGRO]);
Readkey;
End.