Download presentation
Presentation is loading. Please wait.
Published by曰 方 Modified over 5 years ago
1
CherubiAI.java @author: Derek Omuro @team : No Artificial Flavors
2
Interaction between components
getMove(…) Iterative-deepening DFS: explore the tree examine from leaf to root Bookkeeping: remember which moves are best manage array of values Evaluation function: evaluate a board configuration use for leaf nodes DFS 1 2 3 … depth-1 depth h(x) Interaction between components
3
Iterative-deepening DFS
public Point getMove(...) depthLimit = 1 while depthLimit != maxDepth bestMove = search(depthLimit++) return bestMove private Point search(...) push current state on stack while stack isn’t empty if out of time, return null node = stack.peek() while node is not a leaf && node has not been visited stack.push(possible moves of node) mark node as visited stack.pop() // evaluate and bookkeeping... A B C D E F G Example tree; depth limit is 2
4
Bookkeeping int values[] = private Point search(...)
1 2 3 ... max depth -inf +inf ±inf int values[] = private Point search(...) node = stack.pop() int value; if node is a leaf value = node.evaluate() else //node has been visited value = values[node.depth] reset values from node.depth to depthLimit if value is better than values[node.depth-1] values[node.depth-1] = value if node.depth == 1 bestMove = node.lastMove A B C 1 5 3 2 max min
5
Evaluation Function Look at every possible win vector
public int evaluate(...) value = 0 for every possible win vector value += score(winVector[]) return value Update points based on pieces in each win vector private int score(byte winVector[]) if different pieces in winVector return 0 else return 5^(# of pieces)*(±1) O = 0 = 25 = 5 O O X
6
Putting it all together
Point getMove(…) Iterative-deepening DFS: Iterative: keep searching one level deeper DFS: pop from leaves to root Bookkeeping: You only need a single integer array Update parent based on child If updating root, save the last move Evaluation function: Use to evaluate nodes at depth limit Look at every possible win vector DFS 1 2 3 … depth-1 depth max depth h(x) Interaction between components
7
Coding Tips Do not code everything up at once!
IDDFS: pop from leaf to root Simple evaluation function Bookkeeping: manage int values[] Improve evaluation function To do: Alpha-beta pruning Much more…
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.