Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 3 4 [5] 6

Author Topic: Astronaut text based game (Python)  (Read 8541 times)

Frajic

  • Bay Watcher
    • View Profile
Re: Astronaut text based game (Python)
« Reply #60 on: January 19, 2011, 10:59:55 am »

Code: [Select]
                   vostok1crew = Cosmonaut[0][1] # First, we declare the "vostok1crew" variable. I chose to make it the skill of the first cosmonaut, but 0 is just as good, if not better.
                   
            for cosmonaut in Cosmonaut: # Now, for every entry in Cosmonaut...
                if cosmonaut[1] > vostok1crew: # We'll check if the entry's skill is better than the current one.
                    vostok1crew = cosmonaut[1] # If so, we'll use that one instead.
^ the code, explained ^

EDIT: OH, and I forgot to explain. When you make a "for" loop, what you call the entry(like "for cosmonaut in Cosmonaut", in this case) will be what you refer to it as. It could be "cosmonaut" as well as "entry" or "fmvairlfkjs".
« Last Edit: January 19, 2011, 11:02:22 am by Dwarf Midget »
Logged
EoS company name: Vikings Inc.

Deadmeat1471

  • Bay Watcher
    • View Profile
Re: Astronaut text based game (Python)
« Reply #61 on: January 19, 2011, 11:10:10 am »

I get it now, thanks!

So the cosmonaut[1] was just a number to be replaced by a larger number in the list?
« Last Edit: January 19, 2011, 11:12:26 am by Deadmeat1471 »
Logged

Darvi

  • Bay Watcher
  • <Cript> Darvi is my wifi.
    • View Profile
Re: Astronaut text based game (Python)
« Reply #62 on: January 19, 2011, 11:20:29 am »

Gah, I did the cosmonauts in a seperate pad while I was testing, forgot to add the 'moral' statistic! Thanks for the spot!
Yea, suspected it might be like that.
Quote

Win!
Logged

Eagleon

  • Bay Watcher
    • View Profile
    • Soundcloud
Re: Astronaut text based game (Python)
« Reply #63 on: January 19, 2011, 11:25:55 am »

Here's where my lack of knowledge in Python may be dangerous, but it seems like there's a little bit of confusion here because the iterator is the same name as the list. It might actually be clearer like this
Code: [Select]
                   vostok1crew = Cosmonaut[0][1]
            for index in Cosmonaut:
                if Cosmonaut[index] > vostok1crew: #
                    vostok1crew = Cosmonaut[index] # If so, we'll use that one instead.
Notice, I changed the first 'cosmonaut' to 'index', and the '1's to 'index' as well - that's because the value of 'index' will cycle through however long the Cosmonaut list was. '1' is always just an integer - unless the for loop was actually resorting Cosmonaut, the other code would always just check the first entry.
Logged
Agora: open-source, next-gen online discussions with formal outcomes!
Music, Ballpoint
Support 100% Emigration, Everyone Walking Around Confused Forever 2044

Frajic

  • Bay Watcher
    • View Profile
Re: Astronaut text based game (Python)
« Reply #64 on: January 19, 2011, 12:43:23 pm »

Here's where my lack of knowledge in Python may be dangerous, but it seems like there's a little bit of confusion here because the iterator is the same name as the list. It might actually be clearer like this
Code: [Select]
                   vostok1crew = Cosmonaut[0][1]
            for index in Cosmonaut:
                if Cosmonaut[index] > vostok1crew: #
                    vostok1crew = Cosmonaut[index] # If so, we'll use that one instead.
Notice, I changed the first 'cosmonaut' to 'index', and the '1's to 'index' as well - that's because the value of 'index' will cycle through however long the Cosmonaut list was. '1' is always just an integer - unless the for loop was actually resorting Cosmonaut, the other code would always just check the first entry.
Won't work, due to this:
vostok1crew = Cosmonaut[index]

There aren't integers in Cosmonaut, there are more lists(aka cosmonauts).
Code: [Select]
Gagarin = ['Gagarin', 3, 1, 1, 1, 1]
Titov = ['Titov', 2, 1, 1, 1, 1]
Nikolayev = ['Nikolayev', 2, 1, 1, 1, 3]
Popovich = ['Popovich', 2, 1, 1, 2, 3]
Bykovsky = ['Bykovsky', 2, 2, 2, 2, 3]
Tereshkova = ['Tereskova', 0, 1, 1, 0, 1]
Player = ['Player', 3, 1, 1, 1, 1]

Cosmonaut = [Gagarin, Titov, Nikolayev, Popovich, Bykovsky, Tereshkova, Player]

We're looking for the largest [1] value in those lists. But yeah, naming the entries "cosmonaut" was a bad idea, seeing how confusing it is.
Logged
EoS company name: Vikings Inc.

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Astronaut text based game (Python)
« Reply #65 on: January 19, 2011, 12:51:11 pm »

Here's where my lack of knowledge in Python may be dangerous, but it seems like there's a little bit of confusion here because the iterator is the same name as the list. It might actually be clearer like this
Code: [Select]
                   vostok1crew = Cosmonaut[0][1]
            for index in Cosmonaut:
                if Cosmonaut[index] > vostok1crew: #
                    vostok1crew = Cosmonaut[index] # If so, we'll use that one instead.
Notice, I changed the first 'cosmonaut' to 'index', and the '1's to 'index' as well - that's because the value of 'index' will cycle through however long the Cosmonaut list was. '1' is always just an integer - unless the for loop was actually resorting Cosmonaut, the other code would always just check the first entry.
A for loop in Python, when looping over a collection, binds the loop variable to consecutive elements in the collection (granted, 'consecutive' doesn't make much sense for a dictionary, but it just treats the dictionary as a vector or array IIRC). So in this case, index is an element from Cosmonaut (and thus a misnomer).
Also, if I've got a collection that represents a collection of elements (as opposed to an array that represents a single map for example), I prefer to use plurals, to avoid confusions like this. "For each cosmonaut in comsonauts" looks better then "for each entry in cosmonaut", because the latter looks like I'm trying to loop over a single cosmonaut.
Logged

Deadmeat1471

  • Bay Watcher
    • View Profile
Re: Astronaut text based game (Python)
« Reply #66 on: January 20, 2011, 09:29:03 pm »

Tested mission code. I was too lazy to write it better but it works.
Spoiler (click to show/hide)


Bugs - improving skill is timesing not adding.
aseries makes the roll for all parts of mission
vostok1crew I think = 3 not the persons name
mission stages need to be in list, utilising if oib is in vostok1 etc etc.

Im going to be a good lil programmer and make a flow chart for mission res tomorrow. It will aid in my thinking.


Updated code

Spoiler (click to show/hide)
« Last Edit: January 20, 2011, 09:37:03 pm by Deadmeat1471 »
Logged

Darvi

  • Bay Watcher
  • <Cript> Darvi is my wifi.
    • View Profile
Re: Astronaut text based game (Python)
« Reply #67 on: January 21, 2011, 05:39:14 am »

Quote
Code: [Select]
[...]
##viewskills##
        if choice == '4':
            print 'Your skills are\n'
            print 'Cap: ' + str(c)[...]
Again, fixed.
 
Quote

Code: [Select]

##rest##
        elif choice == '1':
            mor = random.randint(0, 5)
            print 'moral increased by ' + str(increase) + ' to ' + str(m)
            time.sleep(2)
            choice = 5

##Socialise##
        elif choice == '3':
            vis = random.randint(0, 4)
            print 'You go to a local party, increasing your visibility to the elite by ' + str(increase) + ' making it ' + str(vis)
            time.sleep(2)
            choice = 5


This confuses me a little. Those values don't get increased, just replaced by a random number. Also, increase is never defined, I think. Unless I just missed it.
« Last Edit: January 21, 2011, 05:48:33 am by Darvi »
Logged

Deadmeat1471

  • Bay Watcher
    • View Profile
Re: Astronaut text based game (Python)
« Reply #68 on: January 21, 2011, 05:46:11 am »

How did i do that.
Logged

Deadmeat1471

  • Bay Watcher
    • View Profile
Re: Astronaut text based game (Python)
« Reply #69 on: January 21, 2011, 09:05:21 am »

I dont get those increases yet either, Im thinking what I had before was better. It worked and I could see why it worked :D
Logged

Darvi

  • Bay Watcher
  • <Cript> Darvi is my wifi.
    • View Profile
Re: Astronaut text based game (Python)
« Reply #70 on: January 21, 2011, 09:12:47 am »

Yeah, if anything, it should be like
Code: [Select]
##rest##
        elif choice == '1':
            increase = random.randint(0, 5)
            mor += increase
            if mor >= 100:
                     mor = 100
                     print 'moral is maximized!'
            else
                     print 'moral increased by ' + str(increase) + ' to ' + str(mor)
            time.sleep(2)
            choice = 5
Dose python have the =+ operator? *gugure*

Ok, it's +=.
« Last Edit: January 21, 2011, 09:18:05 am by Darvi »
Logged

Frajic

  • Bay Watcher
    • View Profile
Re: Astronaut text based game (Python)
« Reply #71 on: January 21, 2011, 09:15:48 am »

Code: [Select]
##rest##
        elif choice == '1':
            increase = random.randint(0, 5)
            m += increase
            print 'moral increased by ' + str(increase) + ' to ' + str(m)
            time.sleep(2)
            choice = 5

##Socialise##
        elif choice == '3':
            increase = random.randint(0, 4)
            vis += increase
            print 'You go to a local party, increasing your visibility to the elite by ' + str(increase) + ' making it ' + str(vis)
            time.sleep(2)
            choice = 5
Yeah, Python has [ x ]= operators.
Logged
EoS company name: Vikings Inc.

Darvi

  • Bay Watcher
  • <Cript> Darvi is my wifi.
    • View Profile
Re: Astronaut text based game (Python)
« Reply #72 on: January 21, 2011, 09:17:38 am »

Also I think visibility should be popularity. But that's just me.
Logged

Deadmeat1471

  • Bay Watcher
    • View Profile
Re: Astronaut text based game (Python)
« Reply #73 on: January 21, 2011, 03:05:15 pm »

Popularity sounds good, I just thought it was the wrong word. Popularity seems to me to be the amount people like you, wheras visibility is how respected and known you are. Just my reasons.
Logged

Darvi

  • Bay Watcher
  • <Cript> Darvi is my wifi.
    • View Profile
Re: Astronaut text based game (Python)
« Reply #74 on: January 21, 2011, 03:10:48 pm »

Social status then?
Logged
Pages: 1 ... 3 4 [5] 6