I have a bug I can't solve with an array and a if loop
jonduncan
Posts: 40
I have a bug with this code
if ((VWalls[noparse][[/noparse]x] >> y) & 1)
for some reason it is never true in my code
x and y·go from 0 to 15
I filled all values of VWalls with $ffff for debuging purposes
and it is never true?????
I think the problem is with this code, but I am not completely sure is the code above correct code to find if a certain bit is a 1
if ((VWalls[noparse][[/noparse]x] >> y) & 1)
for some reason it is never true in my code
x and y·go from 0 to 15
I filled all values of VWalls with $ffff for debuging purposes
and it is never true?????
I think the problem is with this code, but I am not completely sure is the code above correct code to find if a certain bit is a 1
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Parallax Forums - If you're ready to learn, we're ready to help.
{ Micromouse Maze Mapper.
This program maps a 16 by 16 maze using a flooding technique
Author: Jonathan Duncan
Date: March 16, 2007}}
Con
· _CLKMODE = XTAL1 + PLL16X
· _XINFREQ =5_000_000
· INF = 255
obj
··· SS : "Simple_Serial"
dat ' sets the distance from the center if there were no walls
startweight· byte 14, 13, 12, 11, 10,· 9,· 8,· 7,· 7,· 8,· 9, 10, 11, 12, 13, 14, 13, 12, 11, 10,· 9,· 8,· 7,· 6,· 6,· 7,· 8,· 9, 10, 11, 12, 13, 12, 11, 10,· 9,· 8,· 7,· 6,· 5,· 5,· 6,· 7,· 8,· 9, 10, 11, 12, 11, 10,· 9,· 8,· 7,· 6,· 5,· 4,· 4,· 5,· 6,· 7,· 8,· 9, 10, 11, 10,· 9,· 8,· 7,· 6,· 5,· 4,· 3,· 3,· 4,· 5,· 6,· 7,· 8,· 9, 10, 9,· 8,· 7,· 6,· 5,· 4,· 3,· 2,· 2,· 3,· 4,· 5,· 6,· 7,· 8,· 9, 8,· 7,· 6,· 5,· 4,· 3,· 2,· 1,· 1,· 2,· 3,· 4,· 5,· 6,· 7,· 8, 7,· 6,· 5,· 4,· 3,· 2,· 1,· 0,· 0,· 1,· 2,· 3,· 4,· 5,· 6,· 7,· 7,· 6,· 5,· 4,· 3,· 2,· 1,· 0,· 0,· 1,· 2,· 3,· 4,· 5,· 6,· 7, 8,· 7,· 6,· 5,· 4,· 3,· 2,· 1,· 1,· 2,· 3,· 4,· 5,· 6,· 7,· 8,· 9,· 8,· 7,· 6,· 5,· 4,· 3,· 2,· 2,· 3,· 4,· 5,· 6,· 7,· 8,· 9, 10,· 9,· 8,· 7,· 6,· 5,· 4,· 3,· 3,· 4,· 5,· 6,· 7,· 8,· 9, 10, 11, 10,· 9,· 8,· 7,· 6,· 5,· 4,· 4,· 5,· 6,· 7,· 8,· 9, 10, 11, 12, 11, 10,· 9,· 8,· 7,· 6,· 5,· 5,· 6,· 7,· 8,· 9, 10, 11, 12, 13, 12, 11, 10,· 9,· 8,· 7,· 6,· 6,· 7,· 8,· 9, 10, 11, 12, 13, 14, 13, 12, 11, 10,· 9,· 8,· 7,· 7,· 8,· 9, 10, 11, 12, 13, 14
VAR
· byte x
· byte y
· byte MapWeights[noparse][[/noparse]256]
· byte· Hwalls[noparse][[/noparse]17]
· byte· Vwalls[noparse][[/noparse]17]
· byte· nib0
· byte· nib1·
pub main· | i , j
· SS.start( -1, 30, 19200)
· repeat i from 0· to 255
··· MapWeights[noparse][[/noparse]i] := startweight[noparse][[/noparse]i]
··repeat i from 0 to 16·· ' set all walls on for debuging purposes
···· hwalls[noparse][[/noparse]i] := $ffff
···· vwalls[noparse][[/noparse]i] := $ffff
· repeat
··· SetMapWeight·· ·' set new weight according to the walls
··· repeat i from 0 to 15··· ' Sends map over serial for debuging
····· repeat j from 0 to 15
······· nib0 := MapWeights[noparse][[/noparse]j + i* 16] & $0f
······· nib1 := (MapWeights[noparse][[/noparse]j + i* 16] & $f0)>> 4
······· if nib0 > 9
········· nib0 := nib0 + 55
······· else
········· nib0 := nib0 + $30
······· if nib1 > 9
········· nib1 := nib1 + 55
······· else
········· nib1 := nib1 + $30
······· SS.tx(nib1)
······· SS.tx(nib0)
······· SS.tx($20)
····· SS.tx($A)
····· SS.tx($D)
Pub SetMapWeight | t, Weight
· repeat t from 0 to INF
··· repeat x from 0 to 15
····· repeat y from 0 to 15
······· Weight := MapWeights[noparse][[/noparse]x +(y* 16)]
········ if not (Weight == 0)
·········· Weight := FindNewWeight
·········· if Weight > INF
······························· Weight := INF
·········· MapWeights[noparse][[/noparse]x +(y* 16)] := Weight
Pri FindNewWeight : NewWeight | xminus, xplus, yminus, yplus
· if ((VWalls[noparse][[/noparse]x] >> y) & 1)· 'test this one this is where the problem is <----never does this
··· xminus:=INF···
· else
··· xminus:= MapWeights[noparse][[/noparse]x-1 + y*16]
· if ((VWalls[noparse][[/noparse]x + 1] >> y)| 1)·· ' always true to test if case above
··· xplus:=INF···
· else
··· xplus:= MapWeights[noparse][[/noparse]x+1 + y*16]
· if ((HWalls[noparse][[/noparse]y] >> (15 - x)) | 1 )·· ' always true to test if case above
··· yminus:=INF···
· else
··· yminus:= MapWeights[noparse][[/noparse]x + (y-1)*16]
· if ((HWalls[noparse][[/noparse]y + 1] >> (15 - x)) | 1 )·· ' always true to test if case above
··· yplus:=INF···
· else
··· yplus:= MapWeights[noparse][[/noparse]x + (y+1)*16]······
· NewWeight := xminus <# xplus <# yminus <# yplus
· NewWeight++
{
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF 00 00 FF FF FF FF FF FF FF
FF FF FF FF FF FF FF 00 00 01 02 03 04 05 06 07
08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17
18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27
28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37
38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47
48 49 4A 4B 4C 4D 4E 4F 50 51 52 53 54 55 56 57
58 59 5A 5B 5C 5D 5E 5F 60 61 62 63 64 65 66 67
68 69 6A 6B 6C 6D 6E 6F 70 71 72 73 74 75 76 77
·output it should be
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF 00 00 FF FF FF FF FF FF FF
FF FF FF FF FF FF FF 00 00 FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
·since all walls are on}
Exactly.
The answer is always there. With compound statements, you simply deconstruct the statement and examine the outputs.
Debugging is my favorite task when programming. I can't tell you how many times I've heard programmers blame the compiler, the operating system and even the computer for things.
I simply tell them: What is, is. Then I start deconstructing. It's not so much an art as an act of patience, in my experience.
Regards