Hello, I've been looking at your code (currently learning ProLog). I understand all of the code, except the end (which seems to be the important part).
oplay(Brd,NewBrd) :- omove(Brd, o, NewBrd), win(NewBrd, o),!. oplay(Brd,NewBrd) :- omove(Brd, o, NewBrd), not(can_x_win(NewBrd)). oplay(Brd,NewBrd) :- omove(Brd, o, NewBrd). oplay(Brd,NewBrd) :- not(member(a,Brd)),!, write('Game Ended without Winner!'), nl, NewBrd = Brd.
I'm unsure how to understand that. I saw that every time I play 1, it always play 2, so the IA is pretty basic (which is not a problem for learning). How does the omove work?
you are right this AI is very simple, it's unable to learn (learning from failures), however omove is simply make few check in order to play first check is (if O played in a position and win) second check is (if O played where you wont be able to win) third check is (if O played in a position that O will be near to win) and lastly O is just play without checking anything which properly happen at the first play
in the part the AI, will search if it can make a move to stop x from winning. that's why I put "not" and the AI knows that by studying the blocks at the beginning of the code.
السلام عليكم ورحمه الله وبركاته جزاك الله خيراً على الشروحات المفيده آخي الفاضل لو تفضلت بالمساعده اكون شاكره جدا لك عندي اسايمنت عن Animal Identifier و Working Memory و SWI Prolog آذا تستطيع مساعدتي في شرح مالمطلوب او كيف اقوم بالحل او ان كان لديك مراجع استطيع ان افهم منها المطلوب اكون لك من الشاكرين ..
آذا تستطيع مساعدتي سا آرسل لك ال PDF الموجود فيه الاسايمنت و المحاضره
No problems, man! I have trouble understanding two parts, my friend. The first is: What change would be made so that the human player could never win, that is, there will always be a draw or victory of player 2. The second is: can_x_win(Brd) :- omove(Brd, x, NewBrd), win(NewBrd, x).
oplay(Brd,NewBrd) :- omove(Brd, o, NewBrd), win(NewBrd, o),!. oplay(Brd,NewBrd) :- omove(Brd, o, NewBrd), not(can_x_win(NewBrd)). oplay(Brd,NewBrd) :- omove(Brd, o, NewBrd). oplay(Brd,NewBrd) :- not(member(a,Brd)),!, write('Game Ended without Winner!'), nl, NewBrd = Brd.
Regarding your Q1: the answer is allow player 2 (AI player) to learn from you. this nowadays called machine learning. at the beginning the AI player will be easy to beat. However, once it has enough data (mistakes to learn from) it will become difficult to win which ends either in draw or AI wins.
Q2: this part of the code checks the next move for the AI. so first if AI can win in one single move then AI will wins. if not, then AI will see if it can block you from winning in the next step. If not, AI will make a move. Else, AI will consider this game as a draw.
Hello,
ReplyDeleteI've been looking at your code (currently learning ProLog). I understand all of the code, except the end (which seems to be the important part).
can_x_win(Brd) :- omove(Brd, x, NewBrd), win(NewBrd, x).
oplay(Brd,NewBrd) :-
omove(Brd, o, NewBrd),
win(NewBrd, o),!.
oplay(Brd,NewBrd) :-
omove(Brd, o, NewBrd),
not(can_x_win(NewBrd)).
oplay(Brd,NewBrd) :-
omove(Brd, o, NewBrd).
oplay(Brd,NewBrd) :-
not(member(a,Brd)),!,
write('Game Ended without Winner!'), nl,
NewBrd = Brd.
I'm unsure how to understand that. I saw that every time I play 1, it always play 2, so the IA is pretty basic (which is not a problem for learning). How does the omove work?
Thanks
you are right this AI is very simple, it's unable to learn (learning from failures), however omove is simply make few check in order to play
Deletefirst check is (if O played in a position and win)
second check is (if O played where you wont be able to win)
third check is (if O played in a position that O will be near to win)
and lastly O is just play without checking anything which properly happen at the first play
How did you create the executable file?
ReplyDeleteThis comment has been removed by the author.
Deleteit was build by my supervisor at that time, he asked me to share
DeleteHi,
ReplyDeletei have a problem understanding this part of the code :
oplay(Brd,NewBrd) :-
omove(Brd, o, NewBrd),
not(can_x_win(NewBrd)).
why you put not before can_x_win ? and how the AI know the right position where the user wont be able to win?
in the part the AI, will search if it can make a move to stop x from winning. that's why I put "not"
Deleteand the AI knows that by studying the blocks at the beginning of the code.
السلام عليكم ورحمه الله وبركاته
ReplyDeleteجزاك الله خيراً على الشروحات المفيده
آخي الفاضل لو تفضلت بالمساعده اكون شاكره جدا لك
عندي اسايمنت عن
Animal Identifier و Working Memory و SWI Prolog
آذا تستطيع مساعدتي في شرح مالمطلوب او كيف اقوم بالحل او ان كان لديك مراجع استطيع ان افهم منها المطلوب اكون لك من الشاكرين ..
آذا تستطيع مساعدتي سا آرسل لك ال
PDF
الموجود فيه الاسايمنت و المحاضره
شكرا جزيلا
وفقك الله
Good afternoon, my friend, do you have any complete explanation of this code?
ReplyDeleteHi,
DeleteI am afraid, I don't. Sorry.
However, I will do my best to remember the purpose of a specific lines if you got a trouble in some.
No problems, man! I have trouble understanding two parts, my friend.
ReplyDeleteThe first is: What change would be made so that the human player could never win, that is, there will always be a draw or victory of player 2.
The second is:
can_x_win(Brd) :- omove(Brd, x, NewBrd), win(NewBrd, x).
oplay(Brd,NewBrd) :-
omove(Brd, o, NewBrd),
win(NewBrd, o),!.
oplay(Brd,NewBrd) :-
omove(Brd, o, NewBrd),
not(can_x_win(NewBrd)).
oplay(Brd,NewBrd) :-
omove(Brd, o, NewBrd).
oplay(Brd,NewBrd) :-
not(member(a,Brd)),!,
write('Game Ended without Winner!'), nl,
NewBrd = Brd.
Regarding your Q1:
Deletethe answer is allow player 2 (AI player) to learn from you. this nowadays called machine learning. at the beginning the AI player will be easy to beat. However, once it has enough data (mistakes to learn from) it will become difficult to win which ends either in draw or AI wins.
Q2:
this part of the code checks the next move for the AI. so first if AI can win in one single move then AI will wins. if not, then AI will see if it can block you from winning in the next step. If not, AI will make a move. Else, AI will consider this game as a draw.
This comment has been removed by the author.
ReplyDeletehello Motaz, can u help me to tranlate your program game tictactoe become a program visual prolog? i have a last task, please help me :(
ReplyDeleteHow does the coding work, man?
ReplyDelete