Author Topic: Eyes  (Read 3144 times)

Offline Darwin226

  • Bot Neophyte
  • *
  • Posts: 18
    • View Profile
Eyes
« on: November 05, 2008, 04:58:06 PM »
I've made a code that determines which eye has the greatest value and sets it as a focus eye.
This is it:

[div class=\'codetop\']CODE[div class=\'codemain\' style=\'height:200px;white-space:pre;overflow:auto\']cond
*.mode 1 =
start
-4 .focuseye store
stop

cond
*.mode 1 =
*.eye2 *.eye1 >
start
-3 .focuseye store
stop

cond
*.mode 1 =
*.eye3 *.eye2 >
start
-2 .focuseye store
stop

cond
*.mode 1 =
*.eye4 *.eye3 >
start
-1 .focuseye store
stop

cond
*.mode 1 =
*.eye5 *.eye4 >
start
0 .focuseye store
stop

cond
*.mode 1 =
*.eye6 *.eye5 >
start
1 .focuseye store
stop

cond
*.mode 1 =
*.eye7 *.eye6 >
start
2 .focuseye store
stop

cond
*.mode 1 =
*.eye8 *.eye7 >
start
3 .focuseye store
stop

cond
*.mode 1 =
*.eye9 *.eye8 >
start
4 .focuseye store
stop

The problem:
It's 9 genes. Has anyone thought of something that has the same effect but it less genes?

If someone has, can I use it?


As usual, thanks in advance =)

Offline bacillus

  • Bot Overlord
  • ****
  • Posts: 907
    • View Profile
Eyes
« Reply #1 on: November 05, 2008, 11:12:35 PM »
Even better, I did it in one store   :
Code: [Select]
-4 *.eye1 *.eye9 sub sgn 0 floor mult *.eye1 *.eye8 sub sgn 0 floor mult *.eye1 *.eye7 sub sgn 0    floor mult *.eye1 *.eye6 sub sgn 0 floor mult *.eye1 *.eye5 sub sgn 0 floor mult *.eye1 *.eye4 sub   sgn 0 floor mult *.eye1 *.eye3 sub sgn 0 floor mult *.eye1 *.eye2 sub sgn 0 floor mult 4 *.eye9     *.eye8 sub sgn 0 floor mult *.eye9 *.eye7 sub sgn 0 floor mult *.eye9 *.eye6 sub sgn 0 floor mult
 *.eye9 *.eye5 sub sgn 0 floor mult *.eye9 *.eye4 sub sgn 0 floor mult *.eye9 *.eye3 sub sgn 0 floor  mult *.eye9 *.eye2 sub sgn 0 floor mult *.eye9 *.eye1 sub sgn ++ sgn mult add -3 *.eye2 *.eye9 sub   sgn ++ sgn mult *.eye2 *.eye8 sub sgn 0 floor mult *.eye2 *.eye7 sub sgn 0 floor mult *.eye2 *.eye6  sub sgn 0 floor mult *.eye2 *.eye5 sub sgn 0 floor mult *.eye2 *.eye4 sub sgn 0 floor mult *.eye2    *.eye3 sub sgn 0 floor mult *.eye2 *.eye1 sub sgn ++ sgn mult add 3 *.eye8 *.eye9 sub sgn ++ sgn     mult *.eye8 *.eye7 sub sgn 0 floor mult *.eye8 *.eye6 sub sgn 0 floor mult *.eye8 *.eye5 sub sgn 0   floor mult *.eye8 *.eye4 sub sgn 0 floor mult *.eye8 *.eye3 sub sgn 0 floor mult *.eye8 *.eye2 sub   sgn ++ sgn mult *.eye8 *.eye1 sub sgn ++ sgn mult add -2 *.eye3 *.eye9 sub sgn ++ sgn mult *.eye3    *.eye8 sub sgn ++ sgn mult *.eye3 *.eye7 sub sgn 0 floor mult *.eye3 *.eye6 sub sgn 0 floor mult
 *.eye3 *.eye5 sub sgn 0 floor mult *.eye3 *.eye4 sub sgn 0 floor mult *.eye3 *.eye2 sub sgn ++ sgn   mult *.eye3 *.eye1 sub sgn ++ sgn mult add 2 *.eye7 *.eye9 sub sgn ++ sgn mult *.eye7 *.eye8 sub     sgn ++ sgn mult *.eye7 *.eye7 sub sgn 0 floor mult *.eye7 *.eye6 sub sgn 0 floor mult *.eye7 *.eye5  sub sgn 0 floor mult *.eye7 *.eye4 sub sgn ++ sgn mult *.eye7 *.eye2 sub sgn ++ sgn mult *.eye7     *.eye1 sub sgn ++ sgn mult add -1 *.eye4 *.eye9 sub sgn ++ sgn mult *.eye4 *.eye8 sub sgn ++ sgn mult *.eye4 *.eye7 sub sgn ++ sgn mult *.eye4 *.eye6 sub sgn 0 floor mult *.eye4 *.eye5 sub sgn 0    floor mult *.eye4 *.eye3 sub sgn ++ sgn mult *.eye4 *.eye2 sub sgn ++ sgn mult *.eye4 *.eye1 sub     sgn ++ sgn mult add 1 *.eye4 *.eye9 sub sgn ++ sgn mult *.eye4 *.eye8 sub sgn ++ sgn mult *.eye4    *.eye7 sub sgn ++ sgn mult *.eye4 *.eye6 sub sgn ++ sgn mult *.eye4 *.eye5 sub sgn 0 floor mult
 *.eye4 *.eye3 sub sgn ++ sgn mult *.eye4 *.eye2 sub sgn ++ sgn mult *.eye4 *.eye1 sub sgn ++ sgn     mult add 0 *.eye5 *.eye9 sub sgn ++ sgn mult *.eye5 *.eye8 sub sgn ++ sgn mult *.eye5 *.eye7 sub     sgn ++ sgn mult *.eye5 *.eye6 sub sgn ++ sgn mult *.eye5 *.eye4 sub sgn ++ sgn mult *.eye5 *.eye3   sub sgn ++ sgn mult *.eye5 *.eye2 sub sgn ++ sgn mult *.eye5 *.eye1 sub sgn ++ sgn mult add .focuseye store
Sorry about the indentations.
"They laughed at Columbus, they laughed at Fulton, they laughed at the Wright brothers. But they also laughed at Bozo the Clown."
- Carl Sagan

Offline Darwin226

  • Bot Neophyte
  • *
  • Posts: 18
    • View Profile
Eyes
« Reply #2 on: November 06, 2008, 06:34:18 AM »
OH MEH GAWD!!!

Whaaaa....
How?

*runs away*

Though I'm a little scared to ask, could you explain how it works?

If it's too long to explain or something you don't need to.
« Last Edit: November 06, 2008, 06:40:28 AM by Darwin226 »

Offline bacillus

  • Bot Overlord
  • ****
  • Posts: 907
    • View Profile
Eyes
« Reply #3 on: November 07, 2008, 01:04:54 AM »
PART 1

Code: [Select]
-4 *.eye1 *.eye9 sub sgn 0 floor mult
subtracting *.eye9 from *.eye1 returns 0 if equal, positive if .eye1 is greater, and negative if .eye9 is greater. (sgn simple reduces this difference to -1, 0 or 1.)
0 floor makes both -1 and 0 equal to 0.
the resultant is multiplied by -4, the focuseye value for eye1.
repeat this process for each of the eye pairings with .eye1:
 
Code: [Select]
-4 *.eye1 *.eye9 sub sgn 0 floor mult
 *.eye1 *.eye8 sub sgn 0 floor mult
 *.eye1 *.eye7 sub sgn 0 floor mult
 *.eye1 *.eye6 sub sgn 0 floor mult
 *.eye1 *.eye5 sub sgn 0 floor mult
 *.eye1 *.eye4 sub sgn 0 floor mult
 *.eye1 *.eye3 sub sgn 0 floor mult
 *.eye1 *.eye2 sub sgn 0 floor mult
(Looks so much neater that way, but not as impressive   )

and voila, you know whether .eye1 should be selected or not!
This process is repeated for each eye.
Sometimes, you have to use ++ sgn instead of 0 floor. This makes -1 to 0, and 0 and 1 to 1. This gives certain eyes priority over others when there's a clash eg. both eyes have same readings.

PART 2
Because of the priority setting bit, only one number will equate to a nonzero value (unless each eye is equal to 0 or eye5 takes priority). However, there's still a whole lot of zeros on the stack. To get rid of these, simply add them all together. This will leave you with one nice number to finish it all off:

.focuseye store

This code is practically unreadable unless you know how it works, and I had to remind myself (believe me, I found a glitch in it and it took me forever to find it   )
Anyways, that's about as simple as I can make it.  
« Last Edit: November 07, 2008, 01:06:42 AM by bacillus »
"They laughed at Columbus, they laughed at Fulton, they laughed at the Wright brothers. But they also laughed at Bozo the Clown."
- Carl Sagan

Offline Darwin226

  • Bot Neophyte
  • *
  • Posts: 18
    • View Profile
Eyes
« Reply #4 on: November 07, 2008, 02:06:39 PM »
Great! I understand everything. (not sarcastic)

Thanks =)

Offline Welwordion

  • Bot Destroyer
  • ***
  • Posts: 325
    • View Profile
Eyes
« Reply #5 on: November 08, 2008, 06:21:47 AM »
I have something that might help, I tried to complete it to a full one store gene but for some unknown reasons its always gets messed up

Code: [Select]
*.eye1 *.eye2 add 2 div dup *.eye2 sub abs add
*.eye3 add 2 div dup *.eye2 sub abs add
*.eye4 add 2 div dup *.eye4 sub abs add
*.eye5 add 2 div dup *.eye5 sub abs add
*.eye6 add 2 div dup *.eye6 sub abs add
*.eye7 add 2 div dup *.eye7 sub abs add
*.eye8 add 2 div dup *.eye8 sub abs add
*.eye9 add 2 div dup *.eye9 sub abs add

It calculates the highest eyevalue its alittle math trick
I tried to complete it with

Code: [Select]
dup *.eye9 sub sgn abs swapint
dup *.eye8 sub sgn abs swapint
dup *.eye7 sub sgn abs swapint
dup *.eye6 sub sgn abs swapint
dup *.eye5 sub sgn abs swapint
dup *.eye4 sub sgn abs swapint
dup *.eye3 sub sgn abs swapint
dup *.eye2 sub sgn abs swapint
*.eye1 sub sgn abs

1 add
mult 1 add mult 1 add mult 1 add mult 1 add
mult 1 add mult 1 add mult 1 add mult 1 add
5 sub - .focuseye store

or

[div class=\'codetop\']CODE[div class=\'codemain\' style=\'height:200px;white-space:pre;overflow:auto\']dup
*.eye1 =
-4 swapint
dropbool

dup
*.eye2 =
-3 swapint
dropbool

dup
*.eye3 =
-2 swapint
dropbool

dup
*.eye4 =
-1 swapint
dropbool

dup
*.eye5 =
0 swapint
dropbool

dup
*.eye6 =
1 swapint
dropbool

dup
*.eye7 =
2 swapint
dropbool

dup
*.eye8 =
3 swapint
dropbool


dup
*.eye9 =
4 swapint
dropbool

swapint

.focuseye store

and some stuff more and like I said the code always seemed to be bugged in a way
« Last Edit: November 08, 2008, 06:22:26 AM by Welwordion »

Offline Moonfisher

  • Bot Overlord
  • ****
  • Posts: 592
    • View Profile
Eyes
« Reply #6 on: November 08, 2008, 03:24:56 PM »
The only problem with taking the eye with the greatest value is that if you turn and see a friend, then turn to see another friend... then you'll turn back to see the first friend again asf asf....
Basicaly you need memmory for that to work, making the whole process more complex...

Best solution I found so far is just to offset all eyes to one side, then turn to the eye closest to the focus eye that sees something... so the bot always turns in the same direction.

Here's the fixed and more cost effective eyes I was planning on using for the new version of spinner... if I ever get around to making it (Something always comes up, starting to think I'll never get time to build it)...
Just cut out the parts one would need to use the eyes effectively... ofcourse the conditions for turning and all that should just be your own, this is just a basic example of using them.

To adjust this to your needs the only thing you need to do is change the constants to the values you like, the current setup just spreads out the eyes evenly with eye9 as the focus eye in the center (where eye5 used to be). Then it turns to the closest eye with something in it... so you don't need to remember anything, and in just 9 cycles you'll have checked out everything around you...
And ofcourse change the conditions for when you want to set up what eyes and when you want to turn (conspec and all that).
You can also have different setups, just add some constants and a gene that triggers changes in the eyes. It shouldn't matter how you change the constants, the eyes should keep working.


[div class=\'codetop\']CODE[div class=\'codemain\' style=\'height:200px;white-space:pre;overflow:auto\']'------------------ vars
def seteyes 50
def seteyewidth 51
def seteyespace 52
def setoffset 53

'-------------------- constants
def spineyewidth 0 'if you want wider eyes just set the value here, I prefer the default.
def spineyespace 105
def spinoffset 140
def eyedist 35

cond
*.robage 0 =
start
.seteyes inc
.spineyespace .seteyespace store
.spinoffset .setoffset store
.spineyewidth .seteyewidth store
stop

cond
*.seteyes 1 =
start
*.setoffset .eye9dir store
*.setoffset *.seteyespace add .eye8dir store
*.setoffset *.seteyespace 2 mult add .eye7dir store
*.setoffset *.seteyespace 3 mult add .eye6dir store
*.setoffset *.seteyespace 4 mult add .eye5dir store
*.setoffset *.seteyespace 5 mult add .eye4dir store
*.setoffset *.seteyespace 6 mult add .eye3dir store
*.setoffset *.seteyespace 7 mult add .eye2dir store
*.setoffset *.seteyespace 8 mult add .eye1dir store
4 .focuseye store
0 .seteyes store

*.seteyewidth 0 !=
*.seteyewidth .eye9width store
*.seteyewidth .eye7width store
*.seteyewidth .eye5width store
*.seteyewidth .eye3width store
*.seteyewidth .eye1width store
*.seteyewidth .eye8width store
*.seteyewidth .eye6width store
*.seteyewidth .eye4width store
*.seteyewidth .eye2width store
0 .seteyewidth store
stop

cond
*.eyef 0 =
*.refeye *.myeye =
*.refshoot *.myshoot = and or
*.eye1 *.eye2 add *.eye3 add *.eye4 add *.eye5 add *.eye6 add *.eye7 add *.eye8 add *.eye9 add abs 0 > and
start
*.aim *.eye1dir add .eyedist 4 mult add
1 500 2 add * abs sgn sub mult
*.aim *.eye2dir add .eyedist 3 mult add
1 500 3 add * abs sgn sub mult
*.aim *.eye3dir add .eyedist 2 mult add
1 500 4 add * abs sgn sub mult
*.aim *.eye4dir add .eyedist 1 mult add
1 500 5 add * abs sgn sub mult
*.aim *.eye5dir add .eyedist 0 mult sub
1 500 6 add * abs sgn sub mult
*.aim *.eye6dir add .eyedist 1 mult sub
1 500 7 add * abs sgn sub mult
*.aim *.eye7dir add .eyedist 2 mult sub
1 500 8 add * abs sgn sub mult
*.aim *.eye8dir add .eyedist 3 mult sub
.setaim store
stop

Offline bacillus

  • Bot Overlord
  • ****
  • Posts: 907
    • View Profile
Eyes
« Reply #7 on: November 08, 2008, 03:40:37 PM »
Code: [Select]
-4 *.eye1 sgn mult *.eye2 sgn -- abs mult *.eye3 sgn -- abs mult *.eye4 sgn -- abs mult *.eye5 sgn -- abs mult
*.eye6 sgn -- abs mult *.eye7 sgn -- abs mult *.eye8 sgn -- abs mult *.eye9 sgn -- abs mult 4 *.eye9 sgn mult *.eye2 sgn
-- abs mult *.eye3 sgn -- abs mult *.eye4 sgn -- abs mult *.eye5 sgn -- abs mult *.eye6 sgn -- abs mult *.eye7 sgn --
abs mult *.eye8 sgn -- abs mult add -3 *.eye2 sgn mult *.eye3 sgn -- abs mult *.eye4 sgn -- abs mult *.eye5 sgn -- abs
mult *.eye6 sgn -- abs mult *.eye7 sgn -- abs mult *.eye8 sgn -- abs mult add 3 *.eye8 sgn mult *.eye3 sgn -- abs mult
*.eye4 sgn -- abs mult *.eye5 sgn -- abs mult *.eye6 sgn -- abs mult *.eye7 sgn -- abs mult add -2 *.eye3 sgn mult
*.eye4 sgn -- abs mult *.eye5 sgn -- abs mult *.eye6 sgn -- abs mult *.eye7 sgn -- abs mult add 2 *.eye7 sgn mult
*.eye4 sgn -- abs mult *.eye5 sgn -- abs mult *.eye6 sgn -- abs mult add -1 *.eye4 sgn mult *.eye5 sgn -- abs mult
*.eye6 sgn -- abs mult add 1 *.eye6 sgn mult *.eye5 sgn -- abs mult add 0 *.eye5 sgn mult add .focuseye
store
This is a slightly "simplified" version, which sorts eyes in a priority, depending on which eye closest to eye5 returns data.
Yes, we are just showing off now  
« Last Edit: November 08, 2008, 03:43:41 PM by bacillus »
"They laughed at Columbus, they laughed at Fulton, they laughed at the Wright brothers. But they also laughed at Bozo the Clown."
- Carl Sagan

Offline Moonfisher

  • Bot Overlord
  • ****
  • Posts: 592
    • View Profile
Eyes
« Reply #8 on: November 09, 2008, 09:52:17 AM »
Ok sorry didn't test the new eyes... they don't work... fixed it now.
I know I know... I should know better than just posting untested code... thought it worked

Code: [Select]
'------------------ vars
def seteyes 50
def seteyewidth 51
def seteyespace 52
def setoffset 53

'-------------------- constants
def spineyewidth 0 'if you want wider eyes just set the value here, I prefer the default.
def spineyespace 105
def spinoffset 140
def eyedist 35

cond
*.robage 0 =
start
.seteyes inc
.spineyespace .seteyespace store
.spinoffset .setoffset store
.spineyewidth .seteyewidth store
stop

cond
*.seteyes 1 =
start
*.setoffset .eye9dir store
*.setoffset *.seteyespace add .eye8dir store
*.setoffset *.seteyespace 2 mult add .eye7dir store
*.setoffset *.seteyespace 3 mult add .eye6dir store
*.setoffset *.seteyespace 4 mult add .eye5dir store
*.setoffset *.seteyespace 5 mult add .eye4dir store
*.setoffset *.seteyespace 6 mult add .eye3dir store
*.setoffset *.seteyespace 7 mult add .eye2dir store
*.setoffset *.seteyespace 8 mult add .eye1dir store
4 .focuseye store
0 .seteyes store

*.seteyewidth 0 !=
*.seteyewidth .eye9width store
*.seteyewidth .eye7width store
*.seteyewidth .eye5width store
*.seteyewidth .eye3width store
*.seteyewidth .eye1width store
*.seteyewidth .eye8width store
*.seteyewidth .eye6width store
*.seteyewidth .eye4width store
*.seteyewidth .eye2width store
0 .seteyewidth store
stop

cond
*.eyef 0 =
*.refeye *.myeye =
*.refshoot *.myshoot = and or
*.eye1 *.eye2 add *.eye3 add *.eye4 add *.eye5 add *.eye6 add *.eye7 add *.eye8 add *.eye9 add abs 0 > and
start
*.aim *.eye1dir add .eyedist 4 mult add
1 500 2 add * abs sgn sub mult
*.aim *.eye2dir add .eyedist 3 mult add
500 2 add * abs sgn mult add
1 500 3 add * abs sgn sub mult
*.aim *.eye3dir add .eyedist 2 mult add
500 3 add * abs sgn mult add
1 500 4 add * abs sgn sub mult
*.aim *.eye4dir add .eyedist 1 mult add
500 4 add * abs sgn mult add
1 500 5 add * abs sgn sub mult
*.aim *.eye5dir add .eyedist 0 mult sub
500 5 add * abs sgn mult add
1 500 6 add * abs sgn sub mult
*.aim *.eye6dir add .eyedist 1 mult sub
500 6 add * abs sgn mult add
1 500 7 add * abs sgn sub mult
*.aim *.eye7dir add .eyedist 2 mult sub
500 7 add * abs sgn mult add
1 500 8 add * abs sgn sub mult
*.aim *.eye8dir add .eyedist 3 mult sub
500 8 add * abs sgn mult add
.setaim store
stop
« Last Edit: December 22, 2011, 11:45:54 AM by Shasta »