New OOTS products from CafePress
New OOTS t-shirts, ornaments, mugs, bags, and more
Page 6 of 12 FirstFirst 123456789101112 LastLast
Results 151 to 180 of 356

Thread: ProgrammersitP

  1. - Top - End - #151
    Titan in the Playground
    Join Date
    Mar 2009
    Location
    Sweden
    Gender
    Male

    Default Re: ProgrammersitP

    It seems like you allow i and j to increment above the greatest indices of the arrays, which could be a cause of your out of range error. What confuses me is that it doesn't crash for any other moves than those at the last row/column...
    Clouddreamer Teddy by me, high above the world, far beyond its matters...

    Spoiler: Banner by Vrythas
    Show

  2. - Top - End - #152
    Barbarian in the Playground
     
    BarbarianGuy

    Join Date
    Feb 2010
    Location
    Calgary
    Gender
    Male

    Default Re: ProgrammersitP

    My understanding of for loops in python is, when I do
    Code:
    for i in range(8)
    , it should start at 0 and go to 7 the 8 is not included.

    I tried changing my loop to 7 instead of 8, it doesn't get the error but I can't pick the last row or column.

    Our TA gave us a website that may help going to go over it right now.
    Last edited by Balain; 2012-12-05 at 04:47 PM.

  3. - Top - End - #153
    Titan in the Playground
    Join Date
    Mar 2009
    Location
    Sweden
    Gender
    Male

    Default Re: ProgrammersitP

    Playing around with Python a bit, I now think I know what your problem is caused by. The error lies just where I thought it was, but it turns out that negative indices let you index from the end of a list in Python, which is why it isn't triggered when you click any other square, which is what confused me in the first case.

    To clarify, I've marked the flawed parts of your code in red:
    Spoiler
    Show

    Code:
            delta = [[0,-1],[1,-1],[1,0],[1,1],[0,1],\
                                    [-1,1],[-1,0],[-1,-1]]
    Code:
            def play_move(self, move):
                    m,n=move[0],move[1]
                    for d in range(8):
                            i, j = m, n
                            if self.check_move(move,d):
                                    i, j = i+self.delta[d][0], j+self.delta[d][1]
                                    while self.board[i][j] == 1-self.turn:
                                            self.board[i][j] = self.turn
                                            i, j = i+self.delta[d][0], j+self.delta[d][1]
                    self.board[m][n]=self.turn

    When m or n is 7, i or j will for some d become 8, causing a list index out of range error to be thrown. This normally never occurs, because due to the above mentioned list oddity, you'll already have reversed (or whatever you call it. I don't know reversi) any tile to the right or below the clicked one, causing the loop to terminate before any offense has happened (I'm not sure what will happen if you keep playing, however), but when you click somewhere in the last row or column, the red line will increase the index before any tests can be made to break the bad habit.

    I suggest you change the blue line to this:
    Spoiler
    Show

    Code:
                                    while i != -1 and i != 8 and j != -1 and j != 8 and self.board[i][j] == 1-self.turn:

    This will cause the loop to break before testing a too large or negative index (as I suspect you don't want it to crawl over the edge to the left and reappear to the right, which is what it should be doing right now).
    Clouddreamer Teddy by me, high above the world, far beyond its matters...

    Spoiler: Banner by Vrythas
    Show

  4. - Top - End - #154
    Barbarian in the Playground
     
    BarbarianGuy

    Join Date
    Feb 2010
    Location
    Calgary
    Gender
    Male

    Default Re: ProgrammersitP

    Yeah I added some print statements and was watching that. The problem is, the instructions are I can't change any of functions or methods except get_moves, check_moves and select_move. I will make those changes for now for the simple test.

    Once I get the basic(no rules) working I'll work on check_move to return false and true with real reversi rules.

    Thank you very much for taking time to look over my code

  5. - Top - End - #155
    Barbarian in the Playground
     
    BarbarianGuy

    Join Date
    Feb 2010
    Location
    Calgary
    Gender
    Male

    Default Re: ProgrammersitP

    Ughh...I hate trying to work on assignments while I'm sick, my concentration sucks and so does my logic it seems.

    I think I have fixed my problems except one and I don't see the problem...Python is saying I have an indentation error at the blue line and I don't see it...


    Edit: okay found that problem too I think I'm done...
    Last edited by Balain; 2012-12-07 at 03:15 PM.

  6. - Top - End - #156
    Barbarian in the Playground
    Join Date
    Dec 2010
    Location
    Ireland
    Gender
    Male

    Default Re: ProgrammersitP

    Just something I'm wondering with Java; is there a way of getting the name of a variable to a String? e.g., say I have
    Code:
    public int number = 5;
    Is there some way of accessing the variable number by using a String called number?

    Here's a bit of pseudo-code as to what I'm looking for:

    Code:
    public class Test
    {
        public int number = 5;
        public int anotherNumber = 2;
        
        public int getVariable(String input) //input in this case is "number"
        {
                //take in String, "number"
                //find variable with the name number
                //returns the int variable number
        }
    }
    Though something I just realised was the return type, though you could around this by just having different methods, e.g. getStringVariable, getIntVariable, getBooleanVariable, etc.

    I've done this before with a switch statement, like this:

    Spoiler
    Show
    Code:
    protected Stat str = new Stat("str"); //stats
    protected Stat dex = new Stat("dex");
    protected Stat con = new Stat("con");
    protected Stat ine = new Stat("int");
    protected Stat wis = new Stat("wis");
    protected Stat cha = new Stat("cha");
    
    public Stat getStat(String choice)//takes in choice, returns specific stat
        {
            switch(choice.toLowerCase())
            {
                case "str":
                    return str;
                case "dex":
                    return dex;
                case "con":
                    return con;
                case "int":
                    return ine;
                case "wis":
                    return wis;
                case "cha":
                    return cha;
                default:
                    return null;  //only returns if invalid string is entered
            }
        }


    But I'm wondering is there some automated way of doing this so that I don't have create a switch statement that encompasses all the variables I want?

  7. - Top - End - #157
    Ogre in the Playground
     
    AlterForm's Avatar

    Join Date
    Jul 2007
    Location
    United States
    Gender
    Male

    Default Re: ProgrammersitP

    According to a couple questions on StackOverflow, no, it's not possible to get a variable name at runtime. (In Java)

    I would suggest looking at using a HashMap<String, int>, or possibly HashMap<enum, int>. You may need to use Integer instead of int; I'm a little fuzzy on whether Java stores primitives as references or as values.

    Thus your code would become:

    Code:
    public class Test
    {
        private int number = 5;
        private int anotherNumber = 2;
        private HashMap<String, int> attribs;
    
        public Test(){
            // Little rusty on the syntax here; you get the idea
            attribs.put("number", number);
            attribs.put("anotherNumber", anotherNumber);
        
        public int getVariable(String input) //input in this case is "number"
        {
                return attribs.get(input);
        }
    }
    All this is predicated on there not being a better data structure for your code than a String -> int mapping. (Which I suspect there is, since if you have a string that unambiguously refers to a particular variable at compile time, you may as well just write a getter/setter pair)

    [EDIT]: Reviewing what the SO threads and what Akma posted below, it seems you can get at a variable's name at runtime. It's just a Very Bad IdeaTM.
    Last edited by AlterForm; 2012-12-12 at 12:50 PM.

  8. - Top - End - #158
    Barbarian in the Playground
    Join Date
    Jul 2007
    Gender
    Male

    Default Re: ProgrammersitP

    There is a way to get the variable name from a String, but it`s not recommended*
    Relevent link: http://docs.oracle.com/javase/tutori...ect/index.html

    Basically, this is how you would do this:
    Class clazz = instance.getClass(); //method inherited from Object
    Field field = clazz.getField("field name");
    (you can also get a Class instance for primitive types and void, but that`s more complicated)

    There are also similiar methods to get methods and constructors, including private methods, changing final variables, etc.

    *Reflective code is slower to execute then regular code, and there are more exceptions you would have to manage. It`s better to avoid it whenever possible (for exemple case: "method3" this.method3();)
    Madly In Science, an RPG in which you play mad scientists, you can get it for free.

    Spoiler: Some other things.
    Show
    A world behind the mirror (stand alone plane)
    (Wall) passer, a rogue variant
    My not realy extanded homebrewer signature

    Quote Originally Posted by Grinner View Post
    In a world ruled by small birds, mankind cannot help but wonder how this state of affairs came about.

  9. - Top - End - #159
    Titan in the Playground
    Join Date
    Mar 2009
    Location
    Sweden
    Gender
    Male

    Default Re: ProgrammersitP

    Quote Originally Posted by AlterForm View Post
    I would suggest looking at using a HashMap<String, int>, or possibly HashMap<enum, int>. You may need to use Integer instead of int; I'm a little fuzzy on whether Java stores primitives as references or as values.
    Yes, you must write Integer instead of int. And you can't write enum just like that either, you need to specify a specific enum for it to work (just clarifying).

    Otherwise, yes, I'd say a Map is indeed the best structure, and a HashMap is probably the best choice for strings, but as already has been said, if you only need a limited and well known set of named variables, a parser combined with getters and setters will probably work just as well.
    Clouddreamer Teddy by me, high above the world, far beyond its matters...

    Spoiler: Banner by Vrythas
    Show

  10. - Top - End - #160
    Ogre in the Playground
    Join Date
    Nov 2006

    Default Re: ProgrammersitP

    So... Version Control (specifically: GitHub).

    I was looking into bundling code from other libraries into my own projects, and stumbled across Git submodules. Unfortunately, everything I'm reading about them makes it sound as if they're completely half-baked, and horribly unwieldy. Anyone have any thoughts on them, or perhaps suggestions as to alternatives?

  11. - Top - End - #161
    Barbarian in the Playground
    Join Date
    Dec 2010
    Location
    Ireland
    Gender
    Male

    Default Re: ProgrammersitP

    So, I want to start learning how to build/use databases in Java; just looking for any guides or info useful for someone who hasn't used databases before, but does anyone have any recommendations? Is there any particular one I should go for (MySQL/JDBC/etc)?

  12. - Top - End - #162
    Colossus in the Playground
     
    BlackDragon

    Join Date
    Feb 2007
    Location
    Manchester, UK
    Gender
    Male

    Default Re: ProgrammersitP

    JDBC isn't a database in its own right, as far as I know--it's a method for connecting to a database from Java. As far as databases are concerned, what OS are you targeting? The freebie SQL Server Express is Windows-only, but it gives you better tools to work with than MySQL does. I have no experience with PostgreSQL or Oracle, sorry.

  13. - Top - End - #163
    Ettin in the Playground
     
    The Succubus's Avatar

    Join Date
    Sep 2008
    Location
    UK
    Gender
    Male

    Default Re: ProgrammersitP

    A question for y'all.

    I'm thinking about a career change to the wonderful world of IT but I'm not sure what would be an appropriate starting qualification to aim for. I've got a fair amount of PC knowledge - installing OSes, mucking around with drivers, fixing new hardware - a gamer's toolkit basically. A friend suggested a Comp TIA A+ course or possibly the Linux+ version. I've also been looking at the CCNA but I fear it might be a little too advanced.

    Can any UK playgrounders offer me advice?

  14. - Top - End - #164
    Ogre in the Playground
    Join Date
    Nov 2006

    Default Re: ProgrammersitP

    Quote Originally Posted by Miscast_Mage View Post
    So, I want to start learning how to build/use databases in Java; just looking for any guides or info useful for someone who hasn't used databases before, but does anyone have any recommendations? Is there any particular one I should go for (MySQL/JDBC/etc)?
    Quote Originally Posted by factotum View Post
    JDBC isn't a database in its own right, as far as I know--it's a method for connecting to a database from Java. As far as databases are concerned, what OS are you targeting? The freebie SQL Server Express is Windows-only, but it gives you better tools to work with than MySQL does. I have no experience with PostgreSQL or Oracle, sorry.
    There probably isn't a way to get around using some form of SQL. I've heard good things about MariaDB, though I don't have any firsthand experience with it.

  15. - Top - End - #165
    Colossus in the Playground
     
    BlackDragon

    Join Date
    Feb 2007
    Location
    Manchester, UK
    Gender
    Male

    Default Re: ProgrammersitP

    Quote Originally Posted by The Succubus View Post
    I'm thinking about a career change to the wonderful world of IT
    This is the point where I have to run up and knock you into unconsciousness to prevent you making such a ghastly mistake, isn't it?

    Seriously, can't offer too much advice because my route into the IT world was rather unorthodox--my degree is in Electrical and Electronic Engineering, and I then spent nearly a decade programming for a living before heading into the world of sysadmin. A lot of IT and programming work is getting outsourced to India nowadays, too, so the job prospects aren't as good as you might like them to be.

  16. - Top - End - #166
    Ogre in the Playground
    Join Date
    Oct 2009

    Default Re: ProgrammersitP

    Quote Originally Posted by factotum View Post
    This is the point where I have to run up and knock you into unconsciousness to prevent you making such a ghastly mistake, isn't it?

    Seriously, can't offer too much advice because my route into the IT world was rather unorthodox--my degree is in Electrical and Electronic Engineering, and I then spent nearly a decade programming for a living before heading into the world of sysadmin. A lot of IT and programming work is getting outsourced to India nowadays, too, so the job prospects aren't as good as you might like them to be.
    Well at least in Germany there are about one trillion job offers for programmers (mainly php, android, iphone and java stuff)
    Last edited by Emmerask; 2013-01-02 at 05:04 PM.

  17. - Top - End - #167
    Firbolg in the Playground
     
    Recaiden's Avatar

    Join Date
    Apr 2008
    Location
    Fever dreams
    Gender
    Male

    Default Re: ProgrammersitP

    Quote Originally Posted by AlterForm View Post
    I would suggest looking at using a HashMap<String, int>, or possibly HashMap<enum, int>. You may need to use Integer instead of int; I'm a little fuzzy on whether Java stores primitives as references or as values.
    Values, which is why you have to wrap it in an Integer class instead of just using it (I think. It might actually just require classes for the templates).
    ~Inner Circle~
    Quote Originally Posted by Raz_Fox View Post
    He takes normality and reason and turns them UP TO 11!
    Quote Originally Posted by Anarion View Post
    Recaiden, stop using your mastery of the English language to confuse the issue.
    Echidna by Serpentine

  18. - Top - End - #168
    Ogre in the Playground
    Join Date
    Oct 2011
    Location
    The last place you look
    Gender
    Male

    Default Re: ProgrammersitP

    How do I run php programs from the command line? And before you ask, I'm using Windows 7
    Avatar by Venetian Mask. It's of an NPC from a campaign I may yet run (possibly in PbP) who became a favorite of mine while planning.

    Quote Originally Posted by Razanir View Post
    Everyone knows frying pans are actually weapons that people repurpose for cooking
    I am a 10/14/11/15/12/14 LG Clr 2

  19. - Top - End - #169
    Troll in the Playground
    Join Date
    Jan 2012

    Default Re: ProgrammersitP

    Quote Originally Posted by Elimu Marimech View Post
    How do I run php programs from the command line? And before you ask, I'm using Windows 7
    Have you got a PHP server set up?

  20. - Top - End - #170
    Colossus in the Playground
     
    BlackDragon

    Join Date
    Feb 2007
    Location
    Manchester, UK
    Gender
    Male

    Default Re: ProgrammersitP

    I'm not overly familiar with PHP, but if you just have a standalone program I'm pretty sure you can run it by prefacing it with the name of the PHP interpreter EXE, e.g. something like:

    PHP my_program.php

    If it's something that's designed to work on a web server then you'd need one set up in order to run the program, which is a massively complicated topic.

  21. - Top - End - #171
    Troll in the Playground
    Join Date
    Jan 2012

    Default Re: ProgrammersitP

    Quote Originally Posted by factotum View Post
    If it's something that's designed to work on a web server then you'd need one set up in order to run the program, which is a massively complicated topic.
    MoWes Portable was extremely easy to setup. You just select which packages you want on the download page and unzip the download.

    I don't think it's made to handle the demands of an actual server, but it more than suffices for the purposes of learning PHP.

  22. - Top - End - #172
    Ogre in the Playground
    Join Date
    Oct 2011
    Location
    The last place you look
    Gender
    Male

    Default Re: ProgrammersitP

    How do I set it up for executing from the command line? I set up a small local server to run programs off of, but my class requires it to work correctly from the command line
    Avatar by Venetian Mask. It's of an NPC from a campaign I may yet run (possibly in PbP) who became a favorite of mine while planning.

    Quote Originally Posted by Razanir View Post
    Everyone knows frying pans are actually weapons that people repurpose for cooking
    I am a 10/14/11/15/12/14 LG Clr 2

  23. - Top - End - #173
    Troll in the Playground
    Join Date
    Jan 2012

    Default Re: ProgrammersitP

    Quote Originally Posted by Elimu Marimech View Post
    How do I set it up for executing from the command line? I set up a small local server to run programs off of, but my class requires it to work correctly from the command line
    Have you added php.exe's directory the the PATH environment variable?
    Last edited by Grinner; 2013-01-07 at 06:46 PM.

  24. - Top - End - #174
    Ogre in the Playground
    Join Date
    Oct 2011
    Location
    The last place you look
    Gender
    Male

    Default Re: ProgrammersitP

    Quote Originally Posted by Grinner View Post
    Have you added php.exe's directory the the PATH environment variable?
    I tried that. Didn't work. BUT, I found a brute force solution.

    Code:
    >cd "C:\php"
    >php "[insert file path here]"
    Avatar by Venetian Mask. It's of an NPC from a campaign I may yet run (possibly in PbP) who became a favorite of mine while planning.

    Quote Originally Posted by Razanir View Post
    Everyone knows frying pans are actually weapons that people repurpose for cooking
    I am a 10/14/11/15/12/14 LG Clr 2

  25. - Top - End - #175
    Ettin in the Playground
     
    The Succubus's Avatar

    Join Date
    Sep 2008
    Location
    UK
    Gender
    Male

    Default Re: ProgrammersitP

    Back again,

    With a little luck, I should have my Linux Mint OS set up on my second hard drive this weekend and I was advised by someone that learning Python could be beneficial when messing around in Linux.

    Do any of you know much about Python as a language? Is it fairly simple to understand and use? How does one go about compiling it, etc?

    It's been years since I last did coding - it'll be fun to put my programming hat back on again, even briefly. =)

  26. - Top - End - #176
    Titan in the Playground
    Join Date
    Mar 2009
    Location
    Sweden
    Gender
    Male

    Default Re: ProgrammersitP

    Quote Originally Posted by The Succubus View Post
    Back again,

    With a little luck, I should have my Linux Mint OS set up on my second hard drive this weekend and I was advised by someone that learning Python could be beneficial when messing around in Linux.

    Do any of you know much about Python as a language? Is it fairly simple to understand and use? How does one go about compiling it, etc?

    It's been years since I last did coding - it'll be fun to put my programming hat back on again, even briefly. =)
    I know practically nothing, but thankfully, it's a very simple language if you know any other object-oriented (or at least imperative) programming languages, so with some help from the API, I can hack together simple scripts without too much hassle anyway. The only real quirk as I see it is its somewhat off-standard indentation rules.

    I'm not sure about compiling, my experiments tells me Python uses an interpretter rather than a compiler. Either way, to start programming, install Python on your computer, open a plain text document (.txt), write your program and save it as a .py file. Then you can run it from the command line by writing "python filename.py" (you may have some problems with finding either Python or the file, in which case I suggest calling the command from Python's directory and using the full file path rather than just the filename).
    Last edited by Teddy; 2013-01-10 at 05:47 AM.
    Clouddreamer Teddy by me, high above the world, far beyond its matters...

    Spoiler: Banner by Vrythas
    Show

  27. - Top - End - #177
    Ettin in the Playground
     
    The Succubus's Avatar

    Join Date
    Sep 2008
    Location
    UK
    Gender
    Male

    Default Re: ProgrammersitP

    My previous programming experience consists of some vaguely remembered Pascal lessons from my Computer Studies A-level, some self taught Visual Basic that almost caused me to fail my A-level* and some Amstrad Basic from the days when I thought getting my CPC to spam rude words over and over was the pinnacle of programming skill. ^_^

    10 PRINT "[REDACTED]"
    20 GOTO 10

    Computers were magic boxes back when I was six. They still are sometimes.

    * I bet you're curious now, aren't you....;)
    Last edited by The Succubus; 2013-01-10 at 06:07 AM.

  28. - Top - End - #178
    Colossus in the Playground
     
    BlackDragon

    Join Date
    Feb 2007
    Location
    Manchester, UK
    Gender
    Male

    Default Re: ProgrammersitP

    If you definitely want to look at Python then I'm sure there are Windows interpreters available for it. Isn't PHP the usual language used, though? Pretty sure that's what the P in LAMP (Linux, Apache, MySQL, PHP) is...

    Also, why are you putting Linux on a second drive? That has the disadvantage you have to reboot your machine to use it. If all you're doing is looking at Linux programming then it would be more efficient to install something like VirtualBox and create yourself a Linux virtual machine; you could run such a thing at the same time as your Windows installation. You'd need a bit more RAM to do this, but Linux doesn't require that much so a spare gig would be enough for most things. (You can also use the WUBI version of Ubuntu if you want to run Linux under Windows--works quite well).

    Of course, if there are specific reasons why all this has to be the way you've described, ignore me...

  29. - Top - End - #179
    Ettin in the Playground
     
    The Succubus's Avatar

    Join Date
    Sep 2008
    Location
    UK
    Gender
    Male

    Default Re: ProgrammersitP

    Quote Originally Posted by factotum View Post
    If you definitely want to look at Python then I'm sure there are Windows interpreters available for it. Isn't PHP the usual language used, though? Pretty sure that's what the P in LAMP (Linux, Apache, MySQL, PHP) is...

    Also, why are you putting Linux on a second drive? That has the disadvantage you have to reboot your machine to use it. If all you're doing is looking at Linux programming then it would be more efficient to install something like VirtualBox and create yourself a Linux virtual machine; you could run such a thing at the same time as your Windows installation. You'd need a bit more RAM to do this, but Linux doesn't require that much so a spare gig would be enough for most things. (You can also use the WUBI version of Ubuntu if you want to run Linux under Windows--works quite well).

    Of course, if there are specific reasons why all this has to be the way you've described, ignore me...
    I'd like to learn to use Linux au naturalle, as it were. To learn how it works on a real hard drive, with real PC components, to learn how to do Linux driver troubleshooting, and maybe even learn how to compile kernals and do custom setups.

    The reason I want to do it on a second disk is because if it all goes fruit-shaped as it inevitably will, the SSD with Windows on will be unscathed and fine. Besides, partitioning hard disks is a bitch, I've found. -.-

    I'll be using Linux from time to time, rather than constantly because although a fair percentage of the games I play work in Linux, not all of them do sadly, so I still need a fully working Windows PC for most of the time. However, I'll be looking to do as much as I can in Linux though. =)

  30. - Top - End - #180
    Titan in the Playground
    Join Date
    Mar 2009
    Location
    Sweden
    Gender
    Male

    Default Re: ProgrammersitP

    Quote Originally Posted by factotum View Post
    If you definitely want to look at Python then I'm sure there are Windows interpreters available for it.
    Are you thinking of IDE interpretters? Because, as I said, Python itself is an interpretter, but it lacks an IDE in and on itself.
    Clouddreamer Teddy by me, high above the world, far beyond its matters...

    Spoiler: Banner by Vrythas
    Show

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •