King of the Torus!

5

King of the Torus!

Your job is to conquer the torus, but wait, there are multiple other players banded together in teams facing you! You will need to use your wit's to conquer the torus.

There are three teams: red, blue and green. Teams are self-assigned arbitrarily. If the teams are even you may join the team of your choice, otherwise you must join the smallest team(s). The map is a torus presented as a square of length 640 by 640. Lets take a look at a sample map

OOOOOOOOOOOOOOOOOOOOOOOOOOO
RRRRRRRRRRRRRRRRRRRRRRRRRRR
OOOOOOOOOOOOOOOOOOOOOOOOOOO
GGGGGOOOOOOOOBBBBBBBBBBBBBB
GGGGGGGGGGGGGGGGGGGGGOOOOOG
OOOOOOOOOOOOOOOOOOOOOOOOOGG
RRRRRRRRRRRRRRRRRRRRRRRRRRR
OOOOOOOOOOOOOOOOOOOOOOOOOOO

as you can see, the red team has built a wall to safely conquer the territory between the two walls. Blue, and green will have to fight it out. This scaled down version of the map is representative of the larger one.

Red would likely win this battle as they would finish the game (once the board is filled or a large number of turns have passed) with the most territory

Now each bot has a location (known only to you). You can only move to an adjacent square if it is owned by your team. At the start of your game, you start on a single square of your teams color. Your goal is to expand this splotch by conquering other land. At any turn you can choose to move to any adjacent color of your own territory or you may alternatively choose to attack an adjacent territory. If the attacked square is unowned it will be captured.

Java API

You will override the Bot class to return a single number (0-3) for attempted moves and 4-7 for an attempted attack. Your bot's should only take 10 milliseconds to move, but the rule will not be formally enforced unless it becomes a problem. Problematic, malicous, or otherwise obnoxious bots are clearly not in the spirit of this competition and will be disqualified with an immediate low quality flag. Otherwise bots acting in good faith, but otherwise buggy will be given time as needed for bug repairs. Method summary

public abstract class Bot{
public final int team;// 0 = red 1 = green 2 = blue
public Bot(int inTeam){team=inTeam}//be sure to call super(inTeam);
public int move(){};//you will override this
}

Methods available

Color Bot.getColor(int x,int y){}//returns a Color object with rgb values where the r g or b value of the team owning it will be 100.
getX(); returns the X position of your bot
getY(); returns the y position of your bot
Bot.getMap();//returns the array representing the map. I.e Bot.getMap[i][j] returns a color with r g b values representing each teams stake in that spot.
//only one r g b value will be greater than 0 as only one team can hold a spot
Do not abuse the map access. Giving direct access (as opposed to a copy) is to speed up access to the map. Abusing it will result in disqualification!

A wrapper program may be made available as long as it still allows the program to run smoothly.

How to play:

Step one: Post your bot here as an answer and ensure it follows the specs.
Step Two Head over to this gitHub repository fork it and add your bot's file in as well as add these two lines after '//init bots' Bot.run. Be sure to choose the team with the least members if applicable.

  bots.add(new UniqueBotNameHere(team=choiceOfTeam,x=getRandom(0,map.length),y=getRandom(0,map[0].length)));
    map[x][y].colors[team]=255;

Step Three: Make a pull request. I will accept your pull request and your bot will automagically be added to the tournament.
Step Four: Download the source files and copy them into the proper package. Run the build and enjoy watching the bots


Good luck and don't let your team down! Team's will be made even by my sample bots. I may also move around teams to ensure equal members.

Interesting trivia

Modifying the Half Hearted flood filling sample bot, gives an interesting map generator. Reminds of the Mediterranean sea!

Rohan Jhunjhunwala

Posted 2016-08-02T21:53:22.257

Reputation: 2 569

related – flawr – 2016-08-02T22:13:55.433

Answers

1

Waller

He builds a wall, but he can't make the other team pay for it! He makes a nice low level bot to help debug your submissions.

public class Trump extends Bot{
int moves;
int direction;
    public Trump(int team, int inX, int inY) {
        super(team, inX, inY);
direction = Bot.getRandom(0, 4);
    }

    @Override
    public int move() {
int ret = direction;
switch(++moves%4){
    case 0:
        ret = direction+4;
        break;
    case 1:
        ret = direction;
        break;
    case 2:
        ret = direction + 1;
        break;
    case 3:
        ret = direction +3;
}
return ret;
    }

}

Rohan Jhunjhunwala

Posted 2016-08-02T21:53:22.257

Reputation: 2 569

0

Half Hearted Flood Filler

Another low level bot. He tries to flood fill the map, but he only puts in 50% effort! I will enter another more competitve bot, but this guy is just to demonstrate one possible approach.

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package toroidal.domination;

import java.awt.Color;
import java.util.Stack;

/**
 *
 * @author rohan
 */
public class HalfHeartedFloodFillBot extends Bot{
    public static class Node{
        public final int x,y;
        public Node(int x, int y){
            this.x=x;this.y=y;
        }
    }
private Stack<Integer> nodes = new Stack<>();
    public HalfHeartedFloodFillBot(int team, int inX, int inY) {
        super(team, inX, inY);
    }



    @Override
    public int move() {
        int x,y;

        for(int i = 0;i<4;i++){
    if(isEmpty(Bot.getColorAtSpot(x=getX()+(int) Math.cos(i*Math.PI/2),y= getY()+(int) Math.sin(i*Math.PI/2)))){
        nodes.add((i+2)%4);
        return i+4;
    }
}
        //no empty spots found try to backtrack or just do stuff!
return nodes.isEmpty()?Bot.getRandom(0,2)==0?Bot.getRandom(0, 2)==0?0:1:Bot.getRandom(0, 2)==0?2:3:nodes.pop();
    }
    boolean isEmpty(Color c){
        int r = c.getRed();
        int g = c.getGreen();
        int b = c.getBlue();
        return r == 0 && b == 0&& g == 0;
    }
}

Rohan Jhunjhunwala

Posted 2016-08-02T21:53:22.257

Reputation: 2 569

0

SpiralBot

This bot will go until he hits something that is not neutral, then will turn left, making a spiral in the free space.

public class SpiralBot extends Bot{
    int d;

        public SpiralBot (int team, int inX, int inY) {
            super(team, inX, inY);
        d = 0;
        }

    int dx(int move){
        return (int) Math.cos(move * Math.PI / 2);
    }
    int dy(int move){
        return (int) Math.sin(move * Math.PI / 2);
    }

        @Override
        public int move() {
        int x = getX();
        int y = getY();
        Color[]c = new Color[4];
        for(int i = 0;i<4;i++)
            c[i] = Bot.getColor(x+dx(i), y+dy(i));
        if(c[d].equals(Color.black))
            return d;
        if(c[(d+1)%4].equals(Color.black))
            return d = (d+1)%4;
        if(c[(d+3)%4].equals(Color.black))
            return d = (d+3)%4;
        return d + 2;
    }

}

I have no account on GitHub, so if someone could push this for me that would be good. Thank you.

MegaTom

Posted 2016-08-02T21:53:22.257

Reputation: 3 787

d i s not defined – Rohan Jhunjhunwala – 2016-08-10T21:09:29.603

@rohan fixed in an edit. I had an old version of the code. – MegaTom – 2016-08-10T23:07:26.097

Still seems to not work, as the issue is that you must attack a square before moving to it. – Rohan Jhunjhunwala – 2016-08-11T01:04:23.503