Example #1
0
    def set(self):
        if self.refresh == "1":
            thread.start_new_thread(self.slidethread, ())

        else:
            fun.move(int(self.slider.get()), 0.1, self.servselect.get(),
                     self.ser)
Example #2
0
    def process(self):
        self.world: World

        for _, game_map in self.world.get_component(Map):
            for entity, (monster, position, _) in self.world.get_components(Monster, Position, Awake):
                distance = game_map.dijkstra[DijkstraMap.PLAYER][position.y][position.x]
                if 1 <= distance <= len(monster.threat) and random() < 0.9:
                    self.world.add_component(entity, Threatening(threat=monster.threat[distance - 1]))
                else:
                    if self.world.has_component(entity, Threatening):
                        self.world.remove_component(entity, Threatening)

                    if self.world.has_components(entity, Visible, CanTaunt):
                        for player_entity, _ in self.world.get_component(Player):
                            if not self.world.has_component(player_entity, Taunted):
                                if random() < 0.3:
                                    self.world.add_component(player_entity, Taunted())
                                    self.world.create_entity(Message(
                                        text=f"[color=#FFFFFF00]The {monster.name} taunts you![/color]",
                                        priority=40,
                                    ))
                                    return

                    target = move_dijkstra(self.world, game_map, position, DijkstraMap.PLAYER, strict=False)

                    if target:
                        move(position, target)
    def process(self):
        self.world: World

        for _, game_map in self.world.get_component(Map):
            for _, (position,
                    player) in self.world.get_components(Position, Player):
                if player.action.action_type is ActionType.MOVE and player.action.target:
                    move(position, player.action.target)
Example #4
0
def command_line(dictionary):
    while True:
        command = input('Enter your command: ')
        if command == 'exit':
            return 'exit'
        elif command == 'move':
            functions.move()
        elif command == 'help':
            for command, description in list(commands_list.items()):
                print(command + ' = ' + description)
        elif command == 'add':
            functions.add()
            return functions.update()

        elif command == 'remove':
            functions.remove()
        elif command == 'print':
            continue
        elif command == 'show':
            functions.show()
        elif command == 'train':
            return functions.train(dictionary)
Example #5
0
##########################################
######## Start 2048 Manipulation #########
##########################################

print "start!";
game_state = Tools.getGameState(driver);
grid = Tools.getGridState(game_state)
sg = smartGrid(True, grid, None);
print;

highestTile = sg.getHighestTile();

# move up
#Tools.move(gridElement, "up");
# move right
#Tools.move(gridElement, "left");

moveC = 0;
while(highestTile < 2048):
    moves = generateNextMoves(game_state);
    for move in (moves):
        print "move: " + str(moveC);
        print move
        moveC = moveC + 1;
        Tools.move(gridElement, move);
        game_state = Tools.getGameState(driver);
        grid = Tools.getGridState(game_state)
        sg = smartGrid(True, grid, None);
        highestTile = sg.getHighestTile();
Example #6
0
 def slidethread(self):
     while self.refresh == "1":
         fun.move(int(self.slider.get()), 0.1, self.servselect.get(),
                  self.ser)
Example #7
0
 def left(self):
     fun.move(180, 0.1, self.servselect.get(), self.ser)
Example #8
0
 def right(self):
     fun.move(0, 0.1, self.servselect.get(), self.ser)
Example #9
0
print;



highestTile = sg.getHighestTile();

moveC = 0;
while(moveC < 1):
    nodeDq = generateNextMoves(game_state);
    print nodeDq
    while (nodeDq):
        currentNode = nodeDq.pop();
        print "move: " + str(moveC);
        print currentNode.stepToHere
        moveC = moveC + 1;
        Tools.move(gridElement, currentNode.stepToHere);


        game_state = Tools.getGameState(driver);
        grid = Tools.getGridState(game_state)
        sg = smartGrid(True, grid, None);
        highestTile = sg.getHighestTile();
'''
        currentSg = currentNode.sg;
        restart = False;

        for x in range(1):
            for y in range(4):
                if (currentSg.intGrid[x][y] != sg.intGrid[x][y]):
                    restart = True;
Example #10
0
grid = Tools.getGridState(game_state)
sg = smartGrid(True, grid, None);
print;

highestTile = sg.getHighestTile();

moveC = 0;
while(highestTile < 2048):
    nodeDq = generateNextMoves(game_state);
    print nodeDq
    while (nodeDq):
        currentNode = nodeDq.pop();
        print "move: " + str(moveC);
        print currentNode.stepToHere
        moveC = moveC + 1;
        Tools.move(gridElement, currentNode.stepToHere);


        game_state = Tools.getGameState(driver);
        grid = Tools.getGridState(game_state)
        sg = smartGrid(True, grid, None);
        highestTile = sg.getHighestTile();
'''
        currentSg = currentNode.sg;
        restart = False;

        for x in range(1):
            for y in range(4):
                if (currentSg.intGrid[x][y] != sg.intGrid[x][y]):
                    restart = True;
        if i < 2:
            print("-+-+-")


board = ["_"] * 9
forbidden_position = []
winner = "_"
player_turn = True
while winner == "_":
    print_grid(board)
    if len(forbidden_position) == 9:
        print("Draw!")
        sys.exit(0)
    if player_turn:
        inp = input("Enter the place: ")
        inp = int(inp)
        if fun.posibible_move(inp, forbidden_position):
            fun.move(board, inp - 1, "O")
            player_turn = not player_turn
            forbidden_position.append(inp)
            winner = fun.winner(board)
        else:
            print("The move is illegal")
    else:
        move = fun.random_computer_move(forbidden_position)
        fun.move(board, move - 1, "X")
        player_turn = not player_turn
        forbidden_position.append(move)
        winner = fun.winner(board)
print("The winner is \"" + winner + "\"")
Example #12
0
    def process(self):
        self.world: World

        for player_entity, player in self.world.get_component(Player):
            if player.action.action_type is ActionType.USE_ITEM:
                for entity, (item, _) in self.world.get_components(
                        Item, DefendTarget):
                    self.world.create_entity(
                        Message(
                            text=script.ITEM_USE.format(
                                name=color_item_name(self.world, entity)),
                            priority=50,
                        ))

                    if self.world.has_component(entity, HealingPotion):
                        player.health = min(player.health + 2, MAX_HEALTH)

                    if self.world.has_component(entity, SmokeBomb):
                        for monster_entity, _ in self.world.get_components(
                                Monster, Visible):
                            self.world.add_component(monster_entity, Blinded())

                    if self.world.has_component(entity, FireScroll):
                        for monster_entity, (monster,
                                             _) in self.world.get_components(
                                                 Monster, DefendTarget):
                            self.world.delete_entity(monster_entity,
                                                     immediate=True)
                            self.world.create_entity(
                                Message(
                                    text=script.ITEM_FIRE.format(
                                        name=monster.name),
                                    priority=45,
                                ))
                            player.kills[monster.name] += 1

                    if self.world.has_component(entity, TeleportScroll):
                        for _, game_map in self.world.get_component(Map):
                            blocked = get_blocked_tiles(self.world)

                            for _ in range(1000):
                                x = randint(0, game_map.w - 1)
                                y = randint(0, game_map.h - 1)

                                if not game_map.walkable[y][x] or (
                                        x, y) in blocked:
                                    continue

                                for position in self.world.try_component(
                                        player_entity, Position):
                                    move(position, (x, y))
                                    break

                                break

                            else:
                                self.world.create_entity(
                                    Message(
                                        text=script.ITEM_TELEPORT_FAIL,
                                        priority=45,
                                    ))

                    self.world.delete_entity(entity, immediate=True)
Example #13
0
# -*- coding: utf-8 -*-
'''
Created on 2017年6月29日

@author: Administrator
'''
from functions import my_abs, move
import math

print(my_abs(1))
v = move(100, 200, 60, math.pi / 6)
print(v)
Example #14
0
def main(random_gen, canLose, player_name):
    """ Main function. Contains the main loop of the game.

    INPUTS: 
            if True, toggles random generation (bool)
            name of the player (str)
    """

    # List of all the Blocks
    blocks = []

    # Init the player
    player = entities.Player.Player()

    # Display Setup
    WINDOW = pygame.display.set_mode((
        cfg.SIZE_X,  # Dimensions of WINDOW
        cfg.SIZE_Y))

    # Time
    CLOCK = pygame.time.Clock()

    # Inits TODO: explain variables
    chunk_num = 1  # 1 because of the init chunk
    prev_chunks_passed = 0

    chunk_times = []
    last_time = 0

    # Loads the first chunk of the map
    functions.loadChunk(blocks, levels.level[0], 0)

    # Idle screen
    # Using this to wait for the user input to start time but still picture the level
    chunk_num = idleLoop(random_gen, blocks, chunk_num, WINDOW, player)

    start_time = pygame.time.get_ticks() / 1000

    # Main loop
    over = False
    while not over:

        CLOCK.tick(20)  # 20 FPS

        for e in pygame.event.get():
            pygame.event.set_allowed(None)
            pygame.event.set_allowed((QUIT, MOUSEBUTTONDOWN, KEYDOWN))
            pygame.event.pump()

            if e.type == pygame.QUIT or (e.type == KEYDOWN and e.key
                                         == K_RETURN):  # quit condition
                over = True

        if player.rect.y + cfg.PLAYER_HEIGHT > cfg.SIZE_Y and canLose:
            over = True

        # Moves the camera if needed
        functions.camera(player, blocks)

        # Moves the player when m1 is on click
        if pygame.mouse.get_pressed()[0]:
            functions.mouse(player)

        # Moves the player
        functions.move(player, blocks)

        # Not very viable but works for that list length
        chunks_passed = 0
        for block in blocks:
            if block.type == "end" and block.rect.x < player.rect.x:
                chunks_passed += 1

        if chunks_passed == prev_chunks_passed + 1:
            current_time = pygame.time.get_ticks() / 1000 - start_time
            print("chunk n°", chunks_passed, ": ", current_time)

            chunk_times.append(round(current_time - last_time, 3))
            last_time = current_time
            prev_chunks_passed += 1

        # Loads the next chunk if needed
        chunkWasLoaded = functions.levelGeneration(random_gen, blocks,
                                                   levels.level, chunk_num)

        if chunkWasLoaded:
            chunk_num += 1

        functions.display(WINDOW, blocks, player)  # Window dispay

    # Displays the score in console
    score, chunks_passed, end_time = functions.score_func(
        current_time, player, blocks)
    print('Chunk nb:', chunks_passed, 'Time:', end_time)
    print('Score:', score)

    # Saving
    filename = os.path.join(cfg.DATA_FOLDER, cfg.DATA_FILE)
    functions.save(filename, player_name, score, chunks_passed, end_time,
                   chunk_times, levels.NB_CHUNK)
Example #15
0
        status = False
        while not status:
            # Choose one particle
            random_particle_idx = choice(get_particles_pos(box))
            # print(random_particle_idx)

            # Choose a random move
            rnd_move = random_move()
            # print(rnd_move)

            # Check if the move is possible        
            status = check_move(box,random_particle_idx,rnd_move)
            # print(status)

        # Do the move 
        new_box = move(box,random_particle_idx,rnd_move)

        # Compare energies
        # e = calculate_energy(box)
        # new_e = calculate_energy(new_box)
        e = calc_e(box)
        new_e = calc_e(new_box)

        # Accept or discard new state
        if new_e <= e:
                box = new_box
        elif new_e>e:
            p = np.exp(-1*(new_e-e)/ T)  
            rnd_n = np.random.rand(1)[0]
            # print('delta E = ', new_e-e)
            # print('formula(T={}) = '.format(T), p)