is it possible that 'code writes code'?

This forum is for anything that doesn't specifically have to do with Better Than Wolves
Post Reply
User avatar
CheGiuAn
Posts: 198
Joined: Sun Jul 17, 2011 3:35 am
Location: Székelyudvarhely (Transilvania)

is it possible that 'code writes code'?

Post by CheGiuAn »

I'm not a programmer, I'm just curious about it (maybe you can use it sometime if it's possible)
My question is:
Is it possible, that you write a code, that allows for example to make half blocks in the way vanill Minecraft does, but from any kind of block. And if this code meets with a new block (maybe from an other mod), it will automatically write a code for the new blocks half block (behaviour the same as all half block, the texture the same as the original block, etc.) So that you don'T have to spend time codeing that too.
The idea is not about the half blocks, I just used them as an example, but in general, is it possible to write a code, that writes a code?
'Who want's to do, will always find a solution. Who Doesn't want to do, will always find an excuse.'

'If you want to teach something, you shall be the liveing example of it.'
User avatar
gftweek
Posts: 674
Joined: Thu Jul 07, 2011 5:33 pm

Re: is it possible that 'code writes code'?

Post by gftweek »

I guess the best answer is maybe.

It's entirely possible, but it relies on objects all being inherited from a similar structure, so that they can be treated the same way. Unfortunately not all objects are, for example sand and gravel obey gravity, but other blocks do not, so what should their half blocks (to use your example) do if unsupported. Also because they behave differently to say stone and wood (which are again different, with different hardness, explosion resistance strength, flammability, etc), they may not get treated the way you expect, so your code may not work for a new block that doesn't behave in a similar manner.
User avatar
CheGiuAn
Posts: 198
Joined: Sun Jul 17, 2011 3:35 am
Location: Székelyudvarhely (Transilvania)

Re: is it possible that 'code writes code'?

Post by CheGiuAn »

Well, the Vanilla wooden half blocks are not flameable, but as I said, I just used that idea as an example.
And I don't know if I'm right, if I'm not expecting the answer for me (as I'm not a programmer), but for the programmers, who could use it (or who knew that it's possible, but haven'T thought of useing it and they could make good things with it)
'Who want's to do, will always find a solution. Who Doesn't want to do, will always find an excuse.'

'If you want to teach something, you shall be the liveing example of it.'
Banpower1
Posts: 32
Joined: Mon Aug 15, 2011 4:57 pm

Re: is it possible that 'code writes code'?

Post by Banpower1 »

In theory i think you are very able to write a code that creates half blocks for everything, but then it would be EVERYTHING unless you filter by some weird property...

you would need to write code saying

Code: Select all

find all blocks
create new block for each block found with collision being half in height
Use half the texture of the original block on the sides
give it same properties (usage, reaction, etc.) as original stone slab
recipe: 3 of original block in a line (like stone slab, just translated)
this would (if written in actual code) in theory be a possibility, TMI is able to detect all blocks, no matter what you install.
problem is, you would get halfblocks of for example ovens, redwire, torches, saplings and pistons, all of them not working any different than a regular slab :P
User avatar
CheGiuAn
Posts: 198
Joined: Sun Jul 17, 2011 3:35 am
Location: Székelyudvarhely (Transilvania)

Re: is it possible that 'code writes code'?

Post by CheGiuAn »

I shouldn't have used any example >.<
anyways, I think, I got the answer, it's possible (I think o.<)
Hope someone can use it to make something nice :)
'Who want's to do, will always find a solution. Who Doesn't want to do, will always find an excuse.'

'If you want to teach something, you shall be the liveing example of it.'
Banpower1
Posts: 32
Joined: Mon Aug 15, 2011 4:57 pm

Re: is it possible that 'code writes code'?

Post by Banpower1 »

Well to return to the more theoretical part: its possible to write code that reacts to other code without actually writing the other code into it (reaction to unknown code with only a certain standard) but it is not possible to actually write code with code, since the code you are "executing" (running) is something that is compiled from a human understandable level to a non human understandable level, which takes time, (not hours on end, but it would take more time that you would want a game to load extra than all the other stuff (has to write code, and then compile code, and probably move it from temp folders into the actual code)) so in theory: sure you can write code from inside the game, but you need to reload the code every time you do, which can take time, aside from the time of the actual code writing and compiling

(if i said anything that makes no sense to you, please do point it out, don't mind specifying stuff :) )
User avatar
finite8
Posts: 587
Joined: Mon Jul 04, 2011 9:31 pm
Location: Melbourne, Australia

Re: is it possible that 'code writes code'?

Post by finite8 »

You have stumbled upon many a thesis topic.

What you thinking of has two separate approaches:
- Have a block have all of its properties and behaviours entirely dynamic and run-time configurable.
- Have a "template" code structure that defines what a block is and then build a new class based upon then template.

This kind of stuff reminds me of this particular article: http://www.codeproject.com/KB/cs/nduck.aspx

Alternatively, such an approach would require everything in-game have all of their behaviours as "delegates" (i know java has the equivalent). This way, you would effectively be able to bind code to particular events in each of the blocks. As such, you could effectively have a block be whatever you wanted it to be and have the declared and modifiable at runtime.
Flowerchild (IRC) wrote:I'm not trying to stop you BTW ..., I'm saying that I think you're a piece of shit...not the same thing
Banpower1
Posts: 32
Joined: Mon Aug 15, 2011 4:57 pm

Re: is it possible that 'code writes code'?

Post by Banpower1 »

finite8 wrote:You have stumbled upon many a thesis topic.

What you thinking of has two separate approaches:
- Have a block have all of its properties and behaviours entirely dynamic and run-time configurable.
- Have a "template" code structure that defines what a block is and then build a new class based upon then template.

This kind of stuff reminds me of this particular article: http://www.codeproject.com/KB/cs/nduck.aspx

Alternatively, such an approach would require everything in-game have all of their behaviours as "delegates" (i know java has the equivalent). This way, you would effectively be able to bind code to particular events in each of the blocks. As such, you could effectively have a block be whatever you wanted it to be and have the declared and modifiable at runtime.
eh?
I'm sorry sir, i think i lost you there... either way not my question, i'll learn about it eventually along the way :P

RETHINK: (not edit, it came before posting, but after 1 min timeout after creating a response)
I think i understand now, and with that i understand you probably could write code that would write code for you while you play... i would simply put be using the run-time client to edit its own files... :P
User avatar
Zhil
Posts: 4486
Joined: Thu Jul 14, 2011 3:12 pm
Location: Belgium

Re: is it possible that 'code writes code'?

Post by Zhil »

It's possible, but not in the way you suggest. There's no need to "generate" code (which is possible and not too hard either). It can be done with just a bit of Object Oriented programming.

It's hard to explain to a non-programmer, but it would be possible to create half-steps for all blocks you want it for, using up only one block ID for all of them. I don't think anyone has done it yet, but it wouldn't be difficult at all.
Come join us at Vioki's Discord! discord.gg/fhMK5kx
empath
Posts: 33
Joined: Tue Jul 05, 2011 12:41 pm

Re: is it possible that 'code writes code'?

Post by empath »

I think the OP has just independently invented object oriented programming.

Not joking around, you should probably think about learning how to program, sounds like you have a knack for it :)
User avatar
Zhil
Posts: 4486
Joined: Thu Jul 14, 2011 3:12 pm
Location: Belgium

Re: is it possible that 'code writes code'?

Post by Zhil »

Yeah, it's the suggestion of someone with a good brain, but no programming knowledge. You should buy a book man :)
Come join us at Vioki's Discord! discord.gg/fhMK5kx
User avatar
CheGiuAn
Posts: 198
Joined: Sun Jul 17, 2011 3:35 am
Location: Székelyudvarhely (Transilvania)

Re: is it possible that 'code writes code'?

Post by CheGiuAn »

Gilberreke wrote:Yeah, it's the suggestion of someone with a good brain, but no programming knowledge. You should buy a book man :)
Not needed (my brother has one for JAVA in 24 hours, and one for C++ 24 hours)
But neh, it's not my cup of tea (I even have problems where to plug in the keyboard or the mouse to the comuter.... I'm really naab with this kind of thing)
We leart 'Borland Pascal' or what in the past 2 years (we won't anyomere) in the school, I liked that too, but I don'T want to dig deeper...
But I like maths anyway :D
Spoiler
Show
And I'm going horse riding sometimes, cuz that's awsome :D
'Who want's to do, will always find a solution. Who Doesn't want to do, will always find an excuse.'

'If you want to teach something, you shall be the liveing example of it.'
User avatar
Zhil
Posts: 4486
Joined: Thu Jul 14, 2011 3:12 pm
Location: Belgium

Re: is it possible that 'code writes code'?

Post by Zhil »

I'm a complete computer klutz too man, that has nothing to do with programming. If you love math, you should get into programming, it's just too fun to ignore.

I started with Pascal too, it's a pretty boring language compared to what's out there. And if you like math, you'll love programming.
Come join us at Vioki's Discord! discord.gg/fhMK5kx
User avatar
CheGiuAn
Posts: 198
Joined: Sun Jul 17, 2011 3:35 am
Location: Székelyudvarhely (Transilvania)

Re: is it possible that 'code writes code'?

Post by CheGiuAn »

I yet don't wanna try it.
My brother is quite into it, and I don't want to 'copy' him, and his well, lets say 'expertness' (compared to my 0 knowledge) would have a 'discourageing' effect on me (as far as I know myself). This is just not for me :)
'Who want's to do, will always find a solution. Who Doesn't want to do, will always find an excuse.'

'If you want to teach something, you shall be the liveing example of it.'
User avatar
BinoAl
Posts: 2552
Joined: Mon Jul 04, 2011 9:39 pm
Location: Everywhere.

Re: is it possible that 'code writes code'?

Post by BinoAl »

Ive always thought about something like this, but on a bigger scale than a minecraft mod. My idea was make a program that creates, say 500 programs. just random functions plastered together. Once per day, have a line added or removed, and simulate natural selection, but with code. My problem with the concept was how i would detect which code was "better". Im not much of a programmer as it is, so this is definitely out of my scope, but i would absolutely love to do this someday ^.^
Image
empath
Posts: 33
Joined: Tue Jul 05, 2011 12:41 pm

Re: is it possible that 'code writes code'?

Post by empath »

That's called a genetic algorithm. There are plenty of examples of it.

http://en.wikipedia.org/wiki/Genetic_algorithm

What you're looking for is a test for fitness. There are lots of ways to measure it.

For example, there's a build order generator for starcraft that lets you input the number of units you want to build, and it just does random build orders and breeds the ones with faster times that get the requested units.
User avatar
Zhil
Posts: 4486
Joined: Thu Jul 14, 2011 3:12 pm
Location: Belgium

Re: is it possible that 'code writes code'?

Post by Zhil »

BinoAl wrote:Im not much of a programmer as it is, so this is definitely out of my scope, but i would absolutely love to do this someday ^.^
If you want to be original, I'm afraid you're a bit late. There's been people writing evolving programs since the 50's.

One such approach can be found here: http://en.wikipedia.org/wiki/Genetic_algorithm
Come join us at Vioki's Discord! discord.gg/fhMK5kx
User avatar
Fracture
Posts: 570
Joined: Tue Jul 05, 2011 12:38 am

Re: is it possible that 'code writes code'?

Post by Fracture »

Cannot be arsed to read replies, giving my opinion on OP:

Yes. For something like that, you would have a "Half-Block" class. When, for instance, you'd put modblock x in front of a powered saw (event), it first checks to see if modblock x has a half block (goes through the damage value classes of the half-block ID, checking for one with the name property "modblock x"). If not, it will create a new class, inherited from half-block, and then assign the appropriate properties to the block (name, texture from wherever modblock x's original texture came from, etc), and make it a block with the half-block ID and the next highest damage value compared to what already exists.

I'm fairly sure, in fact, you could even have it save those classes, but that last step I have not yet learned so far.
Abracadabra, you're an idiot.
User avatar
CheGiuAn
Posts: 198
Joined: Sun Jul 17, 2011 3:35 am
Location: Székelyudvarhely (Transilvania)

Re: is it possible that 'code writes code'?

Post by CheGiuAn »

Fracture wrote:I'm fairly sure, in fact, you could even have it save those classes, but that last step I have not yet learned so far.
Well, yeah, I meant it that way, that it would save the .class files, and add the to the game / mod / whatsoever, not in a way to write it each time you play :)
'Who want's to do, will always find a solution. Who Doesn't want to do, will always find an excuse.'

'If you want to teach something, you shall be the liveing example of it.'
Post Reply