Skip to content

Instantly share code, notes, and snippets.

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
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)
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
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]
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)
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)
%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)
@yvan
yvan / tangent.py
Last active October 28, 2017 17:13
%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)
%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))
@yvan
yvan / calc_reg.py
Last active October 28, 2017 16:26
# 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)