REVERSE function in Lisp for minimax-alpha-beta











up vote
-1
down vote

favorite












I have a function that the minimax-alpha-beta does, the fact is that it reads from left to right and I would like it to read backwards and I thought about the "reverse" function but I can not get it to work for me.



The code is the following:



(defun minimax-alpha-beta (nodo alpha beta)
(cond
((hoja nodo)
(let ((val (evalua nodo)))
(format t "~A " val)
val))
((nodo-min nodo)
(let ((beta-tmp beta))
(do ((ch (hijos nodo) (cdr ch)))
((or (null ch) (<= beta-tmp alpha)) beta-tmp)
(let ((r (minimax-alpha-beta (car ch) alpha beta-tmp)))
(if (< r beta-tmp) (setf beta-tmp r))))))
((nodo-max nodo)
(let ((alpha-tmp alpha))
(do ((ch (hijos nodo) (cdr ch)))
((or (null ch) (<= beta alpha-tmp)) alpha-tmp)
(let ((r (minimax-alpha-beta (car ch) alpha-tmp beta)))
(if (< alpha-tmp r) (setf alpha-tmp r))))))))


And I have an example tree implemented like this:



(defparameter *tree-001*
'(max ((min ((max ((min (15 14))
(min (13 12))))
(max ((min (11 10))
(min (9 8))))))
(min ((max ((min (7 6))
(min (5 4))))
(max ((min (3 2))
(min (1 0)))))))))


Where would I have to put the "reverse" so that I would do it the other way around?










share|improve this question
























  • What do you mean by “left to right” and “the other way around”? What is the expected return value?
    – Svante
    Nov 5 at 8:23










  • Also, please indent properly. gigamonkeys.com/book/…
    – Svante
    Nov 5 at 8:24










  • I mean that the alpha-beta pruning makes the reading of numbers from left to right and the function is done like this, to read the numbers from left to right. What I want is that I do it the other way round, that I read the numbers from right to left and I do not know how to implement the reverse function. This should give another way out.
    – Roman345
    Nov 5 at 9:08










  • I indented your code to make sense of it.
    – Svante
    Nov 5 at 9:38










  • @Roman345 Do not change the question after you have answers.
    – Goyo
    2 days ago















up vote
-1
down vote

favorite












I have a function that the minimax-alpha-beta does, the fact is that it reads from left to right and I would like it to read backwards and I thought about the "reverse" function but I can not get it to work for me.



The code is the following:



(defun minimax-alpha-beta (nodo alpha beta)
(cond
((hoja nodo)
(let ((val (evalua nodo)))
(format t "~A " val)
val))
((nodo-min nodo)
(let ((beta-tmp beta))
(do ((ch (hijos nodo) (cdr ch)))
((or (null ch) (<= beta-tmp alpha)) beta-tmp)
(let ((r (minimax-alpha-beta (car ch) alpha beta-tmp)))
(if (< r beta-tmp) (setf beta-tmp r))))))
((nodo-max nodo)
(let ((alpha-tmp alpha))
(do ((ch (hijos nodo) (cdr ch)))
((or (null ch) (<= beta alpha-tmp)) alpha-tmp)
(let ((r (minimax-alpha-beta (car ch) alpha-tmp beta)))
(if (< alpha-tmp r) (setf alpha-tmp r))))))))


And I have an example tree implemented like this:



(defparameter *tree-001*
'(max ((min ((max ((min (15 14))
(min (13 12))))
(max ((min (11 10))
(min (9 8))))))
(min ((max ((min (7 6))
(min (5 4))))
(max ((min (3 2))
(min (1 0)))))))))


Where would I have to put the "reverse" so that I would do it the other way around?










share|improve this question
























  • What do you mean by “left to right” and “the other way around”? What is the expected return value?
    – Svante
    Nov 5 at 8:23










  • Also, please indent properly. gigamonkeys.com/book/…
    – Svante
    Nov 5 at 8:24










  • I mean that the alpha-beta pruning makes the reading of numbers from left to right and the function is done like this, to read the numbers from left to right. What I want is that I do it the other way round, that I read the numbers from right to left and I do not know how to implement the reverse function. This should give another way out.
    – Roman345
    Nov 5 at 9:08










  • I indented your code to make sense of it.
    – Svante
    Nov 5 at 9:38










  • @Roman345 Do not change the question after you have answers.
    – Goyo
    2 days ago













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I have a function that the minimax-alpha-beta does, the fact is that it reads from left to right and I would like it to read backwards and I thought about the "reverse" function but I can not get it to work for me.



The code is the following:



(defun minimax-alpha-beta (nodo alpha beta)
(cond
((hoja nodo)
(let ((val (evalua nodo)))
(format t "~A " val)
val))
((nodo-min nodo)
(let ((beta-tmp beta))
(do ((ch (hijos nodo) (cdr ch)))
((or (null ch) (<= beta-tmp alpha)) beta-tmp)
(let ((r (minimax-alpha-beta (car ch) alpha beta-tmp)))
(if (< r beta-tmp) (setf beta-tmp r))))))
((nodo-max nodo)
(let ((alpha-tmp alpha))
(do ((ch (hijos nodo) (cdr ch)))
((or (null ch) (<= beta alpha-tmp)) alpha-tmp)
(let ((r (minimax-alpha-beta (car ch) alpha-tmp beta)))
(if (< alpha-tmp r) (setf alpha-tmp r))))))))


And I have an example tree implemented like this:



(defparameter *tree-001*
'(max ((min ((max ((min (15 14))
(min (13 12))))
(max ((min (11 10))
(min (9 8))))))
(min ((max ((min (7 6))
(min (5 4))))
(max ((min (3 2))
(min (1 0)))))))))


Where would I have to put the "reverse" so that I would do it the other way around?










share|improve this question















I have a function that the minimax-alpha-beta does, the fact is that it reads from left to right and I would like it to read backwards and I thought about the "reverse" function but I can not get it to work for me.



The code is the following:



(defun minimax-alpha-beta (nodo alpha beta)
(cond
((hoja nodo)
(let ((val (evalua nodo)))
(format t "~A " val)
val))
((nodo-min nodo)
(let ((beta-tmp beta))
(do ((ch (hijos nodo) (cdr ch)))
((or (null ch) (<= beta-tmp alpha)) beta-tmp)
(let ((r (minimax-alpha-beta (car ch) alpha beta-tmp)))
(if (< r beta-tmp) (setf beta-tmp r))))))
((nodo-max nodo)
(let ((alpha-tmp alpha))
(do ((ch (hijos nodo) (cdr ch)))
((or (null ch) (<= beta alpha-tmp)) alpha-tmp)
(let ((r (minimax-alpha-beta (car ch) alpha-tmp beta)))
(if (< alpha-tmp r) (setf alpha-tmp r))))))))


And I have an example tree implemented like this:



(defparameter *tree-001*
'(max ((min ((max ((min (15 14))
(min (13 12))))
(max ((min (11 10))
(min (9 8))))))
(min ((max ((min (7 6))
(min (5 4))))
(max ((min (3 2))
(min (1 0)))))))))


Where would I have to put the "reverse" so that I would do it the other way around?







lisp common-lisp clisp






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago









Goyo

6,93211430




6,93211430










asked Nov 5 at 7:07









Roman345

56




56












  • What do you mean by “left to right” and “the other way around”? What is the expected return value?
    – Svante
    Nov 5 at 8:23










  • Also, please indent properly. gigamonkeys.com/book/…
    – Svante
    Nov 5 at 8:24










  • I mean that the alpha-beta pruning makes the reading of numbers from left to right and the function is done like this, to read the numbers from left to right. What I want is that I do it the other way round, that I read the numbers from right to left and I do not know how to implement the reverse function. This should give another way out.
    – Roman345
    Nov 5 at 9:08










  • I indented your code to make sense of it.
    – Svante
    Nov 5 at 9:38










  • @Roman345 Do not change the question after you have answers.
    – Goyo
    2 days ago


















  • What do you mean by “left to right” and “the other way around”? What is the expected return value?
    – Svante
    Nov 5 at 8:23










  • Also, please indent properly. gigamonkeys.com/book/…
    – Svante
    Nov 5 at 8:24










  • I mean that the alpha-beta pruning makes the reading of numbers from left to right and the function is done like this, to read the numbers from left to right. What I want is that I do it the other way round, that I read the numbers from right to left and I do not know how to implement the reverse function. This should give another way out.
    – Roman345
    Nov 5 at 9:08










  • I indented your code to make sense of it.
    – Svante
    Nov 5 at 9:38










  • @Roman345 Do not change the question after you have answers.
    – Goyo
    2 days ago
















What do you mean by “left to right” and “the other way around”? What is the expected return value?
– Svante
Nov 5 at 8:23




What do you mean by “left to right” and “the other way around”? What is the expected return value?
– Svante
Nov 5 at 8:23












Also, please indent properly. gigamonkeys.com/book/…
– Svante
Nov 5 at 8:24




Also, please indent properly. gigamonkeys.com/book/…
– Svante
Nov 5 at 8:24












I mean that the alpha-beta pruning makes the reading of numbers from left to right and the function is done like this, to read the numbers from left to right. What I want is that I do it the other way round, that I read the numbers from right to left and I do not know how to implement the reverse function. This should give another way out.
– Roman345
Nov 5 at 9:08




I mean that the alpha-beta pruning makes the reading of numbers from left to right and the function is done like this, to read the numbers from left to right. What I want is that I do it the other way round, that I read the numbers from right to left and I do not know how to implement the reverse function. This should give another way out.
– Roman345
Nov 5 at 9:08












I indented your code to make sense of it.
– Svante
Nov 5 at 9:38




I indented your code to make sense of it.
– Svante
Nov 5 at 9:38












@Roman345 Do not change the question after you have answers.
– Goyo
2 days ago




@Roman345 Do not change the question after you have answers.
– Goyo
2 days ago












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










I guess that hijos returns the children of each node. This might be the thing you want to reverse.






share|improve this answer





















  • Effectively just that is what I want to do but I do not know how to use it or where to put the "reverse" function to get that done
    – Roman345
    Nov 5 at 10:06










  • To reverse the list returned by (hijos nodo): (reverse (hijos nodo)). How do you claim to have written the code in the question without having understood basic function application syntax?
    – Svante
    Nov 5 at 10:28










  • Well really the function cost me a lot to do it. I'm new to Lisp and the truth is that it's the first time I ask for help in this way, I usually try everything but sometimes it costs me more. With what you have advised me, I did this: (do ((ch (reverse(hijos nodo)) (cdr ch))) It is right?
    – Roman345
    Nov 5 at 11:01













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53149774%2freverse-function-in-lisp-for-minimax-alpha-beta%23new-answer', 'question_page');
}
);

Post as a guest
































1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










I guess that hijos returns the children of each node. This might be the thing you want to reverse.






share|improve this answer





















  • Effectively just that is what I want to do but I do not know how to use it or where to put the "reverse" function to get that done
    – Roman345
    Nov 5 at 10:06










  • To reverse the list returned by (hijos nodo): (reverse (hijos nodo)). How do you claim to have written the code in the question without having understood basic function application syntax?
    – Svante
    Nov 5 at 10:28










  • Well really the function cost me a lot to do it. I'm new to Lisp and the truth is that it's the first time I ask for help in this way, I usually try everything but sometimes it costs me more. With what you have advised me, I did this: (do ((ch (reverse(hijos nodo)) (cdr ch))) It is right?
    – Roman345
    Nov 5 at 11:01

















up vote
1
down vote



accepted










I guess that hijos returns the children of each node. This might be the thing you want to reverse.






share|improve this answer





















  • Effectively just that is what I want to do but I do not know how to use it or where to put the "reverse" function to get that done
    – Roman345
    Nov 5 at 10:06










  • To reverse the list returned by (hijos nodo): (reverse (hijos nodo)). How do you claim to have written the code in the question without having understood basic function application syntax?
    – Svante
    Nov 5 at 10:28










  • Well really the function cost me a lot to do it. I'm new to Lisp and the truth is that it's the first time I ask for help in this way, I usually try everything but sometimes it costs me more. With what you have advised me, I did this: (do ((ch (reverse(hijos nodo)) (cdr ch))) It is right?
    – Roman345
    Nov 5 at 11:01















up vote
1
down vote



accepted







up vote
1
down vote



accepted






I guess that hijos returns the children of each node. This might be the thing you want to reverse.






share|improve this answer












I guess that hijos returns the children of each node. This might be the thing you want to reverse.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 5 at 9:40









Svante

38.8k662109




38.8k662109












  • Effectively just that is what I want to do but I do not know how to use it or where to put the "reverse" function to get that done
    – Roman345
    Nov 5 at 10:06










  • To reverse the list returned by (hijos nodo): (reverse (hijos nodo)). How do you claim to have written the code in the question without having understood basic function application syntax?
    – Svante
    Nov 5 at 10:28










  • Well really the function cost me a lot to do it. I'm new to Lisp and the truth is that it's the first time I ask for help in this way, I usually try everything but sometimes it costs me more. With what you have advised me, I did this: (do ((ch (reverse(hijos nodo)) (cdr ch))) It is right?
    – Roman345
    Nov 5 at 11:01




















  • Effectively just that is what I want to do but I do not know how to use it or where to put the "reverse" function to get that done
    – Roman345
    Nov 5 at 10:06










  • To reverse the list returned by (hijos nodo): (reverse (hijos nodo)). How do you claim to have written the code in the question without having understood basic function application syntax?
    – Svante
    Nov 5 at 10:28










  • Well really the function cost me a lot to do it. I'm new to Lisp and the truth is that it's the first time I ask for help in this way, I usually try everything but sometimes it costs me more. With what you have advised me, I did this: (do ((ch (reverse(hijos nodo)) (cdr ch))) It is right?
    – Roman345
    Nov 5 at 11:01


















Effectively just that is what I want to do but I do not know how to use it or where to put the "reverse" function to get that done
– Roman345
Nov 5 at 10:06




Effectively just that is what I want to do but I do not know how to use it or where to put the "reverse" function to get that done
– Roman345
Nov 5 at 10:06












To reverse the list returned by (hijos nodo): (reverse (hijos nodo)). How do you claim to have written the code in the question without having understood basic function application syntax?
– Svante
Nov 5 at 10:28




To reverse the list returned by (hijos nodo): (reverse (hijos nodo)). How do you claim to have written the code in the question without having understood basic function application syntax?
– Svante
Nov 5 at 10:28












Well really the function cost me a lot to do it. I'm new to Lisp and the truth is that it's the first time I ask for help in this way, I usually try everything but sometimes it costs me more. With what you have advised me, I did this: (do ((ch (reverse(hijos nodo)) (cdr ch))) It is right?
– Roman345
Nov 5 at 11:01






Well really the function cost me a lot to do it. I'm new to Lisp and the truth is that it's the first time I ask for help in this way, I usually try everything but sometimes it costs me more. With what you have advised me, I did this: (do ((ch (reverse(hijos nodo)) (cdr ch))) It is right?
– Roman345
Nov 5 at 11:01




















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53149774%2freverse-function-in-lisp-for-minimax-alpha-beta%23new-answer', 'question_page');
}
);

Post as a guest




















































































這個網誌中的熱門文章

Academy of Television Arts & Sciences

L'Équipe

1995 France bombings