Exemplo n.º 1
0
    STEPS = 10
    #Initialize a points collection
    #Point(x,y,s): s == 0 is self point, s == 1 is opponent point
    #You must make sure there is no two points of the same position!
    points = Points();

    game = Game(steps = STEPS)
    
    for i in range(STEPS):
        print("Playing red for round {}".format(i))
        pt = game.Play(points)
        points.append(Point(pt[0],pt[1],0))
        vor = Voronoi(points)
        print("Red placed a stone at {}".format(pt))
        print("Current area: {}".format(game.Area(points, vor.polygons)))
        game.Draw(points, vor.polygons)
        
        print("Playing blue for round {}".format(i))
        reverse(points)
        pt = game.Play(points)
        points.append(Point(pt[0],pt[1],0))
        reverse(points)
        vor = Voronoi(points)
        print("Blue placed a stone at {}".format(pt))
        print("Current area: {}".format(game.Area(points, vor.polygons)))
        game.Draw(points, vor.polygons)
    
    areas, areao = game.Area(points,vor.polygons)
    if areas > areao:
        print("Red wins at {}!".format(areas/1e6))
    else:
Exemplo n.º 2
0
    pygame.display.set_caption('Net Bomb (v1.0)')

    game = Game(screen)

    time_elapsed = 0.0
    time_last = time.clock()
    time_step = 0.01

    while True:

        time_current = time.clock()
        time_elapsed = time_current - time_last
        time_last = time_current

        # We want our simulation to advance by a given time step regardless of our frame-rate.
        time_remaining = time_elapsed
        while time_remaining > 0.0:
            time_delta = time_step if time_step < time_remaining else time_remaining
            game.Advance(time_delta)
            time_remaining -= time_delta

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                print(game.score)
                sys.exit()
            else:
                game.HandleEvent(event)

        game.Draw(time_elapsed)

        pygame.display.flip()