Results 1 to 2 of 2
Thread: Alpha Beta pruning help!
 04232012, 12:46 AM #1Member
 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, depth1, α, β, not(Player) )) if β ≤ α break (* Beta cutoff *) return α else for each child of node β := min(β, alphabeta(child, depth1, α, β, not(Player) )) if β ≤ α break (* Alpha cutoff *) 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
Java 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? } }
 04232012, 01:04 PM #2AN21XX
 Join Date
 Mar 2012
 Location
 Munich
 Posts
 301
 Rep Power
 9
Similar Threads

Pruning?? (NQueens problem)
By n00neimp0rtant in forum New To JavaReplies: 1Last Post: 02142010, 07:41 AM 
minmax with Alpha  Beta Pruning
By Zosden in forum Advanced JavaReplies: 6Last Post: 05022008, 09:40 AM 
Alphabeta algorithm, game tree
By ljaf_1985 in forum New To JavaReplies: 0Last Post: 03282008, 05:21 PM 
SableCC 4alpha.3
By levent in forum Java SoftwareReplies: 0Last Post: 07262007, 08:59 PM 
MegaBlock 0.0.1 alpha
By JavaBean in forum Java SoftwareReplies: 0Last Post: 07142007, 09:25 PM
Bookmarks