Announcement

Collapse
No announcement yet.

Borjes Brick Game in Source Code forum

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #21
    Ok, I see that now - thanks Patrick! Clever algo there. My mind is not of latest model,
    so it takes a while for it to start (and it runs out of fuel very fast too.. )


    ------------------
    http://www.tolkenxp.com/pb
    Download: incLean, PBcodec, custom controls and code, etc.
    Borje Hagsten - [email protected]

    Comment


    • #22
      To beat a dead horse, the following is
      leaner and faster than previous
      '----------------------------------------------
      RANDOMIZE
      IF 2*INT(n/2)=n THEN Odd=0 ELSE Odd=1
      FOR i=0 TO n-1
      r=RND(0,n-1)
      WHILE r=i :r=RND(0,n-1):LOOP
      SWAP bPos(i).z,bPos(r).z
      NEXT
      IF Odd THEN SWAP bPos(0).z,bPos(RND(1,n-1)).z
      '------------------------------------------------
      This works because the following is true-
      Given a solvable position then
      one swap of two different bricks will make it unsolvable
      and another swap of two different bricks will make
      it solvable again. Thus an even number of swaps
      of 2 different bricks each time will always leave a
      solvable position.
      Patrick

      ------------------

      Comment

      Working...
      X