Пример #1
0
def notify(checkfornew, time_del):
    result = os.popen(
        """osascript -e 'display dialog "Do you want what you just downloaded to be a single-use file?" buttons {"Yes","No & Move","No"} default button "No" with title "Single-Use File? " with icon Caution
'""").readlines()
    if result == ['button returned:Yes\n']:
        remove(checkfornew, time_del)
    if result == ['button returned:No & Move\n']:
        move(checkfornew)
Пример #2
0
    def moveRoutine(self, pygame, map, player):
        ms_passed = pygame.time.get_ticks()
        if (ms_passed % 150) <= 15:
            self.sprite_index = (self.sprite_index + 1) % len(yeti_running)

        if (player.collides(self.rect)):
            self.y_momentum = -2
            player.do_damage(1)

        self.rect, collisions = move(self.rect, self.movement, map.tiles)

        if collisions['right']:
            self.direction = -1
            self.flipped = True
        if collisions['left']:
            self.direction = 1
            self.flipped = False

        if self.direction == 1:
            self.moveRight()
        else:
            self.moveLeft()
        # stage = int(0.001*pygame.time.get_ticks())%2
        # if(stage==0):
        #   self.moveRight();
        # else:
        #   self.moveLeft();
        self.move(map, collisions)
Пример #3
0
    def test_move_around_wall(self):
        # arrange
        test_map = ("##########\n"
                    "#.G#E....#\n"
                    "#.##.....#\n"
                    "#........#\n"
                    "##########\n")
        test_state = parse_map(test_map)

        # act
        (actual_did_move, actual_state,
         actual_new_pos) = move(test_state, (2, 1))
        (_walls, actual_units) = actual_state

        # assert
        expected_goblin_position = (1, 1)
        expected_elf_position = (4, 1)

        self.assertTrue(expected_goblin_position in actual_units)
        self.assertTrue(actual_units[expected_goblin_position][0] == "G")

        self.assertTrue(expected_elf_position in actual_units)
        self.assertTrue(actual_units[expected_elf_position][0] == "E")

        self.assertTrue(actual_did_move)
        self.assertEqual(actual_new_pos, expected_goblin_position)
Пример #4
0
def parse_path(path, myloc, direction):
    newloc = [myloc[0], myloc[1]]
    curDir = helpers.parseDir(direction)
    if path[0].isdigit():
        print('\tContinue for ' + str(path[0] + " blocks"))
        newloc = helpers.move(path, curDir, myloc)
    elif len(path) == 1:
        curDir = helpers.turn(path, curDir)
        print('\tTurn: ' + path)
    elif path.replace(' ', '').isalpha():
        print('\tContinue straight until you reach the ' + path)
    else:
        new_dir = helpers.parseDir(path[0])
        newloc = helpers.move(path[1:], new_dir, myloc)
        print('\tHead ' + path[0] + ' for ' + path[1:] + " blocks")

    return (newloc, helpers.getDir(curDir))
Пример #5
0
def expand(node: State) -> list:
    # Create a list of neighbors generating all possible moves from the current state
    neighbors = [
        State(move(node.state, move_dir), node, move_dir, node.depth + 1,
              node.cost + 1) for move_dir in ['left', 'right', 'up', 'down']
    ]
    valid_neighbors = [n for n in neighbors if n.state]
    return valid_neighbors
Пример #6
0
def expand(node: State) -> list:
    neighbors = []
    for move_dir in ['left', 'right', 'up', 'down']:
        board_conf = move(node.state, move_dir)
        if not board_conf:
            continue
        cost = calc_cost(board_conf, node.depth + 1)
        # Create a list of neighbors generating all possible moves from the current state
        neighbors.append(
            State(board_conf, node, move_dir, node.depth + 1, cost))
    return neighbors
Пример #7
0
    def test_move_no_other_units(self):
        # arrange
        test_walls = {}
        test_units = {(0, 0): ("E", 200, 3)}
        test_state = (test_walls, test_units)

        # act
        actual = move(test_state, (0, 0))

        # assert
        expected = (False, test_state, (0, 0))
        self.assertEqual(actual, expected)
Пример #8
0
    def test_move_ignore_similar_units(self):
        # arrange
        test_walls = {}
        test_units = {
            (0, 0): ("E", 200, 3),
            (2, 2): ("E", 200, 3),
        }
        test_state = (test_walls, test_units)

        # act
        actual = move(test_state, (0, 0))

        # assert
        expected = (False, test_state, (0, 0))
        self.assertEqual(actual, expected)
Пример #9
0
    def test_move_toward_enemy_manhattan_distance(self):
        # arrange
        test_units = {
            (0, 0): ("E", 200, 3),
            (2, 2): ("G", 200, 3),
        }
        test_state = (set(), test_units)

        # act
        actual = move(test_state, (0, 0))

        # assert
        expected_units = {
            (1, 0): ("E", 200, 3),
            (2, 2): ("G", 200, 3),
        }
        expected_state = (set(), expected_units)
        expected = (True, expected_state, (1, 0))
        self.assertEqual(actual, expected)
Пример #10
0
    def test_move_toward_nearest_enemy(self):
        # arrange
        test_units = {
            (0, 0): ("E", 200, 3),
            (5, 1): ("G", 200, 3),
            (11, 2): ("E", 200, 3),
        }
        test_state = (set(), test_units)

        # act
        actual = move(test_state, (5, 1))

        # assert
        expected_units = {
            (0, 0): ("E", 200, 3),
            (5, 0): ("G", 200, 3),
            (11, 2): ("E", 200, 3),
        }
        expected_state = (set(), expected_units)
        expected = (True, expected_state, (5, 0))
        self.assertEqual(actual, expected)
Пример #11
0
def sort(current, id3tags):
    move(current, id3tags)
Пример #12
0
def sort(current, id3tags):
    move(current, id3tags)
Пример #13
0
def game():
    # When the game is called with GET, it displays the game HTML template, passing in various jinja features.
    if request.method == "GET":
        return render_template("game.html",
                               rows=rows,
                               option=option,
                               difficulty=difficulty[0],
                               message="Your Turn!")

    # Else, if game is called with POST, the computer processes the user's move and then makes its move.
    else:
        # This counts the total number of moves made so far.
        moves = 0
        for i in range(3):
            for j in range(3):
                moves += abs(board[i][j])

        # If no moves have been made (so it was the user's first move), the defer option is removed.
        if moves == 0:
            option.remove("Let CPU Go First")

        # If the user defered his/her move, we move on without doing anything.
        if request.form.get("space") == "Let CPU Go First":
            # I found pass on a StackExchange forum
            pass
        # Else, we count the user's move and increment the moves counter. We first get the id of the button the user clicked.
        # The first digit of the id is the row number, and the second digit is the column number (both 0-indexed).
        # Then, we fill in that space with a 1 in the board list and an X in the rows list.
        else:
            space = int(request.form.get("space"))
            row = space // 10
            column = space % 10
            moves += 1
            board[row][column] = 1
            rows[row][column] = "X"

        # Next, we check if the user won the game on that move
        if userwin(board) == 1:
            # Any not-taken space in rows is converted to an empty character so that a button no longer shows up (this looks nicer).
            for i in range(3):
                for j in range(3):
                    if board[i][j] == 0:
                        rows[i][j] = ""
            # The result of this game is added into the history database.
            db.execute(
                "INSERT INTO history (id, difficulty, result) VALUES(:ident, :diff, :result)",
                ident=session["user_id"],
                diff=difficulty[0],
                result="Win")
            # The game board is returned, with the message altered to reflect the user win.
            return render_template("game.html",
                                   rows=rows,
                                   option=option,
                                   difficulty=difficulty[0],
                                   message="You Won!")

        # Next, we check if the game is a draw (so there have been nine total moves).
        if moves == 9:
            # The result of the game is added into the history database.
            db.execute(
                "INSERT INTO history (id, difficulty, result) VALUES(:ident, :diff, :result)",
                ident=session["user_id"],
                diff=difficulty[0],
                result="Tie")
            # The game board is returned, with the message altered to reflect the tie game.
            return render_template("game.html",
                                   rows=rows,
                                   option=option,
                                   difficulty=difficulty[0],
                                   message="Tie Game!")

        # If no win or tie, the CPU makes its move.
        # The CPU picks a space, and puts a -1 in the board and an O in rows.
        if difficulty[0] == "Easy":
            # If the difficulty is easy, the computer will move randomly half the time.
            x = randint(1, 2)
            if x == 1:
                y = randomspot(board)
                board[y[0]][y[1]] = -1
                rows[y[0]][y[1]] = "O"
            else:
                y = move(board, moves)
                board[y[0]][y[1]] = -1
                rows[y[0]][y[1]] = "O"
        elif difficulty[0] == "Medium":
            # If the difficulty is medium, the computer will move randomly one quarter of the time.
            x = randint(1, 4)
            if x == 1:
                y = randomspot(board)
                board[y[0]][y[1]] = -1
                rows[y[0]][y[1]] = "O"
            else:
                y = move(board, moves)
                board[y[0]][y[1]] = -1
                rows[y[0]][y[1]] = "O"
        else:
            # Else, the difficulty is hard, and the computer will never make a mistake.
            x = move(board, moves)
            board[x[0]][x[1]] = -1
            rows[x[0]][x[1]] = "O"
        # After the computer moved, the moves counter is incremented.
        moves += 1

        # Next, we check if the computer just won the game.
        if cpuwin(board) == -1:
            # Any not-taken space in rows is converted to an empty character so that a button no longer shows up (this looks nicer).
            for i in range(3):
                for j in range(3):
                    if board[i][j] == 0:
                        rows[i][j] = ""
            # The result of the game is inserted into the history database
            db.execute(
                "INSERT INTO history (id, difficulty, result) VALUES(:ident, :diff, :result)",
                ident=session["user_id"],
                diff=difficulty[0],
                result="Loss")
            # The game board is returned with a message that reflects the loss.
            return render_template("game.html",
                                   rows=rows,
                                   option=option,
                                   difficulty=difficulty[0],
                                   message="You Lost!")

        # Next, we check if the game was a tie (so nine moves have been made)
        if moves == 9:
            # The result of the game is insderted into the history database.
            db.execute(
                "INSERT INTO history (id, difficulty, result) VALUES(:ident, :diff, :result)",
                ident=session["user_id"],
                diff=difficulty[0],
                result="Tie")
            # The game board is returned with a message that reflects the tie.
            return render_template("game.html",
                                   rows=rows,
                                   option=option,
                                   difficulty=difficulty[0],
                                   message="Tie Game!")

        # Else, we reload the game to reflect the user's counted move and the CPU's move.
        return redirect("/game")