Wednesday, August 10, 2011

A Hippocampus Anatomy Game

Problem: Write a game, any kind of game. Just start doing it, do a small version, make it bigger, keep a list of things to do, and do them.

I made this Choose Your Own Adventure-like game as practice after learning about branches and functions, if-else statements and while loops. I wanted to make an educational game that incorporated a deep interest of mine, neuroscience. So the subject of this game is a way to learn and explore one of the most studied regions in the brain, the hippocampus. The hippocampus is primarily known to be involved in memory and is located in the medial temporal lobe. Keep in mind: this region is very complex and this is only a crude (but hopefully fun) way to explore it.

This turned out to be fairly straightforward endeavor, thanks to Zed Shaw's Learn Python the Hard Way. I really enjoyed reviewing the anatomy of the hippocampus and finding better ways to navigate through the game. As of yet, I haven't used classes, lists nor dictionaries in this version of the game, but plan on doing so in the next. If you have any suggestions within these parameters, please feel free to share them.

In this game, you are in control and can decide where you want to travel and how much you want to learn about the hippocampus anatomy.

Here's what the code looks like:
from sys import exit

def entorhinal_cortex():
    print "You are currently in between layer 2 and 3 of the entorhinal cortex. You have the option of traveling in either layer. Which layer do you want to walk along?"

    next = raw_input ("> ")
    if "2" in next or "3" in next:
        how_much = int(next)
        dead("Sorry, no can do. Guess you're stuck in the entorhinal cortex!")
    if how_much == 2:
        print "Welcome! Now you have the option of exploring the dentate gyrus or the hippocampal region CA3. Enter your choice."

        while True:
            next = raw_input("> ")
            if next.lower() == "dentate gyrus":
            elif next.lower() == "hippocampal region ca3":
                print "That doesn't make much sense. Try typing that in again."
    elif how_much == 3:
        print "Sweet pick. Since the entorhinal cortex has 2 major projections, you have the option of exploring the hippocampal region CA1 or the subiculum. Enter your choice."

        while True:
            next = raw_input("> ")
            if next.lower() == "hippocampal region CA1":
            elif next.lower() == "subiculum":
                dead("You just missed out on such a good adventure. Bummer.")

def dentate_gyrus():
    print "Ah, the dentate gyrus. Good pick. The dentate gyrus is one of the few regions in the adult brain where neurogenesis is thought to take place. It also plays a role in depression."
    print "There are three major types of neurons found here."
    print "Would you like to learn about them?"

    while True:
        next = raw_input ("> ")
        if next.lower() == "yes":
            print "The dentate gyrus primarily consists of granule cells, interneurons and pyramidal cells." 
            print "The dentate gyrus' main projection is to the CA3. So off to there you go!"
            dead("Aww, too bad. Guess you don't really want to explore the hippocampus.")

def hippocampal_region_CA3():
    print "Now you're in the hippocampal region CA3 or simply, CA3."
    print "There are a few proposed behavioral functions of the CA3."
    print "Would you like to learn about one?"

    next = raw_input ("> ")
    if next.lower() == "yes":
        print "The CA3 plays a role in the encoding of new spatial information within short-term memory with a duration of seconds and minutes."
        print "The CA3's main projection is to the CA1. So that's where you're headed to next."
        dead("Ok, you missed out. But no problem.")
def subiculum():
    print "Hey, now you're in the most inferior region of the hippcampus called the subiculum. It lies between the entorhinal cortex and the CA1."
    print "Do you want to stay or leave?"

    next = raw_input("> ")
    if next.lower() == "stay":
        dead("Alright guess I'll leave you here.") 
    elif next.lower() == "leave":
        print "Huh? Try again."

def hippocampal_region_CA1():
    print "--------------------"
    print "Welcome to the hippocampal region CA1 or simply, CA1."
    print "This region sends a large amount of output to the subiculum and some inputs back to the entorhinal cortex."
    print "Which way would you like to travel?"

    while True:
        next = raw_input("> ")
        if next.lower() == "subiculum":
        elif next.lower() == "entorhinal cortex":
            print "Try typing that again."
def entorhinal_cortex_2():
    print "You have now, more or less, made a full loop within the connections of the hippocampus. Congratulations!"
    print "If you want to explore a bit more, please replay the game! Is this what you want to do?"
    next = raw_input("> ")
    if next.lower() == "yes":
        dead("Thanks for playing.")
def dead(why):
    print why, "Have a good one."

def start():
    print "Hello. You're about to explore the hippocampus."
    print "There will be many paths and therfore, many decisions you can make."
    print "Enter 'Ready!' when prompted and you can begin your journey."

    next = raw_input("> ")  

    if next.lower() == "ready!":
        dead("Maybe another time!")

Here's what the output of one possible route looks like:
In my desire to add more flexibility to the program, I only experimented with how to allow the user to be able to respond to prompts in any case. This actually took me a little experimenting (and time) to figure how to do in a concise way.

Goals for improving the code and behavior of this game:
1) Make it more concise and clearer to read. Remove any repetition.
2) Incorporate classes, lists and dictionaries.
3.) Figure out how to travel backwards through the game. Give the user a chance to change their mind and reverse direction.
4.) This game made me realize that I don't know the full extent of possible operations that I have at my disposal. I want to experiment with more of them in the next version of the game.

1.) Is there anything in my code that is considered bad practice?
2.) What are some ways that I can condense the code?
3.) Can I improve the naming of functions?
If you'd like a copy of the program to play with (and expand!), you can go here

1 comment:

  1. Answering to your questions...
    1) raw_input allows any input from the user... you should check if the input is the type you expected, if not... tell the user to do the input again... this can be done with something like this...
    for example... in a numeric situation...

    value = 0
    >>>>value = int(raw_input('some message: '))
    >>except ValueError:
    >>>>print 'The value is not a number!'
    ... more code here...

    the ">" notation... goes for spacing

    1 & 2) using classes, dictionaries and lists will condense the code making it cleaner and better...

    3) The naming... is alright as long as it represents something to your domain...
    for example...

    picture you are devoloping some mapping software...
    THIS is OK:

    class Map(object):
    >>def introduceCoordinates(self,x,y):
    >>>>...some code...

    THIS is WRONG:

    class Map(object):
    >>def doYourThing(self,x,y):
    >>>>...some code being the same as above...

    Hope it does help you