Example #1
0
 def closeEvent(self, event):
     r"""Things in here happen on GUI closing."""
     close_immediately = True
     filename = os.path.join(get_output_dir(), 'pentago.pkl')
     if close_immediately:
         GameStats.save(filename, self.state.game_hist)
         event.accept()
     else:
         # Alternative with user choice
         reply = QMessageBox.question(self, 'Message', \
             "Are you sure to quit?", QMessageBox.Yes | \
             QMessageBox.No, QMessageBox.No)
         if reply == QMessageBox.Yes:
             GameStats.save(filename, self.state.game_hist)
             event.accept()
         else:
             event.ignore()
Example #2
0
 def initialize_state(self, filename):
     r"""Loads the previous game based on settings and whether the file exists."""
     # preallocate to not load
     load_game = False
     if OPTIONS['load_previous_game'] == 'No':
         pass
     elif OPTIONS['load_previous_game'] == 'Yes':
         load_game = True
     # ask if loading
     elif OPTIONS['load_previous_game'] == 'Ask':
         widget = QWidget()
         reply = QMessageBox.question(widget, 'Message', \
             "Do you want to load the previous game?", QMessageBox.Yes | \
             QMessageBox.No, QMessageBox.No)
         if reply == QMessageBox.Yes:
             load_game = True
     else:
         raise ValueError(
             'Unexpected value for the load_previous_game option.')
     # initialize outputs
     self.state = State()
     # load previous game
     if load_game:
         if filename is None:
             filename = os.path.join(get_output_dir(), 'pentago.pkl')
         if os.path.isfile(filename):
             self.state.game_hist = GameStats.load(filename)
             self.state.cur_game = Counter(len(self.state.game_hist) - 1)
             self.state.cur_move = Counter(
                 len(self.state.game_hist[-1].move_list))
             self.state.board       = create_board_from_moves(self.state.game_hist[-1].move_list, \
                 self.state.game_hist[-1].first_move)
             self.state.move_status = {
                 'ok': False,
                 'pos': None,
                 'patch_object': None
             }
         else:
             raise ValueError(
                 f'Could not find file: "{filename}"')  # pragma: no cover
Example #3
0
 def closeEvent(self, event):
     r"""Things in here happen on GUI closing."""
     filename = os.path.join(get_output_dir(), 'tictactoe.pkl')
     GameStats.save(filename, self.state.game_hist)
     event.accept()
Example #4
0
 def test_function(self):
     folder = dcs2.get_output_dir()
     self.assertEqual(folder, os.path.join(dcs2.get_root_dir(), 'results'))
Example #5
0
import pprofile

from dstauffman2 import get_output_dir, setup_dir
import dstauffman2.games.knight as knight

#%% Script
if __name__ == '__main__':

    do_board = 'none' # from {'none', 'small', 'large', 'both'}

    # convert board to numeric representation for efficiency
    board1 = knight.char_board_to_nums(knight.BOARD1)
    board2 = knight.char_board_to_nums(knight.BOARD2)

    # create the output folder
    folder = os.path.join(get_output_dir(), 'knight')
    setup_dir(folder)

    # create profiler
    profile = pprofile.Profile()

    # Small board
    if do_board in {'small', 'both'}:
        print('\nSolve the smaller board for the minimum length solution.')
        # enable/disable profiler while running solver
        profile.enable()
        moves3 = knight.solve_min_puzzle(board1)
        profile.disable()

        # print solution
        print(moves3)
import dstauffman2.archery.scoring as score

#%% Script
if __name__ == '__main__':
    # turn interactive plotting off
    plt.ioff()

    #%% folder and file locations
    username = getpass.getuser()
    folder = os.path.join(r'C:\Users', username,
                          r'Google Drive\Python\2015-16_Indoor_Scores')
    xlsx_datafile = os.path.join(folder, '2015-16 Indoor Scorecards.xlsx')

    #%% opts settings for plots
    opts = Opts()
    opts.save_path = get_output_dir()
    opts.save_plot = True
    opts.plot_type = 'png'

    #%% process data
    (scores, names, dates) = score.read_from_excel_datafile(xlsx_datafile)
    (nfaa_score, usaa_score) = score.convert_data_to_scores(scores)

    #%% Specific dates
    inner10 = []
    outer10 = []
    tulare = []
    vegas = []
    for (ix, this_name) in enumerate(names):
        if 'Tulare' in this_name:
            tulare.append(usaa_score[ix])