http://img.photobucket.com/albums/v6...Cymon/logo.gifButtons (hey, you come up with a better name then...)
The game in my sig, as I said, is a smaller, stripped down version of a bigger program. The code has been formated in a less readable format so it fits in as few lines as possible. I actually made 2 version of this. The other version is 7 lines, has better looking graphics, but only 1 solution. However, this actually makes a better intro game, so I'll post it here: Code:
#define z printf Code:
**********...** ...** ... Code:
******** +===+ +===+ +===+ Well, the 5 line version below looks a bit different but plays similarly. I'll repost the code here incase I change my sig: Code:
int n,d[2],m[9]={27,7,54,73,186,292,216,448,432};p(){int c=6,k=0;puts("");for(;c Code:
789 *.. Code:
7.. *.. So there you go, an explination of my sig and a teaser for future programs to come. Feedback is welcome and if you all like it I'll post more of my super-cool C programs. For anyone who wants a more readable version of the game, here it is: Code:
/* Buttons Code:
**bd = rand () % 0x01FE + 1; Code:
**bd = rand () % 0x01FE + 1; goal[lv] = rand () % 0x01FF; |
Please post a few more.
Did you try to optmize your programs for speed as well or merely fo as small as possibl ? You don't mention the header files that are needed and getche isn't available at my place. |
<div class='quotetop'>QUOTE(Data @ Jun 5 2006, 10:12 AM) [snapback]234432[/snapback]</div>
Quote:
Header files are unnecessary. everything is kept in the single file. just be sure to name it with a .c instead of .cpp and every complier I've used can handle it. (Even M$, although I've only complied in a windows environment. If your complier is different, let me know.) As for getche(), that is a non-standard function. But all of my programs are designed so that getche () can be replaced with the ANSI standard getchar() and (1) still funciton and (2) not consume any more space. (I leave a space after getche_ for the extra letter in getchar every time.) No, my programs are not optimized for speed. For programs as small as this that's kind of silly. Besides, I'm not very good at optimizing for speed. more programs to come... |
So, which one to continue with? I'll start with a small one and move on to a somewhat bigger one, then let you all choose.
Jumping Balls (please hold back the grade school snickering) What inspired this little programming spree was when I found a couple of old books of BASIC programs that I would read in High School. Of course, by High School BASIC was a thing of the past, so all I could do was read the programs an imagine how cool it'd be to play them. So when I found the entire text of both books online years later I decided that I would like to finally see these programs run. Only, instead of whipping out gwBASIC (or whatever) I'd convert the programs in it to C! One of these programs I found such a suscinct way of expressing in C that I decided to see if it would fit in a sig. It did, and in 3 lines no less: Code:
main(){char b[11]="\toooo.OOOO";int e=5,n,t=0;puts("\t123456789");puts(b);for(;n In a a perfect game you can win in 24 moves. How well can you do? Below is the full, more readable, and longer more compelte version Code:
/* Jumping Balls |
Interesting how compact source code can be, even though I have a different view about what "minimal" source code is.
What I would like to know is how long it would take you to complete such a transformation on code that you have not seen before? |
<div class='quotetop'>QUOTE(Eagg @ Jun 9 2006, 12:03 AM) [snapback]235363[/snapback]</div>
Quote:
Which is a perfect segway into the next program. Robot Escapehttp://img.photobucket.com/albums/v6...llerRobots.gif The instructions are in the game, so just read down a few lines to see them: Code:
/* Robot Escape Code:
Stunned... Press ENTER I wanted to see how small I could get it. My goal was 1K, less than 1024 characters. After much work I got it. But oh the sacrifices that had to be made: Code:
#define q(a)(a)*(a) In the 1k version there is technically no winning condition, so you can play until you are overwhelmed by sheer numbers. But Robotescape1k has a fixed max number of enemies on screen which, by the way, is 98 enemies and you makes 99. I was so crammed for space that adding one more digit to that number would have put me over. You exceed the maximum if you make it to level 24, which will consequenly crash the game. This however is an highly difficult thing to do, so consider the game beaten if you make it that far. The 1k restriction also introduced a bug concerning the conditions of winning a level where it checks to see if all the robots are dead before checking if you are. In other words, if the last robot(s) kill themselves upon you, you still win and move on to the next level. Ah well, such is the price of this sort of pursuit. However, it can be a strange sort of satisfying to win by kamikaze / jihad / whatever. .:EDIT:. CRA...UD. I wrote this ages ago and just noticed in the last line that "if(w)" can be removed, saving me 5 characters meaning I could take the game up to 9999999 on screen characters, more than the screen can handle, erradicating the level 24 cap. Meh, screw it. I never survived past level 16 myself anyways. |
I would give a Toe to understand this.. :wallbash:
|
Poll at the end of this post, don't forget to vote!
<div class='quotetop'>QUOTE(U-Boat Commander David @ Jun 9 2006, 04:25 PM) [snapback]235479[/snapback]</div> Quote:
Sound like too much work? Hey, you wanted to give up a toe. If I just take the pinky toe you have to learn how to walk all over. You think you don't need it, but it's got so much to do with balance. Trust me, typing a few tried and tested programs is easier than learning how to walk again. So what program should I do next? Maybe I'll let the people decide. Here's the list of possible choices:
|
May I ask why you chose C and it's old-fashioned procedural programming paradigm over more modern ones such as OO? Mind you, I can appreciate the beauty in an obfuscated piece of C-code (although as a Java guy, I really hate doing memory managment myself), I was just curious.
|
4 in a row please.
Interrested in seeing the ai part especially. Reup OO is a way solving the problem. not the way. there is nothing wrong with procedural programming I think. OO was overrated in its hype. (which fortuntaly has a passed a bit) |
The current time is 02:07 AM (GMT) |
Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.