Programming Q&A

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Derakon
    Prophet
    • Dec 2009
    • 9022

    Programming Q&A

    We have a wide range of developers here, of varying levels of experience and with varying types of expertise. Some of us are just starting out, or have been playing in a very specific domain (say, a certain large C program) and want to branch out. Others have more experience. It occurred to me that it would probably be a good idea to have an area where we could help train each other. So let's open this thread up to questions, and then whoever feels themselves competent can come in and give advice.

    Personally my areas of greatest expertise are object-oriented development and Python, though I still remember a decent amount of C. So come on, hit me.
  • Antoine
    Ironband/Quickband Maintainer
    • Nov 2007
    • 1010

    #2
    Does anyone know much about Pygame for Android? (he asked hopefully)

    A.
    Ironband - http://angband.oook.cz/ironband/

    Comment

    • Derakon
      Prophet
      • Dec 2009
      • 9022

      #3
      I have some experience with PyGame in general, none with Android.

      My thinking on this thread was that we'd stay somewhat removed from specific technologies and instead discuss strategies and concepts. It's more of a catchup-school for people who never got to take mid- or upper-level programming courses than it is a replacement for, say, StackOverflow.

      Comment

      • Antoine
        Ironband/Quickband Maintainer
        • Nov 2007
        • 1010

        #4
        Originally posted by Derakon
        I have some experience with PyGame in general, none with Android.

        My thinking on this thread was that we'd stay somewhat removed from specific technologies and instead discuss strategies and concepts. It's more of a catchup-school for people who never got to take mid- or upper-level programming courses than it is a replacement for, say, StackOverflow.

        I reread that post three times and all i hear is you offering to debug my Pygame code. I'll email you the source.

        A
        Ironband - http://angband.oook.cz/ironband/

        Comment

        • Magnate
          Angband Devteam member
          • May 2007
          • 5110

          #5
          Originally posted by Antoine
          I reread that post three times and all i hear is you offering to debug my Pygame code. I'll email you the source.
          Brilliant. I just laughed my cup of tea all over the place.

          So, Derakon, my first question is about stats. In Angband, stats are an array which is part of the state struct: p_ptr->state.stat_ind[] ... and the individual stats are #defines.

          I thought it would be helpful to define stats in an external file (excuse me but I am unfamiliar with JSON so will use Angband-style config) which could contain things like:

          N:1
          Label: STR
          Name: Strength
          Description: An entity's physical strength - important for carrying stuff, hitting things hard and opening doors.
          Min: 3
          Max: 40

          So my question is, is it possible to read that stuff in from the file and then refer to stat[STR] in the code? Come to think of it, I wouldn't know how to do this in C either, but I'm actually interested in Python because I kind of have a hunch that Python can do this.

          (Let's leave aside the question of why one would hard-code references to stats which are defined in an external file - one thing at a time!)
          "Been away so long I hardly knew the place, gee it's good to be back home" - The Beatles

          Comment

          • Mikko Lehtinen
            Veteran
            • Sep 2010
            • 1246

            #6
            Originally posted by Derakon
            It's more of a catchup-school for people who never got to take mid- or upper-level programming courses
            Mid- or upper level? Hmm.

            I'd like to read a book about beginning C programming. It would need to be well and intelligently written, so I could just read it from cover to cover leisurely, maybe taking peeks at the Angband code at the same time.

            I've actually managed to code in all the game mechanics I've been able to think of, and I'm getting quite fast at it, but I sometimes have to do things in a very stupid and ugly manner. I care much more about the beauty of the game mechanics than about the beauty of the code, but still... It bothers me a bit.

            Programming is only in a minor way related to my work -- text processing and web development are most useful areas.

            Comment

            • Timo Pietilä
              Prophet
              • Apr 2007
              • 4096

              #7
              Originally posted by Mikko Lehtinen
              Mid- or upper level? Hmm.

              I'd like to read a book about beginning C programming. It would need to be well and intelligently written, so I could just read it from cover to cover leisurely, maybe taking peeks at the Angband code at the same time.

              I've actually managed to code in all the game mechanics I've been able to think of, and I'm getting quite fast at it, but I sometimes have to do things in a very stupid and ugly manner. I care much more about the beauty of the game mechanics than about the beauty of the code, but still... It bothers me a bit.

              Programming is only in a minor way related to my work -- text processing and web development are most useful areas.
              I have had some c courses, but my teacher was a nutjob that didn't have a clue about programming. To get an equivalent of "A" (not our scale) you just needed to indent your nonsense code by three spaces and make it look pretty. It didn't matter did the code actually work or even compile, just remember to indent by three spaces. And remember to never ever ask anything about your code (you ended up with even more crazy coding assignment and never got an answer to your question).

              I have learned c much more by examining angband code than I ever did in that course. Not that I have learned much by examining that code. Just more.

              To Q&A about angband code is how do you know which file does what and how to follow the flow of the code (flowchart??) to figure out what you need to change in order to actually change the thing you are changing.

              Comment

              • Mikko Lehtinen
                Veteran
                • Sep 2010
                • 1246

                #8
                Originally posted by Timo Pietilä
                To Q&A about angband code is how do you know which file does what and how to follow the flow of the code (flowchart??) to figure out what you need to change in order to actually change the thing you are changing.
                grep is my best friend.

                Comment

                • Timo Pietilä
                  Prophet
                  • Apr 2007
                  • 4096

                  #9
                  Originally posted by Mikko Lehtinen
                  grep is my best friend.
                  In order to use grep you need to know what you are searching. My question goes one step up from that: how do you know what to search?

                  Comment

                  • Mikko Lehtinen
                    Veteran
                    • Sep 2010
                    • 1246

                    #10
                    I can't google up Leon Marrick's article "Caveman Guide to Angband Programming". It was really useful to me. I think it used to be in Thangorodrim, and the site seems to be down. Does anyone have a copy of the article somewhere? Let's put it back on the web!

                    Comment

                    • Magnate
                      Angband Devteam member
                      • May 2007
                      • 5110

                      #11
                      Originally posted by Mikko Lehtinen
                      I can't google up Leon Marrick's article "Caveman Guide to Angband Programming". It was really useful to me. I think it used to be in Thangorodrim, and the site seems to be down. Does anyone have a copy of the article somewhere? Let's put it back on the web!
                      Found it ...

                      EDIT: for some reason that link doesn't take you straight there. You need to click on the "Impatient?" link in the bottom-right corner.
                      "Been away so long I hardly knew the place, gee it's good to be back home" - The Beatles

                      Comment

                      • Nick
                        Vanilla maintainer
                        • Apr 2007
                        • 9634

                        #12
                        Originally posted by Mikko Lehtinen
                        I can't google up Leon Marrick's article "Caveman Guide to Angband Programming". It was really useful to me. I think it used to be in Thangorodrim, and the site seems to be down. Does anyone have a copy of the article somewhere? Let's put it back on the web!
                        Wayback machine link to Thangorodrim, and look in the Angband Development link. Sheer coincidence that I stumbled on that today.

                        EDIT: Well, that's two coincidences
                        One for the Dark Lord on his dark throne
                        In the Land of Mordor where the Shadows lie.

                        Comment

                        • fizzix
                          Prophet
                          • Aug 2009
                          • 3025

                          #13
                          Originally posted by Timo Pietilä
                          In order to use grep you need to know what you are searching. My question goes one step up from that: how do you know what to search?
                          This is a good question. My usual approach, which may not be the best but usually works, is to search for an in-game message string that is somewhat related to what I want to change, and trace from there, often by figuring out what called that function, and so on.

                          There probably are more elegant approaches, but this was my go-to method when I started, and I still use it when I'm working in sections of the code that I am unfamiliar with.

                          Comment

                          • Derakon
                            Prophet
                            • Dec 2009
                            • 9022

                            #14
                            Fizzix's technique is the same one I use. Unfortunately, finding the code that performs a given task in Angband's codebase is not very easy, especially since there's no particular pattern you can search for to limit your search to function definitions.

                            Magnate: yes, what you want is possible. You should use a datatype known as a "map" (or, in Python, a "dict", for dictionary). This container maps one object to another. For example:
                            Code:
                            >>> foo = dict()
                            >>> foo[1] = 'apples'
                            >>> foo['bananas'] = [4, 5, 6]
                            >>> print foo
                            {1: 'apples', 'bananas': [4, 5, 6]}
                            >>> foo['bananas']
                            [4, 5, 6]
                            >>> foo['carrots']
                            Traceback (most recent call last):
                              File "<stdin>", line 1, in <module>
                            KeyError: 'carrots'
                            So you could create a dict named "stats" and then load it up so that stats['STR'] referred to the creature's STR stat.

                            Comment

                            • Magnate
                              Angband Devteam member
                              • May 2007
                              • 5110

                              #15
                              Originally posted by Derakon
                              So you could create a dict named "stats" and then load it up so that stats['STR'] referred to the creature's STR stat.
                              Excellent, thank you. I'll see if I can get that sorted out then. ISTR you have already done code for reading in JSON-format text files, so I'll crib from that.
                              "Been away so long I hardly knew the place, gee it's good to be back home" - The Beatles

                              Comment

                              Working...
                              😀
                              😂
                              🥰
                              😘
                              🤢
                              😎
                              😞
                              😡
                              👍
                              👎