Wednesday, December 26, 2007

Calculating Big (really really really really really MONSTEROUSLY BIG) numbers

The curious thing about programming and mathematics is that I'm not at all a good mathematician (C in Algebra 1, B in Geometry, D in Algebra 2), except when it comes to the computer, and the thing that has intrigued me most so far is the concept of computers being able to calculate extremely large numbers. Pi has been found to some odd billion digits, prime numbers (as far as we know) have been found using computers up to and beyond the 10 millionth digit (www.mersenne.org), and computers are used for other mathematical purposes as well (Seti, folding@Home, protein formations, etc).

The list is quite endless, I'm sure.

So as a novice programmer I also wanted to do something with higher math. Simply squaring numbers and all that is a little boring, yet the fibonacci sequence fascinated me, so I wrote a program to calculate that.

But it died after runs through the sequence. The 64 bits of data become clogged after about 19 digits, and fibonacci has been calculated to 10 million with some god-awful C++ code that was several lines long. So I asked the gods at www.javaranch.com, and they helped. The program no longer died after 91 runs through.

But then I realized that with an output to screen I couldn't retrieve the information, at all (what's the use of calculating a really really really big number if you can't get to it), which meant I had to solve another problem.

So I went searching, went on a journey, tried a bunch of things, looked at the hard-to-decipher-if-you-try-to-read-deep-in java docs, and then realized that the solution was right under my nose. The BigInteger class used to represent numbers larger than 64 bit (that is, 19 digits long or so) is an object. Every object has a toString method (returns it as a series of text). Text is savable to a file. My teacher went on about how these really big ass numbers are just strings of text..............

CLICK!

The only problem now is processing. The only solution for that is time.

Guess I'll be leaving something on overnight. Hey, fibonacci is already to the 100,000th digit :)

Tuesday, December 25, 2007

Welcome to Code Hell

Why the hell did I do my combat system that way?



With the way it was before, I was using about three different methods to do things I could use with just if-then logic. I dunno why I was doing it that way other than the idea that I was maybe only thinking one step at a time.

Building a game is a precarious thing. It's already 1500 some-odd lines (a lot are printouts, and stuff like that, but there's also some stuff that goes into the guts of the program) and I really don't feel like I've done that much at all with it, yet.

It doesn't help that my first draft of the game was something that meant one little change required a lot of stuff. The applications we write in CS are just quick and dirty little things that teach a lot about one little aspect of the language, but not necessarily how it all meshes too well. I had to learn that the hard way when I started on the game. The way I had learned coding up to that point would make anything semi-big unmaintainable.

Don't get me wrong, I'm not knocking my computer science course. It's nothing too advanced because its a first-year program but its nothing to laugh about either because it is an AP course. I'm just saying that my limited experience, trying to work on a big project has actually been a good thing. I've gotten my head around classes and objects a little before the need to do so was required (something I'm glad happened before I got my Gridworld assignment, or i'd have been lost) and am looking at applying new concepts I learn to the game.

The irony of it is its a text-based RPG. Right now its just singleplayer but i might make it into a MUD if its any good. The ironic thing is I don't play MUDS, really. Because they're just so dang complex that its hard to understand, or i feel lost, not having a map, and stuff.

However I think its largely due to the fact that I never could quite immerse yself into them, not that MUDs were bad. But with my game I can make it how I want, and strip away the complex learning curve (all those bajillion commands) and hopefully add depth.

Maybe.

All else fails I'll just work on it to learn CS.

But I have so many ideas for the thing, where I want to take it... And it's just a baby right now. Maybe when it's matured a bit it'll be something awesome.

Thursday, December 20, 2007

Winter Break

WINTER BREAK IS HERE!!!!!!!!!!!!

Whew.

I'm exhausted.

And I have no idea why.

I mean I have an idea asto why, and I think it pertains to the fact that I've pretty much worked my ass off the past few months (gaming, school, work, we all know that gaming is actually hard work) but was kept in a perpetual state of work until now.

And the week has winded down, and its now catching up to me. It's the whole time dilation effect, you know. When you don't have time to think until its all over. And then it hits you. HITS you.

So, yeah.

I have nothing over winter break save a lot of programming to do. Which means it'll be an awesome two weeks, sans work.

Thursday, December 13, 2007

Perfect Simulation

Computer Science, at its core, takes a model of a real-world situation and simulates it, perfectly. If two programmers utilize this concept to a perfect degree their code will look the same, raising an eerie question of "how do you judge who's a better programmer?"

Of course, always holding onto such an ideal is difficult, if not impossible in practice, because it entails not only solving a problem to get from point A to point B, but solving it in such a way that the underlying logic FITS in with how the world works.

This raises quite a few interesting questions.

1. What is a real-world situation? Do we interact with the world using windows user interfaces on a daily basis? Are games "real-world" situations? They could be an extension of fiction, but, how do you quantify the underlying code?

2. How do you quantify a programmer's skills, if both of them code in the same manner? Time spent?

3. Does this concept include the idea of getting it right, the first time?

4. Does this include variable names? XP :)

Of course, before a developer could even begin to do this, he would have to have a solid command of the language, and, of course, as humans we are not perfect, so do to this on a regular basis would be impossible.

However, I think it does say that there is always improvement in some aspects of code, which, when studied long enough, will allow for programs to run better if the necessary changes are made.

These are just my thoughts of course. We haven't explored the concept too much.

Wednesday, December 5, 2007

AP practice tests for CS

Had two tests this week. The one yesterday was a 40 question multiple choice in which we were required to answer 30. A majority of them dealt with classes, which is a JAVA concept I have been wrapping my head around the past few months (the concept finally clicked when some classmates showed me a few things). Actually the concept of classes was something I had in my mind before I knew how to go about programming in such a manner (You develop a very ambitious project and you begin to realize very quick that its not just a quick and dirty application).

The second portion of the practice test was a free-response question. The first involved the simulation of a parking garage, and I had to write code for three different parts.

The first part was to find out if the parking garage is full. This was simple enough. Check each level and if a level isn't full, then the garage isn't full.

The second part was to place a car in the next available space in the garage, and the third part was to remove a car. Since the value of "null" represented an empty space, it was just a matter of finding this empty spot and placing the car there. The third part was also quite similar, but a little different because it involved comparisons between two strings (sentences) and I'm not sure if I got it right. The problem is I'm not too keen on how objects work (something I need to practice on if I am to do good on the real thing).

Unfortunately, this took me around an hour to code. The one disadvantage with AP testing is that I don't have the compiler on hand to trace through code. I'm not talking about the debugger, but actually running the program and seeing where it goes as opposed to where I think it might go.

The second problem involved HTML processing. Since strings can't be deleted (for whatever reason), I got stuck on the whole "remove things from a string" idea. The ironic thing is I could have completed this easily if I would have realized that the second and third problems were really just variations of the first one.

Oh well. Chalk it up to learning lesson 2 about AP style testing :)

I can't wait until Christmas break. Two weeks of sheer, no-school bliss!