Results 1 to 2 of 2
Thread: Alpha Beta pruning help!
- 04-22-2012, 11:46 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 7
- Rep Power
- 0
Alpha Beta pruning help!
Im writing an engine for a game I'm developing
I'm trying to follow the pseudo code given on Wikipedia
Java Code:function alphabeta(node, depth, α, β, Player) if depth = 0 or node is a terminal node return the heuristic value of node if Player = MaxPlayer for each child of node α := max(α, alphabeta(child, depth-1, α, β, not(Player) )) if β ≤ α break (* Beta cut-off *) return α else for each child of node β := min(β, alphabeta(child, depth-1, α, β, not(Player) )) if β ≤ α break (* Alpha cut-off *) return β (* Initial call *) alphabeta(origin, depth, -infinity, +infinity, MaxPlayer)
for some reason my code does not work, so I'm wondering if a implemented the pseudo code into java correctly
the game has only 2 players, and it is a zero sum game
any clarifications needed, just askJava Code:private int calculate(Game template, int depth, int alpha, int beta, byte player) { int score; //i'll refer to this later if (depth == 0) { return Evaluation.evaluate(template, player); //value of the current board } //starts the alpha/beta pruning if (player == 1) { //were 1 is player 1 of 2, am i supposed to do that? score = alpha; //used in my own "min/max" function Game[] children = pMoves(template); //this generates the possible moves, and creates the "children" of the first node for (byte i = 0; i < 9; i++) { //loops through all the possible moves if (children[i] != null) { //this is just a legal check, u may ignore score = calculate(children[i], depth - 1, alpha, beta, (byte) 2); //gets the value from the child //this is the equivalent of min/max function? if (score > alpha) { //compares child alpha = score; //we found a better move Xmove = i; //i have to store the best move somehow, ignore } else if (score < alpha) { return score; //cuts off the bad move } } } return alpha; //this is the best move for player 1? } else { score = beta; Game[] Children = pMoves(template); for (byte i = 0; i < 9; i++) { if (Children[i] != null) { score = -1 * calculate(Children[i], depth - 1, alpha, beta, (byte) 1); if (score < beta) { beta = score; Ymove = i; } else if (score > beta) { return score; } } } return beta; //this is the best move for player 2? } }
- 04-23-2012, 12:04 PM #2
AN21XX
- Join Date
- Mar 2012
- Location
- Munich
- Posts
- 297
- Rep Power
- 2
Similar Threads
-
Pruning?? (N-Queens problem)
By n00neimp0rtant in forum New To JavaReplies: 1Last Post: 02-14-2010, 06:41 AM -
minmax with Alpha - Beta Pruning
By Zosden in forum Advanced JavaReplies: 6Last Post: 05-02-2008, 08:40 AM -
Alpha-beta algorithm, game tree
By ljaf_1985 in forum New To JavaReplies: 0Last Post: 03-28-2008, 04:21 PM -
SableCC 4-alpha.3
By levent in forum Java SoftwareReplies: 0Last Post: 07-26-2007, 07:59 PM -
MegaBlock 0.0.1 alpha
By JavaBean in forum Java SoftwareReplies: 0Last Post: 07-14-2007, 08:25 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks