Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Saturday, August 29, 2009

Back to Basics


It feels like just yesterday I was programming card games in C++, but now I'm starting to learn Java so it's back to the basics -- the obligatory "Hello World" program.

NetBeans feels similar to C++ IDEs that I've used, so navigating the menus isn't hard, and once I learn to code a bit more, I'll try and make a few of my own programs and see what I can do.

Wednesday, August 26, 2009

Mmm, A Fresh Cup of Java™

I'm signed up for the AP Computer Science course at my school which focuses on Java programming, so I'm going to start learning it ahead of time. The more I can learn before the class starts, the faster I'll be able to the assignments, the more time I'll have to just chill out in class/work on my own side-projects.

I'll be following the tutorials from the Java website and using the NetBeans IDE for writing and compiling my code.

Saturday, May 16, 2009

Lab 10: Laser Tag

Well that was easy.

Lab 10 was an introduction to using structs--I had to write a program which simulates a game of laser tag between two people by using structs to store the player's names (ex: player1.name = "Tony"), their laser strength, and their shield strength. At the end the program displays the winner of that round of laser tag.

Structs are pretty simple to use and are useful (it makes organizing a lot of info much easier), and this lab only took me about 20-30 minutes.

The source code: http://www.mediafire.com/?xmzjlzjym02

Thursday, May 7, 2009

Lab 9: Eight Queens

For the past few days I have been working on a C++ assignment in my "Intro to Programming II" class at school. Up until now these labs have been fairly simple to handle with a bit of logical thinking and an understanding of what needs to get done in order for the program to work correctly. Lab 9 is a bit tough and only a few people in the class have done it. Many people have just decided to skip it altogether, but I'm a stubborn programmer.

The gist of the assignment is to write a program which will place eight queens on an 8x8 chessboard. The catch is that the queens have to be placed so that none of them would be able to take some other queen in one move.

My current program is on the computer at school, so I'll update this post with my (very rough draft-esque) code.

Update:
The code as of 5/8/09
http://www.mediafire.com/file/nojt5251wlf/lab 9 eight queens.cpp
(see update 3)

It works up until the program runs into a dead end in the recursive function, where it just stops instead of returning to the previous column to try a different path. It shouldn't be too hard to fix once I find out why exactly the program stops.

Update2: So apparently the program runs fine on my computer (in Visual C++ 2008 and in Code::Blocks), but not in Xcode on my school's computers. Huh.


Update 3:
Yes! It works!
http://www.mediafire.com/download.php?nwyj3zc2cvi

It turns out that all I needed to fix the progran was "if (row>=8) return 1;"
The problem was that the function which checks up, down, left right, and the diagonals for queens makes a call to the 2d array "board[8][8]" (which represents the chessboard). On certain occasions, the program will try to check the element "board[8][x]" where x=8 which is impossible since that would mean the program is trying to check the ninth row (which doesn't exist), causing the program to end (apparently Code::Blocks isn't as picky about these sorts of things as Xcode is).