קוד:
<%@ Page Language="VB" Debug="true" %>
<script runat="server">
function Check_for_moves(board(,) as integer,m as integer,n as integer) as integer()
dim i as integer,j as integer
dim legal_moves(9) as integer
for i=1 to 9
legal_moves(i)=0
next
for i=1 to 9
if(board(m,i)<>0) then
legal_moves(board(m,i))=1
end if
next
for i=1 to 9
if(board(i,n)<>0) then
legal_moves(board(i,n))=1
end if
next
'3 first cubs
if (m<=3) and (n<=3) then
for i= 1 to 3
for j=1 to 3
if board(i,j)<>0 then
legal_moves(board(i,j))=1
end if
next
next
end if
if (m<=3) and (n>=4 and n<=6) then
for i= 1 to 3
for j=4 to 6
if board(i,j)<>0 then
legal_moves(board(i,j))=1
end if
next
next
end if
if (m<=3) and (n>=7) then
for i= 1 to 3
for j=7 to 9
if board(i,j)<>0 then
legal_moves(board(i,j))=1
end if
next
next
end if
'3 more cubes
if (m>=4 and m<=6) and (n<=3) then
for i= 4 to 6
for j=1 to 3
if board(i,j)<>0 then
legal_moves(board(i,j))=1
end if
next
next
end if
if (m>=4 and m<=6) and (n>=4 and n<=6) then
for i= 4 to 6
for j=4 to 6
if board(i,j)<>0 then
legal_moves(board(i,j))=1
end if
next
next
end if
if (m>=4 and m<=6) and (n>=7) then
for i= 4 to 6
for j=7 to 9
if board(i,j)<>0 then
legal_moves(board(i,j))=1
end if
next
next
end if
'3 last cubs
if (m>=7) and (n<=3) then
for i= 7 to 9
for j=1 to 3
if board(i,j)<>0 then
legal_moves(board(i,j))=1
end if
next
next
end if
if (m>=7) and (n>=4 and n<=6) then
for i= 7 to 9
for j=4 to 6
if board(i,j)<>0 then
legal_moves(board(i,j))=1
end if
next
next
end if
if (m>=7) and (n>=7) then
for i= 7 to 9
for j=7 to 9
if board(i,j)<>0 then
legal_moves(board(i,j))=1
end if
next
next
end if
return(legal_moves)
end function
function solve(board as integer(,),level as integer)
if level>80 then return(0)
dim m as integer,n as integer,i as integer,save as integer,k as integer,l as integer,found_empty as boolean
found_empty=false
for m=1 to 9
for n=1 to 9
if board(m,n)=0
found_empty=true
exit for
end if
next
if found_empty then
exit for
end if
next
'response.write(m)
' response.write(" ")
' response.write(n)
'response.write(found_empty)
' response.write("<br>")
if not found_empty then
response.write("found borad!!!!!")
response.write("<br>")
for k=1 to 9
for l=1 to 9
if l=4 or l=7 then
response.write("|")
end if
response.write(board(k,l))
response.write (" ")
next
if k=3 or k=6 then
response.write("<br>")
response.write("------------------------")
end if
response.write("<br>")
next
return(0)
end if
'if m>=9 then
' for k=1 to 9
' for l=1 to 9
' if l=4 or l=7 then
'' response.write("|")
' end if
' response.write(board(k,l))
' response.write (" ")
' next
' if k=3 or k=6 then
' response.write("<br>")
' response.write("------------------------")
' end if
' response.write("<br>")
' next
' end if
dim temp as integer()=Check_for_moves(board,m,n)
for i=1 to 9
if temp(i)=0 then
save=board(m,n)
board(m,n)=i
solve(board,level+1)
board(m,n)=save
end if
next
end function
Sub Page_Load(Sender As Object, E As EventArgs)
dim board(9,9) as integer
board(1,1)=0
board(1,2)=7
board(1,3)=0
board(1,4)=4
board(1,5)=0
board(1,6)=0
board(1,7)=0
board(1,8)=9
board(1,9)=0
board(2,1)=6
board(2,2)=0
board(2,3)=0
board(2,4)=0
board(2,5)=0
board(2,6)=9
board(2,7)=0
board(2,8)=2
board(2,9)=0
board(3,1)=5
board(3,2)=0
board(3,3)=0
board(3,4)=8
board(3,5)=0
board(3,6)=0
board(3,7)=7
board(3,8)=0
board(3,9)=0
board(4,1)=4
board(4,2)=0
board(4,3)=0
board(4,4)=0
board(4,5)=3
board(4,6)=0
board(4,7)=0
board(4,8)=6
board(4,9)=2
board(5,1)=0
board(5,2)=0
board(5,3)=0
board(5,4)=9
board(5,5)=0
board(5,6)=5
board(5,7)=0
board(5,8)=0
board(5,9)=0
board(6,1)=2
board(6,2)=9
board(6,3)=0
board(6,4)=0
board(6,5)=4
board(6,6)=0
board(6,7)=0
board(6,8)=0
board(6,9)=7
board(7,1)=0
board(7,2)=0
board(7,3)=4
board(7,4)=0
board(7,5)=0
board(7,6)=7
board(7,7)=0
board(7,8)=0
board(7,9)=6
board(8,1)=0
board(8,2)=5
board(8,3)=0
board(8,4)=1
board(8,5)=0
board(8,6)=0
board(8,7)=0
board(8,8)=0
board(8,9)=3
board(9,1)=0
board(9,2)=6
board(9,3)=0
board(9,4)=0
board(9,5)=0
board(9,6)=3
board(9,7)=0
board(9,8)=5
board(9,9)=0
dim board2 (9,9) as integer
board2(1,1)=1
board2(1,2)=1
board2(1,3)=0
board2(1,4)=3
board2(1,5)=2
board2(1,6)=1
board2(1,7)=1
board2(1,8)=1
board2(1,9)=7
board2(2,1)=4
board2(2,2)=9
board2(2,3)=7
board2(2,4)=1
board2(2,5)=6
board2(2,6)=2
board2(2,7)=5
board2(2,8)=1
board2(2,9)=1
board2(3,1)=2
board2(3,2)=1
board2(3,3)=4
board2(3,4)=1
board2(3,5)=1
board2(3,6)=7
board2(3,7)=9
board2(3,8)=2
board2(3,9)=1
board2(4,1)=1
board2(4,2)=4
board2(4,3)=1
board2(4,4)=1
board2(4,5)=7
board2(4,6)=2
board2(4,7)=1
board2(4,8)=2
board2(4,9)=3
board2(5,1)=1
board2(5,2)=7
board2(5,3)=1
board2(5,4)=1
board2(5,5)=1
board2(5,6)=5
board2(5,7)=1
board2(5,8)=4
board2(5,9)=1
board2(6,1)=9
board2(6,2)=6
board2(6,3)=1
board2(6,4)=1
board2(6,5)=3
board2(6,6)=1
board2(6,7)=1
board2(6,8)=7
board2(6,9)=1
board2(7,1)=1
board2(7,2)=1
board2(7,3)=9
board2(7,4)=6
board2(7,5)=1
board2(7,6)=1
board2(7,7)=1
board2(7,8)=1
board2(7,9)=5
board2(8,1)=1
board2(8,2)=2
board2(8,3)=1
board2(8,4)=1
board2(8,5)=2
board2(8,6)=1
board2(8,7)=7
board2(8,8)=2
board2(8,9)=6
board2(9,1)=2
board2(9,2)=2
board2(9,3)=4
board2(9,4)=2
board2(9,5)=2
board2(9,6)=1
board2(9,7)=2
board2(9,8)=2
board2(9,9)=2
dim m as integer,n as integer,t as integer
for m=1 to 9
for n=1 to 9
if n=4 or n=7 then
response.write("|")
end if
response.write(board(m,n))
response.write (" ")
next
if m=3 or m=6 then
response.write("<br>")
response.write("------------------------")
end if
response.write("<br>")
next
solve(board,1)
End Sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<!-- Insert content here -->
</form>
</body>
</html>