예제 #1
0
 def set_data(self, string):
     dt = string.split(" ")
     self.pos.x = float(dt[0])
     self.pos.y = float(dt[1])
     self.vel.x = float(dt[2])
     self.vel.y = float(dt[3])
     teta_vb = self.vel.teta(pos.Pos(0, 0))
     r_vb = self.vel.r()
     self.vel_p = pos.Polar(r_vb, teta_vb)
예제 #2
0
 def __init__(self):
     self.polar = pos.Polar(-100, 10)
     self.open_angle = 0
     self.goal_vector = pos.Polar(-100, 10)
예제 #3
0
 def pos_p(self, o):
     teta_b = self.pos.teta(o)
     r_b = self.pos.dist(o)
     return pos.Polar(r_b, teta_b)
예제 #4
0
 def __init__(self):
     self.pos = pos.Pos(-1000, -1000)
     self.vel = pos.Pos(-1000, -1000)
     self.vel_p = pos.Polar(-100, 10)
예제 #5
0
파일: logextractor.py 프로젝트: mroa4/LOGAI
def extractFeatur(log, player_types):
    os.chdir("../features")
    file_name = str(counter())
    new_log = open(file_name + ".rcb", "w")
    # write types in file
    for pt in player_types:
        new_log.write("pt " + str(pt.id) + " " + str(pt.kickAble_area) + "\n")
    lines = log.split("\n")

    last_kickAble_cycle = -10
    last_kickAble_unum = -1
    for line in lines:
        #Reading a cycle data
        if line.find("*") != -1:
            last_kickAble_unum = -1
            last_kickAble_cycle = -10
        if (line.find("R") == -1):
            continue
        details = line.split("|")
        cycle = int(details[1])
        ballobj = ball.Ball()
        ballobj.set_data(details[2])

        players = []
        for ply_str in details:
            if ply_str == '':
                continue
            if ply_str[0] != "r" and ply_str[0] != "l":
                continue
            playerobj = player.Player()
            playerobj.set_data(ply_str, player_types)
            players.append(playerobj)

        if not side(players, ballobj, "l"):
            if side(players, ballobj, "r"):
                last_kickAble_unum = -1
                last_kickAble_cycle = -10
            continue

        n = 0
        for i in range(len(players)):
            if players[i].is_kickAble(ballobj.pos) and players[i].side == "l":
                n = i
                break
        polars = []
        polars_n = []
        kicker = players[n]
        for plyr in players:
            teta = plyr.pos.teta(kicker.pos)
            r = plyr.pos.dist(kicker.pos)
            polar = pos.Polar(r, teta)
            polars.append(polar)
            next_pos = pos.plus(plyr.pos, plyr.vel)
            teta_n = next_pos.teta(kicker.pos)
            r_n = next_pos.dist(kicker.pos)
            polar_n = pos.Polar(r_n, teta_n)
            polars_n.append(polar_n)
        new_line = ""
        new_line += "R|" + str(cycle) + "|"
        #find polar pos and vel of ball
        teta_b = ballobj.pos.teta(kicker.pos)
        r_b = ballobj.pos.dist(kicker.pos)
        polar_b = pos.Polar(r_b, teta_b)
        next_ballpos = pos.Pos(ballobj.pos.x + ballobj.vel.x,
                               ballobj.pos.y + ballobj.vel.y)
        teta_vb = next_ballpos.teta(ballobj.pos)
        r_vb = ballobj.vel.r()
        polar_vb = pos.Polar(r_vb, teta_vb)
        new_line += str(polar_b.r) + " " + str(polar_b.teta) + " " + str(
            polar_vb.r) + " " + str(polar_vb.teta) + "|"
        for i_p in range(len(polars)):
            new_line += str(polars[i_p].r) + " " + str(polars[i_p].teta) + "|"
        #     new_line += str(polars_n[i_p].r) + " " + str(polars_n[i_p].teta) + "|"
        # for plyr in players:
        #     new_line += str(plyr.pos.x/52.5) + " " + str(plyr.pos.y/34) + "|"
        new_line += str(last_kickAble_unum) + " " + str(kicker.unum) + "|"
        if last_kickAble_unum != -1:
            new_log.write(new_line + "\n")
        last_kickAble_unum = kicker.unum
        # print("feature:",cycle)
    new_log.close()
    f_log = open(file_name + ".rcb", "r").read()
    new_log = open(file_name + ".rcb", "w")
    lines = f_log.split("\n")
    for i in range(len(lines) - 2):
        if lines[i].find("pt") != -1:
            continue
        line = lines[i].split("|")[:-1]
        next_line = lines[i + 1].split("|")[:-1]
        line[-1] = next_line[-1]
        newline = ""
        for w in line:
            newline += w + "|"
        new_log.write(newline + "\n")
    os.chdir("../samples")