Advertisement
teleias

Untitled

Mar 10th, 2016
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.List;
  3.  
  4. class Node
  5. {
  6. Node parent;
  7. List<Node> children = new ArrayList<Node>();
  8. int depth;
  9. final int MAX_DEPTH = 3;
  10. Player original;
  11. Player playerA, playerB;
  12. Board board;
  13. double score;
  14. boolean leaf = false;
  15. Node bestChild = null;
  16. public Node(Node parent, int depth, Player original, Player playerA, Player playerB, Board board)
  17. {
  18. this.parent = parent;
  19. this.depth = depth;
  20. this.original = original;
  21. this.playerA = playerA;
  22. this.playerB = playerB;
  23. this.board = board;
  24. if(depth < MAX_DEPTH)
  25. {
  26. for(Board b : mm.getAll(playerA, board))
  27. Node n = new Node(this, depth+1, original, playerB, playerA, b);
  28. if(parent.bestChild == null || parent.score < score)
  29. {
  30. bestChild = this;
  31. parent.score = score;
  32. }
  33. }
  34. else
  35. {
  36. leaf = true;
  37. score = n.board.score(playerA);
  38. if(parent.bestChild == null || parent.score < score)
  39. {
  40. bestChild = this;
  41. parent.score = score;
  42. }
  43. }
  44. }
  45. public Node root()
  46. {
  47. if(parent == null)
  48. return this;
  49. return parent.root();
  50. }
  51. double[] scores = new double[MAX_DEPTH];
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement