Results 151 to 180 of 356
Thread: ProgrammersitP
-
2012-12-04, 06:02 AM (ISO 8601)
- Join Date
- Mar 2009
- Location
- Sweden
- Gender
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
-
2012-12-05, 04:46 PM (ISO 8601)
- Join Date
- Feb 2010
- Location
- Calgary
- Gender
Re: ProgrammersitP
My understanding of for loops in python is, when I do
Code:for i in range(8)
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.
-
2012-12-05, 06:19 PM (ISO 8601)
- Join Date
- Mar 2009
- Location
- Sweden
- Gender
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
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
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
-
2012-12-05, 07:30 PM (ISO 8601)
- Join Date
- Feb 2010
- Location
- Calgary
- Gender
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
-
2012-12-06, 07:50 PM (ISO 8601)
- Join Date
- Feb 2010
- Location
- Calgary
- Gender
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.
-
2012-12-12, 08:32 AM (ISO 8601)
- Join Date
- Dec 2010
- Location
- Ireland
- Gender
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;
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 } }
I've done this before with a switch statement, like this:
SpoilerCode: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?
-
2012-12-12, 11:38 AM (ISO 8601)
- Join Date
- Jul 2007
- Location
- United States
- Gender
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); } }
[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.
-
2012-12-12, 12:13 PM (ISO 8601)
- Join Date
- Jul 2007
- Gender
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.
-
2012-12-12, 12:56 PM (ISO 8601)
- Join Date
- Mar 2009
- Location
- Sweden
- Gender
Re: ProgrammersitP
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
-
2012-12-23, 07:33 PM (ISO 8601)
- Join Date
- Nov 2006
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?Avatar by araveugnitsuga | Play by Post (Guide) | Steam
Homebrewers' Extended Signatures
Hey Look, a Summer Reading List!
-
2013-01-02, 04:58 AM (ISO 8601)
- Join Date
- Dec 2010
- Location
- Ireland
- Gender
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)?
-
2013-01-02, 07:37 AM (ISO 8601)
- Join Date
- Feb 2007
- Location
- Manchester, UK
- Gender
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.
-
2013-01-02, 07:58 AM (ISO 8601)
- Join Date
- Sep 2008
- Location
- UK
- Gender
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?
-
2013-01-02, 03:48 PM (ISO 8601)
- Join Date
- Nov 2006
Re: ProgrammersitP
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.
Avatar by araveugnitsuga | Play by Post (Guide) | Steam
Homebrewers' Extended Signatures
Hey Look, a Summer Reading List!
-
2013-01-02, 04:31 PM (ISO 8601)
- Join Date
- Feb 2007
- Location
- Manchester, UK
- Gender
Re: ProgrammersitP
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.
-
2013-01-02, 05:03 PM (ISO 8601)
- Join Date
- Oct 2009
-
2013-01-04, 01:22 PM (ISO 8601)
- Join Date
- Apr 2008
- Location
- Fever dreams
- Gender
-
2013-01-07, 02:16 PM (ISO 8601)
- Join Date
- Oct 2011
- Location
- The last place you look
- Gender
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.
I am a 10/14/11/15/12/14 LG Clr 2
-
2013-01-07, 04:26 PM (ISO 8601)
- Join Date
- Jan 2012
-
2013-01-07, 05:41 PM (ISO 8601)
- Join Date
- Feb 2007
- Location
- Manchester, UK
- Gender
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.
-
2013-01-07, 05:51 PM (ISO 8601)
- Join Date
- Jan 2012
Re: ProgrammersitP
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.
-
2013-01-07, 05:59 PM (ISO 8601)
- Join Date
- Oct 2011
- Location
- The last place you look
- Gender
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.
I am a 10/14/11/15/12/14 LG Clr 2
-
2013-01-07, 06:42 PM (ISO 8601)
- Join Date
- Jan 2012
-
2013-01-07, 08:06 PM (ISO 8601)
- Join Date
- Oct 2011
- Location
- The last place you look
- Gender
Re: ProgrammersitP
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.
I am a 10/14/11/15/12/14 LG Clr 2
-
2013-01-10, 05:29 AM (ISO 8601)
- Join Date
- Sep 2008
- Location
- UK
- Gender
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. =)
-
2013-01-10, 05:46 AM (ISO 8601)
- Join Date
- Mar 2009
- Location
- Sweden
- Gender
Re: ProgrammersitP
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
-
2013-01-10, 06:06 AM (ISO 8601)
- Join Date
- Sep 2008
- Location
- UK
- Gender
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....;)
-
2013-01-10, 07:44 AM (ISO 8601)
- Join Date
- Feb 2007
- Location
- Manchester, UK
- Gender
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...
-
2013-01-10, 08:06 AM (ISO 8601)
- Join Date
- Sep 2008
- Location
- UK
- Gender
Re: ProgrammersitP
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. =)
-
2013-01-10, 08:44 AM (ISO 8601)
- Join Date
- Mar 2009
- Location
- Sweden
- Gender
Re: ProgrammersitP
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