Ejemplo n.º 1
0
def worker(output_queue):
    while True:
        # setup table, cue, and cue ball
        table = pt.PocketTable(model_name='7_foot')
        balls = pt.get_nine_ball_rack(table,
                                      spacing_factor=spacing_factor,
                                      ordered=True)
        balls['cue'].rvw[0] = get_cue_pos(balls['cue'], table)
        cue = pt.Cue(cueing_ball=balls['cue'])

        # Aim at the head ball then strike the cue ball
        cue.aim_at_ball(balls['1'])
        cue.strike(V0=8)

        # Evolve the shot
        shot = pt.System(cue=cue, table=table, balls=balls)
        try:
            shot.simulate(continuize=False, quiet=True)
        except Exception as e:
            continue

        if len(
                shot.events.filter_ball(
                    balls['cue']).filter_type('ball-pocket')):
            # Cue ball was potted. Illegal shot
            output_queue.put(shot.as_dict())
            continue

        output_queue.put(shot.as_dict())

    # Code never reaches here because worker is terminated by main thread
    return
Ejemplo n.º 2
0
def main():
    # Initialize the GUI
    interface = pt.ShotViewer()

    # Create a system state
    table = pt.PocketTable(model_name='7_foot')
    balls = pt.get_nine_ball_rack(table, ordered=True)
    cue = pt.Cue(cueing_ball=balls['cue'])

    # Set up a shot
    shot = pt.System(cue=cue, table=table, balls=balls)
    shot.cue.aim_at_ball(shot.balls['1'])
    shot.cue.strike(V0=8)

    # Now instead of simulating, save the system as a pickle file
    filepath = pt.utils.get_temp_file_path()
    shot.save(filepath)

    # Ok now make a new system and attach the old state
    shot2 = pt.System()
    shot2.load(filepath)

    # Now simulate the first
    shot.simulate(continuize=True)
    interface.show(shot, title='Original system state')

    # Now simulate the second
    shot2.simulate(continuize=True)
    interface.show(shot2, title='Pickled system state')

    # Now make a copy of the second. This is a 'deep' copy, and
    # uses the same underlying methods that created shot2
    shot3 = shot2.copy()
    interface.show(shot3, title='Copied system state')
Ejemplo n.º 3
0
def main(args):
    if not args.force:
        raise ConfigError(
            "Many of the unit tests are generated automatically by parsing the output of this script. "
            "That means the output serves as a ground truth. By running this script, you are deciding "
            "that a new ground truth should be issued, which is clearly no joke. Provide the flag --force "
            "to proceed. The trajectories of the balls in this simmulation will be taken as true and used "
            "to compare the identicality of future versions of the code.")

    table = pt.PocketTable(model_name='7_foot')
    balls = pt.get_nine_ball_rack(table, ordered=True)
    cue = pt.Cue(cueing_ball=balls['cue'])

    # Aim at the head ball then strike the cue ball
    cue.aim_at_ball(balls['1'])
    cue.strike(V0=8)

    # Evolve the shot
    shot = pt.System(cue=cue, table=table, balls=balls)
    shot.simulate(continuize=True, dt=0.01)

    # Visualize the shot
    interface = pt.ShotViewer()
    interface.show(shot, 'This is the new benchmark.')

    # Save the shot
    output_dir = Path(pt.__file__).parent / 'tests' / 'data'
    output_dir.mkdir(exist_ok=True)
    shot.save(output_dir / 'benchmark.pkl')
Ejemplo n.º 4
0
def main(args):
    if not args.no_viz:
        interface = pt.ShotViewer()
    while True:
        # setup table, cue, and cue ball
        table = pt.PocketTable(l=4, w=2)

        balls = {}
        balls['cue'] = place_ball('cue', balls, table)
        for i in range(args.N):
            balls[str(i)] = place_ball(str(i), balls, table)

        cue = pt.Cue(cueing_ball=balls['cue'])

        # Aim at the head ball then strike the cue ball
        cue.aim_at_ball(balls['1'])
        cue.strike(V0=40)

        # Evolve the shot
        shot = pt.System(cue=cue, table=table, balls=balls)
        try:
            shot.simulate(continuize=False, quiet=False)
        except KeyboardInterrupt:
            shot.progress.end()
            break
        except:
            shot.progress.end()
            shot.run.info("Shot calculation failed", ":(")
            continue

        if not args.no_viz:
            interface.show(shot)
Ejemplo n.º 5
0
def main(args):
    if not args.no_viz:
        interface = pt.ShotViewer()

    if args.seed:
        import numpy as np
        np.random.seed(args.seed)

    table = pt.PocketTable(model_name='7_foot')
    balls = pt.get_nine_ball_rack(table,
                                  ordered=True,
                                  spacing_factor=args.spacing_factor)
    cue = pt.Cue(cueing_ball=balls['cue'])

    # Aim at the head ball then strike the cue ball
    cue.aim_at_ball(balls['1'])
    cue.strike(V0=args.V0)

    # Evolve the shot
    shot = pt.System(cue=cue, table=table, balls=balls)
    shot.simulate()

    if not args.no_viz:
        interface.show(shot)

    if args.save:
        shot.save(args.save)
Ejemplo n.º 6
0
#! /usr/bin/env python

import numpy as np
import pooltool as pt

# Setup a shot
table = pt.PocketTable(model_name='7_foot')
balls = {
    'cue': pt.Ball('cue', xyz=(table.w / 2, table.l / 3, pt.R)),
    '1': pt.Ball('1', xyz=(table.w / 4, table.l * 0.2, pt.R)),
}
cue = pt.Cue(cueing_ball=balls['cue'])
cue.set_state(phi=225, V0=2)
system = pt.System(cue=cue, table=table, balls=balls)

collection = pt.SystemCollection()

for x in np.linspace(0, 0.7, 20):
    shot = system.copy()
    shot.cue.set_state(b=-x)
    shot.cue.strike()
    shot.simulate()
    collection.append(shot)

interface = pt.ShotViewer()
interface.show(collection)