Tuesday, December 11, 2012

Lunar Lander

Just made a lunar lander game thingy based on some of the constraints found at http://www.cs.carleton.edu/faculty/dmusican/cs111s10/lunarlander.html. /shruggies, took about 10 minutes.

basic lunar lander simulation based on constraints found at:

import sys

class LunarLander(object):
    'Lunar lander object'
    def __init__(self):
        self.altitude = 10
        self.velocity = 4
        self.fuel = 2
    def getVelocity(self):
        return self.velocity
    def getAltitude(self):
        return self.altitude
    def getFuel(self):
        return self.fuel
    def thrust(self, fuel):
        if fuel > self.fuel:
            self.velocity -= fuel * 4
            self.fuel = 0
        self.velocity -= fuel * 4
        self.fuel -= fuel
    def tick(self, fuel):
        self.velocity += 2
        self.altitude -= self .velocity
        #check for landing or crash
        if self.altitude <= 0 and self.velocity < 5:
            print 'skrrttt~ Houston, we have landed. ~skrrtt~ Victory! \'Murica! Fuck yeah!'
        elif self.altitude <= 0 and self.velocity > 4:
            print 'Oh no, you crashed!'
    def report(self):
        print '\nAlt = %d Vel = %d Fuel = %d' % (self.getAltitude(),
    def restart(self):
        restart = raw_input('Replay? Y/N >')
        if restart.lower() == 'y':
        sys.exit('game over!')
def main():
    print 'Welcome to Lunar Lander!'
    lander = LunarLander()  

    running = True
    while running:
        x = 0
        x = input('input thrust: ')


compiling binaries in the UNIX environment with gcc compiler... from the *nix command line! woot.

vim commands
:q quit, save
:w save
:q! quit without saving

i : insert mode
esc : command mode
h, j, k, l : movement in command mode
w, e : skip to the beginning/end of next word
f, n : find next instance of the word, goto Next instance
A : move to end of line and insert mode (A = append?)
$ : move to end of line
gg, G : move to beginning/end of the file

-i just realized i ought to write my blogposts in vim from now on....

UNIX terminal stuff
permission groups, directory bits
the command I should never ever use: "rm -rf /" aka "recursively remove everything from the contents of root"

./executable : execute file in the current directory?
rm - remove file
mkdir - make directory
cp file file2 - make copy of file to file2name
ls -la - list directory -l = long (permissions), -a = all
touch <filename.ext> : create file
vim <filename optional> : enter vim, edit file or create file
cat : output contents of file
| : (pipes) -> redirect stdout of one program to stdin or another prog1 stdout | prog2 stdin
chmod (a+x) : change permissions... ??
chown : change owners
sudo : "superuser do" -> execute program with root authority [not safe]

gcc complier stuff
makefiles are utility scripts that are used by gcc to compile / clean your binaries in a specified way
gcc looks for these files (in order): GNUMakefile, Makefile, makefile
can call with a certain  makefile in mind, e.g., makefile -f MyMakeFile <file to make>