示例#1
0
文件: engine.py 项目: Kdsantos/MP
def cmb():
    load()
    ca()
    shuffle(ca.w)
    cmb.scramble = shuffle.randomized
    ts(shuffle.randomized)
    cmb.chk=""
    for n in cmb.scramble:
        if n not in cmb.chk:
            cmb.chk+=n
        else:
            continue
    cmb.tot = ts.TS
示例#2
0
文件: engine.py 项目: Kdsantos/MP
def ca():
    import random
    load()
    integers = []
    chkr = 2
    chb = 0
    while chb < chkr:
        num = random.randint(0, len(load.d))
        if num not in integers:
            chb+=1 
            integers.append(num)
    ca.w = []
    for j in range(len(integers)):
        ca.w.append(load.d[integers[j]])
示例#3
0
def get_required_data():
    eng = engine.load('ROTAX_912ULS')
    prop = propeller()
    prop.read_xls('MDO_initial')
    beta = 19.0

    thrust = FixedPitchThrust(eng)
    thrust.beta = beta
    thrust.prop = prop
    W = 620.0*9.81
    rho = 1.2255
    pset = array([50.0,75.0,95.0])
    vel = list()
    LD = list()
    effy = list()
    ff = list()
    sfc = list()
    print 'pset\t fuelFlow kg/s\tV,m/s\teffy\tP,W'
    for p in pset:
        rpm,V = thrust.velocity_at_power_setting(p,rho,W)
        data = prop.analyze_prop(beta,rpm,V,rho)
        effy.append(data[-1])
        vel.append(V)
        fuelFlow = eng.get_fuelFlow(rho,rpm,p)
        ff.append(fuelFlow)
        print '%.1f\t%.2e\t%.4f\t%.4f\t%.4f'%(p,fuelFlow,V,data[-1],data[1])
示例#4
0
def load():
	output('This is saves:', foreGroundColor.DARKSKYBLUE)
	saves = engine.get_saves()
	for save in saves:
		output(str(save[0]), foreGroundColor.PINK, ' ')
		output(save[1], foreGroundColor.PURPLE, ' ')
		output(save[2], foreGroundColor.YELLOW)
	i = int(input('choose your save'))
	return engine.load(i-1)
示例#5
0
def test_03():
    eng = engine.load('ROTAX_912ULS')
    prop = propeller.load('MDO_optimum')
    pset = 100.0
    rho = 1.2255
    weight = 620.0*9.81
    thrust = FixedPitchThrust(eng)
    thrust.prop = prop
    thrust.beta = 28.5
    rpm = thrust.thrust_at_velocity(50.0,pset,rho,weight)
    print rpm
示例#6
0
def run_test2():
    eng = engine.load('ROTAX_912ULS')
    prop = propeller.load('neuform')
    thrust = Thrust(prop,eng)
    pset = 95.0
    rho = 1.05
    prop.set_beta(15.0)
    print 'direct'
    thrust.max_efficiency(pset,rho)
    print thrust.prop.neval
    thrust.prop.neval = 0
    print '\n IDF'
    thrust.max_efficiency2(pset,rho)
    print thrust.prop.neval
    print eng.get_fuelFlow(rho,2300.,pset)
示例#7
0
def run_design():
    eng = engine.load('ROTAX_912ULS')
    thrust = FixedPitchThrust(eng)
    thrust.W = array([550.0,620.0])*9.81
    pset = array([50.0,75.0,95.0])
    thrust.max_efficiency(pset,1.2255)
示例#8
0
class Tile(pygame.sprite.Sprite):
    IMAGES = {
        '1': load('RIGHT_WALL.png'),
        '2': load('TOP_RIGHT_WALL.png'),
        '3': load('DOWN_WALL.png'),
        '4': load('TOP_LEFT_WALL.png'),
        '5': load('LEFT_WALL.png'),
        '6': load('DOWN_LEFT_WALL.png'),
        '7': load('DOWN_WALL.png'),
        '8': load('DOWN_RIGHT_WALL.png'),
        '9': load('TOP_RIGHT_WALL_2.png'),
        '0': load('TOP_LEFT_WALL_2.png'),
        '-': load('DOWN_LEFT_WALL_2.png'),
        '=': load('DOWN_RIGHT_WALL_2.png'),
        'r': load('DOOR_RIGHT.png'),
        'l': load('DOOR_LEFT.png'),
        'b': load('DOOR_TOP.png'),
        't': load('DOOR_BOTTOM.png'),
        'B': load('BOX.png'),
        'B1': load('BARREL.png'),
        'M': load('MONSTER.png'),
        'P': load('UPSTAIRS.png'),
        'C': load('CHEST.png'),
        'T': load('TORCH.png'),
        'E': load('DOWNSTAIRS.png'),
        ' ': load('DARK.png'),
        '.': load('FLOOR.png'),
        '.0': load('FLOOR_CRACKED_0.png'),
        '.1': load('FLOOR_CRACKED_1.png'),
        '.2': load('FLOOR_CRACKED_2.png'),
        '.3': load('FLOOR_CRACKED_3.png')
    }

    def __init__(self, tile_type: str, x: int, y: int):
        super().__init__(all_sprites_list)

        self.tile_type = tile_type.upper()  # тип тайла
        self.image = Tile.IMAGES[self.tile_type]
        self.rect = self.image.get_rect().move(x * TILE_SIZE, y * TILE_SIZE)
示例#9
0
def run_game():
    # Define colours for convenience
    BLACK = [0, 0, 0]
    WHITE = [255, 255, 255]
    COLOUR_WHITE = [200, 200, 200]
    COLOUR_BlACK = [50, 50, 50]

    # Manage framerate
    global clock
    clock = pygame.time.Clock()

    # initialize screen
    size = [1280, 800]
    global screen
    screen = pygame.display.set_mode(size)
    pygame.display.set_caption('Chess v0.5 ')
    font = pygame.font.SysFont('default', 22)

    # Track allowed and castlable squares, and check
    global allowed_sqs
    global check
    allowed_sqs = []
    check = False

    # Track moves made
    global moves
    moves = []
    global engine_moves
    engine_moves = []
    # Get width and height of window, compute box dimensions
    w, h = pygame.display.get_surface().get_size()
    play_area = min([w, h])
    global box_side
    box_side = play_area / 8

    # Create global live_board variable populate it from ini file
    global live_board
    live_board = set_board('board.ini')

    # Set up sidebar buttons
    global buttons
    buttons = {}
    global initial_time
    initial_time = 25 * 60
    global increment
    increment = 0
    global clock_time
    clock_time = [initial_time, initial_time]
    initialize_sidebar()

    # Set starting turn to white
    global turn_colour
    global counter
    turn_colour = ['w', 'b']
    counter = 0

    # Queening screen check
    global queening
    queening = [False, None]

    # Set up engine
    global AI
    AI = engine.load('ai/stockfish-8-linux/Linux/stockfish_8_x64')
    engine.put(AI, 'uci')
    engine.put(AI, 'uci setoption name Skill Level value 0')
    engine.put(AI, 'ucinewgame')
    garbage = engine.get(AI)
    print 'AI started.'

    global AI_plays
    AI_plays = False

    # Loop until user closes
    global done
    done = False
    #  ------- Main Program Loop ------
    while not done:

        #  --- Main event loop ---
        for event in pygame.event.get():
            m_pos = pygame.mouse.get_pos()
            if event.type == pygame.QUIT:
                quit_game()
            elif event.type == pygame.MOUSEBUTTONDOWN:
                # If mouse over moves list, handle scrolling
                if (829 < m_pos[0] < (829 + 250)) and (101 < m_pos[1] <
                                                       (101 + 335)):
                    if event.button == 4:
                        scroll_moves_up()
                    elif event.button == 5:
                        scroll_moves_down()
                # If mouse is over board, do chess logic
                if 0 < m_pos[0] < 800:
                    m_sq = pix_to_classic(m_pos)
                    # Right click delesects all board
                    if pygame.mouse.get_pressed() == (0, 0, 1):
                        for piece_ in live_board:
                            deselect(piece_)
                    # Left click
                    elif pygame.mouse.get_pressed() == (1, 0, 0):
                        for piece_ in live_board:
                            if getattr(piece_, 'selected') == True:
                                if m_sq in allowed_sqs:
                                    turn(piece_, m_sq)
                            # If there's a piece on the square we clicked, and that piece is of the right colour
                            # deselect everything, and select that piece.
                            elif getattr(piece_,
                                         'pos') == m_sq and turn_colour[
                                             counter % 2] == getattr(
                                                 piece_, 'colour'):
                                for all_piece in live_board:
                                    deselect(all_piece)
                                select(piece_)
            # Quit on 'q'
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_q:
                    quit_game()

        #  --- Drawing code ---

        # Display moves to the right of the board

        screen.fill([255, 255, 255])

        if queening[0]:
            # Fill with grey
            pygame.draw.rect(screen, [100, 100, 100], (0, 0, 800, 800))
            # Draw queening options
            textfont = pygame.font.Font('assets/Lato-Bold.ttf', 72)
            draw_text('Choose your piece', textfont, [0, 0, 0], 75, 100)
            available_piecetypes = ['queen', 'knight', 'bishop', 'rook']
            for i in range(0, len(available_piecetypes)):
                try:
                    draw_im_button('assets/'+ available_piecetypes[i] + '_' + getattr(queening[1], 'colour') + '.png'\
                        , 50 + i*200, 200, queen_piece, [queening[1], available_piecetypes[i], live_board])
                except AttributeError:
                    continue

        else:
            # Draw board and pieces
            draw_board(COLOUR_WHITE, COLOUR_BlACK)
            for piece_ in live_board:
                draw_piece(piece_)
            for sq in allowed_sqs:
                highlight(sq)
            check = in_check(turn_colour[counter % 2], live_board)
            if check:
                king = [
                    x for x in live_board
                    if getattr(x, 'colour') == turn_colour[counter % 2]
                    and getattr(x, 'type_') == 'king'
                ]
                highlight(getattr(king[0], 'pos'), [254, 86, 160])

        draw_sidebar()

        pygame.display.flip()

        # Limit fps
        clock.tick(60)

        # Update clock
        if not queening[0] and not checkmate(turn_colour[counter % 2],
                                             live_board):
            frametime = clock.get_time()
            if counter > 0:
                clock_time[counter % 2] -= frametime * 0.001

        if AI_plays:
            turn_engine()

    # Exit gracefully
    pygame.quit()
示例#10
0
文件: engine.py 项目: Kdsantos/MP
def ang():
    import random
    load()
    ang.word = random.choice(load.d)
    ang.possible = []
    ang.anagram = []
    while len(ang.word) < 5:
        ang.word = random.choice(load.d)
    def anag():
        for a in range(len(load.d)):
            if len(load.d[a]) == len(ang.word):
                ang.possible.append(load.d[a])
        for b in range(len(ang.possible)):
            if sorted(ang.word) == sorted(ang.possible[b]):
                ang.anagram.append(ang.possible[b])
            else:
                continue
    while len(ang.anagram) < 3:
        ang.word = random.choice(load.d)
        while len(ang.word) < 5:
            ang.word = random.choice(load.d)
        ang.possible = []
        ang.anagram = []
        anag()
    for a in ang.anagram:
        if a == ang.word:
            ang.anagram.remove(a)
    ang.final = "".join(ang.anagram)
    compute(ang.final)
    ang.tot = len(ang.anagram)
    ang.score = 0
    ang.life = 3
    ang.correct = []
    ang.incorrect = []
    while ang.life != 0 and ang.score <= ang.tot:
        if ang.life == 0:
            print("=============================================================")
            print("Uwurd Unscwambler <3")
            print("ANAGWAMS MODE!!!")
            print("heart:", ang.life)
            print("score:", ang.score, "/", ang.tot)
            print("Find the anagrams for:", ang.word)
            print()
            print("GAME OVER!")
        elif ang.score == ang.tot:
            print("=============================================================")
            print("Uwurd Unscwambler <3")
            print("ANAGWAMS MODE!!!")
            print("heart:", ang.life)
            print("score:", ang.score, "/", ang.tot)
            print()
            print("Anagrams for " + '"' + ang.word + '"' + ": ", end="")
            for x in range(len(ang.correct)):
                if x == len(ang.correct)-1:
                    print(ang.correct[x])
                else:
                    print(ang.correct[x] + ", ", end="")
            print()
            print("Whoa! You really found all the anagwams! Congwats UwU!")
            break
        else:
            print("=============================================================")
            print("Uwurd Unscwambler <3")
            print("ANAGWAMS MODE!!!")
            print("heart:", ang.life)
            print("score:", ang.score, "/", ang.tot)
            print()
            #print(ang.anagram)
            print("Find the anagrams for:", ang.word)
            if len(ang.correct) != 0:
                print("Correct guesses: ", end="")
                for x in range(len(ang.correct)):
                    if x == len(ang.correct)-1:
                        print(ang.correct[x])
                    else:
                        print(ang.correct[x] + ", ", end="")
            else: 
                print("Correct guesses: ")
            if len(ang.incorrect) != 0:
                print("Incorrect guesses: ", end="")
                for x in range(len(ang.incorrect)):
                    if x == len(ang.incorrect)-1:
                        print(ang.incorrect[x])
                    else:
                        print(ang.incorrect[x] + ", ", end="")
            else:
                print("Incorrect guesses: ")
            print()
            print("Your guess: ", end="")
            inp = str(input())
            if inp in ang.anagram:
                ang.correct.append(inp)
                compute(inp)
                ang.score += 1
            else:
                ang.incorrect.append(inp)
                print("Oh no! That's wrong!")
                ang.life-=1
示例#11
0
def load_E(choose):
	global chapter_on
	chapter_on = engine.load(choose)
	show_chapter(engine.getChapterContent(chapter_on))
	show_options(engine.getNextChapters(chapter_on), visit_chapter_E)