Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.List;
- class Node
- {
- Node parent;
- List<Node> children = new ArrayList<Node>();
- int depth;
- final int MAX_DEPTH = 3;
- Player original;
- Player playerA, playerB;
- Board board;
- double score;
- boolean leaf = false;
- Node bestChild = null;
- public Node(Node parent, int depth, Player original, Player playerA, Player playerB, Board board)
- {
- this.parent = parent;
- this.depth = depth;
- this.original = original;
- this.playerA = playerA;
- this.playerB = playerB;
- this.board = board;
- if(depth < MAX_DEPTH)
- {
- for(Board b : mm.getAll(playerA, board))
- Node n = new Node(this, depth+1, original, playerB, playerA, b);
- if(parent.bestChild == null || parent.score < score)
- {
- bestChild = this;
- parent.score = score;
- }
- }
- else
- {
- leaf = true;
- score = n.board.score(playerA);
- if(parent.bestChild == null || parent.score < score)
- {
- bestChild = this;
- parent.score = score;
- }
- }
- }
- public Node root()
- {
- if(parent == null)
- return this;
- return parent.root();
- }
- double[] scores = new double[MAX_DEPTH];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement