Forum > Beginners
Minimax algorithm
Tirans:
Hello, can someone please help me out to fix my minimax function, i dont know what im doing wrong :(
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function minimax(node, depth, maximizingPlayer);begin if depth = 0 or node is a terminal node then result:= 1; if maximizingPlayer then value := −2; for each child of node do value := max(value, minimax(child, depth − 1, FALSE)) return value else (* minimizing player *) value := +2; for each child of node do value := min(value, minimax(child, depth − 1, TRUE)) result := value;end;
dseligo:
You don't have types defined, you need to do something like:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function minimax(node, depth, maximizingPlayer: Integer): Integer;
dseligo:
And now that I looked it better I see many more errors in your code.
Variable 'value' is not declared.
What is this 'node is a terminal node'? If there is more conditions in 'if' statement, they should be in parenthesis.
What is that 'return' in line 9 doing? Are you trying to translate some C code?
You are probably missing 'begin'/'end' pairs between line 6-9 and 11-14.
This is also not correct: for each child of node do
You are missing semicolons in lines 8 and 13.
Maybe something else.
If you are translating C code, can you show it so we can help you further?
marcov:
That is some form pseudo code. with deliberate gotchas in them. You probably need to translate it to Pascal using courseware as an excercise.
Tirans:
Do you have discord? I think it would be a bit easier to explain everything.
--- Quote from: dseligo on April 02, 2022, 02:58:16 pm ---And now that I looked it better I see many more errors in your code.
Variable 'value' is not declared.
What is this 'node is a terminal node'? If there is more conditions in 'if' statement, they should be in parenthesis.
What is that 'return' in line 9 doing? Are you trying to translate some C code?
You are probably missing 'begin'/'end' pairs between line 6-9 and 11-14.
This is also not correct: for each child of node do
You are missing semicolons in lines 8 and 13.
Maybe something else.
If you are translating C code, can you show it so we can help you further?
--- End quote ---
Navigation
[0] Message Index
[#] Next page