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?
lisp common-lisp clisp
add a comment |
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?
lisp common-lisp clisp
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
add a comment |
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?
lisp common-lisp clisp
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
lisp common-lisp clisp
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
add a comment |
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
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
I guess that hijos returns the children of each node. This might be the thing you want to reverse.
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
add a comment |
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
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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