Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TYPE Pt
- x AS INTEGER
- y AS INTEGER
- v AS INTEGER
- END TYPE
- DIM Pt(1000) AS Pt
- SCREEN 13
- 'Puzzle Generator
- 'walk in a square with some random element. more interesting than a random blob.
- seed = 0
- RANDOMIZE seed
- OPEN "c:\warmup.txt" FOR BINARY AS #1
- c = 250 'number of square walking steps to take
- FOR i = 1 TO 1999
- IF (1999 - i) * RND < c THEN 'uniformly distributed square-walking steps
- d = INT(i / 500) 'this walks us in a square
- c = c - 1
- ELSE
- d = INT(RND * 5) 'this steps us randomly (or drops markers)
- END IF
- IF d = 0 THEN a$ = "Up, "
- IF d = 1 THEN a$ = "Left, "
- IF d = 2 THEN a$ = "Down, "
- IF d = 3 THEN a$ = "Right, "
- IF d = 4 THEN
- IF RND < .5 THEN a$ = "A, " ELSE a$ = "B, "
- END IF
- PUT #1, , a$
- NEXT
- a$ = "Start" 'don't forget to terminate!
- PUT #1, , a$
- CLOSE #1
- PRINT "generation complete"
- SLEEP
- 'Puzzle Solver
- OPEN "c:\warmup.txt" FOR INPUT AS #1
- c = 0
- WHILE NOT EOF(1)
- INPUT #1, r$: c = c + 1
- LOCATE 1, 1: PRINT c; r$; " "
- col = 8
- IF r$ = "Up" THEN y = y + 1
- IF r$ = "Down" THEN y = y - 1
- IF r$ = "Left" THEN x = x - 1
- IF r$ = "Right" THEN x = x + 1
- 'build up arrays of A and B markers
- IF r$ = "A" THEN col = 12: p = p + 1: Pt(p).x = x: Pt(p).y = y: Pt(p).v = 0
- IF r$ = "B" THEN col = 10: p = p + 1: Pt(p).x = x: Pt(p).y = y: Pt(p).v = 1
- PSET (160 + x, 100 + y), col
- WEND
- CLOSE #1
- PRINT p
- SLEEP
- 'Part 1
- FOR i = 1 TO p
- dx = Pt(i).x
- dy = Pt(i).y
- d = ABS(dx) + ABS(dy)
- IF d > dmax THEN dmax = d: i0 = i
- NEXT
- PRINT dmax
- CIRCLE (160, 100), 5, 15
- CIRCLE (160 + Pt(i0).x, 100 + Pt(i0).y), 5, 15
- SLEEP
- 'Part 2
- 'small enough set for O[n^2] search. would use spatial partitioning otherwise.
- dmax = 0
- FOR i = 1 TO p - 1
- FOR j = i + 1 TO p
- dx = Pt(i).x - Pt(j).x
- dy = Pt(i).y - Pt(j).y
- d = ABS(dx) + ABS(dy)
- IF d > dmax AND Pt(i).v <> Pt(j).v THEN dmax = d: i0 = i: j0 = j
- NEXT
- NEXT
- PRINT dmax
- CIRCLE (160 + Pt(i0).x, 100 + Pt(i0).y), 5, 12
- CIRCLE (160 + Pt(j0).x, 100 + Pt(j0).y), 5, 10
- SLEEP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement