November 27th, 2006 Luke
Recently, while lurking the Dreamincode forums, I found a post on the forums regarding someone’s C++ assignment. I wasn’t quite sure how to solve it, but I’ve copied the assignment, and here it is:
Problem:
Create a simulation of doodlebugs life
Description of the Problem:
The goal for this programming project is to create a simple two-dimensional predator-prey simulation. In this simulation the prey are ants and the predators are doodlebugs. These critters live in a world composed of a 20x20 grid of cells. Only one critter may occupy a cell at a time. The grid is enclosed, so a critter is not allowed to move off the edges of the world. Time is simulated in time steps. Each critter performs some action every time step.
The ants behave according to the following model:
â?¢ Move. Every time step randomly try to move up, down, left, or right. If the neighbouring cell in the selected direction is occupied or would move the ant off the grid, then the ant stays in the current cell.
â?¢ Breed. If an ant survives for three time steps, then at the end of the time step (that is; after moving) the ant will breed. This is simulated by creating a new ant in adjacent (up, down, left, or right) cell that is empty. If there is no empty cell available, then no breeding occurs. Once an offspring is produced an ant cannot produce an offspring until three more steps have elapsed.
The doodlebugs behave according to the following model:
â?¢ Move. Every time step, if there is an adjacent ant (up, down, left, or right), then the doodlebug will move to that cell and eat the ant. Otherwise, the doodlebug moves according to the same rules as the ant. Note that a doodlebug cannot eat other doodlebugs.
â?¢ Breed. If a doodlebug survives for eight-time step, then at the end of time step it will spawn off a new doodlebug in the same manner as the ant.
â?¢ Starve. If a doodlebug has not eaten an ant within the last three time steps, then at the end of the third time step it will starve and die. The doodlebug should then be removed from the grid of cells.
During one turn, the doodlebugs should move before the ants do.
Write a program to implement this simulation and draw the world using ASCII characters of â??oâ? for an ant and â??Xâ? for a doodlebug. Create a class named Organism that encapsulates basic data common to both ants and doodlebugs.
Initialize the world with 5 doodlebugs and 100 ants. After each time step, prompt the user to press Enter to move to the next time step. You should see a cyclical pattern between population of predators and prey, although random perturbations may lead to the elimination of one or both species.
Classes to be created:
(use the concept of objects, classes, constructors and destructors with or without overloading, Data encapsulation, Data abstraction and Inheritance).
Create an inheritance hierarchy to represent doodlebugs and ants that derived from Organism class.
I couldn’t help the original poster, but it looks like an interesting project to try. I’m going to get to working on that.
Posted in C++, Code | No Comments »
November 21st, 2006 Luke
Now that Parakeet is ‘finished’ (read: being tweaked), everything is falling into place. My awesome webhost is offering a holiday hosting offer that looks like it would be good to use as a launching setup for Parakeet when it actually gets released. All I have to do is design the main page and navigational interface setup before December 31st. However…I don’t have a name for Parakeet yet.
I’ve thought of a few. Most of them have been ruthlessly vetoed by my sounding boards though…which means they aren’t a good idea. I need a name that is unique enough that I can get a domain for it, but at the same time communicates the point that Parakeet (or whatever it will be called) is a budgeting web application.
I need to find myself a graphic designer to make me a few smaller graphics - things like a green checkmark, red x, and the generalized logo. Maybe I’ll see if they have any good ideas.
Posted in Parakeet, webdev | No Comments »
November 20th, 2006 Luke
After about a month of working on Parakeet during my spare time, it’s now ‘finished’. I’ve managed to get it all working(albeit kludgily), and I’m now on to planning out and sketching new features and interfaces. However, it doesn’t work under IE yet.
IE doesn’t seem to like the fact that I use this snippet of code to interact with part of the expense list:
addAmount = cell[1].childNodes[2].nodeValue;
For some reason, IE complains about that piece of code. It works just fine under Safari and Firefox, though.
IE also seems to have a problem with this piece of code:
document.getElementById(expenseID).innerHTML = req.responseText;
freeReq();
updateTotal();
freeReq() and updateTotal() are both my functions, and neither of them are having any problems(they work just fine in other areas). But for some reason, setting the innerHTML of an element is bad. Or something. IE complains, at any rate.
IE also ignores a lot of my CSS setups. When we add a row to the expense table, we also dynamically set it’s class and ID attributes. I don’t think that IE is working with either of those, because the ID attribute doesn’t get used correctly in updateTotal(), and the class attributes don’t appear to be taking effect.
I never really liked IE; my dislike is now growing into seething hatred.
Posted in Parakeet, microsuck, webdev | No Comments »
November 11th, 2006 Luke
A little while ago, I was working on Parakeet and I had a problem: I wanted to highlight a <tr> element when there was an error, by applying a unique background-color and border to it. However…you can’t apply a border to a <tr> element. That’s because a <tr> isn’t technically rendered, per se, so much as used by the browser to denote where a row starts and where a row stops.
This was a problem, that I was determined to solve. It took a custom class for the <tr> element, and some a few descendent selectors to get working, but it did. Here’s the breakdown:
.errorRow td {
border-top: 1px solid black;
border-bottom: 1px solid black;
background-color: green;
}
This piece of code makes it so that EVERY <td> inside anything with the class of ‘errorRow’ has these style rules applied to it. This allows us to set a default view for every cell within the table.
.errorRow td.outerLeft {
border: 1px solid black;
border-right: none;
}
.errorRow td.outerRight {
border: 1px solid black;
border-left: none;
}
This code makes it so that the two cells marked ‘outerRight’ and ‘outerLeft’ within our ‘errorRow’ element will override some of their default attributes, and set up their own border rules. The ‘outerRight’ class is applied to the cell that is on the right side of the <tr>, and the ‘outerLeft’ class is applied to the cell that is on the left side of the <tr>.
After setting all of this up, we can easily apply a border to the entire <tr> simple by setting its class to ‘errorRow’, or in some cases adding the class of ‘errorRow’ to it.
Here’s the code, all summed up:
.errorRow td {
border-top: 1px solid black;
border-bottom: 1px solid black;
background-color: green;
}
.errorRow td.outerLeft {
border: 1px solid black;
border-right: none;
}
.errorRow td.outerRight {
border: 1px solid black;
border-left: none;
}
Posted in Code, css, hack | No Comments »
November 9th, 2006 Luke
I spent about an hour last night trying to get Ace working with a friend, and right now Terminal is busily working on getting DarwinPorts to install Gobby for me. I’ve recently added a forum to girasquid.com, even though I’m highly doubtful it will actually be put to use. Right now, I’m reading up on how to setup and install activecollab, and I’ve always got a tab open to the Parakeet page on Backpack.
Truly, I am a sucker for random tools that seem useful. I can think of a few things that I can use all of these for - I use this blog for personal reflection, because I know that no one is going to read it(ever, chances are. Unless Parakeet suddenly takes off - not likely). The forum, I might use for class notes, or as a way for people to leave me messages besides e-mailing. Gobby is so that friends and I can collaborate on stuff, and that’s what activecollab is there for, too. But I just can’t stop installing tools that strike me as neat. At some point, I’ll put up a “Toolbox” page, that links all of my web-tools if anyone actually cares to see what I use(or my harddrive fails again).
It’s a good thing that my awesome webhost gave me 250 MySQL databases to play with.
Posted in Tools | No Comments »