Commits

Anton Gravestam committed 26e67ac

Added two helper sot AbstractBrain

Comments (0)

Files changed (1)

api/src/main/java/se/citerus/crazysnake/BaseBrain.java

 
     protected HeatMeta meta;
     protected Set<BrainId> participants;
+    
+    /**
+     * 
+     * @param state, the current heat state.
+     * @return Returns your opponent in the heat as a Snake.
+     */
+    protected Snake getOpponent(HeatState state) {
+    	BrainId brainId = new BrainId(this);
+    	for (BrainId id : participants) {
+			if(!id.equals(brainId)) {
+				return state.getSnake(id);
+			}
+		}
+    	return null;
+    }
+    
+    /**
+     * 
+     * @param state, the current heat state.
+     * @return Returns your own brains Snake.
+     */
+    protected Snake getMe(HeatState state) {
+    	BrainId brainId = new BrainId(this);
+    	for (BrainId id : participants) {
+			if(id.equals(brainId)) {
+				return state.getSnake(id);
+			}
+		}
+    	return null;
+    }
+    
+    
 
     /**
      * Default, empty implementation.