Jump to content

Learning a Programming Language


DarthTofu
 Share

Recommended Posts

I know E is a code-monkey, and I think some of the other forum members are. I'm not going to go so far as to call myself anything even approaching a code protozoan, much less a code monkey. That being said, I've taken a fondness to programming my calculator of late, and have derived an incredible amount of pleasure from creating a little fighter game for it ("Little" meaning "includes about ten inter-locked programs"), that is both a two-player and a one-player game.

 

That being said, I'm sort of making this stuff up as I go, and learning the basics from friends who have bothered with tutorials, and the decidedly vague tutorials I've found online. My TI-83 is the result of somebody named Tiffany losing hers in the airport, and me taking it out of the Lost and Found box ninety days later when nobody had claimed it. (It's completely legal- no worries.) Thus, I don't actually have the manual that would have come with it.

 

Now, while I could download the manual in PDF format (I found where I can do that online), I'm more inclined to learn to actually program on a computer. Nothing heavy-duty; I don't intend to make something along the lines of Doom 3! I just want to learn a very basic, easy programming language, so that I can continue this hobby, and make stupid little games. I was thinking that my next project would be to code a version of Monopoly in my spare time ("Spare time" meaning "When I should be paying attention in AP Statistics, which is really just BS math and an incompetent teacher"), but the large number of variables I'd have to store suggests that it would be a better idea to try this out on a computer.

 

I asked for some basic programming stuff for my birthday- IE a beginners guide to C, C+, or C++, but just to get another opinion- what's a relatively easy to learn, relatively basic programming language that I could use to start learning to make this sort of stuff? It's a lot of fun to make these little games, and I've noticed that a lot of folks who don't know jack about their TI-83/TI-84 really enjoy my fighting game program, and want a link to it. If I can keep making these, who knows? I might even become semi-popular! :lol:

12/14/07

Nu kyr'adyc, shi taab'echaaj'la

Not gone, merely marching far away

Link to comment
Share on other sites

The C languages are the best for modern games plus knowledge in all that DirectX and such. Many use languages that are off shoots to specificly deal with certain avenue of prgramming. Such as graphics heavy, web based, Xbox/PC multiplatform gaming language stuff I think they call XNA.

 

It gets real complex and may take years of college to learn in order to do anything really useful.

 

A easy way was Visual Basic but the graphics are very limited.

 

If you want to make quick fast games to get the hang of it -this is not really for a career per sey- use that simple Dark Basic Pro. It does all the hard work for you.

 

I taught myself, and just do it for a hobby when I got time. I had to take a part time job to pay the bills in this nasty economic down turn.

 

In the end, how much time do you want to spend? Do you want to do it professionally?

 

A full blown game can get very messy and wanky with the simple languages, thus C and other higher level languages maybe the only real way to go. It depends on how complex of a game you want to make.

Link to comment
Share on other sites

  • SWR Staff - Executive

Even Monopoly is quite complicated, if you figure all the necessary rules to do it. I would say, forget about graphics at this point.

Do something simple with basic Windows forms ... C# may have some more overhead, Visual Basic is easier to pick up. Either of them will do enough without too much complication.

 

It's good you have a project to tackle though. It makes easier to have a goal.

I wouldn't tackle pure C/C++/Java (or DirectX, XNA, etc) just yet. You learn a lot, but you may get bored or trip over the complicated stuff.

Evaders99

http://swrebellion.com/images/banners/rebellionbanner02or6.gif Webmaster

http://swrebellion.com/images/banners/swcicuserbar.png Administrator

 

Fighting is terrible, but not as terrible as losing the will to fight.

- SW:Rebellion Network - Evaders Squadron Coding -

The cake is a lie.

Link to comment
Share on other sites

Oh, I don't mean to make a career of this by any means! I just want to learn it for hobby purposes, maybe to do the occasional useful bit of work for me (IE programs that will do my homework for me from time to time, and analyze circuits, etc.), or else just making semi-basic game programs. Monopoly wouldn't be too bad, provided I only chose it for one player against the AI, or one player against another player. The biggest issue would be the number of variables, but that was one thing I was hoping that a computer would be able to tackle for me.

 

Plus, I have a very, very old Star Wars Monopoly CD from, like, 1996, when the Special Edition trilogy was being released. I don't know if I can crack it or not, but if I can, that ought to lend me a ton of info on how to do this stuff. It came out of a box of cereal, so I don't figure General Mills will get too ticked at me if I crack it. Factor in the fact that I'm not making cash off of it- I'd say it's perfectly legal.

 

Apparently somebody made Risk for his Calculator (gotta find and download that program(s)), and the same fellow was trying to do Monopoly. I figure, if he could get Monopoly on a calculator, I ought to be able to get it on a computer, even if it's purely text-based.

12/14/07

Nu kyr'adyc, shi taab'echaaj'la

Not gone, merely marching far away

Link to comment
Share on other sites

... It came out of a box of cereal, so I don't figure General Mills will get too ticked at me if I crack it...

General Mills is NOT the license holder, only a temporary distributor. Lucas Arts maintains their rights (and will probably NEVER give them up), so GM won't get ticked at you, but GL will!

Finally, after years of hard work I am the Supreme Sith Warlord! Muwhahahaha!! What?? What do you mean "there's only two of us"?
Link to comment
Share on other sites

  • SWR Staff - Executive

AI is actually pretty complicated. Getting a computer to do something that players naturally do is tough. Our brains are extremely complicated, much more than any computer.

If multiplayer (which Monopoly isn't), you are best just to have each player input their transactions the same way.

 

Second, you're not going to crack SW Monopoly and get it to any useful code you can use. It is binary code... compiled for specific OS (Windows). All you'll get is assembly; reading that is like looking at a screw and saying "oh now I can build a suspension bridge"

 

Not to discourage you of course. It should be a fun hobby. I would definitely say go for it.

Evaders99

http://swrebellion.com/images/banners/rebellionbanner02or6.gif Webmaster

http://swrebellion.com/images/banners/swcicuserbar.png Administrator

 

Fighting is terrible, but not as terrible as losing the will to fight.

- SW:Rebellion Network - Evaders Squadron Coding -

The cake is a lie.

Link to comment
Share on other sites

Well, that's bothersome....

 

So far as the programming for a Monopoly AI goes, here's how I'm thinking it ought to work:

 

have 36 "squares," which each one corresponding to specific number. Start at "square" zero, and use two randomly generated numbers, from one to six, to determine how far the player moves. Store the player's position as former position (initially zero) plus the new dice rolls.

 

Once the position is equal to something greater than 36, the position is stored as zero, and the remainder is tacked onto zero. I can do that with a conditional statement.

 

If Position + DC > 36

then

position + DC - 36 store as position

 

Each position value will act as a separate square.

 

If I make this more than just two player, it'll get more complicated, but I think I'll keep it at two player.

 

For each square, have a variable that begins by being stored as zero. If player one elects to purchase the property, then the variable is stored as one. If the AI has the cash to purchase it (always purchase when possible, electing to maintain about $200 in "spending money," unless a monopoly is possible in the purchase, in which case it buys the property) the value is stored as two.

 

Then just do a three-part conditional statement for landing on the square. Say the variable is A, and that player one (human) is going.

If A=0

then

execute some sort of "would you like to buy this" command.

else

if A=1

then

goto the AI's turn

else

if A=2

then

pay whatever the rent is, unless a monopoly is owned (IE go to a new program for that property set, where if A, B, and C are all equal to 2, you pay the appropriate amount based on houses and hotels)

 

The hardest part, I think, will be the mortgages. I'm not sure how I'll instruct the AI on what to mortgage based on prices... Of course, this is all theoretical, too. I'm assuming that I'll be able to use more than 26 variables when I learn some C++. I may wind up only being able to use 26 letters of the alphabet for variables, and then I'm a tidbit hosed. :lol:

12/14/07

Nu kyr'adyc, shi taab'echaaj'la

Not gone, merely marching far away

Link to comment
Share on other sites

  • SWR Staff - Executive
Generally you can name the variables anything you want (within limits, certain characters are special.. and some are keywords)

Evaders99

http://swrebellion.com/images/banners/rebellionbanner02or6.gif Webmaster

http://swrebellion.com/images/banners/swcicuserbar.png Administrator

 

Fighting is terrible, but not as terrible as losing the will to fight.

- SW:Rebellion Network - Evaders Squadron Coding -

The cake is a lie.

Link to comment
Share on other sites

So.... are you saying that I could store a number as "Bob," and that if Bob=3, and I tell the computer to "display Bob," I won't get product of upper-case b, lower case o, and lower case b displayed- I'll get three? Sorry I haven't gotten to know the language more yet; I'm busy as heck right now, but in about a week I should be able to start educating myself in this stuff. 'Course, a week after that, my life will end, as Res 5 will be released.... :lol:

12/14/07

Nu kyr'adyc, shi taab'echaaj'la

Not gone, merely marching far away

Link to comment
Share on other sites

  • SWR Staff - Executive
Correct. Every real programming language should let you declare "bob = 3" and use "bob" as a variable :)

Evaders99

http://swrebellion.com/images/banners/rebellionbanner02or6.gif Webmaster

http://swrebellion.com/images/banners/swcicuserbar.png Administrator

 

Fighting is terrible, but not as terrible as losing the will to fight.

- SW:Rebellion Network - Evaders Squadron Coding -

The cake is a lie.

Link to comment
Share on other sites

Tofu, I'd recommend Python for starters and if you're interested in writing 2D games, you might want to check out Pygame library.

 

Python is imho the best choice if you want to learn programming, since it's basically a pseudocode, easily readable and mainly doesn't force you to use any specific programming paradigm (eg. both C# and Java enforce object oriented programming even if you don't have the slightest idea what the heck that means).

 

If you'd be pining for Windows.Forms or .NET in general, there is also a version of python called IronPython that runs on Microsoft's CLI (Common Language Infrastructure).

 

Some links:

Python - http://www.python.org/

PyGame - http://www.pygame.org/news.html - pygame

IronPython - http://www.codeplex.com/Wiki/View.aspx?ProjectName=IronPython

 

and of course a tutorial - http://docs.python.org/tutorial/

 

Wiki:

http://en.wikipedia.org/wiki/Python_(programming_language)

http://en.wikipedia.org/wiki/Pygame

 

hope that helps

 

PS: there's a huge theory about artificial intelligence and games (chess, checkers, poker, canasta, even computer games :)) however one of the most crucial points is to abstract the state into numbers and be able to say which state is better than the other. this is usually a weighted sum of certain factors - number of houses, player's money, upgrades on houses, streets, special buildings, distance from the start, etc. (I don't remember monopoly exactly). and then the AI basically examines all possible actions and chooses the best one according to this function. this is the simplest AI possible (and probably very stupid), the real fun starts when you try to think multiple turns in advance and take into account other players and the random element (dice).

 

Hmm, yes, AI for monopoly is difficult. Othello (Reversi) is much easier.

-rebellion2 enthusiast-

Terra Reconstructed

Link to comment
Share on other sites

lol- I may or may not use other games, such as Risk, as starters beforehand. I've heard that python is almost disgustingly easy to learn, which makes me think that I may try to get the hang of that, too, but I'm going to stick with what I have a "For Dummies" book of for now, which is C++. Thanks for the help, guys- I really do appreciate it! I'll probably heckle you about stuff once I start trying to code and encountering obstacles.

12/14/07

Nu kyr'adyc, shi taab'echaaj'la

Not gone, merely marching far away

Link to comment
Share on other sites

  • 2 weeks later...

Ba-ba-ba-bump!

 

Okay, so I finally got around to cracking open that book of C++. I've only read the first chapter so far, but I'm still a little bit fuzzy on how the code works.

 

First off: What do the #include commands mean? I'm not clear on what they're saying to include; at first I thought they meant including certain things as variables, but I can see now that that's not the case.

 

Second (and, currently, last): When the program ends, it reads "endl." What's the point of the lowercase "L" after "end" ?

12/14/07

Nu kyr'adyc, shi taab'echaaj'la

Not gone, merely marching far away

Link to comment
Share on other sites

  • SWR Staff - Executive

Basically C++ has a lot of code written for you. They are usually in header files (.h)... stuff to open files, write out text, etc.

The includes are used to load up these files. For now, I wouldn't worry about exactly what they do, just that you need the right include for the job (stdio = standard input/out, math = math functions, etc).

 

endl just means "end line" :)

Evaders99

http://swrebellion.com/images/banners/rebellionbanner02or6.gif Webmaster

http://swrebellion.com/images/banners/swcicuserbar.png Administrator

 

Fighting is terrible, but not as terrible as losing the will to fight.

- SW:Rebellion Network - Evaders Squadron Coding -

The cake is a lie.

Link to comment
Share on other sites

End line? The program contains several lines of code, though... or am I using the wrong defenition of "line" in this case? Would a "line" just be one function of a program?

 

For instance, say I wanted a program that would add five to a variable, and then subtract six. I wanted to display the variable plus five, and then to display the variable minus six.

 

Would I end the line after I added five, and then end it again after I subtracted six, or would I wait until I'd gone through the whole program to end the line?

12/14/07

Nu kyr'adyc, shi taab'echaaj'la

Not gone, merely marching far away

Link to comment
Share on other sites

  • SWR Staff - Executive

I don't really understand the context of "endl"... where does it show? Screenshot?

 

x = x + 5;
cout << "This is the variable plus 5" << x;
x = x - 6;
cout << "This is the variable minus 6" << x;

 

You can display the variable whenever necessary... remember the commands here are generally sequential (at least within one function)

Evaders99

http://swrebellion.com/images/banners/rebellionbanner02or6.gif Webmaster

http://swrebellion.com/images/banners/swcicuserbar.png Administrator

 

Fighting is terrible, but not as terrible as losing the will to fight.

- SW:Rebellion Network - Evaders Squadron Coding -

The cake is a lie.

Link to comment
Share on other sites

Minimize the Use of the endl Manipulator

 

Many programmers append the endl manipulator after each cout expression, as in:

 

cout << "user login" << endl;
cout << "enter your name: " << endl;
cin >> name;  

In the first line, the endl manipulator is added to force a line break. However, it's cheaper in terms of performance to use the '\n' character instead of endl because endl also flushes the stream rather than just adding a line break. Flushing a stream can be a costly operation. The second cout expression too has a redundant endl manipulator because the display must appear on the screen before the cin expression is executed, as cin and cout are tied.

 

The bottom line: avoid using the endl manipulator if you can because it slows down your program. Use \n instead. :wink:

 

cout << "The value of x is " << x << ’\n’;
cout << "The value of x is " << x << endl;

 

You would think this is the same, but it is not for performance.

Link to comment
Share on other sites

  • SWR Staff - Executive
Consider he just started out, I don't think he'll care about performance of adding numbers :)

Evaders99

http://swrebellion.com/images/banners/rebellionbanner02or6.gif Webmaster

http://swrebellion.com/images/banners/swcicuserbar.png Administrator

 

Fighting is terrible, but not as terrible as losing the will to fight.

- SW:Rebellion Network - Evaders Squadron Coding -

The cake is a lie.

Link to comment
Share on other sites

lol- no, not likely. I just saw that the first, most basic program, a conversion program for converting Fahrenheit temperatures to Celsius, ended with an "endl" command.

 

Most likely my early projects will just be very simple text-based games, similar to the type I already produce on my calculator. When I get better, I intend to make a larger, multi-level version of the game that I can burn to a CD and give to a few of my friends as parting gifts for graduation (my text-based TI-83/84 calculator games are exceedingly entertaining according to my friends, most likely because I include all sorts of inside jokes throughout. My "company" (IE The logo that I put on the games) is Negative Friction, a concept a friend and I invented when we epically failed at an AP Physics lab and had an object accelerating when it made contact with a table as opposed to when it was just flying through the air. Pretty epic, I know)

 

I'm going to read some more tonight- my next questions will probably deal with conditional statements if I don't understand them; I'm learning out of C++ for Dummies (fifth edition), so if anyone else learned out of that book and has any insight on where it goes or went wrong, feel free to provide it.

12/14/07

Nu kyr'adyc, shi taab'echaaj'la

Not gone, merely marching far away

Link to comment
Share on other sites

If I may make a suggestion? Don't start with a game. It's too complicated. Start with basic mathematical formulas. Before you can get anywhere with a game, you have to know how the computer handles math. I took some C++ classes, and it's amazing how complicated something can get, even if it's simple in your head.

 

Once you know how to get input from the user and use it in math stuff, then output the result, you'd best master variables. How you store variables makes a big difference. I'd avoid pointers for awhile; they'll give you a headache and aren't necessary for the basic sorts of things you're talking about. But you'd best learn what pass by value and pass by reference are, and basic structs would also be handy for you to learn. And naturally, the differences between char, int, double, float, etc. Of course, in order to get these, you'll need to figure out how to call functions, but that really isn't too bad.

 

With math and variables under your belt, I'd suggest tackling menus next. Any sort of program or game beyond the most basic will have a menu of some sort; how you handle the input and do error checking is important. What if the user has CAPSLOCK on? That sort of thing. If you're the only one using it, then error checking becomes much simpler, as you know what the program can and can't handle. But error checking within the formula processing is still vital, as you don't want things going outside of array bounds, or causing segmentation faults, or any of a number of errors.

 

After you can do those things, then you can begin putting together simple games. Graphics is of course way out of the question, but text games or even things with simple grids aren't so bad. I made a Sudoku program that's pretty fun, and I have a couple of useful things as well. Like a converter for standard numbers and Roman numerals, quadratic formula calculations, etc.

 

If you need help, I'll add my name to the list of other guys here who know a bit about programming. Drop me a line! :wink:

Star Wars: Rebellion, A Field Manual

"O be wise, what can I say more?"

Link to comment
Share on other sites

Sudoku? 8O Madness! I wouldn't know where to start with Sudoku, beyond perhaps a random number generator, and crapload of conditional statements.

 

While I don't know how to do most of the things I want to do in C ++ yet (chiefly menus and conditional statements), the first chapter of my books deals with variables and assigning certain numbers as certain variables, changing those variables, what the different variables are, etc.

 

I'm going slowly, seeing as AP exams are coming up, but in a few weeks I hope to have a massive boom in productivity... hope being the key word. Preferably right after I tell my Stats teacher that she can stick her subject where the sun don't shine, because statistics is pointless pseudo math.

12/14/07

Nu kyr'adyc, shi taab'echaaj'la

Not gone, merely marching far away

Link to comment
Share on other sites

  • SWR Staff - Executive
because statistics is pointless pseudo math.

 

Real people take AP Calculus BC :P

(Followed by a long set of Multivariable calculus, differential equations, discrete mathematics...)

Evaders99

http://swrebellion.com/images/banners/rebellionbanner02or6.gif Webmaster

http://swrebellion.com/images/banners/swcicuserbar.png Administrator

 

Fighting is terrible, but not as terrible as losing the will to fight.

- SW:Rebellion Network - Evaders Squadron Coding -

The cake is a lie.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

Copyright (c) 1999-2022 by SWRebellion Community - All logos and trademarks in this site are property of their respective owner. The comments are property of their posters. Star Wars(TM) is a registered trademark of LucasFilm, Ltd. We are not affiliated with LucasFilm or Walt Disney. This is a fan site and online gaming community (non-profit). Powered by Invision Community

×
×
  • Create New...