Skip to content

Instantly share code, notes, and snippets.

@TylerLeite
TylerLeite / PCHD2013.py
Last active December 22, 2015 10:29
PacmanCheckersHeroDeathmatch20013
'''Pacman Checkers Hero Deathmatch 2013
A game by Tyler Leite
'''
# This app is made using Pythonista, an iOS application for creating Python programs
# with audio, graphics, and touch input.
# Documentation for Pythonista can be found here: http://omz-software.com/pythonista/docs/ios/
from scene import *
from random import seed, randrange
@TylerLeite
TylerLeite / TextGame.py
Created September 7, 2013 13:34
Text-based game engine
class Game:
def __init__(self):
self.flags = '1 0 0 0 0 0 0 0'.split()
def check_flags(self, line):
flags = line.split()[1].replace('flags:', '')
if flags == 'none':
return True
for f in range(len(flags)):
if flags[f] == '1' and self.flags[f] == '0':
@TylerLeite
TylerLeite / Vec2.py
Created September 7, 2013 14:06
2d vector class
from math import atan2, sin, cos, sqrt, pi, floor
class Vec2:
def __init__(self, x=0, y=0, form='rect'):
self.x = x
self.y = y
if form == 'rect' or form == 'polar':
self.form = form
else:
print('Invalid Vec2 form: %s' % form)
@TylerLeite
TylerLeite / RPS.py
Last active December 24, 2015 06:09
Rock paper scissors with simple AI
from random import *
def one_liner():
while raw_input('You %s. ' % choice('win lose draw'.split())).lower() not in 'stop exit quit'.split(): party_time = True
def pro_strats():
wins = dict(zip('rock paper scissors'.split(), 'scissors rock paper'.split())) #what beats what
loses = dict(zip('rock paper scissors'.split(), 'paper scissors rock'.split())) #what loses to what
hist = list()
clever = False
@TylerLeite
TylerLeite / RegLog.py
Last active December 25, 2015 13:39
Simple login / registration script.
from datetime import datetime
from hashlib import *
from bcrypt import hashpw, gensalt
def super_hash_bros(string, salt):
if salt is None:
salt = gensalt()
return (hashpw(string, salt), salt) # not technically how this is used,
# salt already returned by hashpw
@TylerLeite
TylerLeite / Cockatrice to XMage.py
Last active September 4, 2022 19:22
.cod to .dec file converter
from os import remove
from uuid import uuid4
def get_xml_tag(line):
tag = line = line.strip(' ').strip('<')
tag = tag.split(' ')[0]
if '>' in tag:
tag = tag.split('>')[0]
return tag
@TylerLeite
TylerLeite / random.cpp
Last active March 15, 2019 17:55
Tiny RNG in c++
#include <ctime>
class Random {
public:
Random(int seed=time(NULL)) : m_seed(seed) {}
//Return a random number from 0 to range-1
int next(const int range){
m_seed = (1028597*m_seed + 488249) % 1737017;
return m_seed % range;
@TylerLeite
TylerLeite / random_language.py
Last active October 28, 2018 15:52
Randomly Generated Language With Comparison to Hamlet
import random as r
# Probability distribution of each syllable
syllables = list('11111222222222222222222222333333333333333344456')
# Consonants that can start a word
c_s = "w,wr,r,t,tw,th,thr,y,p,ph,pr,d,dr,f,fr,fl,g,gl,gr,gh,h,j,k,kl,kr,c,ch,cl,cr,z,v,b,br,n,m,s,sl,sk,sm,sn,st,fr,l".split(',')
# Consonants in the middle of a word
c_m = "w,ws,wd,wr,wt,wth,wp,wk,wn,wm,wb,r,rt,rp,rm,rn,rc,rb,rl,rk,rd,rs,rth,rch,t,th,thr,tch,t,ts,y,ys,p,pl,pr,ps,s,sh,sch,st,sm,sn,dr,ddl,dd,f,ff,fr,fl,mp,mn,gs,gl,j,k,kl,kr,kw,l,ll,lm,ls,sl,sk,z,zz,ch,cr,ct,cl,ck,v,b,br,bs,bl,n,ns,m,ms,nth".split(',')
import random
class TicTacToeNode:
def __init__(self):
self.board = ['.'] * 9
self.win_states = (\
[0,1,2], [3,4,5], [6,7,8],\
[0,3,6], [1,4,7], [2,5,8],\
[0,4,8], [2,4,6]\
)
@TylerLeite
TylerLeite / creature_generate.py
Last active December 2, 2016 19:51
Create a random creature
#disgusting code dont try to read
from PIL import Image, ImageFilter
import os
import sys
import random
import math
def fill(arr, x, y):