ErlendHL
1313 posts
|
Hey! I was wondering if it’s possible to write/read single bits to/from a ByteArray.
writeBoolean claims to write a byte, that’s either 0 or 1. By byte, do they mean bit?
|
|
|
NineFiveThree
1370 posts
|
As3 takes a byte to store the boolean as it seems.
Do you want to save one single bit?
You can stack many together in a bigger type, say int for example.
|
|
|
ErlendHL
1313 posts
|
Originally posted by NineFiveThree:
As3 takes a byte to store the boolean as it seems.
Do you want to save one single bit?
You can stack many together in a bigger type, say int for example.
Yeah, I suppose I could do that if there’s no other choice :) The idea was to store things as 4-bit values (a DNA structure which I’m really confused about how to start coding).
|
|
|
Ace_Blue
1091 posts
|
Unless you’re doing something fancy, such as non-standard bases, you need only 2 bits to code for a base:
Adenine (A) = 0 (00)
Cytosine (C ) = 1 (01)
Guanine (G) = 2 (10)
Thymine (T) = 3 (11)
I put them in alphabetical order out of convenience but it turns out that complementary bases are bitwise NOTs of each other. I wonder if you can make use of that to construct the complementary sequence faster?
An uint uses 4 bytes so you can store 16 bases in a single one. Adding a base to a sequence is simply multiplying the sequence by 4 (to free up the last 2 digits in binary) and adding the proper base code (from 0 to 3). For reading, you should read backwards from the end of each 16-base sequence. sequence % 4 gives you the last base, and sequence >> 2 (sequence / 4) ‘pops’ the last base out.
The reason you should read from the end is that if your sequence doesn’t have a multiple of 16 bases the beginning of the last group (of 16 or less, the last integer) is padded with adenines (00). By storing the length of the sequence before the sequence itself you’ll know exactly how many of these adenines to keep. Unless you’re going to store entire genomes in this way the uint limit of ~4billions bases per sequence should be sufficient.
Edit: According to Wikipedia there’s about 3.2 billion base pairs in a human genome, so you could store an entire human genome in this way. Neat!
|
|
|
BobJanova
858 posts
|
In short, no: the API for ByteArray works with bytes. If you want to do things with bits then you’ll have to pack them together in 8s.
|
|
|
ErlendHL
1313 posts
|
Originally posted by BobJanova:
In short, no: the API for ByteArray works with bytes. If you want to do things with bits then you’ll have to pack them together in 8s.
Alright thanks.
@Ace_Blue
I’m not thinking about the human dna. Maybe then DNA is the wrong word, yes certainly, sorry. The right word is genes I think. It’s for the GiTD – lol it’s never gonna be finished ironically. I’m thinking about having the individuals be shapes of vectors, and somehow transcode the genes into vectors and shapes and indeed I would maybe have some other factors… I guess the “organism” should be able to move every single (or just some) of their vectors/shapes.
Every vector, also those in the shapes should have for instance hardness, moveableness (+power), strechyness… etc. properties.
And also I’m thinking about how the organisms are “born” – should they be born small and grow? In that case I guess I should also include that in the gene data. I want most of the stuff to be in the gene, so that the thing reading the gene and building the organism should be almost purely mechanical if you know what I mean…
So this became a pretty advanced project that will certainly not be finished in 10 days. Will have to implement good physics as well. Oh and I think the organisms will kinda float, camera from bird view.
I could really need some thoughts and advice around this! Thanks!
Oh and when I say vector I mean a single line (which is in most cases just one point since you already have the first point where it’s drawn from).
|
|
|
Ace_Blue
1091 posts
|
Oh woah, I see. That’s an amazingly ambitious project. I wish you luck!
Here’s an idea that might simplify your life: Have the organisms reproduce by division, and mutate throughout their life. That removes several problems:
1) Mixing genomes. When organisms reproduce sexually, their offspring have a mixture of both parents’ genomes. You have to figure out rules for that. With asexual reproduction by mitosis (Right? Biologists, help!) both children are identical to the parent. In fact, they’re both half-parent themselves!
2) Competition / survival of the fittest arises immediately: It takes energy for an organism to divide, so they only do it when they’re well-fed. It follows that organisms which are better at feeding themselves get to reproduce more often.
3) If you make the environment itself mutagenic the game will involve less waiting for the next generation. If you wish to compare the effectiveness of two (or more) organisms, you can turn down the mutation rate to 0 and see who prevails in an enclosed space, or has the higher population after X time.
You know, that could be a really fun “make your custom bacterium and send it to fight others in the arena” type of game. :)
|
|
|
JamesObscura
250 posts
|
@Ace_Blue: Asexual reproduction still uses a few techniques to get biodiversity but from what I understand it’s mostly small scale genetic drifting. Also I am not a biologist.
Very cool project by the way.
|
|
|
ErlendHL
1313 posts
|
Thank you very much guys! :D (Funny how the topic evolved from “writing bits” to “implementing genetics, inherit, mutations, crossover, fitness etc” :P)
There are parts of that I didn’t understand. [Edit; no actually I understand all now.] I’m not into the terminology here. I know about mutations (needed to actually make new genes and evolve), fitness (to determine fitness here I would need several factors to make it difficult for the organisms. Your idea about needing food for reproduction is great. I’m also thinking about having a second or several other species around that they can either eat or that are dangerous for them), and I know about the basic stuff about human genes and how new genes are randomly picked and copied and such.
I don’t know what you mean with reproduce by division. You mean like what cells do, so there is only one parent and it duplicates itself? So that they would be identical at birth but mutate throughout their life you mentioned.
Mitosis – I googled that, it’s what I mentioned about cells duplicating I guess. Is it that you mean with reproduce by division?
Well, just now I caught a thought… if the organisms were to do mitosis, there wouldn’t be one big species at the end, they all would just evolve in totally different directions wouldn’t they? Because there would be no blending of genes… But well because of the fitness factors, the ones that fits the best survives, but I still like the idea where the reproduce sexually better. Why – well first off, it’s more, well.. a species. I like that way of evolving best. Think about it – in nature, when some natural factor divides the species in two, they evolve in two directions because of that (speaking sexual reproduction). In the start of the game, the computer could randomly generate (genes) several organisms and the user could choose which individuals to start with. The problem here is maybe, how different can the genes of the few individuals the user chooses be?
Well these are just maybes and might bes, nothing is certain yet :P
I’ve also got a million of other thoughts but I won’t write them all down here :)
Edit: But again, mitosis would be cool. For example after dividing, the offspring are half the size and need to grow to the normal size before dividing again.
Edit2: Reading my post again, I’m too tired to comprehend what I’m thinking lol. Nite.
|
|
|
JamesObscura
250 posts
|
Mitosis works for evolution as well. A microbe splits into two, NEARLY genetically identical children. One is slightly more adapted to its enviroment than it’s parent and it’s sibling. It’s sibling and all of it’s children have a slighly lower chance of survival than the better adapted one and all of it’s children. Over millions of generations(Which for simple bactria could be a couple of years) the better adapted one’s offspring(‘s offspring’s offspring’s offsprings…) is going to have a much higher chance of still being around.
|
|
|
ErlendHL
1313 posts
|
Originally posted by JamesObscura:
Mitosis works for evolution as well. A microbe splits into two, NEARLY genetically identical children. One is slightly more adapted to its enviroment than it’s parent and it’s sibling. It’s sibling and all of it’s children have a slighly lower chance of survival than the better adapted one and all of it’s children. Over millions of generations(Which for simple bactria could be a couple of years) the better adapted one’s offspring(‘s offspring’s offspring’s offsprings…) is going to have a much higher chance of still being around.
That’s right, but it can’t evolve very much that way. Think about making it develop in two different direction by dividing them into two groups. Maybe (this is just an example) one of the groups evolve into a glob with something a little limb that it uses to swim and the other group develops some other kind of feature… This could make the user able to breed several species inside one game. This would also set another factor of fitness: organisms would have to be able to move towards a possible mate. And I’m also thinking that the way the organism searches for food and mates, and how they move their limps when they find something (also threats), is programmed in the genes.
Also, the user could eventually choose what organisms should mate – directly or indirectly – and this would add more interactivity to the game.
Well I will make this choice soon. For now, I’m sleeping :)
|
|
|
JamesObscura
250 posts
|
Yeah, sexual reproduction is probably a better game feature especially if the player is the one controling the organisms. Also there’s a reason we don’t asexually reproduce, sexual reproduction is a significantly more efficient method of reproduction.
|
|
|
Draco18s
6860 posts
|
Originally posted by JamesObscura:
Yeah, sexual reproduction is probably a better game feature especially if the player is the one controling the organisms. Also there’s a reason we don’t asexually reproduce, sexual reproduction is a significantly more efficient method of reproduction.
It’s less efficient, energy wise, but produces a larger number of mutations between parent and child.
|
|
|
Drakim
1148 posts
|
From my own tests all the basic writing and reading methods on the bytearray are equally fast. So using the readDouble and writeDouble will allow you to read and write 64 bits very quickly. Obviously you won’t be able to work on the data in the meanwhile. For that readInt is probably best suited.
|
|
|
Ace_Blue
1091 posts
|
OK, so you’re not going to be even close to real-life genetics anyway, so I would rather look at it from a ‘what is more fun’ standpoint, mingled with a substantial dose of the ‘what is practical to code’ standpoint. And frankly, sexual reproduction seems like a huge complication from a design standpoint.
As long as organisms reproduce by cutting themselves in identical halves, they have one goal: get as much food in their system as they can so they can split as often as possible. As soon as you introduce sexual reproduction, you have complementary goals: survive long enough to reach sexual maturity, find one or more suitable partner(s) and overcome sexual competitors. Although the balance of these aspects seems like it would provide a more compelling gameplay than the ‘eat as much as possible’ one size fits all strategy of the asexual organism, I fear it might prove too complicated.
But of course, it all depends on the scope and the goal of the game. Is the player trying to help one individual within a species or the species as a whole? Does the player have access to the genetics code?
Regarding this: “Well, just now I caught a thought… if the organisms were to do mitosis, there wouldn’t be one big species at the end, they all would just evolve in totally different directions wouldn’t they?” Genetic variation among individuals in a single species is a part of life in our world. The ‘human genome’ in not a fixed sequence. Everyone’s genome is different, except for identical twins. The differences are minor, though. From a practical standpoint, though, if you have asexual reproduction, you can identify as ‘species A’ every single organism which is the direct descendant of an organism of ‘species A’. If you have sexual reproduction, and two organisms of different species happen to mate and produce viable offspring, are the children of any parent’s species? Is a mule a horse? A donkey? Both? Neither? One definition of a species is a group of interfertile individuals, meaning individuals which, when mating, can produce fertile offspring. So if a ‘species A’ organism and a ‘species B’ organism have a fertile child, were they the same species all along? The sexual reproduction way seems more ambiguous to me than the asexual way.
I can’t believe I’m arguing against sex.
|
|
|
Draco18s
6860 posts
|
So if a ‘species A’ organism and a ‘species B’ organism have a fertile child, were they the same species all along?
Yes. By definition.
|
|
|
UnknownGuardian
8141 posts
|
I’m going to argue no for an edge case. Species does mean capable of producing fertile offspring but there are some **rare** cases where organisms don’t have to be in the same species (here as in the biological terms: family, genus, species) to be able to produce fertile offspring.
And its amazing that we go from “writing bits” to “sexual reproduction” in a programming forum.
|
|
|
Draco18s
6860 posts
|
True, there are a few cases of fertile hybrids, but they are fairly rare. It’s an edge case that can be safely ignored in simulations.
|
|
|
NineFiveThree
1370 posts
|
Originally posted by UnknownGuardian:
And its amazing that we go from “writing bits” to “sexual reproduction” in a programming forum.
Well, what’s the difference, really?
Sure enough, those bits are part of a very slow extracting archive file (depends on species), but conceptually, it’s quite similar.
=D
|
|
|
Ace_Blue
1091 posts
|
Originally posted by Draco18s:
So if a ‘species A’ organism and a ‘species B’ organism have a fertile child, were they the same species all along?
Yes. By definition.
You missed the point.
In the simulation game, species presumably belong to players, and saying the two species are one and relabeling means that the two players are now one!
|
|
|
ErlendHL
1313 posts
|
I’ll try to make it sexual reproduction. I see that the AI would have to be more complex, but I’ll have the AI in the genes as well, and let it evolve just like the appearance of the organisms. To survive best, the organisms would need to evolve an AI that would include several goals, like finding a mate, finding food, dodging dangers etc.
I don’t yet know what dangers there are though, but I guess the most natural thing is another species. Let’s say the two species were different in many ways. It’d be preferably if the AI also evolved to find more similar organisms attractive, and more different organisms hostile (food), naturally. The first thing I think will come naturally, because the offspring of two very different organisms will differ very much. And well, if the species started eating each other they would die. But I can’t always predict the ways of the evolution, not even simulated. But imo it’s worth a try, and I’m willing to put lots of work in this project because I find it very interesting.
|