Exemple #1
0
def parsons(problem_name, code_skeleton=False):
    problem_config = load_config(problem_name)
    language = problem_config.get('language', 'python')

    code_lines = problem_config['code_lines'] + \
             '\nprint(\'DEBUG:\', !BLANK)' * 2 + '\n# !BLANK' * 2
    repr_fname = f'{PARSONS_FOLDER_PATH}/{problem_name.lower()}{PARSONS_REPR_SUFFIX}'
    if os.path.exists(repr_fname):
        with open(repr_fname, "r", encoding="utf8") as f:
            code_lines = f.read()

    cur_prob_index = cache[PROBLEM_NAMES].index(problem_name)

    not_last_prob = cur_prob_index < len(cache[PROBLEM_NAMES]) - 1
    not_first_prob = cur_prob_index > 0
    is_required = problem_name in cache[REQUIRED_PROBLEMS]
    return render_template(
        'parsons.html',
        problem_name=problem_name,
        algorithm_description=problem_config['algorithm_description'],
        problem_description=problem_config['problem_description'],
        test_cases=problem_config['test_cases'],
        # TODO(nweinman): Better UI for this (and comment
        # lines as well)
        code_lines=code_lines,
        next_problem=None,
        back_url=None,
        code_skeleton=code_skeleton,
        language=language,
        not_first_prob=not_first_prob,
        not_last_prob=not_last_prob,
        is_required=is_required)
Exemple #2
0
def game():
    # Initialize pygame
    os.environ["SDL_VIDEO_CENTERED"] = "1"
    pygame.init()

    # Set up the display
    pygame.display.set_caption(K.SCREEN_NAME)
    screen = pygame.display.set_mode(K.SCREEN_SIZE)

    # clock setup
    clock = pygame.time.Clock()
    elapsed = 0

    # Create and load board (squares)
    chessboard = BitBoard()
    chessboard.load()
    board_engine = BoardEngine(chessboard)

    # Load teams and players from config players file
    config = load.load_config(load.PLAYER_CONFIG)
    teams = load.load_teams(config, board_engine)
    for team in teams:
        players = load.load_players(config, board_engine, team.name)
        for player in players:
            team.add_player(player)

    # Set current player and load engine -> needed to set up move area
    LOG.debug('Teams: %s' % teams)
    board_engine.set_current_player(teams[0].next_player())
    board_engine.load()

    board_width, board_height = chessboard.get_pixel_size()
    camera = Camera(complex_camera, board_width, board_height)

    running = True
    while running:

        elapsed = clock.tick(K.FPS)
        seconds = elapsed / 1000.0

        for e in pygame.event.get():
            if e.type == pygame.QUIT:
                running = False
                pygame.quit()
            if e.type == pygame.KEYDOWN and e.key == pygame.K_ESCAPE:
                running = False
            # treat players, npc, and others.
            board_engine.event(e, seconds)
            cur_player = board_engine.get_current_player()
            cur_player.event(e, seconds)

        # move player
        key = pygame.key.get_pressed()
        cur_player.keypressed(key, seconds)

        # Start screen (background)
        screen.fill(pygame.Color(K.SCREEN_COLOR))

        camera.update(cur_player)

        # draw methods
        #chessboard.draw(screen)
        chessboard.draw(screen, camera)
        for team in teams:
            for player in team:
                player.draw(screen, camera)
                #player.draw(screen)

        pygame.display.flip()
Exemple #3
0
# Copyright (c) 2015-2016, NVIDIA CORPORATION.  All rights reserved.

import os

# These are the only two functions that the rest of DIGITS needs to use
from load import load_config
from current_config import config_value

if 'DIGITS_MODE_TEST' in os.environ:
    # load the config automatically during testing
    # it's hard to do it manually with nosetests
    load_config()

Exemple #4
0
def game():
    # Initialize pygame
    os.environ["SDL_VIDEO_CENTERED"] = "1"
    pygame.init()
    
    # Set up the display
    pygame.display.set_caption(K.SCREEN_NAME)
    screen = pygame.display.set_mode(K.SCREEN_SIZE)
    
    # clock setup
    clock = pygame.time.Clock()
    elapsed = 0
    
    # Create and load board (squares)
    chessboard = BitBoard()
    chessboard.load()
    board_engine = BoardEngine(chessboard)
    
    # Load teams and players from config players file
    config = load.load_config(load.PLAYER_CONFIG)
    teams = load.load_teams(config, board_engine)
    for team in teams:
        players = load.load_players(config, board_engine, team.name)
        for player in players:
            team.add_player(player)
    
    # Set current player and load engine -> needed to set up move area
    LOG.debug('Teams: %s' % teams)
    board_engine.set_current_player(teams[0].next_player())
    board_engine.load()
    
    board_width, board_height = chessboard.get_pixel_size()
    camera = Camera(complex_camera, board_width, board_height)
  
    running = True
    while running:
        
        elapsed = clock.tick(K.FPS)
        seconds = elapsed/1000.0
    
        for e in pygame.event.get():
            if e.type == pygame.QUIT:
                running = False
                pygame.quit()
            if e.type == pygame.KEYDOWN and e.key == pygame.K_ESCAPE:
                running = False
            # treat players, npc, and others. 
            board_engine.event(e, seconds)       
            cur_player = board_engine.get_current_player()
            cur_player.event(e, seconds)
        
        # move player
        key = pygame.key.get_pressed()
        cur_player.keypressed(key, seconds)
               
        # Start screen (background)
        screen.fill(pygame.Color(K.SCREEN_COLOR))
        
        camera.update(cur_player)
        
        # draw methods
        #chessboard.draw(screen)
        chessboard.draw(screen, camera)
        for team in teams:
            for player in team:
                player.draw(screen, camera)
                #player.draw(screen)

        pygame.display.flip()
Exemple #5
0
 def test_load_config_lowercased(self):
     with self.assertRaises(Exception) as context:
       load.load_config('remove_indexes')
     self.assertIn('remove_indexes.yaml', str(context.exception))
Exemple #6
0
 def test_load_config_camelcased(self):
     with self.assertRaises(Exception) as context:
       load.load_config('SmartFridge')
     # Make sure it lowercases the file name
     self.assertIn('smartfridge.yaml', str(context.exception))
Exemple #7
0
# Copyright (c) 2015, NVIDIA CORPORATION.  All rights reserved.

import os

# These are the only two functions that the rest of DIGITS needs to use
from load import load_config
from current_config import config_value

if 'DIGITS_MODE_TEST' in os.environ:
    # load the config automatically during testing
    # it's hard to do it manually with nosetests
    load_config()