"Multiplayer" AI challenge on StackExchange right now: Create Your Wolf

[h3]http://codegolf.stackexchange.com/questions/25347/survival-game-create-your-wolf[/h3]

Thought this was real cool and thought I’d post it here since it’s Java-centric as well.

Feel free to discuss here, but beware, someone might steal your strategy :stuck_out_tongue:

Demo gif from the Challenge of animals in action to pique your interest:

https://lh3.googleusercontent.com/ff_64yKP-nX_7hhE76uvijI2B-44kZQn3eSnzRaLBxNIxQF9sN1dp0vUEQb2LSwCHQ=w1808-h832

CamoWolf is just genius.

And illegal haha, he won’t be in the competition.

But ingenious nonetheless.

Current testing is indicating my prototype is roughly on par with or beating Alpha. 8)

EDIT: After 1000 iterations:


MyWolf:   100
Alpha:     97
Gathering: 96
Lazy:      90
Camper:    88
Emo:       41
Stone:     38
Bear:       7
Lion:       0

just added my wolf. http://codegolf.stackexchange.com/a/25485/20193

so a quick test for the average living wolves over 100 rounds of 1000 iterations:
class animals.AlphaWolf - 72
class animals.OmegaWolf - 89
class animals.Wolf - 18
class animals.LionHunterWolf - 29
class animals.ProAlpha - 66

Thanks for telling me about this game Pizza!

I will post my WolfKiller when I’m done!

Ok, so beware that survival rate of everything falls sharply as the number of wolf classes increases (expected), turns out my proto is not nearly as good as that previous data indicates for dense games. Alpha is still firmly maintaining it’s crown though.

I’ll do it when I get home, but Moogie, I’d be interested to see how Omega fares with more of the wolves in the simulation.

But will it ever be your wolves vs other peoples wolves then?
I thought he measured the scores with only Lions, Bears, Stones (and normal Wolves or not?)?

No “normal” wolves, and yes, it’s a mosh pit of everyone’s wolves + lions + bears + stones.

Oh yeah I read it, but if he keeps up with the scores, doesn’t he have a download for the game with all the current wolves (in the scoreboard) for us then?
I btw hate it that I got an error in eclipse but in netbeans it worked just fine (in the Game class a xxx.add(new ArrayList) error twice…) I have JRE 8 in both of the IDEs (newest eclipse 4.4.2-M6 which is compatible with Java 8)

Ok, how far I got this hour:

100 rounds, 1000 iterations:
class animals.Bear - 0.47000003
class animals.Lion - 30.09
class animals.Stone - 22.06999
class animals.AlphaWolf - 92.88
class animals.HerjanWolf - 98.41002

Nice job, although be warned: That data means nothing. With so few animals on the field (relative to the actual contest), those numbers are not representational.

Another problem is that the sim takes forever (may optimize the controller) with many wolf classes (aka an accurate sim), so averaging over many round isn’t practical. Right now I have it dump text as it’s going, seems to be the only way to get info with any speed.

Example log: http://pastebin.java-gaming.org/cdd6b4b9c87

I still have some newer classes to add.
Don’t worry, I’m not going to call it “MyWolf” :stuck_out_tongue:

your wish is my command (avg of 100 rounds of 1000 iterations):


class animals.OmegaWolf - 85
class animals.HonorWolf - 82
class animals.ProAlpha - 79
class animals.AlphaWolf - 77
class animals.ShadowWolf - 77
class animals.LazyWolf - 62
class animals.CamperWolf - 61
class animals.StoneEatingWolf - 59
class animals.GatheringWolf - 48
class animals.Sheep - 42
class animals.EmoWolf - 34
class animals.LionHunterWolf - 28
class animals.GamblerWolf - 27
class animals.WolfWithoutFear - 11
class animals.MOSHPITFRENZYWolf - 5
class animals.Wolf - 3
class animals.Stone - 2
class animals.Bear - 0
class animals.Lion - 0
class animals.MimicWolf - 0
class animals.Wion - 0

note that for Gambler wolf i removed its cheating: changing the Math.random() behaviour

also for those who might want it… the following automatically adds all the animals in the animal package:


private static final Class[] classes;
	
	static
	{
		File file = new File("src\\animals");
		System.out.println(file.getAbsolutePath());
		File[] files = file.listFiles();
		ArrayList<Class> animals = new ArrayList<Class>();
		
		for (File child : files)
		{
			String name= child.getName();
			if (!name.contains("1") && !name.equals("Animal.java"))
			{
				if (name.endsWith(".java"))
				{
					name=name.replace(".java", "");
					
					try
					{
						Class clazz = Class.forName("animals."+name);
						animals.add(clazz);
					}
					catch (Exception e)
					{
						e.printStackTrace();
						System.exit(1);
					}
				}
			}
			
		}
		classes= new Class[animals.size()];
		int i=0;
		for (Class animal : animals)
		{
			classes[i++]=animal;
		}
	}

Averages of 100 rounds, 1000 iterations:

Just my wolf and the standard mobs:

class animals.Bear - 2.2600002
class animals.Lion - 41.21
class animals.Stone - 20.159998
class animals.HerjanWolf - 99.99 <-- kind of flawless

Small Wolfgroup:

class animals.Bear - 1.0700002
class animals.Lion - 31.29
class animals.Stone - 23.97
class animals.HerjanWolf - 99.44999 <-- Who's boss
class animals.AlphaWolf - 92.83001
class animals.OmegaWolf - 98.55

Big Wolfgroup:

class animals.Bear - 0.11
class animals.Lion - 0.0
class animals.Stone - 3.21
class animals.AlphaWolf - 82.96001
class animals.HerjanWolf - 74.56999 <-- My score really sucks here though
class animals.GatheringWolf - 57.6
class animals.OmegaWolf - 88.36 <-- This one wins every game on this scale -.- Awesome moogie!
class animals.ShadowWolf - 79.83001
class animals.MOSHPITFRENZYWolf - 5.9399986
class animals.WolfWithoutFear - 11.209999
class animals.MimicWolf - 0.7
class animals.LazyWolf - 73.68999
class animals.Sheep - 41.72
class animals.HonorWolf - 81.91999
class animals.CamperWolf - 70.85998
class animals.GamblerWolf - 34.02999

My Wolf:

package animals;

public class HerjanWolf extends Animal {
    
    private boolean lionTopLeft = false, lionTopLeftReady = false;
    private boolean lionRight = false, lionRightReady = false;
    private boolean lionBot = false, lionBotReady = false;
    private boolean lionDanger = false, careful = true, firstmove = true;
    private final int down = 1, right = 2, left = 3, up = 4;
    
    public HerjanWolf() {
        super('W');
    }
    
    public Attack fight(char c){
        switch (c) {
            case 'B':
                return Attack.SCISSORS;
            case 'L':
                return Attack.SCISSORS;
            case 'S':
                return Attack.PAPER;
            default:
                int rand = (int) (Math.random()*3);
                if(rand < 1)
                    return Attack.PAPER;
                else if(rand < 2)
                    return Attack.SCISSORS;
                else
                    return Attack.ROCK;
        } 
        
    }
    public Move move() { //surroundings[y][x]
        
        checkLions();
        
        if(firstmove){
            if(surroundings[2][0] == 'L')
                lionBotReady = true;
            if(surroundings[0][2] == 'L')
                lionRightReady = true;
            firstmove = false;
        }
        
        if(lionDanger || surroundings[1][0] == 'L' && lionTopLeftReady || surroundings[0][1] == 'L' && lionTopLeftReady){
            
            if (isSafe(1, 2) && surroundings[0][2] != 'W'){
               newMove(right);
               return Move.RIGHT;
            }else if (isSafe(2, 1)){
               newMove(down);
               return Move.DOWN;
            }else if (isSafe(0, 1)){
               newMove(up);
               return Move.UP;
            }else if (isSafe(1, 0)){
               newMove(left);
               return Move.LEFT;
            }else if(isSafe(1,2)){
               newMove(right);
               return Move.RIGHT;
            }
            
            newMove(left);
            return Move.LEFT;
        }
    
        return Move.HOLD;
    }
    
    boolean isSafe(int y, int x){
        if(y <= 1){
            if(x <= 1){
                if(surroundings[y][x] != 'W' && !lionTopLeft)
                    return true;
            }else if(surroundings[1][2] != 'W' && !lionRightReady)
                    return true;
        }else if(surroundings[2][1] != 'W' && !lionBotReady)
            return true;
        
        return false;
    }
    
    public void checkLions(){
        int y = 0, x = 0;

        if(lionTopLeft)
            lionTopLeftReady = true;
        else
            lionTopLeftReady = false;

        if(surroundings[y][x] == 'L')
            lionTopLeft = true;
        else
            lionTopLeft = false;

        if(lionRight)
            lionRightReady = true;
        else
            lionRightReady = false;

        if(surroundings[y][x+1] == 'L') // && !lionTopLeftReady
            lionRight = true;
        else
            lionRight = false;

        if(lionBot)
            lionBotReady = true;
        else
            lionBotReady = false;

        if(surroundings[y+1][x] == 'L' && !lionTopLeftReady)
            lionBot = true;
        else
            lionBot = false;
        
        if(careful){
            if(surroundings[y+1][x] == 'L'){
                lionDanger = true;
            }else if(surroundings[y][x+1] == 'L'){
                lionDanger = true;
            }
                    
            careful = false;
        }
    }
    
    public void newMove(int move){
        lionTopLeft = false;
        lionRight = false;
        lionBot = false;
        
        lionTopLeftReady = false;
        lionRightReady = false;
        lionBotReady = false;
        
        lionDanger = false;
        
        if(move == down){
            if(surroundings[1][0] == 'L')
                lionTopLeft = true;
            if(surroundings[2][0] == 'L')
                lionBot = true;
            
        }else if(move == right){
            if(surroundings[0][1] == 'L')
                lionTopLeft = true;
            if(surroundings[0][2] == 'L')
                lionRight = true;
            
        }else
            careful = true;
    }
}

Again thanks for telling me about this Pizza, it was fun!

EDIT:
At the main topic where my wolf is posted I updated my wolf a little bit so that it has an avg of 85+ in large groups.

Very nice! I dont suppose that you want do give a little explanation of how the wolf behaves?

Ofcourse I can explain.

Here is my lionproof strategy:

Check the topleft corner [0][0] so I know there is a lion coming next turn.
What I also do is check [1][0] so if there is a lion (if it was not in the topleft corner) I know it is going to [2][0] (down) and after that to [2][1] (right)
(and with the right side I do the same [0][1] to [0][2] to [1][2]).
So if the lion is going [2][1] my wolf will be sure  not to go down.

Had to put it in code because of this [0][1]

And that’s the main secret :stuck_out_tongue:
The wolf-dodging tactic is pretty standard though, so I don’t have a lot to say about that. (Just calculating dangers)

I see :slight_smile:

It does seem to be quite effective. well done.

I am trying my hand at a rather more complicated Wolf than what I currently produced. I am not sure whether it will give any benefits however :stuck_out_tongue:

Haha, I like the contest, but I dont think I can make a much better wolf. You can never dodge the moments that you move to the left and another wolf/lion jumps to the right.
The best-performing wolves are all super close so that confirms it, I think. I’m still waiting for the updated scoreboard with my wolf to pop up, and that new DeepWolf looks promising btw.

But I wish you lots of luck with the Omega successor!
I will see it soon enough on one of the forums, be sure to surprise me with your coming ImmortalInvincibleWolf :stuck_out_tongue:

This was funny, annoying that it required Java 8 for no reason. Made a wolf (StoneGuardianWolf) that aims to protect the Stones. Will maybe update it later to more aggressively protect them.

Made also a clunky javascript port for no real good reason - indefinitely available here: http://www.heartpirates.com/wildjs

wowie the author of the DeepWolf is in a league of their own!

Not sure that I can do much to beat it… but will try :stuck_out_tongue:

Oddly enough Deep has been averaging low 70’s in my tests. All those CPU cycles for nothing!

You should really fear Hybrid, it’s nearly unstoppable.