As I recall I didn't say there was anything against procedural programming, only that it was more old-fashioned then OO. I'm also aware that it's not the only and best way. I was merely asking about guesst preference.
Maybe we sould start a 'which paradigm rocks donkey-balls' thread to discuss the benefits of each one? |
Boys, now, let's calm down. No paradgm bashing here.
@ Reup, you haven't voted. I chose plain C because it's a place to start. In fact, it's where I started. I was esentally going back to my roots. The plan was for me to write a few programs in C, then move on to CPP. However, it didn't last that long. When I started getting ready to do Wumpus in CPP, an exelent program to do OO, and life got in the way. That was a few months ago. Some day, soon I hope, I'll be able to finish what I started and show some CPP programs. Then I'm going to start simple graphical programs, then take over the world. |
Well, I've gotten a single vote and that's probably going to be it. So here you go, by popular request:
Four in a Row This was a algorithm adapted directly from a BASIC program and is uniquely frustrating because I've played it tons of times and only beaten it once. The page in the link for the BASIC program above explains a little bit about the procedure the computer takes when making a move. I'll explain a bit after the code. So without further ado: Code:
/* 4inarow How the computer makes a move. First of all, the board data is maintained in strings so that outputting the board is simply a matter of coughing it up. At the top there is an array called v that has a bunch of wierd number in it. Those numbers are the ranking assigned to the successfull creation of 1 in a row, 2 in a row, 3 in a row, and (altho unnecessary because it's an automatic "take it") 4 in a row for enemy first, then self. The compmove routine is called when it's the computer's turn to move. It virutally drops it's oppoenets (your) pieces in each slot, and adds up the rank of each move. Then it virtually drops it's own pieces into each slot and adds up the rank of each of those moves. Assuming that it didn't find that any move made 4 in a row (either pass), in which case it automaticly does that move, it then compares all the possible moves and chooses the highest scorer. And as usual, I already see things I'd do to change it. Ah well, that's programming for you. So come one, come on. Let's choose the next one. One responce with a choice, one program till we're done.
|
Okay. Now do 'joust' :D
Btw, where you say logarithm, don't you mean algorithm? :unsure: |
<div class='quotetop'>QUOTE(Reup @ Jun 13 2006, 06:56 AM) [snapback]236324[/snapback]</div>
Quote:
So, Joust you say, eh? This game was another taken from a BASIC game of the same name (from the second book of BASIC programs). It's kind of a choose your own story with a weighted random. On some of the BASIC programs I converted my attempt was to duplicate the algorithm of the original game exactly, so as to experience the game as it was meant to be played. On this one, however, I couldn't resist making a few small improvements. First of all, the original game had a bug that would allow you to choose defense options that were not shown if you knew their number. Fixed. Also in this one, if you mightaly unseat your opponent your next opponent (unless it's the fearless black night) will bow out. Buy why am I just talking about the game, I should show it to you: Code:
/* Joust Code:
Joust Next?
|
Quote:
And I vote for 3DMaze to be posted here next. ^_^ |
Hey, 13 out of 40 in a competition where no morons are allowed isn't bad. You were doing well just to get in.
3DMaze This is a real cool one. Taken from yet another entry in the International Obvscated C-Code Contest (another exelent place to find C-Code examples written by people better than me). Sean Barrett's winning 1991 entry drew an ascii representation of a first person view through a maze. For the maze the program read it's own code in and used the whitespaces for floor. Clever, but not very dynamic. So I decided to make a random maze generator and attach it to the drawing algorithm. This meant I had to take code that was not formatted for reading and reformat it with variables with understandable names and everything. It was an interesting way to figure out how this extremely clever routine worked. The final result is uber-cool and looks like this: Code:
****\****************************************** / Code:
/* 3DMaze The constants WALL, UNSEEN, SEEN, TRAVL, and EXIT are for the map. When the maze is generated you have WALLs and UNSEEN everywhere and EXIT at the end. As you see an area UNSEEN becomes SEEN and as you go there the spot you stand on becomes TRAVL. That way at the end you can see what path you took through the maze. The maze generating algorithm doesn't make paths through the maze or anything. It just makes sure you can get anywhere from anywhere else one and only one way. It connectes two spaces with a numbered path. If two paths are connected the higher number over rides the other path so that if it wanto to join two areas it only needs to be sure they aren't of the same path, meaining a loop would be generated. A hole is punched in the left side for the exit. I had considered having a square maze, dropping the player in the exact middle, and punching one hole in any of the outside walls, meaning you could wander the wrong direction for a long time before getting out. But I decided against that for a straight east to west progression to make it less diabolical. Besides, a square map of more than 11x11 would not show well on the map printout. This game is so cool I absolutely recomend downloading DevCPP and playing this one. It's a hoot. I wanted to include the executable here, but the boards don't allow it. But you have the code, so go on with you. So there is 3DMaze. What's next?
|
Awari, Awari! (since I don't know what a learning a(?)lgorithm is, and would like to see :D )
|
I don't want to post two in one day, so I'll just say (1) thanks, I missed that one. And (2) did you even play the maze game yet? Tell me what you thought of it.
|
http://img.photobucket.com/albums/v6...ymon/Awari.gifAwari
Awari is an ancient African counting game. Each player has 6 places with 3 markers or stones in each to start and an empty home. A move is made by taking all the markers from any non-empty place on your side, then “sowing” the markers one at a time in a counter-clockwise direction around the board. If the last marker sown lands in your home then you get a second move. (No more than two moves in one turn.) If the last marker is sown in an empty spot and the spot opposite is not empty then you capture the last marker and all the markers in the opposite spot. When either side is empty then the game is finished. Another conversion of a BASIC program of the same name. In the original the board was layed out left to right, more like one would play it in real life. I thought that was a bit confusing so I wrote a new version (just this morning) which layed things out top to bottom. I'm not sure it's that much better so I kept the original version but commented it out. So here we go... Code:
/* Awari */ The list gets shorter every time! This time I added one I had forgotten however.
|
The current time is 03:09 PM (GMT) |
Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.