Documente Academic
Documente Profesional
Documente Cultură
TEMA:
CURSO:
DOCENTE:
Inteligencia Artificial.
PRESENTADO POR:
Cereceda Lopez, Mariela
Rozas Llamacponcca, Ramiro
CUSCO PERU
2014
040978
091965
INTRODUCCIN
Funcionamiento:
Identificaremos a cada jugador como el jugador MAX y el jugador
MIN. MAX ser el jugador que inicia el juego, el cual supondremos que
somos nosotros, y nos marcaremos como objetivo encontrar el conjunto
de movimientos que proporcionen la victoria a MAX (nosotros).
Deber existir una funcin de evaluacin heurstica que devuelva valores
elevados para indicar buenas situaciones, y valores negativos para
indicar situaciones favorables al oponente.
La calidad de nuestras jugadas vendr determinada por la profundidad a
la que lleguemos en cada exploracin. Cuanto mas profunda sea, mejor
jugaremos, pero mayor coste tendr el algoritmo.
En este juego de las tres en raya se puede llegar a la profundidad
mxima puesto que se trata de 9 movimientos fijos, en otros como el
ajedrez o las damas es muy necesario limitar la profundidad y aplicar
medidas que aumenten la eficiencia.
Generacin del rbol de juego. Se generarn todos los nodos hasta llegar
a un estado terminal o determinando una profundidad concreta (poda o
corte). Se considera el nodo raz como la situacin actual del juego.
En el tres en raya:
Es de aprendizaje lento
1.3.
Omitir la expansin de nodos que por sus valores no pueden ser los
mejores (peores).
Interrumpe la bsqueda en algn nivel y aplica evaluaciones
heursticas a las hojas (profundidad limitada).
Si el valor del nodo MAX (alfa) es menor que el ms alto hasta este
momento, entonces omitir nodo.
SI el valor del nodo MIN (beta) es mayor que el nodo ms bajo hasta
el momento, entonces omitir nodo.
As tenemos
marcarTablero([L|Ls],1,C,V,[R|Ls]):-marcarLista(L,C,V,R),!.
marcarTablero([L|Ls],F,C,V,[L|R]):-F1 is F-1, marcarTablero(Ls,F1,C,V,R).
getPuntosLista([],_,_,[]):-!.
getPuntosLista([0|Ls],F,C,[punto(F,C)|R]):-C1 is C+1, getPuntosLista(Ls,F,C1,R),!.
getPuntosLista([_|Ls],F,C,R):-C1 is C+1, getPuntosLista(Ls,F,C1,R).
getPuntosTablero([],_,[]):-!.
getPuntosTablero([L|Ls],F,R):-F1 is F+1, getPuntosLista(L,F,1,R1),
getPuntosTablero(Ls,F1,R2), concatenar(R1,R2,R).
getEstadosMarcados(_,[],_,[]):-!.
getEstadosMarcados(estado(T,J),[punto(F,C)|Ls],NJ,[estado(R,NJ)|Rs]):marcarTablero(T,F,C,J,R),
getEstadosMarcados(estado(T,J),Ls,NJ,Rs).
getListaSucesores(estado(T,J),R):-getPuntosTablero(T,1,LP), genSgteJugador(J,NJ),
getEstadosMarcados(estado(T,J),LP,NJ,R).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Test Terminal %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
getListaVertical([],_,[]):- !.
getListaVertical([L|Ls],P,[E|R]):- getElemenLista(L,P,E), getListaVertical(Ls,P,R),!.
getDiagonalIzq([],_,[]):- !.
getDiagonalIzq([L|Ls],P,[E|R]):- P1 is P+1, getElemenLista(L,P,E),
getDiagonalIzq(Ls,P1,R).
getDiagonalDer([],_,[]):- !.
getDiagonalDer([L|Ls],P,[E|R]):- P1 is P-1, getElemenLista(L,P,E),
getDiagonalDer(Ls,P1,R).
tieneCeroLista([0|_]):- !.
tieneCeroLista([_|Ls]):- tieneCeroLista(Ls), !.
tieneCeroMatriz([L|_]):- tieneCeroLista(L), !.
tieneCeroMatriz([_|Ls]):- tieneCeroMatriz(Ls), !.
% Predicados que determinan si el estado es terminal
tresEnRayaHorizontal(L,J):-getElemenLista(L,1,P), iguales(P,J), !.
tresEnRayaHorizontal(L,J):-getElemenLista(L,2,P), iguales(P,J), !.
tresEnRayaHorizontal(L,J):-getElemenLista(L,3,P), iguales(P,J), !.
tresEnRayaVertical(L,J):- getListaVertical(L,1,P), iguales(P,J), !.
tresEnRayaVertical(L,J):- getListaVertical(L,2,P), iguales(P,J), !.
tresEnRayaVertical(L,J):- getListaVertical(L,3,P), iguales(P,J), !.
tresEnRayaDiagonal(L,J):- getDiagonalIzq(L,1,D), iguales(D,J), !.
tresEnRayaDiagonal(L,J):- getDiagonalDer(L,3,D), iguales(D,J), !.
estadoFinal(estado(T,_),1):- tresEnRayaHorizontal(T,1), !.
estadoFinal(estado(T,_),1):- tresEnRayaVertical(T,1), !.
estadoFinal(estado(T,_),1):- tresEnRayaDiagonal(T,1), !.
estadoFinal(estado(T,_),-1):- tresEnRayaHorizontal(T,-1), !.
estadoFinal(estado(T,_),-1):- tresEnRayaVertical(T,-1), !.
estadoFinal(estado(T,_),-1):- tresEnRayaDiagonal(T,-1), !.
estadoFinal(estado(T,_),0):- not(tieneCeroMatriz(T)), !.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Algoritmo Minimax%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%
% Max-Valor
% MaxValor recibe un estado, alfa, beta,retorna un nuevo estado y un valor de utilidad
maxValor(S, _, _, S, U) :- estadoFinal(S, U), !.
maxValor(S, A, B, NS, U):- getListaSucesores(S, LS),
genEstadoIniMin(IS), V = (-10),
maxLista(LS, A, B, IS, V, NS, U).
maxLista([], _, _, IS, V, IS, V):- !.
maxLista([L|Ls], A, B, IS, V, NS2, U2):- maxElemento(L, A, B, IS, V, NS, U),
getMaxLista(Ls, A, B, NS, U, NS2, U2).
maxElemento(S, A, B, IS, V, NIS, NV):- minValor(S, A, B, _, UM),
getMaxValor(S, UM, IS, V, NIS, NV).
getMaxValor(S, UM, _, V, S, UM):- UM > V, !.
getMaxValor(_, UM, IS, V, IS, V):- UM =< V.
getMaxLista(_, _, B, NS, U, NS, U):- U >= B, !.
getMaxLista(Ls, A, B, NS, U, NS2, U2):- U < B, getMayor(A, U, NA),
maxLista(Ls, NA, B, NS, U, NS2, U2).
% Min-Valor
% MinValor recibe un estado, alfa, beta,retorna un nuevo estado y un valor de utilidad
minValor(S, _, _, S, U) :- estadoFinal(S, U), !.
minValor(S, A, B, NS, U):- getListaSucesores(S, LS),
genEstadoIniMax(IS), V = 10,
minLista(LS, A, B, IS, V, NS, U).
minLista([], _, _, IS, V, IS, V):- !.
minLista([L|Ls], A, B, IS, V, NS2, U2):- minElemento(L, A, B, IS, V, NS, U),
getMinLista(Ls, A, B, NS, U, NS2, U2).
minElemento(S, A, B, IS, V, NIS, NV):- maxValor(S, A, B, _, UM),
getMinValor(S, UM, IS, V, NIS, NV).
getMinValor(S, UM, _, V, S, UM):- UM < V, !.
getMinValor(_, UM, IS, V, IS, V):- UM >= V.
getMinLista(_, A, _, NS, U, NS, U):- U =< A, !.
getMinLista(Ls, A, B, NS, U, NS2, U2):- U > A, getMenor(B, U, NB),
minLista(Ls, A, NB, NS, U, NS2, U2).
% tomaremos como -inf a -10 y como +inf a +10
busquedaAlfaBetaIniMax(S,NS,U):- maxValor(S, -10, 10, NS, U).
busquedaAlfaBetaIniMin(S,NS,U):- minValor(S, -10, 10, NS, U).
%%%%%%%%%%%%%%%%%%%%%%%%%%%% Imprimir el estado actual en
Pantalla %%%%%%%%%%%%%%%%%%%%%