Code center > Darwinbots Program Source Code

Questions on Ceil and Floor

<< < (4/6) > >>

Botsareus:
Num, why fix a bug by adding code when you can fix it by changing code? I believe there is a bug in the vb code you posted. I also believe there is no bug in the code I posted.

The problem is I dont have the rest of your code , thats why I cant pinpoint were the bug is.

Numsgil:
How can there be a bug?

'This one could be very useful
Private Sub DNASgn(robotnumber As Integer) 'returns sign of number on stack
    Dim a As Integer
    a = readst(robotnumber)
   
    writest robotnumber, Sgn(a)
End Sub

"readst" reads the top number of the stack from robotnumber.

"writest" writes a number to the stack of robotnumber.

So where's the bug?  How can there be a bug?  And last, why try to figure it out when you can just add:

if a = 0 then
writest robotnumber, 0
else
writest robotnumber, sgn(a)
end if

Botsareus:
There is a bug in
"readst" reads the top number of the stack from robotnumber.
or
"writest" writes a number to the stack of robotnumber.

Paste the code for thouse custom  functions, paste the code for the stack itself, Paste the code for all the custom functions used by thouse custom functions, And I will show you were the bug is trust me!

Numsgil:
A magical bug that only manifests itself in the DNAsgn function, huh?  A bug that has gone magically unnoticed since DB 1.0 was released?

Okay, sarcasm aside, it's not a bug.  I'll post the DNA parsing module so you can look it over if you like, but you're not going to find anything.

Botsareus:
'boolstack structure used for conditionals
Private Type boolstack
  val(20) As Boolean
  pos As Integer
End Type
Private Const stacklim As Integer = 20
Dim currgene As Long 'for *.thisgene
Dim Condst As boolstack 'for the conditions stack
'/*********I had to gess this
Private Type stackishere
pos As Double
val(255) As Double
End Type
Private Type therobotsarehere
st As stackishere
End Type
Dim rob(20) As therobotsarehere
'\**************

Private Sub DNASgn(robotnumber As Integer) 'returns sign of number on stack
Dim a As Integer
a = readst(robotnumber)

writest robotnumber, Sgn(a)
End Sub

Private Function readst(n As Integer) As Integer
  readst = 0
  If rob(n).st.pos > 0 Then
    readst = rob(n).st.val(rob(n).st.pos)
    rob(n).st.pos = rob(n).st.pos - 1
  End If
End Function

' stack push
Private Sub writest(n As Integer, val)
  If Abs(val) > 32000 Then val = Sgn(val) * 32000
  If rob(n).st.pos < stacklim Then
    rob(n).st.pos = rob(n).st.pos + 1
    rob(n).st.val(rob(n).st.pos) = val
  End If
End Sub

Private Sub Form_Load()
writest 0, 700
DNASgn 0
MsgBox rob(0).st.val(rob(n).st.pos) ' returns 1
'
writest 0, 0
DNASgn 0
MsgBox rob(0).st.val(rob(n).st.pos) ' returns 0
'
writest 0, -700
DNASgn 0
MsgBox rob(0).st.val(rob(n).st.pos) ' returns -1
End Sub
'Even In your own code It returns 0 for 0, rofl , now what?

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version