Beispiel #1
0
def main():
    map_data = ''
    while(True):
        current_line = raw_input()
        if len(current_line) >= 2 and current_line.startswith("go"):
            pw = PlanetWars(map_data)
            do_turn(pw)
            pw.finish_turn()
            map_data = ''
        else:
            map_data += current_line + '\n'
def main():
    map_data = ''
    while True:
        current_line = input()
        if len(current_line) >= 2 and current_line.startswith("go"):
            pw = PlanetWars(map_data)
            DoTurn(pw)
            pw.FinishTurn()
            map_data = ''
        else:
            map_data += current_line + '\n'
Beispiel #3
0
def main():
    A = ''
    D = '{{{{},dns,{}},invs,{{{{{{},tms,{}},MCp,{{},pdie,{}}},invd,{{{},tms,{}},MCp,{{},pdie,{}}}},times,{{{{},nsim,{}},times,{{{},enshd,{}},MCp,{{{},pdin,{}},MCp,{{},pdie,{}}}}},min,{{{},nsim,{}},Pof,{{{{{},tms,{}},MCp,{{{},pdie,{}},MCp,{{},pdie,{}}}},invd,{{{},tms,{}},max,{{{},pdie,{}},invd,{{},pdie,{}}}}},max,{{{{},tms,{}},MCp,{{{},pdie,{}},MCp,{{},pdie,{}}}},invd,{{{},tms,{}},max,{{{},pdie,{}},invd,{{},pdie,{}}}}}}}}},MCp,{{{{{},tms,{}},MCp,{{},tms,{}}},invd,{{{{},tms,{}},max,{{},dsd,{}}},MCp,{{},pdie,{}}}},times,{{{{},nsim,{}},times,{{{},nsim,{}},times,{{{},enshd,{}},MCp,{{{},pdin,{}},MCp,{{},pdie,{}}}}}},min,{{{},nsim,{}},Pof,{{{{{},dns,{}},invs,{{{{},tms,{}},invd,{{{},tms,{}},MCp,{{{},pdie,{}},invd,{{},pdie,{}}}}},times,{{{{},nsim,{}},times,{{{{},nsim,{}},MCp,{{},gd,{}}},times,{{{{},enshd,{}},nega,{{},enshd,{}}},div,{{{},pdin,{}},MCp,{{},enshd,{}}}}}},min,{{{},nsim,{}},Pof,{{{{},nsim,{}},nega,{{{{{{{},nsim,{}},MCp,{{},gd,{}}},times,{{{},nsim,{}},MCp,{{},gd,{}}}},invd,{{{{},nsim,{}},gt,{{},nsim,{}}},invd,{{{},tms,{}},max,{{{},tms,{}},MCp,{{},nsim,{}}}}}},gt,{{},nep,{}}},gt,{{{{{{},nsim,{}},MCp,{{},gd,{}}},times,{{{},nsim,{}},MCp,{{},gd,{}}}},invd,{{{{{{},nsim,{}},lt,{{},pdie,{}}},gt,{{},nsim,{}}},invd,{{{},tms,{}},max,{{{},tms,{}},MCp,{{},nsim,{}}}}},div,{{{{{},nsim,{}},lt,{{},pdie,{}}},gt,{{},nsim,{}}},invd,{{{},tms,{}},max,{{{},tms,{}},MCp,{{{{},nsim,{}},MCp,{{},enshd,{}}},invd,{{{{},nsim,{}},times,{{{},enshd,{}},MCp,{{{},pdin,{}},MCp,{{},pdie,{}}}}},invd,{{{},tms,{}},max,{{{},pdie,{}},invd,{{},pdie,{}}}}}}}}}}},gt,{{},nep,{}}}}},min,{{{{{},nsim,{}},MCp,{{},enshd,{}}},invd,{{{{},nsim,{}},times,{{{},enshd,{}},MCp,{{{},pdin,{}},MCp,{{},pdie,{}}}}},invd,{{{},tms,{}},max,{{{},pdie,{}},invd,{{},pdie,{}}}}}},lt,{{},nep,{}}}}}}}},lt,{{},nep,{}}},min,{{{},amg,{}},Pof,{{},nep,{}}}}}}}}},times,{{{},gd,{}},div,{{},dsd,{}}}}'
    E = DTGT(D)
    while True:
        B = input()
        if len(B) >= 2 and B.startswith('go'):
            C = PlanetWars(A)
            DTu(C, E)
            C.FinishTurn()
            A = ''
        else:
            A += B + '\n'
Beispiel #4
0
def main():
    debug("starting")
    map_data = ''
    while (True):
        current_line = raw_input()
        if len(current_line) >= 2 and current_line.startswith("go"):
            pw = PlanetWars(map_data)
            debug("NEW TURN")
            DoTurn(pw)
            pw.FinishTurn()
            debug("TURN FINISHED")
            map_data = ''
        else:
            map_data += current_line + '\n'
Beispiel #5
0
def main():
    Alpha = float(sys.argv[1])
    Gamma = float(sys.argv[2])
    DatabaseLocation = sys.argv[3]

    map_data = ''
    TurnNumber = 0
    while (True):
        current_line = raw_input()
        if len(current_line) >= 2 and current_line.startswith("go"):
            pw = PlanetWars(map_data)
            TurnNumber = DoTurn(pw, TurnNumber, Alpha, Gamma, DatabaseLocation)
            pw.FinishTurn()
            map_data = ''
        else:
            map_data += current_line + '\n'
Beispiel #6
0
def main():
    global MAX_TURNS
    map_data = ''
    log('*' * 30)
    turn = 0
    while True:
        current_line = stdin.readline()
        if len(current_line) >= 2 and current_line.startswith("go"):
            log('Turn %d ' % turn + '=' * 30 + 'Turn %d' % turn)
            pw = PlanetWars()
            pw.parse_game_state(map_data)
            if MAX_TURNS is None:
                for p, q in product(pw.planets, repeat=2):
                    d = pw.distance(p, q)
                    if d > MAX_TURNS:
                        MAX_TURNS = d
            if MAX_TURNS > 10:
                MAX_TURNS = 10
                log("predicting %s turns in the future" % MAX_TURNS)
            do_turn(pw)
            pw.finish()
            map_data = ''
            turn += 1
        else:
            map_data += current_line
Beispiel #7
0
def main():
    map_data = ""
    while True:
        current_line = raw_input()
        if len(current_line) >= 2 and current_line.startswith("go"):
            pw = PlanetWars(map_data)
            turn(pw)
            map_data = ""
        else:
            map_data += current_line + "\n"
Beispiel #8
0
def main():
    f = open('MyBot2.log', 'w')
    group_ids = []
    if '-g' in sys.argv:
        group_ids = [int(k) for k in sys.argv[2].split(',')]
    f.write('group: ' + str(group_ids) + '\n')

    map_data = ''
    while (True):
        current_line = raw_input()
        f.write(current_line + '\n')
        if len(current_line) >= 2 and current_line.startswith("go"):
            pw = PlanetWars(map_data)
            f.write('--------------- NEW TURN ----------------------------\n')
            DoTurn(pw, group_ids, f)
            f.write('-----------------------------------------------------\n')
            pw.FinishTurn()
            map_data = ''
        else:
            map_data += current_line + '\n'
Beispiel #9
0
def main():
    global theta
    abs_path = os.path.dirname(os.path.abspath(__file__))
    print "cwd:", os.path.dirname(os.path.abspath(__file__))
    print "\r\n\r\n"
    with open(os.path.join(abs_path, "theta.txt")) as f:
        line = f.readline().split(" ")
        theta = map(lambda x: float(x), line)
    #endwith
    debug("starting")
    map_data = ''
    while True:
        current_line = raw_input()
        if len(current_line) >= 2 and current_line.startswith("go"):
            pw = PlanetWars(map_data)
            DoTurn(pw)
            pw.FinishTurn()
            map_data = ''
        else:
            map_data += current_line + '\n'
Beispiel #10
0
def main():
  f = open('MyBot3.log', 'w')
  nickname = 'X'
  if '-g' in sys.argv:
    group_ids = [int(k) for k in sys.argv[2].split(',')]
  if '-n' in sys.argv:
    nickname = str(sys.argv[4])
  f.write('group: ' + str(group_ids) + '\n')
  f.write('nick: ' + str(nickname) + '\n')

  map_data = ''
  while(True):
    current_line = raw_input()
    f.write(current_line + '\n')
    if len(current_line) >= 1 and current_line.startswith("."):
      pw = PlanetWars(map_data)
      DoTurn(pw, group_ids, nickname)
      pw.FinishTurn()
      map_data = ''
    else:
      map_data += current_line + '\n'
Beispiel #11
0
def main():
    map_data = ''
    turn = 0

    try:
        while(True):
            current_line = input()
            #debug("-> %s" % current_line, 'server')
            if len(current_line) >= 2 and current_line.startswith("go"):
                debugger.debug("# %d" % turn)
                pw = PlanetWars(map_data)
                DoTurn(pw)
                #debug("Answer is sent.", 'server')
                pw.FinishTurn()
                turn += 1
                map_data = ''
            else:
                map_data += current_line + '\n'
    except Exception as e:
        debugger.debug(e, "error")
    debugger.debug("The End!")
Beispiel #12
0
def main():
  global MAX_TURNS
  map_data = ''
  log('*'*30)
  turn=0
  while True:
    current_line = stdin.readline()
    if len(current_line) >= 2 and current_line.startswith("go"):
      log('Turn %d '%turn+'='*30+'Turn %d'%turn)
      pw = PlanetWars()
      pw.parse_game_state(map_data)
      if MAX_TURNS is None:
        for p,q in product(pw.planets,repeat=2):
          d=pw.distance(p,q)
          if d>MAX_TURNS:
            MAX_TURNS=d
      if MAX_TURNS>10:
        MAX_TURNS=10
        log("predicting %s turns in the future"%MAX_TURNS)
      do_turn(pw)
      pw.finish()
      map_data = ''
      turn+=1
    else:
      map_data += current_line
Beispiel #13
0
def main():
    import sys
    global theta

    if len(sys.argv) >= NUMBER_OF_FEATURES:
        debug("theta from commandline args")
        theta = sys.argv[1:]
        new_list = []
        for element in theta:
            new_list.append([float(element)])
        theta = new_list
    else:
        debug("random theta")
        # theta = [1.07668319, -4.67252562, -4.83999886, -3.78736198, -2.50656436, 3.8234228, 0.2380]
        theta = [
            0.25499724, -0.03653183, -0.04419227, -0.34623976, 0.67157856,
            0.39569266, 0.05, 0.27693781, 0.5
        ]
    # endif

    debug("starting for theta: {0}".format(str(theta)))

    # with open("results.txt", "a+") as f:
    #     for i in range(NUMBER_OF_FEATURES):
    #         elem = theta[i][0]
    #         f.write("{0} ".format(elem))

    map_data = ''
    while True:
        current_line = raw_input()
        if len(current_line) >= 2 and current_line.startswith("go"):
            pw = PlanetWars(map_data)
            DoTurn(pw)
            pw.FinishTurn()
            map_data = ''
        else:
            map_data += current_line + '\n'
Beispiel #14
0
def main():

    # Uncomment below for debugging
    """
    sys.stdout = os.fdopen(sys.stdout.fileno(), "w", 0)  # Unbuffer stdout

    tee = sub.Popen(["tee", "log2.txt"], stdin=sub.PIPE)
    os.dup2(tee.stdin.fileno(), sys.stdout.fileno())
    os.dup2(tee.stdin.fileno(), sys.stderr.fileno())
    """

    map_data = ""
    while True:
        current_line = raw_input()
        if len(current_line) >= 2 and current_line.startswith("go"):
            pw = PlanetWars(map_data)
            turn(pw)
            map_data = ""
        else:
            map_data += current_line + "\n"
Beispiel #15
0
def batch_run(bots, maps, log_path, start_id=1, end_id=None):
    '''
    Takes a list of bot_specs (see below) and performs a pairwise comparison of 
    each on each of the given maps. Logs out to log_path, starting
    at experiment start_id and stopping at end_id, if specified.
    
    Note, this method prints to std_out, so that you have some idea of its 
    progress.
    
    bot_spec is a dict of:
        'type': bot class
        'params': dict of parameter names and values that will be used to
                  instantiate the bot for each game.
    '''
    game_id = 1
    log = Logger(log_path)
    if end_id is None:
        end_id = len(maps) * len(bots) * ((len(bots) - 1) / 2.)
    if end_id < start_id:
        raise ValueError(
            "start_id must be less than the total number of experiments! (s: %d, e: %d)"
            % (start_id, end_id))
    print "Starting batch. Running games %d to %d." % (start_id, end_id)
    for m in range(len(maps)):
        map_id = PlanetWarsProxy(maps[m])._gameid
        for i in range(len(bots)):
            for j in range(i + 1, len(bots)):
                if game_id >= start_id and game_id <= end_id:
                    bot1 = bots[i]()
                    bot2 = bots[j]()
                    status_str = "Starting game %d, %s vs %s on map %d" % (
                        game_id, bot1, bot2, map_id)
                    log.result(status_str)
                    print status_str
                    Game.do_game(game_id, log, bot1, bot2, PlanetWars(maps[m]))

                    log.flush()
                if game_id > end_id:
                    return
                game_id += 1
Beispiel #16
0
def main():
    group_ids = []
    nickname = 'X'
    mz_map_edit = False
    my_id = -1
    if '-g' in sys.argv:
        group_ids = [int(k) for k in sys.argv[2].split(',')]
    if '-n' in sys.argv:
        nickname = str(sys.argv[4])
    if '-mz' in sys.argv:
        mz_map_edit = True
    f = open('MyBot4_' + str(nickname) + '.log', 'w')
    f.write('group: ' + str(group_ids) + '\n')
    f.write('nick: ' + str(nickname) + '\n')

    map_data = ''
    while (True):
        current_line = raw_input()
        f.write(current_line + '\n')
        if len(current_line) >= 1 and current_line.startswith("."):

            if mz_map_edit:
                tmp_map = ''
                lines = map_data.split("\n")
                if my_id < 0:
                    for line in lines:
                        line = line.split("#")[0]
                        tokens = line.split(" ")
                        if tokens[0] == "Y":
                            if len(tokens) == 2:
                                my_id = int(tokens[1])
                                f.write('my_id: ' + str(my_id) + '\n')
                for line in lines:
                    line = line.split("#")[0]  # remove comments
                    tokens = line.split(" ")
                    if tokens[0] == "P":
                        if len(tokens) == 7:
                            new_line = line
                            if int(tokens[5]) == my_id:
                                # stdout.write('1-- ' + "\n")
                                new_line = "P " + str(tokens[1]) + " " + str(
                                    float(tokens[2])) + " " + str(
                                        float(tokens[3])) + " " + str(
                                            int(tokens[4])) + " " + str(
                                                1) + " " + str(int(tokens[6]))
                                new_line = new_line.replace(".0 ", " ")
                            elif int(tokens[5]) == 1:
                                # stdout.write('2-- ' + "\n")
                                new_line = "P " + str(tokens[1]) + " " + str(
                                    float(tokens[2])) + " " + str(
                                        float(tokens[3])) + " " + str(
                                            int(tokens[4])) + " " + str(
                                                my_id) + " " + str(
                                                    int(tokens[6]))
                                new_line = new_line.replace(".0 ", " ")
                        tmp_map += new_line + '\n'
                    else:
                        tmp_map += line + '\n'
                # stdout.write(str(tmp_map)+ "\n")
                map_data = tmp_map

            pw = PlanetWars(map_data)
            f.write('-------------- NEW TURN ----------------\n')
            DoTurn(pw, group_ids, nickname, f)
            f.write('----------------------------------------\n')
            pw.FinishTurn()
            map_data = ''
        else:
            map_data += current_line + '\n'