/*
 * 
 */
package stockaliens;

import alieninterfaces.*;

/**
 *
 * @author sfreisem-kirov
 */
public class Martian implements Alien {
    int HorizontalMove; 
    int VerticalMove; 
    Context ctx;
    
    public void init(Context ctx) {
        HorizontalMove = 0; 
        VerticalMove = 0; 
        this.ctx = ctx;
    }
    
    // Martians move left, right, left, right
    public MoveDir getMove() {
        return new MoveDir(ctx.getEnergy(), 0);
    }

    
    public Action getAction() {
        try
        {
            if(ctx.getView().isAlienAtPos(ctx.getX(), ctx.getY()))
            {
                return new Action(ActionCode.Fight, Math.max(ctx.getEnergy() - 2, 2));
            }
        }catch (Exception e)
        {
            
        }
        
        if(ctx.getEnergy()< 2)
        {
            return new Action(ActionCode.Gain);
        }
        else if(ctx.getEnergy() < 4)
        {
            return new Action(ActionCode.Research);
        }
        else
        {
            return new Action(ActionCode.Spawn);
        }
    }
    
    public void processResults() {
        ctx.debugOut("Martian: processRsult not supported yet.");
        return;
        // GM: Sam, you don't really want to do this throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.

    }
}

/* SFK code as checked into branch


package consolealiensgame;


public class Martian extends Alien {
    int HorizontalMove;
    int VerticalMove;
    
    public Martian() {
        HorizontalMove = 0;
        VerticalMove = 0;
    }

    // Martians move left, right, left, right
    public MoveDir getMove(AlienAPI api) {
        return new MoveDir(api.energy(), 0);
    }

    public Action getAction(AlienAPI api) {
        try
        {
            if(api.view.isAlienAtPos(api.x(), api.y()))
            {
                return new Action(ActionCode.Fight, Math.max(api.energy() - 2, 2));
            }
        }catch (Exception e)
        {
            
        }
        
        if(api.energy()< 2)
        {
            return new Action(ActionCode.Gain);
        }
        else if(api.energy() < 4)
        {
            return new Action(ActionCode.Research);
        }
        else
        {
            return new Action(ActionCode.Spawn);
        }
        
    }

    @Override
    public void processResults(AlienAPI api) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
}

*/

@@ -25,16 +25,40 @@
 aliens;%0A
+import java.util.Random;
 %0Aimport 
@@ -76,17 +76,16 @@
 aces.*;%0A
-%0A
 /**%0A *%0A 
@@ -98,22 +98,15 @@
 hor 
-sfreisem-kirov
+guberti
 %0A */
@@ -138,32 +138,49 @@
 lements Alien %7B%0A
+    Context ctx;%0A
     int Horizont
@@ -182,25 +182,24 @@
 izontalMove;
- 
 %0A    int Ver
@@ -212,204 +212,602 @@
 ove;
- %0A    Context ctx;%0A    %0A    public void init(Context ctx) %7B%0A        HorizontalMove = 0; %0A        VerticalMove = 0; %0A        this.ctx = ctx;
+%0A    int Remainder;%0A    private static Random rnd = new Random();%0A    public static boolean getRandomBoolean() %7B%0A        return rnd.nextBoolean();%0A    %7D%0A%0A    public Martian() %7B%0A    %7D%0A%0A    @Override%0A    public void init(Context ctx) %7B%0A        ctx = ctx;%0A        Remainder = ctx.getTech() %25 2;%0A        HorizontalMove = (ctx.getTech()-Remainder)/2;%0A        VerticalMove = ctx.getTech()- HorizontalMove;%0A        if(getRandomBoolean() == true)
 %0A    
-%7D%0A
     
+%7B
 %0A    
-// Martians move left, right, left, right
+        HorizontalMove *= -1;%0A        %7D%0A        if(getRandomBoolean() == true)%0A        %7B%0A            VerticalMove *= -1;%0A        %7D%0A    %7D%0A    
 %0A   
@@ -865,26 +865,36 @@
 Dir(
-ctx.getEnergy(), 0
+HorizontalMove, VerticalMove
 );%0A 
@@ -899,21 +899,16 @@
 %0A    %7D%0A%0A
-    %0A
     publ
@@ -1174,36 +1174,85 @@
       %7B%0A        
-    
+return new Action(ActionCode.Fight, ctx.getEnergy());
 %0A        %7D%0A     
@@ -1549,1295 +1549,8 @@
   %7D%0A
-    %7D%0A    %0A    public void processResults() %7B%0A        ctx.debugOut(%22Martian: processRsult not supported yet.%22);%0A        return;%0A        // GM: Sam, you don't really want to do this throw new UnsupportedOperationException(%22Not supported yet.%22); //To change body of generated methods, choose Tools %7C Templates.%0A%0A    %7D%0A%7D%0A%0A/* SFK code as checked into branch%0A%0A%0Apackage consolealiensgame;%0A%0A%0Apublic class Martian extends Alien %7B%0A    int HorizontalMove;%0A    int VerticalMove;%0A    %0A    public Martian() %7B%0A        HorizontalMove = 0;%0A        VerticalMove = 0;%0A    %7D%0A%0A    // Martians move left, right, left, right%0A    public MoveDir getMove(AlienAPI api) %7B%0A        return new MoveDir(api.energy(), 0);%0A    %7D%0A%0A    public Action getAction(AlienAPI api) %7B%0A        try%0A        %7B%0A            if(api.view.isAlienAtPos(api.x(), api.y()))%0A            %7B%0A                return new Action(ActionCode.Fight, Math.max(api.energy() - 2, 2));%0A            %7D%0A        %7Dcatch (Exception e)%0A        %7B%0A            %0A        %7D%0A        %0A        if(api.energy()%3C 2)%0A        %7B%0A            return new Action(ActionCode.Gain);%0A        %7D%0A        else if(api.energy() %3C 4)%0A        %7B%0A            return new Action(ActionCode.Research);%0A        %7D%0A        else%0A        %7B%0A            return new Action(ActionCode.Spawn);%0A        %7D%0A
     
@@ -1610,20 +1610,8 @@
 lts(
-AlienAPI api
 ) %7B%0A
@@ -1758,8 +1758,4 @@
 %7D%0A%7D%0A
-%0A*/%0A

Update Martian to work with new code