Commits

Alex Hixon  committed 6e4d8a5

Try to add heuristics (and set default level of 2 for MinMax)

  • Participants
  • Parent commits 3eff79b

Comments (0)

Files changed (4)

File src/model/Baseline.java

         }
     }
 
+    public int getDistance(BoardCoordinate coordinate) {
+        if (this.location == LineParameter.X) {
+            return coordinate.getX() - this.x;
+        } else {
+            return coordinate.getY() - this.y;
+        }
+    }
+
     @Override
     public String toString() {
         if (this.location == LineParameter.X) {

File src/model/TreeNode.java

-package model;
-
-import com.sun.org.apache.xalan.internal.xsltc.compiler.Template;
-
-import java.util.LinkedList;
-
-public class TreeNode {
-
-    public TreeNode parent;
-    public LinkedList<TreeNode> children;
-    public int heuristic;
-    public BoardCoordinate boardCoordinate;
-
-    public TreeNode (BoardCoordinate b) {
-        this(b, null);
-    }
-
-    public TreeNode (BoardCoordinate b, TreeNode parent){
-        this.parent = parent;
-        this.boardCoordinate = b;
-        children = new LinkedList<TreeNode>();
-    }
-
-    public TreeNode getMinChild () {
-    TreeNode r = null;
-        if(!children.isEmpty()){
-            r = children.peek();
-            for (TreeNode temp : this.children){
-                if(r.heuristic > temp.heuristic){
-                    r = temp;
-                }
-            }
-        }
-        return r;
-    }
-
-    public TreeNode getMaxChild () {
-        TreeNode r = null;
-        if(!children.isEmpty()){
-            r = children.peek();
-            for (TreeNode temp : this.children){
-                if(r.heuristic < temp.heuristic){
-                    r = temp;
-                }
-            }
-        }
-        return r;
-    }
-
-}

File src/model/players/AIPlayer.java

 
 public class AIPlayer extends AbstractPlayer {
 
-    private int difficulty;
+    private int difficulty = 2;
 
     public AIPlayer(String name, String icon, Direction direction) {
         super(name, icon, direction);
                     parent.children.add( new TreeNode(b, parent));
                 } else {
                     TreeNode t = new TreeNode(b, parent);
-                    t.heuristic = heuristic(game);
+                    t.heuristic = heuristic(b);
                 }
                 treeBuilder(level - 1, parent, game);
             }
         }
     }
 
-    private int heuristic(Game boardCoordinate) {
-        return 0; //TODO implement min - max
+    private int heuristic (BoardCoordinate possibility) {
+        //int score = 0;
+        // get our score first
+        //score = boardCoordinate.
+        //possibility
+        int score = this.getFinishBaseline().getDistance (possibility);
+        System.out.println("Had score of " + score + "for possibility " + possibility);
+        return score;
     }
 
     private void minMax (TreeNode root, int level){

File src/model/players/TreeNode.java

+package model.players;
+
+import model.BoardCoordinate;
+
+import java.util.LinkedList;
+
+public class TreeNode {
+
+    public TreeNode parent;
+    public LinkedList<TreeNode> children;
+    public int heuristic;
+    public BoardCoordinate boardCoordinate;
+
+    public TreeNode (BoardCoordinate b) {
+        this(b, null);
+    }
+
+    public TreeNode (BoardCoordinate b, TreeNode parent){
+        this.parent = parent;
+        this.boardCoordinate = b;
+        children = new LinkedList<TreeNode>();
+    }
+
+    public TreeNode getMinChild () {
+    TreeNode r = null;
+        if(!children.isEmpty()){
+            r = children.peek();
+            for (TreeNode temp : this.children){
+                if(r.heuristic > temp.heuristic){
+                    r = temp;
+                }
+            }
+        }
+        return r;
+    }
+
+    public TreeNode getMaxChild () {
+        TreeNode r = null;
+        if(!children.isEmpty()){
+            r = children.peek();
+            for (TreeNode temp : this.children){
+                if(r.heuristic < temp.heuristic){
+                    r = temp;
+                }
+            }
+        }
+        return r;
+    }
+
+}