08-17-2005, 08:04 AM
I am working on a 24 Game (Math 24) Card Solver that is currently very slow. I am wondering if there is any way to use threads in qbasic (have a sub return control to the code that called it immidiatly (sp?) after it begins running), or to make code that does something similar. Here is the function that I would want to apply this concept to:
For the full code of the program, see 24 Game (Math 24) Card Solver.
Code:
FUNCTION CardWork% (Num1 AS INTEGER, Num2 AS INTEGER, Num3 AS INTEGER, Num4 AS INTEGER, cardNum AS INTEGER)
DIM intn(0 TO 3)
SUpTo = 1
intn(0) = Num1
intn(1) = Num2
intn(2) = Num3
intn(3) = Num4
DIM o(0 TO 2)
DIM nu(0 TO 3)
DIM give(0 TO 1)
i = 1
FOR i = 1 TO 999
Solutions(cardNum, i) = ""
NEXT i
FOR n1 = 0 TO 3
FOR n2 = 0 TO 3
IF n2 <> n1 THEN
FOR n3 = 0 TO 3
IF n1 <> n3 AND n2 <> n3 THEN
FOR n4 = 0 TO 3
IF n1 <> n4 AND n2 <> n4 AND n3 <> n4 THEN
FOR o1 = 0 TO 3
FOR o2 = 0 TO 3
FOR o3 = 0 TO 3
nu(0) = intn(n1)
nu(1) = intn(n2)
nu(2) = intn(n3)
nu(3) = intn(n4)
ts(0) = nu(0)
o(0) = o1
o(1) = o2
o(2) = o3
FOR slw = 1 TO 4
FOR tlw = 1 TO 2
IF slw >= 3 THEN tlw = tlw + 2
CALL DoSelects(o(0), p(1), ts(1), e(1), nu(0), nu(1))
IF slw = 1 THEN
give(0) = ts(1)
give(1) = nu(2)
ELSEIF slw = 2 THEN
give(0) = nu(2)
give(1) = ts(1)
ELSEIF slw = 3 THEN
give(0) = nu(2)
give(1) = nu(3)
ELSE
give(0) = nu(3)
give(1) = nu(2)
END IF
CALL DoSelects(o(1), p(2), ts(2), e(2), give(0), give(1))
IF tlw = 1 THEN
give(0) = ts(2)
give(1) = nu(3)
ELSEIF tlw = 2 THEN
give(0) = nu(3)
give(1) = ts(2)
ELSEIF tlw = 3 THEN
give(0) = ts(1)
give(1) = ts(2)
ELSE
give(0) = ts(2)
give(1) = ts(1)
END IF
CALL DoSelects(o(2), p(3), ts(3), e(3), give(0), give(1))
IF slw >= 3 THEN tlw = tlw - 2
IF Check(cardNum) THEN works = TRUE
NEXT tlw
NEXT slw
NEXT o3
NEXT o2
NEXT o1
END IF
NEXT n4
END IF
NEXT n3
END IF
NEXT n2
NEXT n1
IF works THEN CardWork% = TRUE ELSE CardWork% = FALSE
END FUNCTION
For the full code of the program, see 24 Game (Math 24) Card Solver.