6
\$\begingroup\$

Topping the Charts

You are a record label company. Your goal is to get 4 of your signed bands in the top 4 positions in the charts. However, its recently been noted that bands currently in the charts influence who is going to be in the charts the next day.

In this challenge, each player will control 5 bands (instances of your code), each of them placed in alternating order in one of the 11 spots of the scoreboard, with the 11th spot open. Each band will have a unique, hidden ID (from 0-9), and a unique, visible name (a randomly generated integer).

Each turn, the band with the open spot below them in the charts will call an ID. The bot instance with that ID will move to that spot, creating a new open spot. If spot #1 is open, then the 11th bot will be the one to name an ID.

The game is over when spots 1-4 are all held by your bands, giving you 3 points. If a particular band ordering is created more than 3 times, then both labels will tie and be given 1 point. The player with the most points after facing each other player twice (to ensure both labels start with a band in the #1 position) wins.

I/O

Bots will be stay alive between turns. Information will be passed back and forth via STDIO. When multiple pieces of information is passed, it will be comma separated. Each instance of your bot MUST NOT communicate with each other (nor with the other team).

At the beginning of the game, your will be passed three integers, your ID, position, and name, and then you will be passed a list of names of the current positions, with 0 being the open position.

On your turn, you will be passed a list of names of the current positions, with 0 being the open position. You must return the ID you wish to place in the spot below you.

If you get switched, you will be be passed two integers, the name of the person that switched you, and your new position (from 0-10).

If you win, you will be passed 0, at which, you must end your program

The controller can be found here: https://github.com/nathanmerrill/ScoreboardKoTH

\$\endgroup\$
4
  • \$\begingroup\$ I should return an ID, but only know mine and the names of the other bands... That doesn't make sense to me, as I can't say Move bot on position 3 to the empty spot, since I don't know his ID. \$\endgroup\$ Commented Mar 4, 2015 at 15:12
  • \$\begingroup\$ @Manu You can figure out the IDs by trial. \$\endgroup\$ Commented Mar 4, 2015 at 17:21
  • \$\begingroup\$ How? If I swap a band to the empty spot, I don't get notified which one moved. \$\endgroup\$ Commented Mar 4, 2015 at 17:56
  • \$\begingroup\$ But every time you see the state of the chairs. On the turn after you moved somebody, you get to see who was different than last time. \$\endgroup\$ Commented Mar 4, 2015 at 21:34

3 Answers 3

2
\$\begingroup\$

Random Bot

If you couldn't guess, this bot picks a number randomly. Run with python random_bot.py

import sys
import random


def get_data():
    data = sys.stdin.readline().strip()
    if data == "0":
        exit()
    return [int(x) for x in data.split(",")]


def startup():
    global _id, position, name
    all_data = get_data()
    player_names = all_data[3:]
    _id, position, name = all_data[:3]


def switched(switcher, new_position):
    global position
    position = new_position


def call_id(player_names):
    return random.randrange(10)

_id = -1
position = -1
name = -1
startup()
while True:
    data = get_data()
    if len(data) == 1:
        break
    elif len(data) == 2:
        switched(*data)
    else:
        print str(call_id(player_names=data))
        sys.stdout.flush()
\$\endgroup\$
2
\$\begingroup\$

Self Mover Bot

This bot always moves itself. Run with:

javac SelfMover.java
java SelfMover

Code:

import java.util.Scanner;

public class SelfMover {

    private Scanner stdIn;
    private final int id, name;
    private int position;
    
    public static void main(String[] args) {
        new SelfMover();
    }

    public SelfMover() {
        stdIn = new Scanner(System.in);
        Integer[] data = getData();
        id = data[0];
        position = data[1];
        name = data[2];
        mainLoop();
    }
    private void mainLoop() {
        while(true){
            Integer[] data = getData();
            if (data.length == 1){
                return;
            } else if (data.length == 2){
                switched(data[0], data[1]);
            } else {
                System.out.println(callID(data));
            }        
        }
    }
    private Integer[] getData(){
        String data = stdIn.nextLine().trim();
        if (data.equals("0")){
            System.exit(0);
        }
        String[] strData = data.split(",");
        Integer[] intData = new Integer[strData.length];
        for (int i = 0; i < strData.length; i++){
            intData[i] = Integer.parseInt(strData[i]);
        }
        return intData;
    }
    private void switched(int switcher, int newPosition){
        position = newPosition;
    }
    private int callID(Integer[] players){
        return id;
    }
        
}
\$\endgroup\$
1
\$\begingroup\$

Unswitcher bot

This bot mistakenly assumes that its new position is the ID of the bot that switched it, and tries to unswitch.

Run with python unswitcher_bot.py

import sys

last_switched = -1


def get_data():
    data = sys.stdin.readline().strip()
    if data == "0":
        exit()
    return [int(x) for x in data.split(",")]


def startup():
    global _id, position, name
    try:
        all_data = get_data()
    except:
        raise NameError
    player_names = all_data[3:]
    _id, position, name = all_data[:3]


def switched(switcher, new_position):
    global position, last_switched
    position = new_position
    last_switched = switcher


def call_id(player_names):
    return min(position, 9)

_id = -1
position = -1
name = -1
startup()
while True:
    data = get_data()
    if len(data) == 1:
        break
    elif len(data) == 2:
        switched(*data)
    else:
        print call_id(player_names=data)
        sys.stdout.flush()
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.