This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame | |
# declare the size of the map | |
# and the size of map tiles | |
# tile size is in pixels | |
# other sizes are in number of | |
# tiles | |
TILESIZE = 40 | |
MAPWIDTH = 30 | |
MAPHEIGHT = 20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import pygame | |
# this imports things like KEYDOWN, QUIT, and other | |
# useful pygame constants so we have them readily available | |
from pygame.locals import * | |
# create a black color | |
# R,G,B = 0, 0, 0 | |
BLACK = (0,0,0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import random | |
import pygame | |
from pygame.locals import * | |
# declare resources | |
DIRT, GRASS, WATER, COAL, CLOUD, WOOD = 0, 1, 2, 3, 4, 5 | |
# declare valuable resources | |
FIRE, SAND, GLASS, ROCK, STONE, BRICK, DIAMOND = 6, 7, 8, 9 , 10, 11, 12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import random | |
import pygame | |
from pygame.locals import * | |
DIRT, GRASS, WATER, COAL, CLOUD, WOOD = 0, 1, 2, 3, 4, 5 | |
FIRE, SAND, GLASS, ROCK, STONE, BRICK, DIAMOND = 6, 7, 8, 9 , 10, 11, 12 | |
# declare resources for inventory interface | |
resources = [DIRT, GRASS, WATER, COAL, WOOD, FIRE, SAND, GLASS, ROCK, STONE, BRICK, DIAMOND] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import random | |
import pygame | |
from pygame.locals import * | |
DIRT, GRASS, WATER, COAL, CLOUD, WOOD = 0, 1, 2, 3, 4, 5 | |
FIRE, SAND, GLASS, ROCK, STONE, BRICK, DIAMOND = 6, 7, 8, 9 , 10, 11, 12 | |
resources = [DIRT, GRASS, WATER, COAL, WOOD, FIRE, SAND, GLASS, ROCK, STONE, BRICK, DIAMOND] | |
WHITE = (255,255,255) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import random | |
import pygame | |
from pygame.locals import * | |
DIRT, GRASS, WATER, COAL, CLOUD, WOOD = 0, 1, 2, 3, 4, 5 | |
FIRE, SAND, GLASS, ROCK, STONE, BRICK, DIAMOND = 6, 7, 8, 9 , 10, 11, 12 | |
resources = [DIRT, GRASS, WATER, COAL, WOOD, FIRE, SAND, GLASS, ROCK, STONE, BRICK, DIAMOND] | |
WHITE = (255,255,255) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%matplotlib inline | |
import matplotlib.pyplot as plt | |
# calculate the cost at -5 | |
def f(w1): | |
return sum((w1*data['speed'] - data['dist'])**2) | |
w1 = -5 | |
h = 0.1 | |
x_tan = np.linspace(-10, 0, 15) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%matplotlib inline | |
import matplotlib.pyplot as plt | |
# calculate the cost at -5 | |
def f(w1): | |
return np.mean((w1*data['speed'] - data['dist'])**2) | |
w1 = -5 | |
h = 0.1 | |
x_tan = np.linspace(-10, 0, 15) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%matplotlib inline | |
import matplotlib.pyplot as plt | |
# calculate the cost for many different values | |
# of w1 using our cost function | |
costs = [] | |
for i in range(-10,11,1): | |
w1 = i | |
y_actual = data['dist'] | |
y_predict = w1*data['speed'] | |
costs.append(np.mean((y_predict - y_actual)**2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# performs the gradient descent for linear regression | |
def calc_regression_simple(w1, frames, x_data, y_data): | |
learn_rate = 0.001 | |
ys = [] | |
for i in range(frames): | |
# get the gradient and update the parameter | |
w1_gradient = 2*np.mean(x_data*(w1*x_data - y_data)) | |
w1 = w1 - (w1_gradient*learn_rate) | |
# calculate the predictions from this new function | |
x = np.linspace(0,30) |
OlderNewer