Пример #1
0
def directions_for_rat(r: Rat, algorithm: str, target: Room) -> List[str]:
    if algorithm == 'd':
        return r.directions_to(target)
    elif algorithm == 'b':
        return r.bfs_directions_to(target)
    elif algorithm == 'i':
        return r.id_directions_to(target)
    else:
        print("Invalid algorithm code: " + algorithm)
        return []
Пример #2
0
def rat_in_looped_dungeon() -> Rat:
    """Return a rat object ready to explore a dungeon with 6 rooms where there
    are two paths from the start to the finish.
    """
    r0 = Room('start', 0, 9, 9)
    d = Dungeon(r0)
    r1 = Room('one', 1, 9, 8)
    r2 = Room('two', 1, 9, 7)
    r3 = Room('three', 1, 9, 6)
    r4 = Room('four', 1, 9, 5)
    r5 = Room('five', 1, 9, 4)
    unconnected = Room('unconnected', 1, 8, 8)
    # r0 -> r1, r1 -> r2, r3; r2 -> r0, r3 -> r4, r4 -> r5
    r0.add_neighbor(r1, Direction.DOWN)
    r1.add_neighbor(r2, Direction.NORTH)
    r1.add_neighbor(r3, Direction.SOUTH)
    r2.add_neighbor(r0, Direction.UP)
    r3.add_neighbor(r4, Direction.EAST)
    r4.add_neighbor(r5, Direction.SOUTH)
    d.add_room(r1)
    d.add_room(r2)
    d.add_room(r3)
    d.add_room(r4)
    d.add_room(r5)
    d.add_room(unconnected)
    rat = Rat(d, r0)
    return rat
Пример #3
0
def display_rooms_visited_by(rat: Rat) -> None:
    """Display all of the rooms visited by the rat in its last search"""
    rooms = list(set([rm for rm in rat.rooms_visited_by_last_search()]))
    rooms.sort()
    print("Rooms visited in last search:")
    for sublist in chunks(rooms, 6):
        print("    " + "    ".join(sublist))
Пример #4
0
def rat_in_dungeon_x() -> Rat:
    """Return a rat in a dungeon with several long paths and one loop."""
    # The following pseudo-map describes the basic structure of the
    # dungeon, where rooms next to each other and dashed lines indicate
    # neighbors.
    #                  north2
    #                  north1
    # west1 downstairs center east1
    #  |               south1 
    # sw2              south2 stair1 upstairs-east1
    # sw3 -----------------------------> food
    #
    center = Room("center", 1, 5, 5)
    d = Dungeon(center)
    north1 = Room("north1", 1, 5, 6)
    north2 = Room("north2", 1, 5, 7)
    east1 = Room("east1", 1, 6, 5)
    down = Room("downstairs", 0, 5, 5)
    west1 = Room("west1", 0, 5, 4)
    sw2 = Room("sw2", 0, 4, 4)
    sw3 = Room("sw3", 0, 4, 3)
    south1 = Room("south1", 1, 5, 4)
    south2 = Room("south2", 1, 5, 3)
    stair1 = Room("stair1", 2, 5, 3)
    upstairs_east1 = Room("upstairs-east1", 2, 6, 3)
    food_room = Room("food", 1, 6, 2)
    d.add_room(north1)
    d.add_room(north2)
    d.add_room(east1)
    d.add_room(down)
    d.add_room(west1)
    d.add_room(sw2)
    d.add_room(sw3)
    d.add_room(south1)
    d.add_room(south2)
    d.add_room(stair1)
    d.add_room(upstairs_east1)
    d.add_room(food_room)

    center.add_neighbor(north1, Direction.NORTH)
    north1.add_neighbor(north2, Direction.NORTH)
    center.add_neighbor(down, Direction.DOWN)
    down.add_neighbor(west1, Direction.WEST)
    west1.add_neighbor(sw2, Direction.SOUTH)
    sw2.add_neighbor(sw3, Direction.SOUTH)
    sw3.add_neighbor(food_room, Direction.UP)
    center.add_neighbor(east1, Direction.EAST)
    center.add_neighbor(south1, Direction.SOUTH)
    south1.add_neighbor(south2, Direction.SOUTH)
    south2.add_neighbor(stair1, Direction.UP)
    stair1.add_neighbor(upstairs_east1, Direction.EAST)
    upstairs_east1.add_neighbor(food_room, Direction.DOWN)
    rat = Rat(d, center)
    return rat
Пример #5
0
def rat_in_three_room_dungeon() -> Rat:
    """Return a rat object ready to explore a dungeon with three rooms in a row."""
    r0 = Room('start here', 1, 0, 1)
    d = Dungeon(r0)
    r1 = Room('one', 1, 0, 2)
    r2 = Room('two', 2, 0, 3)
    r0.add_neighbor(r1, Direction.NORTH)
    r1.add_neighbor(r2, Direction.NORTH)
    d.add_room(r1)
    d.add_room(r2)
    rat = Rat(d, r0)
    return rat
Пример #6
0
def rat_in_fully_connected_grid() -> Rat:
    """Return a rat in a fully connected dungeon of 20 by 20 rooms"""
    start = Room("0,0", 1, 0, 0)
    d = Dungeon(start)
    for row in range(0, 20):
        for col in range(0, 20):
            if row > 0 or col > 0:
                d.add_room(Room(str(row) + "," + str(col), 1, col, row))
    for row in range(0, 20):
        for col in range(0, 20):
            connect_neighbors(d, row, col)
    rat = Rat(d, start)
    return rat
Пример #7
0
def main():
    REMI_START = Cartesian2D(0, 0)

    FEMI_START = Cartesian2D(100, 100)

    remi = Rat(REMI_START)
    femi = Mole(FEMI_START)

    pursuit = Pursuit(remi, femi)

    pursuit.play()

    pursuit.animate()
Пример #8
0
def bernoulli(n):
    """Return the nth Bernoulli number (as a rational number).

    The algorithm is taken from Experimental Number Theory by F. R.
    Villegas (the algorithm itself is apparently due to D. Zagier).

    Examples:
    >>> for n in range(20):
    ...     print(bernoulli(n))
    1
    -1/2
    1/6
    0
    -1/30
    0
    1/42
    0
    -1/30
    0
    5/66
    0
    -691/2730
    0
    7/6
    0
    -3617/510
    0
    43867/798
    0
    """

    x, res, s, c = Rat(0), Rat(0), Rat(0), Rat(-1)
    for k in range(1, n+2):
        c *= 1 - Rat(n + 2)/k
        s += x**n
        x += 1
        res += c*s/k
    return res
Пример #9
0
def rat_in_square_dungeon() -> Rat:
    """Return a rat object ready to explore a dungeon with 4 rooms in a square."""
    top_left_room = Room('top left', 1, 1, 0)
    bottom_left_room = Room('bottom left', 1, 0, 0)
    top_right_room = Room('top right', 1, 1, 1)
    bottom_right_room = Room('bottom right', 1, 0, 1)
    d = Dungeon(top_left_room)
    d.add_room(bottom_left_room)
    d.add_room(top_right_room)
    d.add_room(bottom_right_room)
    top_left_room.add_neighbor(top_right_room, Direction.EAST)
    top_left_room.add_neighbor(bottom_left_room, Direction.SOUTH)
    bottom_right_room.add_neighbor(bottom_left_room, Direction.WEST)
    bottom_right_room.add_neighbor(top_right_room, Direction.NORTH)
    rat = Rat(d, top_left_room)
    return rat
 def __init__(self):
     self.rat = Rat()
Пример #11
0
 def fight():
   fight = True
   #PROBABLY CHANGE
   opponent = PaintbrushTown.challenger()
   if opponent == 'Rocky':
     enemy = 'bat'
   elif opponent == 'Slander':
     enemy = 'rat'
   elif opponent == 'Kyle':
     enemy = 'caterpillar'
   print(opponent,'chooses', enemy,'\b!')
   if(enemy == 'bat'):
     combatant = Bat()
     Bat.work()
   elif(enemy == 'caterpillar'):
     combatant = Caterpillar()
     Caterpillar.work()
   elif(enemy == 'rat'):
     combatant = Rat()
     Rat.work()
   time.sleep(1)
   while(True):
     start,attack, = '0','0'
     while start != 'k' and start != 'b' and start != 'm':
       start = input('Which bokémon would you like to start with?\n[k = Kennen, b = Belldolpine, m = Meister Beast]\n').lower()
     while(fight == True):
       #PLAYER TURN
       if start == 'k':
         print('You have chosen Kennen!')
         you = 'Kennen'
         pc = Kennen()
       elif start == 'b':
         print('You have chosen Belldolpine!')
         you = 'Belldolpine'
         pc = Belldolpine()
       elif start == 'm':
         print('You have chosen Meister Beast!')
         you = 'MeisterBeast'
         pc = MeisterBeast()
       while attack != 'b' and attack != 's':
         attack = input('Would you like to use your basic attack [b] or your special attack [s]\n')
         if attack == 'b':
           print(you,'does', pc.basicDamage, 'damage to the', enemy)
           combatant.takeDamage(pc.basicDamage)
           attack = '0'
           break
         if attack == 's':
           print(you, 'does', pc.specialDamage, 'damage to the', enemy)
           combatant.takeDamage(pc.specialDamage)
           attack = '0'
           break 
       #ENEMY TURN
       if(combatant.hp > 0):
         time.sleep(1)
         print('The', enemy, 'attacks!')
         combatant.basicAttack()
         print('The', enemy, 'does', combatant.basicAttack(), 'damage to you!')
         pc.takeDamage(combatant.damage)
       else:
         time.sleep(1)
         print('The', enemy, 'is knocked unconscious!\nYou have won!\n',opponent,'congradulates you and hands you a badge.')
         time.sleep(1)
         print('You should take the badge back to Professor Cottonwood so you can go find your parents.')
         time.sleep(5)
         pc.heal()
         fight = False
     break
Пример #12
0
         [1, 0, 0, 0, 0, 0, 0, 1],
         [1, 0, 0, 0, 0, 0, 0, 1],
         [1, 1, 1, 1, 1, 1, 1, 1]];

rewards = [[0 for i in range(0, len(board[0]))] for j in range(0, len(board))];
print rewards;
rewards[2][5] = -50;
rewards[5][5] = 100;

GRAPHICAL_DISPLAY = True;
USER_INPUT = False;
ITER_SPEED = 2;
posFreq = {};

agentStart = [3, 1];
dude = Rat(agentStart[0], agentStart[1], board, rewards);
dudeColor = (0, 128, 255);
wallColor = (255, 128, 0);
rewardColor = (0, 255, 0);
reset = False;

if GRAPHICAL_DISPLAY:
    import sys, pygame
    pygame.init();
    screen = pygame.display.set_mode((800, 600));
    done = False;
    runCount = 0;
    while not done:
        screen.fill((0, 0, 0));
        if reset:
            dude.pos = (agentStart[0], agentStart[1])
Пример #13
0
    [1, 0, 0, 0, 0, 0, 0, 1],
    [1, 1, 1, 1, 1, 1, 1, 1],
]

rewards = [[0 for i in range(0, len(board[0]))] for j in range(0, len(board))]
print rewards
rewards[2][5] = -50
rewards[5][5] = 100

GRAPHICAL_DISPLAY = True
USER_INPUT = False
ITER_SPEED = 2
posFreq = {}

agentStart = [3, 1]
dude = Rat(agentStart[0], agentStart[1], board, rewards)
dudeColor = (0, 128, 255)
wallColor = (255, 128, 0)
rewardColor = (0, 255, 0)
reset = False

if GRAPHICAL_DISPLAY:
    import sys, pygame

    pygame.init()
    screen = pygame.display.set_mode((800, 600))
    done = False
    runCount = 0
    while not done:
        screen.fill((0, 0, 0))
        if reset:
Пример #14
0
def rat_in_none_dungeon() -> Rat:
    """Returns a Rat object in a Dungeon that doesn't have anything more than a main room"""
    room_1 = Room('main room')
    d = Dungeon(room_1)
    rat = Rat(d, room_1)
    return rat