コード例 #1
0
 def test(self):
     self.assertEqual(
         points([
             '1:0', '2:0', '3:0', '4:0', '2:1', '3:1', '4:1', '3:2', '4:2',
             '4:3'
         ]), 30)
     self.assertEqual(
         points([
             '1:1', '2:2', '3:3', '4:4', '2:2', '3:3', '4:4', '3:3', '4:4',
             '4:4'
         ]), 10)
     self.assertEqual(
         points([
             '0:1', '0:2', '0:3', '0:4', '1:2', '1:3', '1:4', '2:3', '2:4',
             '3:4'
         ]), 0)
     self.assertEqual(
         points([
             '1:0', '2:0', '3:0', '4:0', '2:1', '1:3', '1:4', '2:3', '2:4',
             '3:4'
         ]), 15)
     self.assertEqual(
         points([
             '1:0', '2:0', '3:0', '4:4', '2:2', '3:3', '1:4', '2:3', '2:4',
             '3:4'
         ]), 12)
コード例 #2
0
def createRosters(canvas):
    indexLeft, indexRight, size = 25, 75, 60
    if canvas.data.scoreSettings == "Points":
        points(canvas.data.hitterList, canvas.data.hitterStats,
               canvas.data.hitterPointList, canvas.data.hitter,
               canvas.data.pointSettings)
        points(canvas.data.pitcherList, canvas.data.pitcherStats,
               canvas.data.pitcherPointList, canvas.data.pitcher,
               canvas.data.pointSettings)
        #Creates the point list if the user has chosen the pointSettings
        canvas.data.hitterPointList = canvas.data.hitterPointList[::-1]
        canvas.data.pitcherPointList = canvas.data.pitcherPointList[::-1]
        #So that it is sorted from high to low instead of low to high
    else:
        temp_settings = []
        for j in xrange(len(canvas.data.rotisserieSettings)):
            temp_settings += [[
                copy.deepcopy(canvas.data.rotisserieSettings[j]), 0
            ]]
        for i in xrange(canvas.data.numberOfTeams):
            canvas.data.projectedStats += [copy.deepcopy(temp_settings)]
        #Make a list with the stats for each team
    for i in xrange(2 * canvas.data.numberOfTeams + 2):
        canvas.data.first_x_indexes += [[
            indexLeft + size * i, indexRight + size * i
        ]]
    #Creates a list of the x-indexes used to see if a team's roster has been selected to display
    for i in xrange(canvas.data.numberOfTeams):
        canvas.data.allTeams += [copy.deepcopy(canvas.data.autoDraftedTeam)]
    #Creates a list of the rosters of each team
    createPickOrder(canvas)
コード例 #3
0
ファイル: test_points.py プロジェクト: valentk777/codewars
def test_points():
    assert points(
        ['1:0', '2:0', '3:0', '4:0', '2:1', '3:1', '4:1', '3:2', '4:2',
         '4:3']) == 30
    assert points(
        ['1:1', '2:2', '3:3', '4:4', '2:2', '3:3', '4:4', '3:3', '4:4',
         '4:4']) == 10
    assert points(
        ['0:1', '0:2', '0:3', '0:4', '1:2', '1:3', '1:4', '2:3', '2:4',
         '3:4']) == 0
    assert points(
        ['1:0', '2:0', '3:0', '4:0', '2:1', '1:3', '1:4', '2:3', '2:4',
         '3:4']) == 15
    assert points(
        ['1:0', '2:0', '3:0', '4:4', '2:2', '3:3', '1:4', '2:3', '2:4',
         '3:4']) == 12
コード例 #4
0
ファイル: generate_data.py プロジェクト: atkaiser/future_rank
def main(args):
    """
    Gets all the information for the current rankings and tournament and then
    prints them in the correct format to be used in javascript.

    Example run:
        python generate_data.py -n 300 "Brisbane" "ATP 250" > ../static/data.js
    """
    tournament = args.tournament
    points_list = points(args.type)
    if not points_list:
        print("Not a valid tournament type")
        return
    matches, seeds, results = draw(tournament)
    if args.num_rankings:
        num_rankings = args.num_rankings
    else:
        num_rankings = 300
    current_rankings = get_current_rankings(num_rankings)
    new_rankings = subtract_tournament(current_rankings, tournament)
    seeds = extend_seeds(matches, seeds, current_rankings)
    print_players(matches)
    print_seeds(seeds)
    print_new_rankings(new_rankings)
    print_old_rankings(current_rankings)
    print_results(results)
    print_points([str(p) for p in points_list])
    print("var tournament = '{}';".format(tournament))
コード例 #5
0
def main():
    # тикер отрисовки кадров
    clock = pygame.time.Clock()
    # настройки окна
    pygame.display.set_caption(c.GAME_NAME)

    # игровое меню
    intro_font = pygame.font.Font(None, 72)
    a.game_intro(intro_font)

    BG = a.load_image("bg.jpg")

    # очки
    points_font = pygame.font.Font(None, 36)
    point = po.points(points_font)
    # игровой персонаж
    health_font = pygame.font.Font(None, 72)
    man = p.player((800 - 130) / 2, 375, 70, 70, health_font)
    # враги
    viruses = pygame.sprite.Group()
    viruses.add(e.enemy(900, 390, 150, 150, viruses))

    # основной цикл
    while c.runing:

        clock.tick(c.FPS)

        for i in pygame.event.get():
            if i.type == pygame.QUIT:
                runing = False
                break

        # враги
        for virus in viruses:
            virus.move()
            point.up(virus.get_points())

        # столкновение
        if pygame.sprite.spritecollide(man, viruses, False):
            man.wound()

        # управление
        keys = pygame.key.get_pressed()

        if keys[pygame.K_ESCAPE]:
            c.runing = False
            break

        # анализ движения
        man.move(keys)

        # прыжки
        man.jump(keys)

        a.re_draw_window(BG, man, point, viruses)

        # если перса убили, конец игры
        man.kill(intro_font, point, viruses)
コード例 #6
0
 def create_history_template(self, history):
   ''' Actually this template is used to calculate the bonus and that's all'''
   #print 'Explosed bubbles :' 
   #print self.history.xbubbles
   temp = history.create_template(self.height, self.width)
   n = len(history.xbubbles)
   print temp
   #print 'NNumber of explosed bubbles : %d' % n
   self.p = points(n)
   self.p.bonuses(temp, n)
   self.score += self.p.pt
コード例 #7
0
    def test_rand(self):
        from random import randint
        sol = lambda games: sum(3 if i[0] > i[2] else 1 if i[0] == i[2] else 0
                                for i in games)

        for _ in range(50):
            games = [
                str(randint(0, 4)) + ':' + str(randint(0, 4))
                for i in range(10)
            ]
            self.assertEqual(points(games[:]), sol(games),
                             "It should work for random inputs too")
コード例 #8
0
ファイル: finalProject.py プロジェクト: nogarithm/Projects
def createRosters(canvas):
    indexLeft,indexRight,size = 25,75,60
    if canvas.data.scoreSettings == "Points":
        points(canvas.data.hitterList,canvas.data.hitterStats,canvas.data.hitterPointList,canvas.data.hitter,canvas.data.pointSettings)
        points(canvas.data.pitcherList,canvas.data.pitcherStats,canvas.data.pitcherPointList,canvas.data.pitcher,canvas.data.pointSettings)
        #Creates the point list if the user has chosen the pointSettings
        canvas.data.hitterPointList = canvas.data.hitterPointList[::-1]
        canvas.data.pitcherPointList = canvas.data.pitcherPointList[::-1]
        #So that it is sorted from high to low instead of low to high
    else:
        temp_settings = []
        for j in xrange(len(canvas.data.rotisserieSettings)):
            temp_settings += [[copy.deepcopy(canvas.data.rotisserieSettings[j]),0]]
        for i in xrange(canvas.data.numberOfTeams):
            canvas.data.projectedStats += [copy.deepcopy(temp_settings)]
        #Make a list with the stats for each team
    for i in xrange(2*canvas.data.numberOfTeams+2):
        canvas.data.first_x_indexes += [[indexLeft+size*i,indexRight+size*i]]
    #Creates a list of the x-indexes used to see if a team's roster has been selected to display
    for i in xrange(canvas.data.numberOfTeams):
        canvas.data.allTeams += [copy.deepcopy(canvas.data.autoDraftedTeam)]
    #Creates a list of the rosters of each team
    createPickOrder(canvas)
コード例 #9
0
ファイル: ballistics.py プロジェクト: bradrisse/pyBallistics
def solve(drag_function, drag_coefficient, vi, sight_height, shooting_angle, zero_angle, wind_speed, wind_angle):

    t = 0
    dt = 0
    v = 0
    vx = 0
    vx1 = 0
    vy = 0
    vy1 = 0
    dv = 0
    dvx = 0
    dvy = 0
    x = 0
    y = 0

    hwind = windage.headwind(wind_speed, wind_angle)
    cwind = windage.crosswind(wind_speed, wind_angle)

    gy = constants.GRAVITY * \
        math.cos(angles.deg_to_rad((shooting_angle + zero_angle)))

    gx = constants.GRAVITY * \
        math.sin(angles.deg_to_rad((shooting_angle + zero_angle)))

    vx = vi * math.cos(angles.deg_to_rad(zero_angle))
    vy = vi * math.sin(angles.deg_to_rad(zero_angle))

    # y is in feet
    y = -sight_height/12

    n = 0

    hold_overs = points()

    while True:
        vx1 = vx
        vy1 = vy
        v = math.pow(math.pow(vx, 2)+math.pow(vy, 2), 0.5)
        dt = 0.5/v

        # Compute acceleration using the drag function retardation
        dv = drag.retard(drag_function, drag_coefficient, v+hwind)
        dvx = -(vx/v)*dv
        dvy = -(vy/v)*dv

        # Compute velocity, including the resolved gravity vectors.
        vx = vx + dt*dvx + dt*gx
        vy = vy + dt*dvy + dt*gy

        if x/3 >= n:

            if x > 0:
                range_yards = round(x/3)
                print("range_yards {}".format(range_yards))
                # if range_yards == 400:
                moa_correction = -angles.rad_to_moa(math.atan(y / x))
                print("moa_correction {}". format(moa_correction))
                path_inches = y*12
                print("path_inches {}". format(path_inches))
                impact_in = utils.moaToInch(moa_correction, x)
                seconds = t+dt
                print("seconds {}". format(seconds))
                hold_overs.add_point(
                    holdover(range_yards, moa_correction, impact_in, path_inches, seconds))

            n = n + 1

        # Compute position based on average velocity.
        x = x + dt * (vx+vx1)/2
        y = y + dt * (vy+vy1)/2

        if (math.fabs(vy) > math.fabs(3*vx) or n >= constants.BALLISTICS_COMPUTATION_MAX_YARDS):
            break

        t = t + dt

    return hold_overs
コード例 #10
0
ファイル: gun.py プロジェクト: VarlamovAM/python.labi
            if t2.live and b.hittest(t2):
                t2.live = 0
                t2.hit(canv)
                points.hit(canv)
            if t1.live == 0 and t2.live == 0:
                canv.itemconfig(screen1,
                                text='Вы уничтожили цели за ' + str(bullet) +
                                ' выстрелов')
                canv.bind('<Button-1>', '')
                canv.bind('<ButtonRelease-1>', '')
            b.time_live(canv, balls)
        canv.update()
        time.sleep(0.03)
        g1.targetting()
        g1.power_up()
    canv.itemconfig(screen1, text='')
    canv.delete(gun)
    root.after(750, new_game)


t1 = target.target(canv)
t2 = target.target(canv)
screen1 = canv.create_text(400, 300, text='', font='28')
g1 = gun()
bullet = 0
balls = []
points = points.points(canv)

new_game(canv)

tk.mainloop()
コード例 #11
0
import numpy as np
import points

n = 200

# get a grid
v = np.linspace(-1, 1, n)
x, y = np.meshgrid(v, v, indexing='ij')

# get a boundary
theta = np.linspace(0, 2 * np.pi, n, endpoint=False)
bx = 0.5 * np.cos(theta)
by = 0.5 * np.sin(theta)

pg = points.points(x, y)
pb = points.points(bx, by)

close_pg1 = pb.near_points_slow(pg, 0.02)
close_pg2 = pb.near_points(pg, 0.02)


# test whether the fast and slow give the same result
def test_fast_and_slow_same():
    assert np.allclose(close_pg1, close_pg2)
コード例 #12
0
from points import points
File = open('submissionstally.txt')
allData = File.readlines()
maxscore = 0
indexOfMaxScore = None
i = 0
while (i < len(allData)):
    score = 0
    if len(allData[i]) == 2:
        rows = int(allData[i][0])
        j = i + 1
        while j <= rows + i:
            score += points(allData[j])
            # print(i,points(allData[j]),score,j)
            j += 1
    if score > maxscore:
        maxscore = score
        indexOfMaxScore = i
    i += 1
print(indexOfMaxScore, maxscore)
newFile = open('final.txt', 'w')
for i in range(rows + 1):
    newFile.write(allData[i + indexOfMaxScore])