Code center > Darwinbots3
Boolean memory
Numsgil:
I'm not necessarily against it, but when would that be useful? I can't think of any use cases where you'd need to do that except for storing true/false flags to memory, and then you could do something like:
1 custommemoryloc store not 0 custommemoryloc store
Botsareus:
I was hoping you'll ask:
I recently did an AI project for school myself. It has no real Boolean logic, example:
--- Code: ---IF True THEN Sin 29 * CALC Memory(121) OUT Do_Nothing TYPE action DIRECTION clone_up
IF True THEN 250 7 216 * CALC Memory(170) OUT Do_Nothing TYPE action DIRECTION clone_down
IF True THEN Sin 29 * CALC Memory(121) OUT Do_Nothing TYPE action DIRECTION clone_up
IF True THEN Sin 29 * CALC Memory(121) OUT Do_Nothing TYPE action DIRECTION clone_up
IF Memory(167) < Memory(36) THEN 142 0 CALC Memory(99) OUT Do_Nothing TYPE data DIRECTION clone_up
IF True THEN 29 * CALC Memory(197) OUT Do_Nothing TYPE action DIRECTION clone_up
IF Memory(234) = Memory(211) THEN 206 * CALC Memory(178) OUT Do_Nothing TYPE action DIRECTION clone_up
IF True THEN 351.508334281997 1 Cos 39.1118722540835 Cos CALC Memory(76) OUT Do_Nothing TYPE data DIRECTION clone_up
IF False THEN 202 * 217 * CALC Memory(7) OUT Gear2_Reverse TYPE data DIRECTION clone_up
IF True THEN Distance 161 0 * * Sin * 241 * CALC Memory(174) OUT Do_Nothing TYPE data DIRECTION clone_up
IF False THEN 34.3416983468838 202 * 217 * CALC Memory(7) OUT Gear2_Reverse TYPE data DIRECTION clone_up
IF Memory(133) != Memory(213) THEN * 61 * CALC Memory(110) OUT Do_Nothing TYPE data DIRECTION clone_up
--- End code ---
After CALC is the destination of the data (math) result
One of the operators I have is called "Angle_Compare" (btw: I am considering this for DB as well) It compares two angles using this algorithm:
--- Code: --- hold1 = popstack(a) '100
hold2 = popstack(a) '99
calc = IIf(angle_compare(hold1, hold2), 2, -2)
If MD_state = 5 And a = cntrl_math Then debug_print.Text = debug_print.Text & vbNewLine & hold1 'debug
If MD_state = 5 And a = cntrl_math Then debug_print.Text = debug_print.Text & vbNewLine & hold2 'debug
If MD_state = 5 And a = cntrl_math Then debug_print.Text = debug_print.Text & vbNewLine & "DIR:" & calc 'debug
pushstack(a, calc)
Private Function angle_compare(ByVal ang1 As Single, ByVal ang2 As Single) As Boolean
Dim data2 As Integer = ang2
Dim data1 As Integer = ang1
Dim out As Boolean
Dim sp As Boolean = False
If data1 > 180 Then
sp = True
data2 = 360 - data2
data1 = 360 - data1
End If
If (data2 > data1) And (data2 < (data1 + 180)) Then out = True Else out = False
If sp Then angle_compare = IIf(out, True, False) Else angle_compare = IIf(out, False, True)
End Function
--- End code ---
As you can see since there is no real Boolean stack; The functions result is always stored as Integer (2 , -2) and then can be stored into a memory location. Then the system can always compare the result > v. zero. This kind of model worked pretty good for me.
The button line is it will add flexibility of using a Boolean operator as a data operator and vise-versa.
Think about "angle_compare": In DB it will take two Integers and return an Integer (2 or -2) , but it will be cool to turn it into a Boolean right away.
You may catch me here on the fact that I am making an imaginary concept (intotobool) on concept that's imaginary as well (angle_compare) but I hope it'll be alright.
Botsareus:
lol, Numsgil did that post actually made sense since you are slow to reply? :D
Numsgil:
Sorry, I got distracted trying to figure out what your angle_compare was trying to do.
I think it's probably something you can do using a dot product or 2D cross product. Usually when you have to break something out in terms of angles it's a sign you're doing it wrong (at least in terms of programming).
That is:
A dot B = |A| * |B| * cos(angle between them)
So:
(A dot B ) / (|A| * |B|) = cos(angle between them)
And for the 2D cross product:
(A cross B ) \ (|A| * |B|) = sin(angle between them)
Using those two identities you can often get rid of all the trig, which is better computationally and more elegant from a computation standpoint.
Botsareus:
Ouch, that math looks heavy...
I am guessing (angle between them) is: ang1 - ang2
Right?
I also have to assume that A and B are vectors relative to zero
Right?
What values does that formula return?
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version