# This loop runs the game for 1000 ticks, stopping if a goal is found.
for x in range(0, 1000):
    found_goal = game.tick()
    print(
        f"{game.getIteration()}: Robot at: {robot.getLoc()}, Score = {game.getScore()}"
    )
    if found_goal:
        print(f"Found goal at time step: {game.getIteration()}!")
        break
print(f"Final Score: {game.score}")

# Show how much of the world has been explored
im = Image.fromarray(np.uint8(game.exploredMap)).show()

# Create the world estimating network
uNet = WorldEstimatingNetwork()

# Create the digit classification network
classNet = DigitClassificationNetwork()

# This loop shows how you can create a mask, an grid of 0s and 1s
# where 0s represent unexplored areas and 1s represent explored areas
# This mask is used by the world estimating network
mask = np.zeros((28, 28))
for col in range(0, 28):
    for row in range(0, 28):
        if game.exploredMap[col, row] != 128:
            mask[col, row] = 1

# Creates an estimate of what the world looks like
image = uNet.runNetwork(game.exploredMap, mask)
Beispiel #2
0
__author__ = 'Caleytown'

import numpy as np
from random import randint
import random
from networkFolder.functionList import Map, WorldEstimatingNetwork, DigitClassificationNetwork

# Create the world estimating network
uNet = WorldEstimatingNetwork()

# Create the digit classification network
classNet = DigitClassificationNetwork()


def get_goal(digit):
    """
        Returns a tuple containing
        - the goal location based on the digit
    """
    goals = [(0, 27), (27, 27), (27, 0)]
    if digit in range(0, 3):
        goal = goals.pop(0)
    elif digit in range(3, 6):
        goal = goals.pop(1)
    elif digit in range(6, 10):
        goal = goals.pop(2)
    else:
        raise ValueError("Bad digit input: " + str(digit))
    return goal

Beispiel #3
0
def main():
    # nums = np.arange(0,10)
    # for i in nums:
    # print("current img num", i)
    option = "simple"
    M = Map(0)
    data = M.map
    robot = Robot(0, 0)
    navigator = greedy(robot)
    real_goal = get_goal(M.number)
    game = Game(data, real_goal, navigator, robot)
    print("actual goal", real_goal)
    print("actual number:", M.number)
    # pdb.set_trace()
    # define networks
    wEstNet = WorldEstimatingNetwork()
    classNet = DigitClassifcationNetwork()
    mask = np.zeros((28, 28))
    path_taken = np.zeros((28, 28))
    rewards = 0
    while True:
        path_taken[robot.getLoc()[0],
                   robot.getLoc()[1]] = 1  # record path being taken by robot
        for x in range(0, 28):
            for y in range(0, 28):
                if game.exploredMap[x, y] != 128:
                    mask[x, y] = 1
        image = wEstNet.runNetwork(game.exploredMap, mask)
        char = classNet.runNetwork(image)  # softmax output values
        prob = calc_prob(char)
        print("prob:", prob)
        print("current prediction", char.argmax())
        if prob > 0.95:
            break
        new_image = (image * (1 - mask))
        # print("mask", mask[22,17])
        # pdb.set_trace()
        run, rewards = game.tick_greedy(new_image, option, rewards)
        if run == True:
            break
    # print(char)
    # print(char.argmax())
    # Image.fromarray(image).show()
    # a = plt.imshow(image)
    # plt.show()
    # print(mask)
    # pdb.set_trace()
    print("robot finds path")
    robot_goal = get_goal(char.argmax())

    prevLoc = np.array([robot.getLoc()[0], robot.getLoc()[1]])
    while True:
        check_goal, rewards = game.tick(robot_goal, prevLoc, rewards)
        if check_goal == True:
            print("prediction is right")
            print("rewards", rewards)
            break
        if check_goal == False:
            flag = 1
            print("rewards", rewards)
            print("WRONG DESTINATION")

        # check if robot is moving towards the right goal
        prevLoc = np.array([robot.getLoc()[0], robot.getLoc()[1]])
import gzip
import numpy as np
from PIL import Image
from RobotClass import Robot
from GameClass import Game
from RandomNavigator import RandomNavigator
from networkFolder.functionList import Map, WorldEstimatingNetwork, DigitClassifcationNetwork
import matplotlib.pyplot as plt
import copy
import random

plt.close('all')
plt.ion()
#declare the neural network 1 and 2
uNet = WorldEstimatingNetwork()
classNet = DigitClassifcationNetwork()
# change value of x if you have to run step
map = Map()
#print the number hidden in the map
#print(map.number)
#iterating 10 times

# define robot start position
robot = Robot(0, 0)
reward = 0
# truth map
data = map.map
if map.number in [0, 1, 2]:
    goal = [0, 27]
elif map.number in [3, 4, 5]: