Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,75 +1,81 @@
|
|||
100 DECLARE EXTERNAL FUNCTION choosemove
|
||||
100 DECLARE EXTERNAL FUNCTION ChooseMove
|
||||
110 !
|
||||
120 RANDOMIZE
|
||||
130 PUBLIC NUMERIC X, Y, TRUE, FALSE
|
||||
140 LET TRUE = -1
|
||||
150 LET FALSE = 0
|
||||
160 !
|
||||
170 SET WINDOW 1,512,1,512
|
||||
170 SET WINDOW 1, 512, 1, 512
|
||||
180 SET AREA COLOR "black"
|
||||
190 FOR x=0 TO 512-128 STEP 128
|
||||
200 FOR y=0 TO 512-128 STEP 128
|
||||
210 PLOT AREA:x+64,y;x+128,y;x+128,y+64;x+64,y+64
|
||||
220 PLOT AREA:x,y+64;x+64,y+64;x+64,y+128;x,y+128
|
||||
230 NEXT y
|
||||
240 NEXT x
|
||||
250 !
|
||||
260 SET LINE COLOR "red"
|
||||
270 SET LINE WIDTH 6
|
||||
190 LET SW = 512 / 8 ! Width of square
|
||||
200 FOR X = 0 TO 6 STEP 2
|
||||
210 LET SX = X * SW
|
||||
220 FOR Y = 0 TO 6 STEP 2
|
||||
230 LET SY = Y * SW
|
||||
240 PLOT AREA: SX + SW, SY; SX + 2 * SW, SY; SX + 2 * SW, SY + SW; SX + SW, SY + SW
|
||||
250 PLOT AREA: SX, SY + SW; SX + SW, SY + SW; SX + SW, SY + 2 * SW; SX, SY + 2 * SW
|
||||
260 NEXT Y
|
||||
270 NEXT X
|
||||
280 !
|
||||
290 PUBLIC NUMERIC Board(0 TO 7,0 TO 7)
|
||||
300 LET X = 0
|
||||
310 LET Y = 0
|
||||
320 LET Total = 0
|
||||
330 DO
|
||||
340 LET Board(X,Y) = TRUE
|
||||
350 PLOT LINES: X*64+32,Y*64+32;
|
||||
360 LET Total = Total + 1
|
||||
370 LOOP UNTIL choosemove(X, Y) = FALSE
|
||||
380 IF Total <> 64 THEN STOP
|
||||
390 END
|
||||
400 !
|
||||
410 EXTERNAL FUNCTION choosemove(X1, Y1)
|
||||
420 DECLARE EXTERNAL SUB trymove
|
||||
430 LET M = 9
|
||||
440 CALL trymove(X1+1, Y1+2, M, newx, newy)
|
||||
450 CALL trymove(X1+1, Y1-2, M, newx, newy)
|
||||
460 CALL trymove(X1-1, Y1+2, M, newx, newy)
|
||||
470 CALL trymove(X1-1, Y1-2, M, newx, newy)
|
||||
480 CALL trymove(X1+2, Y1+1, M, newx, newy)
|
||||
490 CALL trymove(X1+2, Y1-1, M, newx, newy)
|
||||
500 CALL trymove(X1-2, Y1+1, M, newx, newy)
|
||||
510 CALL trymove(X1-2, Y1-1, M, newx, newy)
|
||||
520 IF M=9 THEN
|
||||
530 LET choosemove = FALSE
|
||||
540 EXIT FUNCTION
|
||||
550 END IF
|
||||
560 LET X = newx
|
||||
570 LET Y = newy
|
||||
580 LET choosemove = TRUE
|
||||
590 END FUNCTION
|
||||
600 !
|
||||
610 EXTERNAL SUB trymove(X, Y, M, newx, newy)
|
||||
620 !
|
||||
630 DECLARE EXTERNAL FUNCTION validmove
|
||||
640 IF validmove(X,Y) = 0 THEN EXIT SUB
|
||||
650 IF validmove(X+1,Y+2) <> 0 THEN LET N = N + 1
|
||||
660 IF validmove(X+1,Y-2) <> 0 THEN LET N = N + 1
|
||||
670 IF validmove(X-1,Y+2) <> 0 THEN LET N = N + 1
|
||||
680 IF validmove(X-1,Y-2) <> 0 THEN LET N = N + 1
|
||||
690 IF validmove(X+2,Y+1) <> 0 THEN LET N = N + 1
|
||||
700 IF validmove(X+2,Y-1) <> 0 THEN LET N = N + 1
|
||||
710 IF validmove(X-2,Y+1) <> 0 THEN LET N = N + 1
|
||||
720 IF validmove(X-2,Y-1) <> 0 THEN LET N = N + 1
|
||||
730 IF N>M THEN EXIT SUB
|
||||
740 IF N=M AND RND<.5 THEN EXIT SUB
|
||||
750 LET M = N
|
||||
760 LET newx = X
|
||||
770 LET newy = Y
|
||||
780 END SUB
|
||||
790 !
|
||||
800 EXTERNAL FUNCTION validmove(X,Y)
|
||||
810 LET validmove = FALSE
|
||||
820 IF X<0 OR X>7 OR Y<0 OR Y>7 THEN EXIT FUNCTION
|
||||
830 IF Board(X,Y)=FALSE THEN LET validmove = TRUE
|
||||
840 END FUNCTION
|
||||
290 SET LINE COLOR "red"
|
||||
300 SET LINE WIDTH 6
|
||||
310 !
|
||||
320 PUBLIC NUMERIC Board(0 TO 7, 0 TO 7)
|
||||
330 LET X = 0
|
||||
340 LET Y = 0
|
||||
350 LET Total = 0
|
||||
360 DO
|
||||
370 LET Board(X, Y) = TRUE
|
||||
380 PLOT LINES: X * SW + 32, Y * SW + 32;
|
||||
390 LET Total = Total + 1
|
||||
400 LOOP UNTIL ChooseMove(X, Y) = FALSE
|
||||
410 IF Total <> 64 THEN STOP
|
||||
420 END
|
||||
430 !
|
||||
440 EXTERNAL FUNCTION ChooseMove(X1, Y1)
|
||||
450 DECLARE EXTERNAL SUB TryMove
|
||||
460 LET M = 9
|
||||
470 CALL TryMove(X1 + 1, Y1 + 2, M, NewX, NewY)
|
||||
480 CALL TryMove(X1 + 1, Y1 - 2, M, NewX, NewY)
|
||||
490 CALL TryMove(X1 - 1, Y1 + 2, M, NewX, NewY)
|
||||
500 CALL TryMove(X1 - 1, Y1 - 2, M, NewX, NewY)
|
||||
510 CALL TryMove(X1 + 2, Y1 + 1, M, NewX, NewY)
|
||||
520 CALL TryMove(X1 + 2, Y1 - 1, M, NewX, NewY)
|
||||
530 CALL TryMove(X1 - 2, Y1 + 1, M, NewX, NewY)
|
||||
540 CALL TryMove(X1 - 2, Y1 - 1, M, NewX, NewY)
|
||||
550 IF M = 9 THEN
|
||||
560 LET ChooseMove = FALSE
|
||||
570 ELSE
|
||||
580 LET X = NewX
|
||||
590 LET Y = NewY
|
||||
600 LET ChooseMove = TRUE
|
||||
610 END IF
|
||||
620 END FUNCTION
|
||||
630 !
|
||||
640 EXTERNAL SUB TryMove(X, Y, M, NewX, NewY)
|
||||
650 !
|
||||
660 DECLARE EXTERNAL FUNCTION ValidMove
|
||||
670 IF ValidMove(X, Y) <> 0 THEN
|
||||
680 IF ValidMove(X + 1, Y + 2) <> 0 THEN LET N = N + 1
|
||||
690 IF ValidMove(X + 1, Y - 2) <> 0 THEN LET N = N + 1
|
||||
700 IF ValidMove(X - 1, Y + 2) <> 0 THEN LET N = N + 1
|
||||
710 IF ValidMove(X - 1, Y - 2) <> 0 THEN LET N = N + 1
|
||||
720 IF ValidMove(X + 2, Y + 1) <> 0 THEN LET N = N + 1
|
||||
730 IF ValidMove(X + 2, Y - 1) <> 0 THEN LET N = N + 1
|
||||
740 IF ValidMove(X - 2, Y + 1) <> 0 THEN LET N = N + 1
|
||||
750 IF ValidMove(X - 2, Y - 1) <> 0 THEN LET N = N + 1
|
||||
760 IF N < M OR (N = M AND RND >= .5) THEN
|
||||
770 LET M = N
|
||||
780 LET NewX = X
|
||||
790 LET NewY = Y
|
||||
800 END IF
|
||||
810 END IF
|
||||
820 END SUB
|
||||
830 !
|
||||
840 EXTERNAL FUNCTION ValidMove(X, Y)
|
||||
850 LET ValidMove = FALSE
|
||||
860 IF X >= 0 AND X <= 7 AND Y >= 0 AND Y <= 7 THEN
|
||||
870 IF Board(X, Y) = FALSE THEN LET ValidMove = TRUE
|
||||
880 END IF
|
||||
890 END FUNCTION
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
generic
|
||||
Size: Integer;
|
||||
package Knights_Tour is
|
||||
|
||||
subtype Index is Integer range 1 .. Size;
|
||||
type Tour is array (Index, Index) of Natural;
|
||||
Empty: Tour := (others => (others => 0));
|
||||
|
||||
function Get_Tour(Start_X, Start_Y: Index; Scene: Tour := Empty) return Tour;
|
||||
-- finds tour via backtracking
|
||||
-- either no tour has been found, i.e., Get_Tour returns Scene
|
||||
-- or the Result(X,Y)=K if and only if I,J is visited at the K-th move
|
||||
-- for all X, Y, Scene(X,Y) must be either 0 or Natural'Last,
|
||||
-- where Scene(X,Y)=Natural'Last means "don't visit coordiates (X,Y)!"
|
||||
|
||||
function Count_Moves(Board: Tour) return Natural;
|
||||
-- counts the number of possible moves, i.e., the number of 0's on the board
|
||||
|
||||
procedure Tour_IO(The_Tour: Tour; Width: Natural := 4);
|
||||
-- writes The_Tour to the output using Ada.Text_IO;
|
||||
|
||||
end Knights_Tour;
|
||||
|
|
@ -1,85 +0,0 @@
|
|||
with Ada.Text_IO, Ada.Integer_Text_IO;
|
||||
|
||||
package body Knights_Tour is
|
||||
|
||||
|
||||
type Pair is array(1..2) of Integer;
|
||||
type Pair_Array is array (Positive range <>) of Pair;
|
||||
|
||||
Pairs: constant Pair_Array (1..8)
|
||||
:= ((-2,1),(-1,2),(1,2),(2,1),(2,-1),(1,-2),(-1,-2),(-2,-1));
|
||||
-- places for the night to go (relative to the current position)
|
||||
|
||||
function Count_Moves(Board: Tour) return Natural is
|
||||
N: Natural := 0;
|
||||
begin
|
||||
for I in Index loop
|
||||
for J in Index loop
|
||||
if Board(I,J) < Natural'Last then
|
||||
N := N + 1;
|
||||
end if;
|
||||
end loop;
|
||||
end loop;
|
||||
return N;
|
||||
end Count_Moves;
|
||||
|
||||
function Get_Tour(Start_X, Start_Y: Index; Scene: Tour := Empty)
|
||||
return Tour is
|
||||
Done: Boolean;
|
||||
Move_Count: Natural := Count_Moves(Scene);
|
||||
Visited: Tour;
|
||||
|
||||
-- Visited(I, J) = 0: not yet visited
|
||||
-- Visited(I, J) = K: visited at the k-th move
|
||||
-- Visited(I, J) = Integer'Last: never visit
|
||||
|
||||
procedure Visit(X, Y: Index; Move_Number: Positive; Found: out Boolean) is
|
||||
XX, YY: Integer;
|
||||
begin
|
||||
Found := False;
|
||||
Visited(X, Y) := Move_Number;
|
||||
if Move_Number = Move_Count then
|
||||
Found := True;
|
||||
else
|
||||
for P in Pairs'Range loop
|
||||
XX := X + Pairs(P)(1);
|
||||
YY := Y + Pairs(P)(2);
|
||||
if (XX in Index) and then (YY in Index)
|
||||
and then Visited(XX, YY) = 0 then
|
||||
Visit(XX, YY, Move_Number+1, Found); -- recursion
|
||||
if Found then
|
||||
return; -- no need to search further
|
||||
end if;
|
||||
end if;
|
||||
end loop;
|
||||
Visited(X, Y) := 0; -- undo previous mark
|
||||
end if;
|
||||
end Visit;
|
||||
|
||||
begin
|
||||
Visited := Scene;
|
||||
Visit(Start_X, Start_Y, 1, Done);
|
||||
if not Done then
|
||||
Visited := Scene;
|
||||
end if;
|
||||
return Visited;
|
||||
end Get_Tour;
|
||||
|
||||
procedure Tour_IO(The_Tour: Tour; Width: Natural := 4) is
|
||||
begin
|
||||
for I in Index loop
|
||||
for J in Index loop
|
||||
if The_Tour(I, J) < Integer'Last then
|
||||
Ada.Integer_Text_IO.Put(The_Tour(I, J), Width);
|
||||
else
|
||||
for W in 1 .. Width-1 loop
|
||||
Ada.Text_IO.Put(" ");
|
||||
end loop;
|
||||
Ada.Text_IO.Put("-"); -- deliberately not visited
|
||||
end if;
|
||||
end loop;
|
||||
Ada.Text_IO.New_Line;
|
||||
end loop;
|
||||
end Tour_IO;
|
||||
|
||||
end Knights_Tour;
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
with Knights_Tour, Ada.Command_Line;
|
||||
|
||||
procedure Test_Knight is
|
||||
|
||||
Size: Positive := Positive'Value(Ada.Command_Line.Argument(1));
|
||||
|
||||
package KT is new Knights_Tour(Size => Size);
|
||||
|
||||
begin
|
||||
KT.Tour_IO(KT.Get_Tour(1, 1));
|
||||
end Test_Knight;
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
function Warnsdorff_Get_Tour(Start_X, Start_Y: Index; Scene: Tour := Empty)
|
||||
return Tour;
|
||||
-- uses Warnsdorff heurisitic to find a tour faster
|
||||
-- same interface as Get_Tour
|
||||
|
|
@ -1,86 +0,0 @@
|
|||
function Warnsdorff_Get_Tour(Start_X, Start_Y: Index; Scene: Tour := Empty)
|
||||
return Tour is
|
||||
Done: Boolean;
|
||||
Visited: Tour; -- see comments from Get_Tour above
|
||||
Move_Count: Natural := Count_Moves(Scene);
|
||||
|
||||
function Neighbors(X, Y: Index) return Natural is
|
||||
Result: Natural := 0;
|
||||
begin
|
||||
for P in Pairs'Range loop
|
||||
if X+Pairs(P)(1) in Index and then Y+Pairs(P)(2) in Index and then
|
||||
Visited(X+Pairs(P)(1), Y+Pairs(P)(2)) = 0 then
|
||||
Result := Result + 1;
|
||||
end if;
|
||||
end loop;
|
||||
return Result;
|
||||
end Neighbors;
|
||||
|
||||
procedure Sort(Options: in out Pair_Array) is
|
||||
N_Bors: array(Options'Range) of Natural;
|
||||
K: Positive range Options'Range;
|
||||
N: Natural;
|
||||
P: Pair;
|
||||
begin
|
||||
for Opt in Options'Range loop
|
||||
N_Bors(Opt) := Neighbors(Options(Opt)(1), Options(Opt)(2));
|
||||
end loop;
|
||||
for Opt in Options'Range loop
|
||||
K := Opt;
|
||||
for Alternative in Opt+1 .. Options'Last loop
|
||||
if N_Bors(Alternative) < N_Bors(Opt) then
|
||||
K := Alternative;
|
||||
end if;
|
||||
end loop;
|
||||
N := N_Bors(Opt);
|
||||
N_Bors(Opt) := N_Bors(K);
|
||||
N_Bors(K) := N;
|
||||
P := Options(Opt);
|
||||
Options(Opt) := Options(K);
|
||||
Options(K) := P;
|
||||
end loop;
|
||||
end Sort;
|
||||
|
||||
procedure Visit(X, Y: Index; Move: Positive; Found: out Boolean) is
|
||||
Next_Count: Natural range 0 .. 8 := 0;
|
||||
Next_Steps: Pair_Array(1 .. 8);
|
||||
XX, YY: Integer;
|
||||
begin
|
||||
Found := False;
|
||||
Visited(X, Y) := Move;
|
||||
if Move = Move_Count then
|
||||
Found := True;
|
||||
else
|
||||
-- consider all possible places to go
|
||||
for P in Pairs'Range loop
|
||||
XX := X + Pairs(P)(1);
|
||||
YY := Y + Pairs(P)(2);
|
||||
if (XX in Index) and then (YY in Index)
|
||||
and then Visited(XX, YY) = 0 then
|
||||
Next_Count := Next_Count+1;
|
||||
Next_Steps(Next_Count) := (XX, YY);
|
||||
end if;
|
||||
end loop;
|
||||
|
||||
Sort(Next_Steps(1 .. Next_Count));
|
||||
|
||||
for N in 1 .. Next_Count loop
|
||||
Visit(Next_Steps(N)(1), Next_Steps(N)(2), Move+1, Found);
|
||||
if Found then
|
||||
return; -- no need to search further
|
||||
end if;
|
||||
end loop;
|
||||
|
||||
-- if we didn't return above, we have to undo our move
|
||||
Visited(X, Y) := 0;
|
||||
end if;
|
||||
end Visit;
|
||||
|
||||
begin
|
||||
Visited := Scene;
|
||||
Visit(Start_X, Start_Y, 1, Done);
|
||||
if not Done then
|
||||
Visited := Scene;
|
||||
end if;
|
||||
return Visited;
|
||||
end Warnsdorff_Get_Tour;
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
with Knights_Tour, Ada.Command_Line;
|
||||
|
||||
procedure Test_Fast is
|
||||
|
||||
Size: Positive := Positive'Value(Ada.Command_Line.Argument(1));
|
||||
|
||||
package KT is new Knights_Tour(Size => Size);
|
||||
|
||||
begin
|
||||
KT.Tour_IO(KT.Warnsdorff_Get_Tour(1, 1));
|
||||
end Test_Fast;
|
||||
|
|
@ -1,270 +0,0 @@
|
|||
include "NSLog.incl"
|
||||
output @"Knight's Move"
|
||||
|
||||
_window = 1
|
||||
_layerView = 10
|
||||
|
||||
begin record moved
|
||||
CGPoint offset
|
||||
Int SquareMove
|
||||
end record
|
||||
|
||||
begin globals
|
||||
dim move(8) as moved
|
||||
int Squares(64)
|
||||
CFMutableArrayRef gFinalArray
|
||||
end globals
|
||||
|
||||
gFinalArray = fn MutableArrayWithCapacity(0)
|
||||
|
||||
local fn PointOffset( pt as CGPoint,offset as CGPoint) as CGPoint
|
||||
pt.x += offset.x
|
||||
pt.y += offset.y
|
||||
end fn = pt
|
||||
|
||||
local fn FindLocation( x as int ) as CGPoint
|
||||
float a,b
|
||||
float y = x/8
|
||||
float z = frac(y)
|
||||
CGPoint pts
|
||||
|
||||
If z == 0
|
||||
a = 8
|
||||
b = 8 - fix(y)
|
||||
else
|
||||
a = z*8
|
||||
b = 8 - fix(y) - 1
|
||||
end if
|
||||
|
||||
pts.x = a*50 - 25
|
||||
pts.y = b*50 + 25
|
||||
|
||||
end fn = pts
|
||||
|
||||
local fn SetRecord
|
||||
for int x = 1 to 64
|
||||
Squares(x) = 0
|
||||
next
|
||||
//8 possible moves for a Knight
|
||||
move.offset.x(1) = -50
|
||||
move.offset.y(1) = -100
|
||||
move.SquareMove(1) = 15
|
||||
move.offset.x(2) = 50
|
||||
move.offset.y(2) = -100
|
||||
move.SquareMove(2) = 17
|
||||
move.offset.x(3) = -50
|
||||
move.offset.y(3) = 100
|
||||
move.SquareMove(3) = -17
|
||||
move.offset.x(4) = 50
|
||||
move.offset.y(4) = 100
|
||||
move.SquareMove(4) = -15
|
||||
move.offset.x(5) = 100
|
||||
move.offset.y(5) = 50
|
||||
move.SquareMove(5) = -6
|
||||
move.offset.x(6) = -100
|
||||
move.offset.y(6) = 50
|
||||
move.SquareMove(6) = -10
|
||||
move.offset.x(7) = 100
|
||||
move.offset.y(7) = -50
|
||||
move.SquareMove(7) = 10
|
||||
move.offset.x(8) = -100
|
||||
move.offset.y(8) = -50
|
||||
move.SquareMove(8) = 6
|
||||
|
||||
end fn
|
||||
|
||||
local fn Check(y as int, x as int ) as bool
|
||||
bool ans = NO
|
||||
|
||||
select y
|
||||
case 1
|
||||
select x
|
||||
case > 48
|
||||
ans = No
|
||||
case 1,9,17,25,33,41,49,57
|
||||
ans = NO
|
||||
case else
|
||||
ans = YES
|
||||
end select
|
||||
case 2
|
||||
select x
|
||||
case > 48
|
||||
ans = NO
|
||||
case 8,16,24,32,40,48,56,64
|
||||
ans = NO
|
||||
case else
|
||||
ans = YES
|
||||
end select
|
||||
case 3
|
||||
select x
|
||||
case < 16
|
||||
ans = NO
|
||||
case 1,9,17,25,33,41,49,57
|
||||
ans = NO
|
||||
case else
|
||||
ans = YES
|
||||
end select
|
||||
case 4
|
||||
select x
|
||||
case < 16
|
||||
ans = NO
|
||||
case 8,16,24,32,40,48,56,64
|
||||
ans = NO
|
||||
case else
|
||||
ans = YES
|
||||
end select
|
||||
case 5
|
||||
select x
|
||||
case < 9
|
||||
ans = NO
|
||||
case 7,8,15,16,23,24,31,32,39,40,47,48,55,56,63,64
|
||||
ans = NO
|
||||
case else
|
||||
ans = YES
|
||||
end select
|
||||
case 6
|
||||
select x
|
||||
case < 9
|
||||
ans = NO
|
||||
case 1,2,9,10,17,18,25,26,33,34,41,42,49,50,57,58
|
||||
ans = NO
|
||||
case else
|
||||
ans = YES
|
||||
end select
|
||||
case 7
|
||||
select x
|
||||
case > 56
|
||||
ans = NO
|
||||
case 7,8,15,16,23,24,31,32,39,40,47,48,55,56,63,64
|
||||
ans = NO
|
||||
case else
|
||||
ans = YES
|
||||
end select
|
||||
case 8
|
||||
select x
|
||||
case > 56
|
||||
ans = NO
|
||||
case 1,2,9,10,17,18,25,26,33,34,41,42,49,50,57,58
|
||||
ans = NO
|
||||
case else
|
||||
ans = YES
|
||||
end select
|
||||
end select
|
||||
end fn = ans
|
||||
|
||||
local fn DrawKnightsPassage( tag as long, array as CFArrayRef) as int
|
||||
CALayerRef layer
|
||||
CAShapeLayerRef shapeLayer
|
||||
BezierPathRef path = fn BezierPathInit
|
||||
int x,count = fn ArrayCount(array)
|
||||
int square = fn StringIntValue(fn ArrayObjectAtIndex( array, 0))
|
||||
|
||||
layer = fn ViewLayer( tag )
|
||||
CALayerSetBackgroundColor( layer, fn ColorClear )
|
||||
CALayerSetBorderWidth( layer, 2 )
|
||||
shapeLayer = fn CAShapeLayerInit
|
||||
CGPoint pt = fn FindLocation( square)
|
||||
Squares(square) = 1
|
||||
BezierPathMoveToPoint( path, pt)
|
||||
for x = 1 to count - 2
|
||||
square = fn StringIntValue(fn ArrayObjectAtIndex( array, x))
|
||||
pt = fn FindLocation( square)
|
||||
BezierPathLineToPoint( path, pt)
|
||||
next
|
||||
|
||||
CAShapeLayerSetPath( shapeLayer, path )
|
||||
CAShapeLayerSetLineWidth( shapeLayer, 2 )
|
||||
CAShapeLayerSetLineCap( shapeLayer, kCALineCapRound )
|
||||
CAShapeLayerSetStrokeColor( shapeLayer, fn ColorBlue )
|
||||
CAShapeLayerSetFillColor( shapeLayer, fn ColorClear )
|
||||
CALayerAddSublayer( layer, shapeLayer )
|
||||
|
||||
end fn = x
|
||||
|
||||
local fn KnightsTour as int
|
||||
int x,j,y
|
||||
int square = rnd(64)//58 //Starting square 58= White left Knight this is random start
|
||||
CFMutableStringRef array = fn MutableStringWithCapacity(0)
|
||||
CGPoint pt = fn FindLocation( square)
|
||||
for x = 1 to 64
|
||||
Squares(x) = 0
|
||||
next
|
||||
Squares(square) = 1
|
||||
MutableStringAppendString( array, fn StringWithFormat( @"%d:", square ))
|
||||
|
||||
for x = 1 to 63
|
||||
j = 1
|
||||
do
|
||||
y = rnd(8)
|
||||
j++
|
||||
until (square > 0 && square < 65 && (fn Check(y,square)) && square + move.SquareMove(y) > 0 && Squares(square + move.SquareMove(y)) == 0) || j == 35
|
||||
if j == 35 then exit next
|
||||
square += move.SquareMove(y)
|
||||
MutableStringAppendString( array, fn StringWithFormat( @"%d:", square ))
|
||||
|
||||
pt = fn PointOffset( pt, move.offset(y))
|
||||
Squares(square) = 1
|
||||
next
|
||||
MutableArrayAddObject( gFinalArray, (CFTypeRef) array )
|
||||
|
||||
end fn = x
|
||||
|
||||
void local fn BuildWnd
|
||||
CGRect r
|
||||
int x,y,j,Item(100000),max
|
||||
ColorRef hue(1) // Thanks Jay
|
||||
CALayerRef layer
|
||||
bool i
|
||||
CFTypeRef ans
|
||||
CFArrayRef array
|
||||
|
||||
window _window, @"Chess Board", ( 0,0,450,450)
|
||||
view _layerView, (20,20,400,400)
|
||||
WindowCenter(_window)
|
||||
WindowSubclassContentView(_window)
|
||||
ViewSetFlipped( _windowContentViewTag, YES )
|
||||
ViewSetNeedsDisplay( _windowContentViewTag )
|
||||
ViewSetWantsLayer( _layerView, YES )
|
||||
layer = fn ViewLayer( _layerview )
|
||||
ViewSetFlipped( _layerview, YES )
|
||||
CALayerSetBackgroundColor( layer, fn ColorClear )
|
||||
CALayerSetBorderWidth( layer, 2 )
|
||||
|
||||
r = fn CGREctMake( 20,20,50,50 )
|
||||
hue(NO) = fn colorLightGray
|
||||
hue(YES) = fn ColorClear
|
||||
i = YES
|
||||
j = 1
|
||||
for x = 1 to 8
|
||||
for y = 1 to 8
|
||||
rect fill r, hue(i)
|
||||
print %(r.origin.x,r.origin.y) j
|
||||
r = fn CGRectOffset( r, 50,0)
|
||||
j++
|
||||
if i == YES then i = NO else i = YES
|
||||
next
|
||||
if i == YES then i = NO else i = YES
|
||||
r = fn CGRectOffset( r , - 400, 50 )
|
||||
next
|
||||
for x = 1 to 100000
|
||||
item(x) = fn KnightsTour
|
||||
next
|
||||
max = 1
|
||||
y = 1
|
||||
for x = 1 to 99999
|
||||
if item(x) > max then max = item(x):y = x
|
||||
next
|
||||
|
||||
ans = fn ArrayObjectAtIndex(gFinalArray, y-1 )
|
||||
array = fn StringComponentsSeparatedByString(ans, @":" )
|
||||
|
||||
fn DrawKnightsPassage( _layerview, array)
|
||||
NSLog(@"Starts at %@",fn ArrayObjectAtIndex( array, 0))
|
||||
NSLog(@"max= %d Item= %d try= %d", max, item(y), y )
|
||||
|
||||
end fn
|
||||
|
||||
fn SetRecord
|
||||
fn BuildWnd
|
||||
|
||||
HandleEvents
|
||||
Loading…
Add table
Add a link
Reference in a new issue