Ejemplo n.º 1
0
    def plant_seed(self):
        # Function for planting trees

        # Test to see if the tile the arborist is on is a tile that a tree can be planted on
        if TileFuncs.get_tile(self.arborist.world,self.arborist.location).plantable == 1:
            self.arborist.hit = 0
            self.arborist.update()
            old_tile = TileFuncs.get_tile(self.arborist.world,Vector2(self.arborist.location))

            darkness = pygame.Surface((32, 32))
            darkness.set_alpha(old_tile.darkness)

            new_tile = Tile.Baby_Tree(self.arborist.world, "GrassWithCenterTree")

            new_tile.darkness = old_tile.darkness

            new_tile.location = TileFuncs.get_tile_pos(self.arborist.world,self.arborist.destination)*32
            new_tile.rect.topleft = new_tile.location
            new_tile.color = old_tile.color

            self.arborist.world.tile_array[int(new_tile.location.y/32)][int(new_tile.location.x/32)] = new_tile
            self.arborist.world.world_surface.blit(new_tile.img, new_tile.location)
            self.arborist.world.world_surface.blit(darkness, new_tile.location)

        # Goes to a random destination no matter what
        self.arborist.hit = 0
        BaseFunctions.random_dest(self.arborist)
Ejemplo n.º 2
0
    def do_actions(self):

        if self.arborist.location == self.arborist.destination and self.arborist.hit >= 4 and TileFuncs.get_tile(
                self.arborist.world,self.arborist.location).plantable == 1:
            self.plant_seed()

        if self.arborist.location == self.arborist.destination and self.arborist.hit != 4 and TileFuncs.get_tile(
                self.arborist.world, self.arborist.location).plantable != 1:
            BaseFunctions.random_dest(self.arborist)
Ejemplo n.º 3
0
    def check_conditions(self):
        if self.angler.location.get_distance_to(self.angler.destination) < self.angler.max_speed:
            location_array = TileFuncs.get_vnn_array(self.angler.world,(self.angler.location), self.angler.view_range)

            for location in location_array:
                # TODO: This will make the angler go into the water, change this to go to the nearest walkable tile.
                test_tile = TileFuncs.get_tile(self.angler.world, location)
                if test_tile.__class__.__name__ == "WaterTile":

                    self.angler.destination = location.copy()
                    return "Fishing"

            BaseFunctions.random_dest(self.angler)
Ejemplo n.º 4
0
    def check_conditions(self):
        if self.lumberjack.location.get_distance_to(self.lumberjack.destination) < 15:
            location_array = TileFuncs.get_vnn_array(self.lumberjack.world,(self.lumberjack.location), self.lumberjack.view_range)

            for location in location_array:
                test_tile = TileFuncs.get_tile(self.lumberjack.world,location)
                if test_tile.name == "GrassWithCenterTree":
                    self.lumberjack.Tree_tile = test_tile
                    self.lumberjack.tree_id = test_tile.id

                    self.lumberjack.destination = location.copy()
                    return "Chopping"

            BaseFunctions.random_dest(self.lumberjack)
Ejemplo n.º 5
0
    def check_conditions(self):
        if self.angler.location.get_distance_to(
                self.angler.destination) < self.angler.max_speed:
            location_array = TileFuncs.get_vnn_array(self.angler.world,
                                                     (self.angler.location),
                                                     self.angler.view_range)

            for location in location_array:
                # TODO: This will make the angler go into the water, change this to go to the nearest walkable tile.
                test_tile = TileFuncs.get_tile(self.angler.world, location)
                if test_tile.__class__.__name__ == "WaterTile":

                    self.angler.destination = location.copy()
                    return "Fishing"

            BaseFunctions.random_dest(self.angler)
Ejemplo n.º 6
0
    def check_conditions(self):
        if self.lumberjack.location.get_distance_to(
                self.lumberjack.destination) < 15:
            location_array = TileFuncs.get_vnn_array(
                self.lumberjack.world, (self.lumberjack.location),
                self.lumberjack.view_range)

            for location in location_array:
                test_tile = TileFuncs.get_tile(self.lumberjack.world, location)
                if test_tile.name == "GrassWithCenterTree":
                    self.lumberjack.Tree_tile = test_tile
                    self.lumberjack.tree_id = test_tile.id

                    self.lumberjack.destination = location.copy()
                    return "Chopping"

            BaseFunctions.random_dest(self.lumberjack)
Ejemplo n.º 7
0
    def feedFoward(self,X):

        a = X.copy() # To avoid changing the values of the input outside the scope of the method.
        aList = []

        for w,b in zip(self.weights,self.bias):

            z = numpy.add(a@w,b) # Applying layer weight to previous activation and adding bias.
            a = BaseFunctions.sigmoid(z) # Activating z with the sigmoid function.
            aList.append(a)

        return aList
Ejemplo n.º 8
0
    def do_actions(self):
        current_tile = TileFuncs.get_tile(self.farmer.world, self.farmer.location)
        if current_tile.tillable:
            darkness = pygame.Surface((self.farmer.TileSize, self.farmer.TileSize))
            darkness.set_alpha(current_tile.darkness)

            new_tile = Tile.SoilTile(self.farmer.world, "Soil2")
            new_tile.darkness = darkness

            new_tile.location = current_tile.location
            new_tile.rect.topleft = new_tile.location
            new_tile.color = current_tile.color # TODO: Figure out what this does.

            self.farmer.world.tile_array[int(new_tile.location.y / 32)][int(new_tile.location.x / 32)] = new_tile
            self.farmer.world.world_surface.blit(new_tile.img, new_tile.location)
            self.farmer.world.world_surface.blit(darkness, new_tile.location)
            # TODO: Update the minimap

            BaseFunctions.random_dest(self.farmer)

        elif self.farmer.location.get_distance_to(self.farmer.destination) < self.farmer.speed:
            BaseFunctions.random_dest(self.farmer)
Ejemplo n.º 9
0
 def check_conditions(self):
     """Check if the explorer should still be exploring"""
     if self.explorer.location.get_distance_to(self.explorer.destination) <= self.explorer.speed:
         BaseFunctions.random_dest(self.explorer)
Ejemplo n.º 10
0
 def entry_actions(self):
     """When the explorer starts exploring (enters exploring state)."""
     BaseFunctions.random_dest(self.explorer)
Ejemplo n.º 11
0
 def entry_actions(self):
     BaseFunctions.random_dest(self.lumberjack)
    # Training the data
    #
    # the traingset will have 130000 examples, since it is too heavy to load a 130000*784 array in one variable the data
    # will flow throught batches. 130 batches with 1000 examples each.
    for i in range(130):

        X = []
        Y = []

        for j in range(1000):

            TrainingSample = list(map(int, f.readline().split()))

            # the first element of each row is the answer of the case
            # it will be converged to an array in order to be compared to the output of the neural network.
            y = BaseFunctions.intToRow(TrainingSample[0], 10)
            Y.append(y)

            x = TrainingSample[1:]
            X.append(x)

        # to avoid overflow, the scale of X's values will be reduced.
        # now each element of x will be in the range [0,1]
        # 0 -> pure black
        # 1 -> pure white
        X = numpy.array(X) / 255
        Y = numpy.array(Y)

        C = Nu.Cost(X, Y)
        print("Cost of Batch {} = {}".format(i + 1, C))
Ejemplo n.º 13
0
    def predict(self,X):
        
        a = self.feedFoward(X)[-1]
        a = BaseFunctions.moldData(a) # rouding the values.

        return a
Ejemplo n.º 14
0
 def entry_actions(self):
     BaseFunctions.random_dest(self.angler)
Ejemplo n.º 15
0
 def entry_actions(self):
     BaseFunctions.random_dest(self.angler)
Ejemplo n.º 16
0
import os
os.chdir("/Users/MRisk/Desktop/SpaceFillingCurves/SpaceFilling")
import BaseFunctions as SFC
import numpy as np
import matplotlib.pyplot as plt

plotA = plt.figure(figsize=(7, 7))
plotA = plt.plot(*zip(*SFC.Hilbert_Polygon(5)), color="black", linewidth=5)
plotA = plt.axis('off', emit=False)
plt.show()

x1, y1 = zip(*SFC.Hilbert_Polygon(2))
x2, y2 = zip(*SFC.Hilbert_Polygon(3))

fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(6, 3))
axes[0].plot(x1, y1, linewidth=3, color="black")
axes[1].plot(x2, y2, linewidth=3, color="black")
axes[0].grid(b=True)
axes[1].grid(b=True)
axes[0].set_xticks([0, 0.25, 0.5, 0.75, 1])
axes[0].set_yticks([0, 0.25, 0.5, 0.75, 1])
axes[1].set_xticks([0, 0.25, 0.5, 0.75, 1])
axes[1].set_yticks([0, 0.25, 0.5, 0.75, 1])
axes[0].set_xticklabels([0, "", "", "", 1])
axes[0].set_yticklabels([0, "", "", "", 1])
axes[1].set_xticklabels([0, "", "", "", 1])
axes[1].set_yticklabels([0, "", "", "", 1])
axes[0].set_xlim([0, 1])
axes[0].set_ylim([0, 1])
axes[1].set_xlim([0, 1])
axes[1].set_ylim([0, 1])
Ejemplo n.º 17
0
 def entry_actions(self):
     BaseFunctions.random_dest(self.lumberjack)
Ejemplo n.º 18
0
 def check_conditions(self):
     if self.fishing_ship.location.get_distance_to(self.fishing_ship.destination) < self.fishing_ship.speed:
         BaseFunctions.random_dest(self.fishing_ship)
Ejemplo n.º 19
0
 def entry_actions(self):
     BaseFunctions.random_dest(self.arborist)
Ejemplo n.º 20
0
 def entry_actions(self):
     BaseFunctions.random_dest(self.farmer)