Commit a8222544 authored by Max Rapp's avatar Max Rapp

Merge branch 'master' of gl.kwarc.info:teaching/AI

parents 10ee2885 d54f09e4
\documentclass[a4paper]{article}
%% Language and font encodings
\usepackage[german,english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
%% Sets page size and margins
\usepackage[a4paper,top=3cm,bottom=2cm,left=3cm,right=3cm,marginparwidth=1.75cm]{geometry}
%% Useful packages
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}
\usepackage[affil-it]{authblk}
\usepackage{url}
\usepackage{hyperref}
\usepackage{tikz}
\usepackage{forest}
\usepackage{caption}
\setlength{\parindent}{0em}
\begin{document}
TODO:
please define and describe your Cost function mathematically!
\begin{itemize}
\item change the tree, so that is is not trivial anymore with some more usage of \texttt{fill=red}
\item add the costs (I would prefer relative costs from $s$ to $s'$, not the absolute paths costs), see the dummy value \textbf{C}
\item add the values of the heuristic, see the dummy value \textbf{H}
\item do all of this twice, since you should define two heuristics
\item \textbf{See the assignment for the rest of the task!}
\end{itemize}
\begin{figure}[!htb]
\centering
\begin{forest}
for tree={circle,
draw,
edge = {->}}
[\tiny$00$
[\tiny$01$, fill=red, label=below:{\tiny $h_{1}$=H}, edge label={node[midway,left] {C}}
[\tiny$03$,label=below:{\tiny $h_{1}$=H}, edge label={node[midway,left] {C}}
[\tiny$07$,label=below:{\tiny $h_{1}$=H}, edge label={node[midway,left] {C}}
[\tiny$15$,l=2cm,label=below:{\tiny $h_{1}$=H}, edge label={node[midway,left] {C}}]
[\tiny$16$,label=below:{\tiny $h_{1}$=H},l=2cm, edge label={node[midway,right] {C}}]
]
[\tiny$08$, label=below:{\tiny $h_{1}$=H}, edge label={node[midway,right] {C}}
[\tiny$17$,l=2cm,label=below:{\tiny $h_{1}$=H}, edge label={node[midway,left] {C}}]
[\tiny$18$,l=2cm,label=below:{\tiny $h_{1}$=H}, edge label={node[midway,right] {C}}]
]
]
[\tiny$04$, label=below:{\tiny $h_{1}$=H},edge label={node[midway,right] {C}}
[\tiny$09$,label=below:{\tiny $h_{1}$=H}, edge label={node[midway,left] {C}}
[\tiny$19$,l=2cm,label=below:{\tiny $h_{1}$=H}, edge label={node[midway,left] {C}}]
[\tiny$20$,l=2cm,label=below:{\tiny $h_{1}$=H}, edge label={node[midway,right] {C}}]
]
[\tiny$10$,label=below:{\tiny $h_{1}$=H}, edge label={node[midway,right] {C}}
[\tiny$21$,l=2cm,label=below:{\tiny $h_{1}$=H}, edge label={node[midway,left] {C}}]
[\tiny$22$,l=2cm,label=below:{\tiny $h_{1}$=H}, edge label={node[midway,right] {C}}]
]
]
]
[\tiny$02$, label=below:{\tiny $h_{1}$=H}, edge label={node[midway,right] {C}}
[\tiny$05$,label=below:{\tiny $h_{1}$=H}, edge label={node[midway,left] {C}}
[\tiny$11$,label=below:{\tiny $h_{1}$=H}, edge label={node[midway,left] {C}}
[\tiny$23$,l=2cm,label=below:{\tiny $h_{1}$=H}, edge label={node[midway,left] {C}}]
[\tiny$24$,l=2cm,label=below:{\tiny $h_{1}$=H}, edge label={node[midway,right] {C}}]
]
[\tiny$12$,label=below:{\tiny $h_{1}$=H}, edge label={node[midway,right] {C}}
[\tiny$25$,l=2cm,label=below:{\tiny $h_{1}$=H}, edge label={node[midway,left] {C}}]
[\tiny$26$,l=2cm,label=below:{\tiny $h_{1}$=H}, edge label={node[midway,right] {C}}]
]
]
[\tiny$06$,label=below:{\tiny $h_{1}$=H}, edge label={node[midway,right] {C}}
[\tiny$13$,label=below:{\tiny $h_{1}$=H}, edge label={node[midway,left] {C}}
[\tiny$27$,l=2cm,label=below:{\tiny $h_{1}$=H}, edge label={node[midway,left] {C}}]
[\tiny$28$,l=2cm,label=below:{\tiny $h_{1}$=H}, edge label={node[midway,right] {C}}]
]
[\tiny$14$,label=below:{\tiny $h_{1}$=H}, edge label={node[midway,right] {C}}
[\tiny$29$,l=2cm,label=below:{\tiny $h_{1}$=H}, edge label={node[midway,left] {C}}]
[\tiny$30$,l=2cm,label=below:{\tiny $h_{1}$=H}, edge label={node[midway,right] {C}}]
]
]
]
]
\end{forest}
\end{figure}
\end{document}
% A Tic-Tac-Toe program in Prolog. S. Tanimoto, May 11, 2003.
% To play a game with the computer, type
% playo.
% To watch the computer play a game with itself, type
% selfgame.
%
% original at https://courses.cs.washington.edu/courses/cse341/03sp/slides/PrologEx/tictactoe.pl.txt
% Predicates that define the winning conditions:
win(Board, Player) :- rowwin(Board, Player).
win(Board, Player) :- colwin(Board, Player).
win(Board, Player) :- diagwin(Board, Player).
rowwin(Board, Player) :- Board = [Player,Player,Player,_,_,_,_,_,_].
rowwin(Board, Player) :- Board = [_,_,_,Player,Player,Player,_,_,_].
rowwin(Board, Player) :- Board = [_,_,_,_,_,_,Player,Player,Player].
colwin(Board, Player) :- Board = [Player,_,_,Player,_,_,Player,_,_].
colwin(Board, Player) :- Board = [_,Player,_,_,Player,_,_,Player,_].
colwin(Board, Player) :- Board = [_,_,Player,_,_,Player,_,_,Player].
diagwin(Board, Player) :- Board = [Player,_,_,_,Player,_,_,_,Player].
diagwin(Board, Player) :- Board = [_,_,Player,_,Player,_,Player,_,_].
% Helping predicate for alternating play in a "self" game:
other(x,o).
other(o,x).
game(Board, Player) :- win(Board, Player), !, write([player, Player, wins]).
game(Board, Player) :-
other(Player,Otherplayer),
move(Board,Player,Newboard),
!,
display(Newboard),
game(Newboard,Otherplayer).
move([b,B,C,D,E,F,G,H,I], Player, [Player,B,C,D,E,F,G,H,I]).
move([A,b,C,D,E,F,G,H,I], Player, [A,Player,C,D,E,F,G,H,I]).
move([A,B,b,D,E,F,G,H,I], Player, [A,B,Player,D,E,F,G,H,I]).
move([A,B,C,b,E,F,G,H,I], Player, [A,B,C,Player,E,F,G,H,I]).
move([A,B,C,D,b,F,G,H,I], Player, [A,B,C,D,Player,F,G,H,I]).
move([A,B,C,D,E,b,G,H,I], Player, [A,B,C,D,E,Player,G,H,I]).
move([A,B,C,D,E,F,b,H,I], Player, [A,B,C,D,E,F,Player,H,I]).
move([A,B,C,D,E,F,G,b,I], Player, [A,B,C,D,E,F,G,Player,I]).
move([A,B,C,D,E,F,G,H,b], Player, [A,B,C,D,E,F,G,H,Player]).
display([A,B,C,D,E,F,G,H,I]) :- write([A,B,C]),nl,write([D,E,F]),nl,
write([G,H,I]),nl,nl.
selfgame :- game([b,b,b,b,b,b,b,b,b],x).
% Predicates to support playing a game with the user:
x_can_win_in_one(Board) :- move(Board, x, Newboard), win(Newboard, x).
% The predicate orespond generates the computer's (playing o) reponse
% from the current Board.
% move and win
orespond(Board,Newboard) :-
move(Board, o, Newboard),
win(Newboard, o),
!.
% a draw occurs
orespond(Board,Newboard) :-
not(member(b,Board)),
!,
write('Cats game!'), nl,
Newboard = Board.
% minimax has to be calculated
% this function computes the list of possible moves,
% calculates the Utility value for each element in this list via minimax
% and returns the board with the largest one (by sorting a List of Tuples (Utility,Board))
orespond(Board,Newboard) :-
show_possiblemoves(Board,o,L),
maplist(minimaxwrap, L, ListofTuples),
predsort(sort_boards,ListofTuples,[(_,Newboard)|_]).
% the wrapper for minimax, used to bind a board to an utilty value
minimaxwrap(Board,(Utility, Board)):-
minimax(x,Board,Utility).
% minimax(Player,Board,Utility value)
% case: draw
minimax(_,Board,0):-
not(win(Board,o)),
not(win(Board,x)),
not(member(b,Board)).
% case: o wins
minimax(_,Board,100):-
win(Board,o).
% case: x wins
minimax(_,Board,-100):-
win(Board,x).
% case: o's turn
minimax(o,Board,Utility):-
show_possiblemoves(Board,o,L),
maplist(minimax(x),L,Utilities),
max_list(Utilities,Utility).
% case: x's turn
minimax(x, Board,Utility):-
show_possiblemoves(Board,x,L),
maplist(minimax(o),L,Utilities),
min_list(Utilities,Utility).
%% HELPER FUNCTIONS
% compare function for a tuple (Utilty,Board)
sort_boards(Delta, (C1,_),(C2,_)):-
C1==C2;
compare(Delta,C2,C1).
%finds all possible moves for Player from Board and stores it into a ListOfBoards
show_possiblemoves(Board, Player, ListOfBoards):-
findall(Newboard, move(Board,Player,Newboard),ListOfBoards).
%% END HELPER FUNCTIONS
% The following translates from an integer description
% of x's move to a board transformation.
xmove([b,B,C,D,E,F,G,H,I], 1, [x,B,C,D,E,F,G,H,I]).
xmove([A,b,C,D,E,F,G,H,I], 2, [A,x,C,D,E,F,G,H,I]).
xmove([A,B,b,D,E,F,G,H,I], 3, [A,B,x,D,E,F,G,H,I]).
xmove([A,B,C,b,E,F,G,H,I], 4, [A,B,C,x,E,F,G,H,I]).
xmove([A,B,C,D,b,F,G,H,I], 5, [A,B,C,D,x,F,G,H,I]).
xmove([A,B,C,D,E,b,G,H,I], 6, [A,B,C,D,E,x,G,H,I]).
xmove([A,B,C,D,E,F,b,H,I], 7, [A,B,C,D,E,F,x,H,I]).
xmove([A,B,C,D,E,F,G,b,I], 8, [A,B,C,D,E,F,G,x,I]).
xmove([A,B,C,D,E,F,G,H,b], 9, [A,B,C,D,E,F,G,H,x]).
xmove(Board, _, Board) :- write('Illegal move.'), nl.
% The 0-place predicate playo starts a game with the user.
playo :- explain, playfrom([b,b,b,b,b,b,b,b,b]).
explain :-
write('You play X by entering integer positions followed by a period.'),
nl,
display([1,2,3,4,5,6,7,8,9]).
playfrom(Board) :- win(Board, x), write('You win!').
playfrom(Board) :- win(Board, o), write('I win!').
playfrom(Board) :- read(N),
xmove(Board, N, Newboard),
display(Newboard),
orespond(Newboard, Newnewboard),
display(Newnewboard),
playfrom(Newnewboard).
% The 0-place predicate playo2 starts a game with the AI.
playo2 :- explain, playfrom2([b,b,b,b,b,b,b,b,b]).
playfrom2(Board) :- win(Board, x), write('You win!').
playfrom2(Board) :- win(Board, o), write('I win!').
playfrom2(Board) :-
orespond(Board, Newboard),
display(Newboard),
(not(member(b,Newboard)),
write('Cats game!');
win(Newboard, x),
write('You win!');
win(Newboard, o),
write('I win!');
read(N),
xmove(Newboard, N, Newnewboard),
display(Newnewboard),
playfrom2(Newnewboard)).
%defines some interesting pairs of numbers
interestingPair(42, 0).
interestingPair(42, 23).
interestingPair(42, 42).
interestingPair(42, 1337).
%shows how findall works
findAllInteresting(Number, ResultList):-
findall(X,interestingPair(Number,X),ResultList).
%helper, adds 1 to Number
addOne(Number,Newnumber):-
Newnumber is 1 + Number.
%shows how maplist executes addOne on List and stores the Result
addOneToList(List,ResultList):-
maplist(addOne,List, ResultList).
%demonstrates min_list
showMinList(List,Minimum):-
min_list(List,Minimum).
\ No newline at end of file
\documentclass[a4paper]{article}
%% Language and font encodings
\usepackage[german,english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
%% Sets page size and margins
\usepackage[a4paper,top=3cm,bottom=2cm,left=3cm,right=3cm,marginparwidth=1.75cm]{geometry}
%% Useful packages
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}
\usepackage{url}
\usepackage[affil-it]{authblk}
\setlength{\parindent}{0em}
% use these fields for a title
\author{AUTHOR}
\title{TITLE}
\begin{document}
\maketitle
This is the full proof of the validity of $A \Rightarrow A$.\\
I do not expect you to do hand in your homework in such a complete form.
You may shorten the steps 1 -- 4, since they are trivial transformations. Also,you may do several steps at once, e.g. 5~\&~6 or 7 \& 8 and so on, as long as you don't make any mistakes!\\
\textbf{Generally:} You may also solve 8.3 without this specific notation, as long as you use \textbf{Interpretations}, \textbf{Value Functions} and \textbf{Assignments} as defined in the lecture.
\begin{align}
& \mathcal{M} \models^\varphi A \Rightarrow A \text{ for all Assignments } \varphi \\
%
\stackrel{valid}{\Leftrightarrow} & \text{ for any } \varphi: \mathcal{I}_\varphi(A \Rightarrow A) = T\\
%
\stackrel{\Rightarrow}{\Leftrightarrow} & \text{ for any } \varphi: \mathcal{I}_\varphi(\neg A \lor A) = T\\
%
\stackrel{\lor}{\Leftrightarrow} & \text{ for any } \varphi: \mathcal{I}_\varphi(\neg ( \neg \neg A \land \neg A)) = T\\
%
\stackrel{\mathcal{I_\varphi}(\neg)}{\Leftrightarrow} & \text{ for any } \varphi: \mathcal{I}(\neg) \mathcal{I}_\varphi(\neg \neg A \land \neg A) = T\\
%
\stackrel{\mathcal{I}(\neg)}{\Leftrightarrow} & \text{ for any } \varphi: \mathcal{I}_\varphi(\neg \neg A \land \neg A) = F\\
%
\stackrel{\mathcal{I_\varphi}(\neg)}{\Leftrightarrow} & \text{ for any } \varphi: \mathcal{I} (\land) [ \mathcal{I}_\varphi(\neg \neg A), \mathcal{I}_\varphi(\neg A) ] = F\\
%
\stackrel{\mathcal{I}(\land)}{\Leftrightarrow} & \text{ for any } \varphi: \text{ either }\mathcal{I}_\varphi(\neg \neg A) = F \text{ or: } \mathcal{I}_\varphi( \neg A) = F \\
%
\stackrel{\mathcal{I_\varphi}(\neg) \text{ on both sides}}{\Leftrightarrow} & \text{ for any } \varphi: \text{ either } \mathcal{I}(\neg)\mathcal{I}_\varphi(\neg A) = F \text{ or: } \mathcal{I}(\neg) \mathcal{I}_\varphi(A) = F \\
%
\stackrel{\mathcal{I}(\neg) \text{ on both sides}}{\Leftrightarrow} & \text{ for any } \varphi: \text{ either } \mathcal{I}_\varphi(\neg A) = T \text{ or: } \mathcal{I}_\varphi(A) = T \\
%
\stackrel{\mathcal{I_\varphi}(\neg) \text{on the left side}}{\Leftrightarrow} & \text{ for any } \varphi: \text{ either }\mathcal{I}(\neg)\mathcal{I}_\varphi(A) = T \text{ or: } \mathcal{I}_\varphi(A) = T \\
%
\stackrel{\mathcal{I}(\neg) \text{on the left side}}{\Leftrightarrow} & \text{ for any } \varphi: \text{ either }\mathcal{I}_\varphi(A) = F \text{ or: } \mathcal{I}_\varphi(A) = T \\
%
\stackrel{\text{def of } \varphi}{\Leftrightarrow} & \text{this holds always } \hspace{0.5cm} \square
\end{align}
\end{document}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment