This kinda thing really interests me. Evolution. Of a computer system. Wow. Evolution / adaptation is an amazing accomplishment, and we all know computers can simulate pretty much any process. What better process to simulate than evolution.
I found this site where you watch the computer try to evolve a car to traverse a track. It is pretty cool. The computer beings by creating 20 random cars, which are 8 triangles with their points at the centre and 2 wheels on hydraulics. You will see they are all one colour and most likely they will all fail real bad.
Then at each generation the cars swap pieces to form the next generation. If you have set the mutation high, you may also see some pieces changing shape.
Somehow, the computer uses the distance travelled to find the best parts and then combines that into the next generation. This process is call natural selection. Pretty sweet stuff. This one has been left going for a while.
You can see sometimes that the natural selection process along with the mutation often forms a worse car. This event occurs in real life, often when the weak that are left behind have the most likely chance of survival and so the weak take over due to pure numbers.
I may do something similar to this as a future project. We shall see.
Friday, 28 January 2011
Thursday, 27 January 2011
Dwarf Fortress and a Puzzle
So I still haven't got back to Tanks. And I'm posting at work again so now screenshots of my other game or anything like that.
I saw on Blops Killer's blog something about Dwarf Fortress. Now I have heard a bit about this game before and with all the down time I seem to have I decided to give it a try. IT'S AWESOME!! If you like those kind of games. It's an ASCII game which means it only uses characters you can type, including the alt-code ones such as ♪, ☺ and incase you are racist ☻. Hold alt and press a couple numbers then release alt.
Luckily they have packs out there that replace the characters with more accurate characters. e.g. the ☺ (alt+1) into an actually dwarf. Pretty cool.
You have to build a fortress to fend off attacks, usually underground, and make sure all your dwarves have something to do, and see sunlight regularly; otherwise they go mental and start killing everyone in your fortress. It's hillarious.
Here's a screen shot of my fortress in progress. Note that it is based entirely on a tutorial. Except where I stuffed it up...
Here's the entrance.
Here's the dining hall, still (the Dwarves live off alcohol), food storage, some rooms, and some work stations. This is about 3 levels underneath the ground.
And here's the future living quarters. Still yet to be dug out. About another 2 levels under the above photo. You can see they have started digging the top section.
I thought it was cool.
Anyways... Here is a test for everyone out there. I bet it will just end up pissing you off. ☺
I saw on Blops Killer's blog something about Dwarf Fortress. Now I have heard a bit about this game before and with all the down time I seem to have I decided to give it a try. IT'S AWESOME!! If you like those kind of games. It's an ASCII game which means it only uses characters you can type, including the alt-code ones such as ♪, ☺ and incase you are racist ☻. Hold alt and press a couple numbers then release alt.
Luckily they have packs out there that replace the characters with more accurate characters. e.g. the ☺ (alt+1) into an actually dwarf. Pretty cool.
You have to build a fortress to fend off attacks, usually underground, and make sure all your dwarves have something to do, and see sunlight regularly; otherwise they go mental and start killing everyone in your fortress. It's hillarious.
Here's a screen shot of my fortress in progress. Note that it is based entirely on a tutorial. Except where I stuffed it up...
Here's the entrance.
Here's the dining hall, still (the Dwarves live off alcohol), food storage, some rooms, and some work stations. This is about 3 levels underneath the ground.
And here's the future living quarters. Still yet to be dug out. About another 2 levels under the above photo. You can see they have started digging the top section.
I thought it was cool.
Anyways... Here is a test for everyone out there. I bet it will just end up pissing you off. ☺
Labels:
challenge,
dwarf,
followers,
fortress,
game,
screenshot,
slacking off,
test
Monday, 24 January 2011
It's my birthday soon! Small update and a little bit about myself.
Going to be 20. Woo! That should be fun. Not really doing anything too exciting. Oh! I am going to Fiji for my girlfriends 21st in February. That should be fun too. Unless I die from the heat...
Sorry I haven't done any work on Tanks since the first release. I will get back to it at some point as I actually want it on my phone. Would be nice when going to job interviews. "Well you can see some of the work I have done here." That would be awesome.
I've run out of decent previous projects to put up here too so everything should be new content. Except there is another game I half made, (actually it's at about the same point as the tanks game is now) where you have to get to the door. There are some glitches I haven't fixed and alot of people don't like the unique control system. I'll put some shots and maybe the executable online for that one aswell. It is about as complicated as Tanks so you might not see any code for it. Simply due to the amount of code.
What else? University is starting in the end of February, so expect alot of content about that. Looking for a house, which means I will be poor. But that should be fun. I do like a challenge. Been going for runs, which is always a good thing. But the weather hasn't helped. See this here.
And a picture for my brother:
[spoiler]
[/spoiler]
That's about it.
Cheers,
Sorry I haven't done any work on Tanks since the first release. I will get back to it at some point as I actually want it on my phone. Would be nice when going to job interviews. "Well you can see some of the work I have done here." That would be awesome.
I've run out of decent previous projects to put up here too so everything should be new content. Except there is another game I half made, (actually it's at about the same point as the tanks game is now) where you have to get to the door. There are some glitches I haven't fixed and alot of people don't like the unique control system. I'll put some shots and maybe the executable online for that one aswell. It is about as complicated as Tanks so you might not see any code for it. Simply due to the amount of code.
What else? University is starting in the end of February, so expect alot of content about that. Looking for a house, which means I will be poor. But that should be fun. I do like a challenge. Been going for runs, which is always a good thing. But the weather hasn't helped. See this here.
And a picture for my brother:
[spoiler]
[/spoiler]
That's about it.
Cheers,
Friday, 21 January 2011
POST YOUR BLOG HERE! AGAIN
Ok, so I've recently started having alot of people advertise there own blogs in comments. I don't approve of this. You may noticed comments with 'Content removed by blog administrator.', thats them.I did have a Post You Blog Here! thing earlier. Though very few actually used it.
If you put a decent comments I do check your page and more often then not I subscribe. I check those I have subscribed to whenever there is new content.
So POST YOUR BLOG HERE!
Anyone who does so, I will check out. And please check out the others who have posted their blog here. Sharing is caring.
If you put a decent comments I do check your page and more often then not I subscribe. I check those I have subscribed to whenever there is new content.
So POST YOUR BLOG HERE!
Anyone who does so, I will check out. And please check out the others who have posted their blog here. Sharing is caring.
Thursday, 20 January 2011
The Darkness of the Heart
This was a story written by my little brother, and cousin when they were 14. Pretty damn good. Did some spell checking on it before posting.
I heard a strange sound that chilled me to the bone. That blood curdling scream echoing down the hall. The fibers in her throat straining to their limits as the sleek blade pierced her chest, sinking deeper.
This feeling. The rush of adrenaline, the feel of absolute power - it's truly intoxicating. A grin crept up across my cheek. I pushed harder, she screamed louder.
The serrated edge of my knife grided away at this woman's ribs. Rich red blood drooled down the hilt and covered my hand. Frantically, she fought back with desolate blows. She knew she was going to die.
I removed the knife, feeling satisfied with the amount of blood pouring out of her wound, only to strike again. And again and again. Twice to her stomach, twice to her heart and one destructive gash to the back of her neck.
I had struck the nerves in her spine, she went limp and collapsed backwards onto the windowsill behind her, keeping her upright.
Both her and I were covered in blood.
A bloodstained hand reached down to my belt and rested on the machete. I paused, taking in the gory scene, I sighed in ecstasy as I licked the blood from the knife.
Within a split second, I grabbed the machete and hacked a two-inch-deep gash in the side of her head.
She wasn't dead, yet.
I could see nothing but pain in her eyes. She had no control over her body, a knife stuck into her neck and a machete deep in her brain. She wanted nothing more than for this to end. I owed her that.
That same bloodstained hand reached down and took the 9mill pistol off my hip and pressed it firmly to her skull. Her eyes, though stricken with pain, whispered a thank-you. I blinked emotionlessly in return and squeezed the trigger.
Blood, the fluid of passion, gushed abruptly out the window.
It was over.
She is gone.
I fell to my knees, suddenly realising what I had done. My heart stopped beating, just as it had before I met her.
Her name, Laura, it always sounded so sweet whenever I heard it.
A tear rolled down my cheek.
I glanced around the room, blood, just blood. That's all I could see. She had decorated this room, it was to be for our child, and now I had destroyed it. She wasn't even pregnant. I couldn't remember why I had killed her, I tried to though, as I dragged her limp, lifeless body down towards the basement.
The stairway wall had been decorated with photos of us, on the beach, at the fairs, in town every memory I shared with her, taunting me on my shameful walk to hide my sin.
The basement had no lights, only faint streams of light descending upon the dusty floor from the cracks in the floor boards. The room always scared me, even considering my past. Maybe I knew I was going to leave her here, before I had thought of killing her.
I sat he up in the far corner. Gazed into her deep, blue eyes. And burst into tears.
There I sat. Dark but distinguished. In this dark, desolate hole. The basement was my only place of refuge and escape, from the thing that I had become. The light came weakly through from the gaps in the floorboards above, flickering and teasing me that there was hope for a new, different life.
I hadn't planed to do it this time. My one true love. Our passion had been a fire, the love of his life. I let out a deafeningly silent scream. A scream of the disgust and anger I had at myself. I felt a trickle of cold, dark blood running down my cheek. A cut, the only punishment for the crimes I had committed. It slowly ran onto my lips and, licking them, I shuddered. Blood, the fuel of life, my drug. It was the sole cause for my loss of control. My need for it was all consuming and not even the strongest of all emotions, love, could control it.
The sound of the rhythmic, torturing dripping of water falling from the ceiling had become too much. I had to get away from it, slowly standing up; I made his way to the door. Then in the corner of my eye, I saw it. The corpse of the one that had fixed and now through my own stupidity destroyed my life. I walked over to her lifeless, motionless body. Looking into those longing, betrayed eyes I couldn't help laughing, it was a cold inhumane laugh that would scare the bravest of men. Laura, his one true love.
Walking through this house to the back door, I shivered. The strong, grilling, summer sunlight is not enough to warm my heart, let alone start it beating again, for it was now forever frozen and dark. Despair passed across me, for from that moment on I knew I would be but a shell of a human.
Far away I heard the screeching of sirens, splitting the happy cries of children and silencing the roar of traffic. Grabbing my knife, I licked it clean of the liquid it had become accustomed to be in contact with. I put it concealed into my belt and then I, the serial killer, fled.
In a crowd I would look like any other ordinary man, but if you got close and saw those sad, regretful eyes, you would know I was different. People who met me often said I was odd and found me difficult to talk to. It wasn't that I was anti-social but when I went out not many talked to me. I was rejected often at bars and clubs. Soon I gave up asking and as time passed I went out less and less, losing the hope I would meet anybody or have any friends.
My life was a wreck and a misery. I had become confined to my house, never leaving unless for food and supplies. Slowly the house become dirty and derelict, with the weeds in the garden high up to the windows, covering the paths and killing any flowers that struggled to live. Parents urged their children to stay away from me. Strangely anybody that came to talk to me about the state of the house never came out again and soon a weak odour filled the air inside the house. Laura's corpse had joined theirs.
When I had met Laura my world opened up to a whole new range of possibilities. I started to go out again, I met new people but most importantly he started to love life again. I was starting to be normal. Laura and I had newly painted the house, cleaning the inside and out. The garden became tidy and bright, glowing flowers grew quickly replacing the colourless weeds. Old friends commented about the change in me and began inviting Laura and I to dinner. It was all because of her ? the candle in my world of darkness, growing brighter and giving me strength. But I had snuffed out that candle, plunging my life into darkness again.
As I walked out the back door I noticed that all of the flowers, which were alive and happy earlier that morning, were dead and dry. Even though it made no logical sense I knew why.
I strolled slowly away from the house, towards the park. Laura always loved the park, so full of happiness whenever we went for a walk together.
I walked down passed a bed of flowers, Tulips and Roses, Laura's favorites. I crouched and picked a Tulip from the group and nestled it in my palms. It's violet colour quickly faded into a deathly grey and shrivelled up to nothing more than an empty shell, just like me.
A shadow swept past be, I recognised the slight chill. I looked up to see a man wearing blue standing over me with his hands on his hips and a sad "not another one." look on his face. I just turned away from him and continued to sob at the dead flower nestled in my palms.
"Sir..." The mans voice spoke.
"... I need you to stand up please." it ordered.
I never really cared too much for this man, he only lasted those few seconds in my memories. Then he was gone - like all the rest.
"I love you, I don't want to leave you." I spun, hoping to catch a glimpse of the speaker.
There was no one there.
I recognised the voice, it was Laura's. No, I must be dreaming, this cant be happening! I dreaded this moment. I knew it would come, it always does and always will.
I became attached to her, I loved her, I wanted to have children with her, I killed her...
This is where it all ends.
Three days later, I was found in her bloody arms with a bullet through my head and a letter in her hands:
Don't cry for me now I'm gone, I knew what I had done and every second I deserved; I killed him. I took his breath away and he mine. Together in each others dieing arms is where we belong.
I heard a strange sound that chilled me to the bone. That blood curdling scream echoing down the hall. The fibers in her throat straining to their limits as the sleek blade pierced her chest, sinking deeper.
This feeling. The rush of adrenaline, the feel of absolute power - it's truly intoxicating. A grin crept up across my cheek. I pushed harder, she screamed louder.
The serrated edge of my knife grided away at this woman's ribs. Rich red blood drooled down the hilt and covered my hand. Frantically, she fought back with desolate blows. She knew she was going to die.
I removed the knife, feeling satisfied with the amount of blood pouring out of her wound, only to strike again. And again and again. Twice to her stomach, twice to her heart and one destructive gash to the back of her neck.
I had struck the nerves in her spine, she went limp and collapsed backwards onto the windowsill behind her, keeping her upright.
Both her and I were covered in blood.
A bloodstained hand reached down to my belt and rested on the machete. I paused, taking in the gory scene, I sighed in ecstasy as I licked the blood from the knife.
Within a split second, I grabbed the machete and hacked a two-inch-deep gash in the side of her head.
She wasn't dead, yet.
I could see nothing but pain in her eyes. She had no control over her body, a knife stuck into her neck and a machete deep in her brain. She wanted nothing more than for this to end. I owed her that.
That same bloodstained hand reached down and took the 9mill pistol off my hip and pressed it firmly to her skull. Her eyes, though stricken with pain, whispered a thank-you. I blinked emotionlessly in return and squeezed the trigger.
Blood, the fluid of passion, gushed abruptly out the window.
It was over.
She is gone.
I fell to my knees, suddenly realising what I had done. My heart stopped beating, just as it had before I met her.
Her name, Laura, it always sounded so sweet whenever I heard it.
A tear rolled down my cheek.
I glanced around the room, blood, just blood. That's all I could see. She had decorated this room, it was to be for our child, and now I had destroyed it. She wasn't even pregnant. I couldn't remember why I had killed her, I tried to though, as I dragged her limp, lifeless body down towards the basement.
The stairway wall had been decorated with photos of us, on the beach, at the fairs, in town every memory I shared with her, taunting me on my shameful walk to hide my sin.
The basement had no lights, only faint streams of light descending upon the dusty floor from the cracks in the floor boards. The room always scared me, even considering my past. Maybe I knew I was going to leave her here, before I had thought of killing her.
I sat he up in the far corner. Gazed into her deep, blue eyes. And burst into tears.
There I sat. Dark but distinguished. In this dark, desolate hole. The basement was my only place of refuge and escape, from the thing that I had become. The light came weakly through from the gaps in the floorboards above, flickering and teasing me that there was hope for a new, different life.
I hadn't planed to do it this time. My one true love. Our passion had been a fire, the love of his life. I let out a deafeningly silent scream. A scream of the disgust and anger I had at myself. I felt a trickle of cold, dark blood running down my cheek. A cut, the only punishment for the crimes I had committed. It slowly ran onto my lips and, licking them, I shuddered. Blood, the fuel of life, my drug. It was the sole cause for my loss of control. My need for it was all consuming and not even the strongest of all emotions, love, could control it.
The sound of the rhythmic, torturing dripping of water falling from the ceiling had become too much. I had to get away from it, slowly standing up; I made his way to the door. Then in the corner of my eye, I saw it. The corpse of the one that had fixed and now through my own stupidity destroyed my life. I walked over to her lifeless, motionless body. Looking into those longing, betrayed eyes I couldn't help laughing, it was a cold inhumane laugh that would scare the bravest of men. Laura, his one true love.
Walking through this house to the back door, I shivered. The strong, grilling, summer sunlight is not enough to warm my heart, let alone start it beating again, for it was now forever frozen and dark. Despair passed across me, for from that moment on I knew I would be but a shell of a human.
Far away I heard the screeching of sirens, splitting the happy cries of children and silencing the roar of traffic. Grabbing my knife, I licked it clean of the liquid it had become accustomed to be in contact with. I put it concealed into my belt and then I, the serial killer, fled.
In a crowd I would look like any other ordinary man, but if you got close and saw those sad, regretful eyes, you would know I was different. People who met me often said I was odd and found me difficult to talk to. It wasn't that I was anti-social but when I went out not many talked to me. I was rejected often at bars and clubs. Soon I gave up asking and as time passed I went out less and less, losing the hope I would meet anybody or have any friends.
My life was a wreck and a misery. I had become confined to my house, never leaving unless for food and supplies. Slowly the house become dirty and derelict, with the weeds in the garden high up to the windows, covering the paths and killing any flowers that struggled to live. Parents urged their children to stay away from me. Strangely anybody that came to talk to me about the state of the house never came out again and soon a weak odour filled the air inside the house. Laura's corpse had joined theirs.
When I had met Laura my world opened up to a whole new range of possibilities. I started to go out again, I met new people but most importantly he started to love life again. I was starting to be normal. Laura and I had newly painted the house, cleaning the inside and out. The garden became tidy and bright, glowing flowers grew quickly replacing the colourless weeds. Old friends commented about the change in me and began inviting Laura and I to dinner. It was all because of her ? the candle in my world of darkness, growing brighter and giving me strength. But I had snuffed out that candle, plunging my life into darkness again.
As I walked out the back door I noticed that all of the flowers, which were alive and happy earlier that morning, were dead and dry. Even though it made no logical sense I knew why.
I strolled slowly away from the house, towards the park. Laura always loved the park, so full of happiness whenever we went for a walk together.
I walked down passed a bed of flowers, Tulips and Roses, Laura's favorites. I crouched and picked a Tulip from the group and nestled it in my palms. It's violet colour quickly faded into a deathly grey and shrivelled up to nothing more than an empty shell, just like me.
A shadow swept past be, I recognised the slight chill. I looked up to see a man wearing blue standing over me with his hands on his hips and a sad "not another one." look on his face. I just turned away from him and continued to sob at the dead flower nestled in my palms.
"Sir..." The mans voice spoke.
"... I need you to stand up please." it ordered.
I never really cared too much for this man, he only lasted those few seconds in my memories. Then he was gone - like all the rest.
"I love you, I don't want to leave you." I spun, hoping to catch a glimpse of the speaker.
There was no one there.
I recognised the voice, it was Laura's. No, I must be dreaming, this cant be happening! I dreaded this moment. I knew it would come, it always does and always will.
I became attached to her, I loved her, I wanted to have children with her, I killed her...
This is where it all ends.
Three days later, I was found in her bloody arms with a bullet through my head and a letter in her hands:
Don't cry for me now I'm gone, I knew what I had done and every second I deserved; I killed him. I took his breath away and he mine. Together in each others dieing arms is where we belong.
Tuesday, 18 January 2011
C Four, Connect Four, miGame
I'm taking a break from miTanks for a while. Here's one of my first ever programs.
I spend alot of my time in lectures at University playing Connect Four on a piece of paper against friends. This is the best paper game we could come up with. Turn based, so could simply pass notes or signal which column to drop in. And there was no need for an eraser; imaging trying to play chess with a pen.
At the time we were learning C programming and had to come up with some simple program to prove we learnt something in the course. Alot of people went with a Facebook similar 'What animal are you?' kind of game. Boring!
It took about 2-3 hours. Remember this was my first C program I created purely by myself, aside from Visual Basic and MicroWorlds (if that even counts).
Code:
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
//C(onnect) Four
//Created by: Milk
//Date of final build: 19/10/09
//Height of each line
#define LINE_HEIGHT 6
#define LINE_WIDTH 7
void DrawBoard(int grid[LINE_HEIGHT][LINE_WIDTH]);
int CalculateWin(int grid[LINE_HEIGHT][LINE_WIDTH], int player);
int ValidInput(int input, int grid[LINE_HEIGHT][LINE_WIDTH]);
int main(void)
{
//Plays connect four
int grid[LINE_HEIGHT][LINE_WIDTH] = {0};
int gameOver = 0;
int input = 0;
int player = 1;
char inputValid;
int i;
//Draw the intitial board (empty)
DrawBoard(grid);
while (gameOver == 0 && (grid[LINE_HEIGHT - 1][0] == 0 || grid[LINE_HEIGHT - 1][1] == 0 || grid[LINE_HEIGHT - 1][2] == 0 || grid[LINE_HEIGHT - 1][3] == 0 || grid[LINE_HEIGHT - 1][4] == 0 || grid[LINE_HEIGHT - 1][5] == 0 || grid[LINE_HEIGHT - 1][6] == 0)) {
//Get input from user
input = 0;
printf("\nWhere would you like to go, player %d?\n", player);
scanf("%d", &input);
//Decide if input is a valid move
inputValid = ValidInput(input, grid);
//If input is not valid prompt for a valid move
while (inputValid == 0) {
printf("Please choose a valid position: ");
scanf("%d", &input);
inputValid = ValidInput(input, grid);
}
//Add input to grid
for (i = 0; i < LINE_WIDTH; i++) {
if (grid[i][input - 1] == 0) {
grid[i][input - 1] = player;
break;
}
}
//Draw the board
DrawBoard(grid);
//Calculate if there is a win
gameOver = CalculateWin(grid, player);
//Set the next players turn
if (player == 1) {
player = 2;
} else {
player = 1;
}
}
//Print winner
if (gameOver == 0) {
printf("\n\nThere are no more available moves!\nIt's a draw\n");
} else {
printf("\n\nCongratulations player %d!\nYou won\n", gameOver);
}
return 0;
}
void DrawBoard(int grid[LINE_HEIGHT][LINE_WIDTH])
{
//Draws the board
int i, j;
printf("\n\n\n\n\n");
for (i = LINE_HEIGHT - 1; i >= 0; i--) {
printf("\nI");
for (j = 0; j < LINE_WIDTH; j++) {
if (grid[i][j] == 0) {
printf(" I");
} else if (grid[i][j] == 1) {
printf(" X I");
} else {
printf(" O I");
}
}
}
printf("\n__1___2___3___4___5___6___7__");
return;
}
int ValidInput(int input, int grid[LINE_HEIGHT][LINE_WIDTH])
{
//Calculate if input is valid
if (input < 0 || input > 8 || grid[LINE_HEIGHT - 1][input - 1] != 0) {
return 0;
} else {
return 1;
}
}
int CalculateWin(int grid[LINE_HEIGHT][LINE_WIDTH], int player)
{
int i, j;
//Calculate if there is a win on the horizontal
for (j = 0; j < LINE_WIDTH - 3; j++) {
for (i = 0; i < LINE_HEIGHT; i++) {
if (grid[i][j] == grid[i][j + 1] && grid[i][j] == grid[i][j + 2] && grid[i][j] == grid[i][j + 3] && grid[i][j] != 0) {
return player;
}
}
}
//Calculate if there is a vertical win
for (i = 0; i < LINE_HEIGHT - 3; i++) {
for (j = 0; j < LINE_WIDTH; j++) {
if (grid[i][j] == grid[i + 1][j] && grid[i][j] == grid[i + 2][j] && grid[i][j] == grid[i + 3][j] && grid[i][j] != 0) {
return player;
}
}
}
//Calculate if there is a diagonal up-right win
for (i = 0; i < LINE_HEIGHT - 3; i++) {
for (j = 0; j < LINE_WIDTH - 3; j++) {
if (grid[i][j] == grid[i + 1][j + 1] && grid[i][j] == grid[i + 2][j + 2] && grid[i][j] == grid[i + 3][j + 3] && grid[i][j] != 0) {
return player;
}
}
}
//Calculate if there is a diagonal up-left win
for (i = 0; i < LINE_HEIGHT - 3; i++) {
for (j = LINE_WIDTH - 1; j >= 0; j--) {
if (grid[i][j] == grid[i + 1][j - 1] && grid[i][j] == grid[i + 2][j - 2] && grid[i][j] == grid[i + 3][j - 3] && grid[i][j] != 0) {
return player;
}
}
}
//No win
return 0;
}
When compiled the exe file is only 56.0KiB. So it's pretty much always on my USB drive now.
And here it is:
http://rapidshare.com/files/443141503/Connect4.txt
I don't think rapidshare likes exe files so once you download just change the file extension (txt) to exe, and it will work. Give it a go.
Looking back at this code there is not actually too many things I would do differently. Would've been a nice OO exercise though.
If anyone wants to give me a game just tell me your starting move. Let's play. Lol
Cheers,
Milk
I spend alot of my time in lectures at University playing Connect Four on a piece of paper against friends. This is the best paper game we could come up with. Turn based, so could simply pass notes or signal which column to drop in. And there was no need for an eraser; imaging trying to play chess with a pen.
At the time we were learning C programming and had to come up with some simple program to prove we learnt something in the course. Alot of people went with a Facebook similar 'What animal are you?' kind of game. Boring!
It took about 2-3 hours. Remember this was my first C program I created purely by myself, aside from Visual Basic and MicroWorlds (if that even counts).
Code:
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
//C(onnect) Four
//Created by: Milk
//Date of final build: 19/10/09
//Height of each line
#define LINE_HEIGHT 6
#define LINE_WIDTH 7
void DrawBoard(int grid[LINE_HEIGHT][LINE_WIDTH]);
int CalculateWin(int grid[LINE_HEIGHT][LINE_WIDTH], int player);
int ValidInput(int input, int grid[LINE_HEIGHT][LINE_WIDTH]);
int main(void)
{
//Plays connect four
int grid[LINE_HEIGHT][LINE_WIDTH] = {0};
int gameOver = 0;
int input = 0;
int player = 1;
char inputValid;
int i;
//Draw the intitial board (empty)
DrawBoard(grid);
while (gameOver == 0 && (grid[LINE_HEIGHT - 1][0] == 0 || grid[LINE_HEIGHT - 1][1] == 0 || grid[LINE_HEIGHT - 1][2] == 0 || grid[LINE_HEIGHT - 1][3] == 0 || grid[LINE_HEIGHT - 1][4] == 0 || grid[LINE_HEIGHT - 1][5] == 0 || grid[LINE_HEIGHT - 1][6] == 0)) {
//Get input from user
input = 0;
printf("\nWhere would you like to go, player %d?\n", player);
scanf("%d", &input);
//Decide if input is a valid move
inputValid = ValidInput(input, grid);
//If input is not valid prompt for a valid move
while (inputValid == 0) {
printf("Please choose a valid position: ");
scanf("%d", &input);
inputValid = ValidInput(input, grid);
}
//Add input to grid
for (i = 0; i < LINE_WIDTH; i++) {
if (grid[i][input - 1] == 0) {
grid[i][input - 1] = player;
break;
}
}
//Draw the board
DrawBoard(grid);
//Calculate if there is a win
gameOver = CalculateWin(grid, player);
//Set the next players turn
if (player == 1) {
player = 2;
} else {
player = 1;
}
}
//Print winner
if (gameOver == 0) {
printf("\n\nThere are no more available moves!\nIt's a draw\n");
} else {
printf("\n\nCongratulations player %d!\nYou won\n", gameOver);
}
return 0;
}
void DrawBoard(int grid[LINE_HEIGHT][LINE_WIDTH])
{
//Draws the board
int i, j;
printf("\n\n\n\n\n");
for (i = LINE_HEIGHT - 1; i >= 0; i--) {
printf("\nI");
for (j = 0; j < LINE_WIDTH; j++) {
if (grid[i][j] == 0) {
printf(" I");
} else if (grid[i][j] == 1) {
printf(" X I");
} else {
printf(" O I");
}
}
}
printf("\n__1___2___3___4___5___6___7__");
return;
}
int ValidInput(int input, int grid[LINE_HEIGHT][LINE_WIDTH])
{
//Calculate if input is valid
if (input < 0 || input > 8 || grid[LINE_HEIGHT - 1][input - 1] != 0) {
return 0;
} else {
return 1;
}
}
int CalculateWin(int grid[LINE_HEIGHT][LINE_WIDTH], int player)
{
int i, j;
//Calculate if there is a win on the horizontal
for (j = 0; j < LINE_WIDTH - 3; j++) {
for (i = 0; i < LINE_HEIGHT; i++) {
if (grid[i][j] == grid[i][j + 1] && grid[i][j] == grid[i][j + 2] && grid[i][j] == grid[i][j + 3] && grid[i][j] != 0) {
return player;
}
}
}
//Calculate if there is a vertical win
for (i = 0; i < LINE_HEIGHT - 3; i++) {
for (j = 0; j < LINE_WIDTH; j++) {
if (grid[i][j] == grid[i + 1][j] && grid[i][j] == grid[i + 2][j] && grid[i][j] == grid[i + 3][j] && grid[i][j] != 0) {
return player;
}
}
}
//Calculate if there is a diagonal up-right win
for (i = 0; i < LINE_HEIGHT - 3; i++) {
for (j = 0; j < LINE_WIDTH - 3; j++) {
if (grid[i][j] == grid[i + 1][j + 1] && grid[i][j] == grid[i + 2][j + 2] && grid[i][j] == grid[i + 3][j + 3] && grid[i][j] != 0) {
return player;
}
}
}
//Calculate if there is a diagonal up-left win
for (i = 0; i < LINE_HEIGHT - 3; i++) {
for (j = LINE_WIDTH - 1; j >= 0; j--) {
if (grid[i][j] == grid[i + 1][j - 1] && grid[i][j] == grid[i + 2][j - 2] && grid[i][j] == grid[i + 3][j - 3] && grid[i][j] != 0) {
return player;
}
}
}
//No win
return 0;
}
When compiled the exe file is only 56.0KiB. So it's pretty much always on my USB drive now.
And here it is:
http://rapidshare.com/files/443141503/Connect4.txt
I don't think rapidshare likes exe files so once you download just change the file extension (txt) to exe, and it will work. Give it a go.
Looking back at this code there is not actually too many things I would do differently. Would've been a nice OO exercise though.
If anyone wants to give me a game just tell me your starting move. Let's play. Lol
Cheers,
Milk
Wednesday, 12 January 2011
miTanks, Part 8, Initial Release!!!
Added another ground type, gravel. But thats about it.
The ground is randomly up and down, but never so high that you can't climb it. I think it's the most realistic ground I have made. Suprisingly easy as well.
Ok guys. I'm running out of ideas. Foo's to get to work on having the menu up and running. I'll going to get to work on some of the inside bits.
I really want to make a release for you guys. What I'm going to do is find a way to put up a .jar file. Because the program has no real visual output, I'll leave you instructions on how to run it through the command line. This will allow you to see what I see. Playable, but in no way is it finished.
How to use:
Download the jar file and place it somewhere on your computer.
Right-click on the file and click 'Properties'.
Copy the location of the file.
Open the command line. (Windows > Search > "cmd").
Type "cd [location in full]" and press enter.
Type "java -jar miTanks.jar" and press enter.
This will open the game.
Notes:
The ground is gravel and there are 3 players (2 human controlled and a computer controlled). The first player is the blue one, he is human controlled. The second is red, and is also human controlled. The last is still red, but he is a computer player that randomly picks a direction, power and fires.
If I get some comments, I'll upload versions with a certain amount of what players and what ground etc.
The angle works like this: 0 is straight up, -90 is left, 90 is right.
Power goes between 0 and 100.
Your power and angle will be displayed in the command line.
Your life comes up here as well as you get damaged.
And some other crap. Sorry I'm still using these tracers so that's why they are still there.
Once you win you will have to close and open again. Just press up when in the command line then Enter.
Controls:
w = increase power
s = decrease power
a = decrease angle
d = increase angle
z = move left
x = move right
q = previous weapon
e = next weapon
Enter = fire
Please leave a comment! Chances are, there will be some issues with this.
The ground is randomly up and down, but never so high that you can't climb it. I think it's the most realistic ground I have made. Suprisingly easy as well.
Ok guys. I'm running out of ideas. Foo's to get to work on having the menu up and running. I'll going to get to work on some of the inside bits.
I really want to make a release for you guys. What I'm going to do is find a way to put up a .jar file. Because the program has no real visual output, I'll leave you instructions on how to run it through the command line. This will allow you to see what I see. Playable, but in no way is it finished.
Download Link:
http://rapidshare.com/files/442108182/miTanks.jar
How to use:
Download the jar file and place it somewhere on your computer.
Right-click on the file and click 'Properties'.
Copy the location of the file.
Open the command line. (Windows > Search > "cmd").
Type "cd [location in full]" and press enter.
Type "java -jar miTanks.jar" and press enter.
This will open the game.
Notes:
The ground is gravel and there are 3 players (2 human controlled and a computer controlled). The first player is the blue one, he is human controlled. The second is red, and is also human controlled. The last is still red, but he is a computer player that randomly picks a direction, power and fires.
If I get some comments, I'll upload versions with a certain amount of what players and what ground etc.
The angle works like this: 0 is straight up, -90 is left, 90 is right.
Power goes between 0 and 100.
Your power and angle will be displayed in the command line.
Your life comes up here as well as you get damaged.
And some other crap. Sorry I'm still using these tracers so that's why they are still there.
Once you win you will have to close and open again. Just press up when in the command line then Enter.
Controls:
w = increase power
s = decrease power
a = decrease angle
d = increase angle
z = move left
x = move right
q = previous weapon
e = next weapon
Enter = fire
Please leave a comment! Chances are, there will be some issues with this.
Labels:
beta,
Code,
command line,
generators,
jar,
java,
mi,
runnable,
screenshot,
tank,
tanks,
test,
upload
Subscribe to:
Posts (Atom)









