Showing posts with label TIL. Show all posts
Showing posts with label TIL. Show all posts

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.



#!/usr/bin/python
'''
lunar_lander.py
basic lunar lander simulation based on constraints found at:
http://www.cs.carleton.edu/faculty/dmusican/cs111s10/lunarlander.html
'''

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.thrust(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!'
            self.restart()
        elif self.altitude <= 0 and self.velocity > 4:
            print 'Oh no, you crashed!'
            self.restart()          
    def report(self):
        print '\nAlt = %d Vel = %d Fuel = %d' % (self.getAltitude(),
                                           self.getVelocity(),
                                           self.getFuel())
    def restart(self):
        restart = raw_input('Replay? Y/N >')
        if restart.lower() == 'y':
            main()
        sys.exit('game over!')
             
def main():
    print 'Welcome to Lunar Lander!'
    lander = LunarLander()  

    running = True
    while running:
        lander.report()
        x = 0
        x = input('input thrust: ')
        lander.tick(x)            
main()

Tuesday, October 9, 2012

Scratchlist #1

So this is my scratchlist, which is a bunch of mental throw-up about stuff I'm working on, learning, and stuff I'm planning on learning next. Might as well write it down and keep track.


project: search engine
In the process of launching learning how to launch my basic search engine from Udacity CS101.  Need to work on receiving and handling queries via forms and familiarize with Google AppEngine's framework.  I do see a problem: I don't really know what I should use for my search corpus.  Ideally, this would be some set of pages whose links eventually terminate, but I can't have my web crawler crawling an infinite # of links.  I think I will have to implement some sort of 'depth-limiter' into the crawler to establish a stopping point for link-indexing.  How?  I don't know.

project: text-based Pokemon game clone
Main objective is practicing OOP-basics in Python.  Perhaps this can also be a good app to experiment on later when I learn some socket-handling and want to make it into a multiplayer game.  That'd really be cool, but I'll have to put that one on the back-burner right now.

project: blog platform
Developing in tandem with CS253 Web Applications class from udacity.com.  This is a great project to learn database interaction with.  I mean, a blog post is essentially a string of text, stored in a table somewhere, should be easy as pie, right? WRONG.

setting up my new domain!
I took the plunge and shelled out for my own domain. Probably a bit premature, but for now at least I have my own little playground.

the Command Line
I feel like science dog when I open terminal.  Forcing myself to do accomplish as much as I know how to do with a CLI instead of gui's... the main reason for this is so many tutorial and educational resources out there basically expect such knowledge, and I don't feel comfortable just entering sudo commands without knowing what effect they'll have.

Java
This is another thing I want to learn in order to better understand what I'm learning (huh? paradox).  Lately I've come across a couple treasure troves of knowledge, all taught in java, which is a strictly-typed language unlike Python, which is dynamically-typed.

check out TheCherno's awesome gamedev tutorial series:  http://www.youtube.com/watch?v=GFYT7Lqt1h8


Friday, September 21, 2012

Toes in the Water!

Here's my first progress update.

I've been following the CS101 - Introduction to Computer Science course on udacity.com.  I've just started Unit 6.  Thus far, we've learned so much about many new concepts that I haven't encountered in  any of the "Intro to Language X" tutorials out there.  I've come to the realization that just getting a program to perform the desired function is really only the tip of the iceberg.  Writing efficient, scalable, optimized, and understandable code is really going to be the hallmark of a pro vs. someone who's still fiddling with the basics.

These concepts are rumbling around in my head like sneakers in a dryer:
  • Architecture of data structures
  • Indexes & Hash Tables
  • Fibonacci Sequences
  • Recursion
We spent most of Unit 5 developing our own hash table from scratch, with create, update, and lookup functions based on a "bucket" system.  The idea behind it was to return a hash value that could be used to narrow down an index search.  When we finally got the thing up and running, the python data type dict was introduced and I'm sure I wasn't the only person having a "oh c'mon... I could have used this from the get-go" moment.

After implementing the dict in my index instead of a nested list, I really appreciated how fast it was to retrieve a value given a key.... and the fact that we built our own version of a dictionary is what allowed me to appreciate that.  I'm not completely sure what kind of algorithm Python is using to make searching easier, I just know there is one.  +1 Understanding!