In our last lesson we looked at Memory and how it is used in conjunction with look ups to provide the user with a list of choices for his – her review or action. Today we will look at Understanding Reason and Logic and the parts they play in your programming.
Thought:
The logical place to start is thought. Without thought there can be no understanding thus no reason and finally no logic. Thought is the mechanic of imagination and memory. Through thought we learn to reason and finally develop understanding.
Understanding:
Understanding is not unique to humans. A dog can be trained to understand many commands as can many other animals. Their understanding is linked directly to their senses and learned through repetition. Mans understanding is different; I won’t go so far as to say it is unique to man; it allows us to give names to sounds which is then used as a trigger to remember an image. When the images are strung together in a logical order it becomes a thought and when spoken out loud or written down a language. Language is then used to trigger other memories, and allows us to think about the cause and effect of things and thus reason.
Reason and Logic:
Reason is a humans way of answering a question either yes, no or I am not sure. In most cases when we reason we simply conceive a sum total. Since reason is built on what we already know and which is stored as memories our reason can be flawed. One could reason that a table has four legs and a dog has four legs therefor a dog is a table. This only happens because the person doing the reckoning does not have or chooses to not use all the facts about dogs and tables (they jump to a conclusion ). Computers use Logic. Logic answers each query as Yes or NO. It cannot speculate but it can give the wrong answer if it does not consider all facts about the query presented to it. As a programmer you must determine what information your program will process, provide all necessary facts and existing knowledge for use by your program through predetermined data tables, electronic input and or user input and provide an error management process to intercept user and or programming errors so the program will deliver results as expected.
Sudoku Puzzle Game:
As always, it is more fun to do programming lessons if there is an actual program being developed and for this lesson we will do a Sudoku puzzle game.
The image above is my Sudoku puzzle game I wrote back in 2006. It’s a good program for us to build since it requires all the elements we have discussed so far; Lookups, variables, randomization and much more. I think it will be educational and fun so lets get started.
Tables:
The form above is bound to a table called sudokupuzzlesolver. Like the traditional game it has 9 blocks with 9 cells each and the user must arrange the values in each cell so that the block row and column all have unique values. In our form cells with a Blue-Glass background are locked and the user cannot move them. In addition to the standard cells; at the top of the form we have 9 fields which by default have the values 1 through 9. On the right are several buttons which control the creation of games, movement in the game and some additional controls. We will be redesigning this form as we go along.
One of the problems I have with other Sudoku puzzle games is not all puzzles they create are solvable. To address this issue we will start with a template table. The template table contains each cell needed for the puzzle.
9Blocks x 9Cells = 81Cells
The fields are:
and finally here is a sample of the values in each field.
Blocks are numbered in tens; 10, 20, 30 etc.. Rows are 1 thru 9. Columns are in 10’s as well and cells are 11 thru 99 and value equals 1 through 9. The Final field is BCell and is logical and I will explain it’s value later. This is a little confusing so I will do my best to explain. To start with, there is only one solution to a Sudoku puzzle. Puzzle’s appear different because the cell values are in a different location within the blocks but each row and column must still add up to 45 and each block, row and column must have unique values. Our template table actually is a solved puzzle. By using a solved puzzle and moving values around we insure each puzzle is solvable. To insure the puzzle is solvable we must adhere to specific rules.
The simple grid above lays out the puzzle board and explains how the blocks, columns, rows and cells can be moved to insure the puzzle is solvable.
When the user clicks New Game, They are presented with the following screen
Lets examine the code for the Computer Generated Puzzle.
New Game OnPush
script_play("LoadSudukoVars") parentform.Commit() b1v = "" b1n = "" b2v = "" b2n = "" pt = "" parentform.Commit()DIM Shared choice as c choice = ui_get_radio("Select Puzzle Type","1","Computer Generated Standard","Manual Enter from Book","Hidden Word from Book", "Your Saved Puzzles") if choice = "" then End end if if Choice = "Computer Generated Standard" then pt="W" script_play("StartNewPuzzle") script_play("BuildRandomGame") goto assign end if if Choice = "Manual Enter from Book" then pt="W" script_play("StartNewPuzzle") script_play("ManualPuzzleDialog") goto assign end if if Choice = "Hidden Word from Book" then script_play("2_Sudoku_HW_Puzzle") sys_send_keys("{F5}") script_play("HWPuzzleDialog") sys_send_keys("{F5}") End end if if Choice = "Your Saved Puzzles" then pt = "W" script_play("playYourSavedPuzzle") script_play("StartNewPuzzle") script_play("BuildRandomGame") goto assign end if assign: tbl = table.open("sudokupuzzlesolver") tbl.change_begin() tbl.cl1 = "1" tbl.Cl2 = "2" tbl.Cl3 = "3" tbl.cl4 = "4" tbl.cl5 = "5" tbl.cl6 = "6" tbl.cl7 = "7" tbl.cl8 = "8" tbl.cl9 = "9" tbl.Vl1 = 9 tbl.vl2 = 8 tbl.Vl3 = 7 tbl.vl4 = 6 tbl.Vl5 = 1 tbl.vl6 = 2 tbl.vl7 = 3 tbl.Vl8 = 4 tbl.vl9 = 5 tbl.change_end(.t.) tbl.close() sys_send_keys("{F5}")ui_freeze(.f.)
The first step is to run our script LoadSudukoVars. This script declaves a variable for each cell on the board and uses an array to set each value to “F”
DIM shared CC as C dim SHARED b1v as C dim SHARED b2v as C dim SHARED b1n as C dim SHARED b2n as Cdim SHARED sk1 as c dim SHARED sk2 as c dim SHARED sk3 as c dim SHARED sk4 as c dim SHARED sk5 as c dim SHARED sk6 as c dim SHARED sk7 as c dim SHARED sk8 as c dim SHARED sk9 as c dim SHARED sk10 as c dim SHARED sk11 as c dim SHARED sk12 as c dim SHARED sk13 as c dim SHARED sk14 as c dim SHARED sk15 as c dim SHARED sk16 as c dim SHARED sk17 as c dim SHARED sk18 as c dim SHARED sk19 as c dim SHARED sk20 as c dim SHARED sk21 as c dim SHARED sk22 as c dim SHARED sk23 as c dim SHARED sk24 as c dim SHARED sk25 as c dim SHARED sk26 as c dim SHARED sk27 as c dim SHARED sk28 as c dim SHARED sk29 as c dim SHARED sk30 as c dim SHARED sk31 as c dim SHARED sk32 as c dim SHARED sk33 as c dim SHARED sk34 as c dim SHARED sk35 as c dim SHARED sk36 as c dim SHARED sk37 as c dim SHARED sk38 as c dim SHARED sk39 as c dim SHARED sk40 as c dim SHARED sk41 as c dim SHARED sk42 as c dim SHARED sk43 as c dim SHARED sk44 as c dim SHARED sk45 as c dim SHARED sk46 as c dim SHARED sk47 as c dim SHARED sk48 as c dim SHARED sk49 as c dim SHARED sk50 as c dim SHARED sk51 as c dim SHARED sk52 as c dim SHARED sk53 as c dim SHARED sk54 as c dim SHARED sk55 as c dim SHARED sk56 as c dim SHARED sk57 as c dim SHARED sk58 as c dim SHARED sk59 as c dim SHARED sk60 as c dim SHARED sk61 as c dim SHARED sk62 as c dim SHARED sk63 as c dim SHARED sk64 as c dim SHARED sk65 as c dim SHARED sk66 as c dim SHARED sk67 as c dim SHARED sk68 as c dim SHARED sk69 as c dim SHARED sk70 as c dim SHARED sk71 as c dim SHARED sk72 as c dim SHARED sk73 as c dim SHARED sk74 as c dim SHARED sk75 as c dim SHARED sk76 as c dim SHARED sk77 as c dim SHARED sk78 as c dim SHARED sk79 as c dim SHARED sk80 as c dim SHARED sk81 as c dim txt as cFOR i = 1 to 81 step 1 eval("sk"+alltrim(str(i))) = "F" Next
When Computer Generated is selected we set a Global variable Pt to equal “W” (this will be explained later) then run two scripts. First is
Start New Puzzle then
Build Random Game
Start New Puzzle clears all values in our puzzle board which always has only one record. If it is character it sets it to null if numeric it is set to 0.
a_tbl = table.open("sudokupuzzlesolver")
update.fields = 81
update.field1 = "B1S1V"
update.expr1 = "if(Var->sk1=\"F\",0,B1S1V)"
update.field2 = "B1s2v"
update.expr2 = "if(Var->sk2=\"F\",0,B1s2v)"
update.field3 = "B1s3v"
update.expr3 = "if(Var->sk3=\"F\",0,B1s3v)"
update.field4 = "B1s4v"
update.expr4 = "if(Var->sk4=\"F\",0,B1s4v)"
update.field5 = "B1s5v"
update.expr5 = "if(Var->sk5=\"F\",0,B1s5v)"
update.field6 = "B1s6v"
update.expr6 = "if(Var->sk6=\"F\",0,B1s6v)"
update.field7 = "B1s7v"
update.expr7 = "if(Var->sk7=\"F\",0,B1s7v)"
update.field8 = "B1s8v"
update.expr8 = "if(Var->sk8=\"F\",0,B1s8v)"
update.field9 = "B1s9v"
update.expr9 = "if(Var->sk9=\"F\",0,B1s9v)"
update.field10 = "B2s1v"
update.expr10 = "if(Var->sk10=\"F\",0,B2s1v)"
update.field11 = "B2s2v"
update.expr11 = "if(Var->sk11=\"F\",0,B2s2v)"
update.field12 = "B2s3v"
update.expr12 = "if(Var->sk12=\"F\",0,B2s3v)"
update.field13 = "B2s4v"
update.expr13 = "if(Var->sk13=\"F\",0,B2s4v)"
update.field14 = "B2s5v"
update.expr14 = "if(Var->sk14=\"F\",0,B2s5v)"
update.field15 = "B2s6v"
update.expr15 = "if(Var->sk15=\"F\",0,B2s6v)"
update.field16 = "B2s7v"
update.expr16 = "if(Var->sk16=\"F\",0,B2s7v)"
update.field17 = "B2s8v"
update.expr17 = "if(Var->sk17=\"F\",0,B2s8v)"
update.field18 = "B2s9v"
update.expr18 = "if(Var->sk18=\"F\",0,B2s9v)"
update.field19 = "B3s1v"
update.expr19 = "if(Var->sk19=\"F\",0,B3s1v)"
update.field20 = "B3s2v"
update.expr20 = "if(Var->sk20=\"F\",0,B3s2v)"
update.field21 = "B3s3v"
update.expr21 = "if(Var->sk21=\"F\",0,B3s3v)"
update.field22 = "B3s4v"
update.expr22 = "if(Var->sk22=\"F\",0,B3s4v)"
update.field23 = "B3s5v"
update.expr23 = "if(Var->sk23=\"F\",0,B3s5v)"
update.field24 = "B3s6v"
update.expr24 = "if(Var->sk24=\"F\",0,B3s6v)"
update.field25 = "B3s7v"
update.expr25 = "if(Var->sk25=\"F\",0,B3s7v)"
update.field26 = "B3s8v"
update.expr26 = "if(Var->sk26=\"F\",0,B3s8v)"
update.field27 = "B3s9v"
update.expr27 = "if(Var->sk27=\"F\",0,B3s9v)"
update.field28 = "B4s1v"
update.expr28 = "if(Var->sk28=\"F\",0,B4s1v)"
update.field29 = "B4s2v"
update.expr29 = "if(Var->sk29=\"F\",0,B4s2v)"
update.field30 = "B4s3v"
update.expr30 = "if(Var->sk30=\"F\",0,B4s3v)"
update.field31 = "B4s4v"
update.expr31 = "if(Var->sk31=\"F\",0,B4s4v)"
update.field32 = "B4s5v"
update.expr32 = "if(Var->sk32=\"F\",0,B4s5v)"
update.field33 = "B4s6v"
update.expr33 = "if(Var->sk33=\"F\",0,B4s6v)"
update.field34 = "B4s7v"
update.expr34 = "if(Var->sk34=\"F\",0,B4s7v)"
update.field35 = "B4s8v"
update.expr35 = "if(Var->sk35=\"F\",0,B4s8v)"
update.field36 = "B4s9v"
update.expr36 = "if(Var->sk36=\"F\",0,B4s9v)"
update.field37 = "B5s1v"
update.expr37 = "if(Var->sk37=\"F\",0,B5s1v)"
update.field38 = "B5s2v"
update.expr38 = "if(Var->sk38=\"F\",0,B5s2v)"
update.field39 = "B5s3v"
update.expr39 = "if(Var->sk39=\"F\",0,B5s3v)"
update.field40 = "B5s4v"
update.expr40 = "if(Var->sk40=\"F\",0,B5s4v)"
update.field41 = "B5s5v"
update.expr41 = "if(Var->sk41=\"F\",0,B5s5v)"
update.field42 = "B5s6v"
update.expr42 = "if(Var->sk42=\"F\",0,B5s6v)"
update.field43 = "B5s7v"
update.expr43 = "if(Var->sk43=\"F\",0,B5s7v)"
update.field44 = "B5s8v"
update.expr44 = "if(Var->sk44=\"F\",0,B5s8v)"
update.field45 = "B5s9v"
update.expr45 = "if(Var->sk45=\"F\",0,B5s9v)"
update.field46 = "B6s1v"
update.expr46 = "if(Var->sk46=\"F\",0,B6s1v)"
update.field47 = "B6s2v"
update.expr47 = "if(Var->sk47=\"F\",0,B6s2v)"
update.field48 = "B6s3v"
update.expr48 = "if(Var->sk48=\"F\",0,B6s3v)"
update.field49 = "B6s4v"
update.expr49 = "if(Var->sk49=\"F\",0,B6s4v)"
update.field50 = "B6s5v"
update.expr50 = "if(Var->sk50=\"F\",0,B6s5v)"
update.field51 = "B6s6v"
update.expr51 = "if(Var->sk51=\"F\",0,B6s6v)"
update.field52 = "B6s7v"
update.expr52 = "if(Var->sk52=\"F\",0,B6s7v)"
update.field53 = "B6s8v"
update.expr53 = "if(Var->sk53=\"F\",0,B6s8v)"
update.field54 = "B6s9v"
update.expr54 = "if(Var->sk54=\"F\",0,B6s9v)"
update.field55 = "B7s1v"
update.expr55 = "if(Var->sk55=\"F\",0,B7s1v)"
update.field56 = "B7s2v"
update.expr56 = "if(Var->sk56=\"F\",0,B7s2v)"
update.field57 = "B7s3v"
update.expr57 = "if(Var->sk57=\"F\",0,B7s3v)"
update.field58 = "B7s4v"
update.expr58 = "if(Var->sk58=\"F\",0,B7s4v)"
update.field59 = "B7s5v"
update.expr59 = "if(Var->sk59=\"F\",0,B7s5v)"
update.field60 = "B7s6v"
update.expr60 = "if(Var->sk60=\"F\",0,B7s6v)"
update.field61 = "B7s7v"
update.expr61 = "if(Var->sk61=\"F\",0,B7s7v)"
update.field62 = "B7s8v"
update.expr62 = "if(Var->sk62=\"F\",0,B7s8v)"
update.field63 = "B7s9v"
update.expr63 = "if(Var->sk63=\"F\",0,B7s9v)"
update.field64 = "B8s1v"
update.expr64 = "if(Var->sk64=\"F\",0,B8s1v)"
update.field65 = "B8s2v"
update.expr65 = "if(Var->sk65=\"F\",0,B8s2v)"
update.field66 = "B8s3v"
update.expr66 = "if(Var->sk66=\"F\",0,B8s3v)"
update.field67 = "B8s4v"
update.expr67 = "if(Var->sk67=\"F\",0,B8s4v)"
update.field68 = "B8s5v"
update.expr68 = "if(Var->sk68=\"F\",0,B8s5v)"
update.field69 = "B8s6v"
update.expr69 = "if(Var->sk69=\"F\",0,B8s6v)"
update.field70 = "B8s7v"
update.expr70 = "if(Var->sk70=\"F\",0,B8s7v)"
update.field71 = "B8s8v"
update.expr71 = "if(Var->sk71=\"F\",0,B8s8v)"
update.field72 = "B8s9v"
update.expr72 = "if(Var->sk72=\"F\",0,B8s9v)"
update.field73 = "B9s1v"
update.expr73 = "if(Var->sk73=\"F\",0,B9s1v)"
update.field74 = "B9s2v"
update.expr74 = "if(Var->sk74=\"F\",0,B9s2v)"
update.field75 = "B9s3v"
update.expr75 = "if(Var->sk75=\"F\",0,B9s3v)"
update.field76 = "B9s4v"
update.expr76 = "if(Var->sk76=\"F\",0,B9s4v)"
update.field77 = "B9s5v"
update.expr77 = "if(Var->sk77=\"F\",0,B9s5v)"
update.field78 = "B9s6v"
update.expr78 = "if(Var->sk78=\"F\",0,B9s6v)"
update.field79 = "B9s7v"
update.expr79 = "if(Var->sk79=\"F\",0,B9s7v)"
update.field80 = "B9s8v"
update.expr80 = "if(Var->sk80=\"F\",0,B9s8v)"
update.field81 = "B9s9v"
update.expr81 = "if(Var->sk81=\"F\",0,B9s9v)"
a_tbl.update()
update.fields = 81 update.field1 = "B1S1" update.expr1 = "if(Var->sk1=\"F\",\"\",B1S1)" update.field2 = "B1s2" update.expr2 = "if(Var->sk2=\"F\",\"\",B1s2)" update.field3 = "B1s3" update.expr3 = "if(Var->sk3=\"F\",\"\",B1s3)" update.field4 = "B1s4" update.expr4 = "if(Var->sk4=\"F\",\"\",B1s4)" update.field5 = "B1s5" update.expr5 = "if(Var->sk5=\"F\",\"\",B1s5)" update.field6 = "B1s6" update.expr6 = "if(Var->sk6=\"F\",\"\",B1s6)" update.field7 = "B1s7" update.expr7 = "if(Var->sk7=\"F\",\"\",B1s7)" update.field8 = "B1s8" update.expr8 = "if(Var->sk8=\"F\",\"\",B1s8)" update.field9 = "B1s9" update.expr9 = "if(Var->sk9=\"F\",\"\",B1s9)" update.field10 = "B2s1" update.expr10 = "if(Var->sk10=\"F\",\"\",B2s1)" update.field11 = "B2s2" update.expr11 = "if(Var->sk11=\"F\",\"\",B2s2)" update.field12 = "B2s3" update.expr12 = "if(Var->sk12=\"F\",\"\",B2s3)" update.field13 = "B2s4" update.expr13 = "if(Var->sk13=\"F\",\"\",B2s4)" update.field14 = "B2s5" update.expr14 = "if(Var->sk14=\"F\",\"\",B2s5)" update.field15 = "B2s6" update.expr15 = "if(Var->sk15=\"F\",\"\",B2s6)" update.field16 = "B2s7" update.expr16 = "if(Var->sk16=\"F\",\"\",B2s7)" update.field17 = "B2s8" update.expr17 = "if(Var->sk17=\"F\",\"\",B2s8)" update.field18 = "B2s9" update.expr18 = "if(Var->sk18=\"F\",\"\",B2s9)" update.field19 = "B3s1" update.expr19 = "if(Var->sk19=\"F\",\"\",B3s1)" update.field20 = "B3s2" update.expr20 = "if(Var->sk20=\"F\",\"\",B3s2)" update.field21 = "B3s3" update.expr21 = "if(Var->sk21=\"F\",\"\",B3s3)" update.field22 = "B3s4" update.expr22 = "if(Var->sk22=\"F\",\"\",B3s4)" update.field23 = "B3s5" update.expr23 = "if(Var->sk23=\"F\",\"\",B3s5)" update.field24 = "B3s6" update.expr24 = "if(Var->sk24=\"F\",\"\",B3s6)" update.field25 = "B3s7" update.expr25 = "if(Var->sk25=\"F\",\"\",B3s7)" update.field26 = "B3s8" update.expr26 = "if(Var->sk26=\"F\",\"\",B3s8)" update.field27 = "B3s9" update.expr27 = "if(Var->sk27=\"F\",\"\",B3s9)" update.field28 = "B4s1" update.expr28 = "if(Var->sk28=\"F\",\"\",B4s1)" update.field29 = "B4s2" update.expr29 = "if(Var->sk29=\"F\",\"\",B4s2)" update.field30 = "B4s3" update.expr30 = "if(Var->sk30=\"F\",\"\",B4s3)" update.field31 = "B4s4" update.expr31 = "if(Var->sk31=\"F\",\"\",B4s4)" update.field32 = "B4s5" update.expr32 = "if(Var->sk32=\"F\",\"\",B4s5)" update.field33 = "B4s6" update.expr33 = "if(Var->sk33=\"F\",\"\",B4s6)" update.field34 = "B4s7" update.expr34 = "if(Var->sk34=\"F\",\"\",B4s7)" update.field35 = "B4s8" update.expr35 = "if(Var->sk35=\"F\",\"\",B4s8)" update.field36 = "B4s9" update.expr36 = "if(Var->sk36=\"F\",\"\",B4s9)" update.field37 = "B5s1" update.expr37 = "if(Var->sk37=\"F\",\"\",B5s1)" update.field38 = "B5s2" update.expr38 = "if(Var->sk38=\"F\",\"\",B5s2)" update.field39 = "B5s3" update.expr39 = "if(Var->sk39=\"F\",\"\",B5s3)" update.field40 = "B5s4" update.expr40 = "if(Var->sk40=\"F\",\"\",B5s4)" update.field41 = "B5s5" update.expr41 = "if(Var->sk41=\"F\",\"\",B5s5)" update.field42 = "B5s6" update.expr42 = "if(Var->sk42=\"F\",\"\",B5s6)" update.field43 = "B5s7" update.expr43 = "if(Var->sk43=\"F\",\"\",B5s7)" update.field44 = "B5s8" update.expr44 = "if(Var->sk44=\"F\",\"\",B5s8)" update.field45 = "B5s9" update.expr45 = "if(Var->sk45=\"F\",\"\",B5s9)" update.field46 = "B6s1" update.expr46 = "if(Var->sk46=\"F\",\"\",B6s1)" update.field47 = "B6s2" update.expr47 = "if(Var->sk47=\"F\",\"\",B6s2)" update.field48 = "B6s3" update.expr48 = "if(Var->sk48=\"F\",\"\",B6s3)" update.field49 = "B6s4" update.expr49 = "if(Var->sk49=\"F\",\"\",B6s4)" update.field50 = "B6s5" update.expr50 = "if(Var->sk50=\"F\",\"\",B6s5)" update.field51 = "B6s6" update.expr51 = "if(Var->sk51=\"F\",\"\",B6s6)" update.field52 = "B6s7" update.expr52 = "if(Var->sk52=\"F\",\"\",B6s7)" update.field53 = "B6s8" update.expr53 = "if(Var->sk53=\"F\",\"\",B6s8)" update.field54 = "B6s9" update.expr54 = "if(Var->sk54=\"F\",\"\",B6s9)" update.field55 = "B7s1" update.expr55 = "if(Var->sk55=\"F\",\"\",B7s1)" update.field56 = "B7s2" update.expr56 = "if(Var->sk56=\"F\",\"\",B7s2)" update.field57 = "B7s3" update.expr57 = "if(Var->sk57=\"F\",\"\",B7s3)" update.field58 = "B7s4" update.expr58 = "if(Var->sk58=\"F\",\"\",B7s4)" update.field59 = "B7s5" update.expr59 = "if(Var->sk59=\"F\",\"\",B7s5)" update.field60 = "B7s6" update.expr60 = "if(Var->sk60=\"F\",\"\",B7s6)" update.field61 = "B7s7" update.expr61 = "if(Var->sk61=\"F\",\"\",B7s7)" update.field62 = "B7s8" update.expr62 = "if(Var->sk62=\"F\",\"\",B7s8)" update.field63 = "B7s9" update.expr63 = "if(Var->sk63=\"F\",\"\",B7s9)" update.field64 = "B8s1" update.expr64 = "if(Var->sk64=\"F\",\"\",B8s1)" update.field65 = "B8s2" update.expr65 = "if(Var->sk65=\"F\",\"\",B8s2)" update.field66 = "B8s3" update.expr66 = "if(Var->sk66=\"F\",\"\",B8s3)" update.field67 = "B8s4" update.expr67 = "if(Var->sk67=\"F\",\"\",B8s4)" update.field68 = "B8s5" update.expr68 = "if(Var->sk68=\"F\",\"\",B8s5)" update.field69 = "B8s6" update.expr69 = "if(Var->sk69=\"F\",\"\",B8s6)" update.field70 = "B8s7" update.expr70 = "if(Var->sk70=\"F\",\"\",B8s7)" update.field71 = "B8s8" update.expr71 = "if(Var->sk71=\"F\",\"\",B8s8)" update.field72 = "B8s9" update.expr72 = "if(Var->sk72=\"F\",\"\",B8s9)" update.field73 = "B9s1" update.expr73 = "if(Var->sk73=\"F\",\"\",B9s1)" update.field74 = "B9s2" update.expr74 = "if(Var->sk74=\"F\",\"\",B9s2)" update.field75 = "B9s3" update.expr75 = "if(Var->sk75=\"F\",\"\",B9s3)" update.field76 = "B9s4" update.expr76 = "if(Var->sk76=\"F\",\"\",B9s4)" update.field77 = "B9s5" update.expr77 = "if(Var->sk77=\"F\",\"\",B9s5)" update.field78 = "B9s6" update.expr78 = "if(Var->sk78=\"F\",\"\",B9s6)" update.field79 = "B9s7" update.expr79 = "if(Var->sk79=\"F\",\"\",B9s7)" update.field80 = "B9s8" update.expr80 = "if(Var->sk80=\"F\",\"\",B9s8)" update.field81 = "B9s9" update.expr81 = "if(Var->sk81=\"F\",\"\",B9s9)" a_tbl.update()
update.fields = 18
update.field1 = "Cl1"
update.expr1 = "\"\""
update.field2 = "Cl2"
update.expr2 = "\"\""
update.field3 = "cl3"
update.expr3 = "\"\""
update.field4 = "Cl4"
update.expr4 = "\"\""
update.field5 = "cl5"
update.expr5 = "\"\""
update.field6 = "cl6"
update.expr6 = "\"\""
update.field7 = "cl7"
update.expr7 = "\"\""
update.field8 = "cl8"
update.expr8 = "\"\""
update.field9 = "Cl9"
update.expr9 = "\"\""
update.field10 = "Vl1"
update.expr10 = "0"
update.field11 = "Vl2"
update.expr11 = "0"
update.field12 = "Vl3"
update.expr12 = "0"
update.field13 = "vl4"
update.expr13 = "0"
update.field14 = "Vl5"
update.expr14 = "0"
update.field15 = "Vl6"
update.expr15 = "0"
update.field16 = "Vl7"
update.expr16 = "0"
update.field17 = "Vl8"
update.expr17 = "0"
update.field18 = "Vl9"
update.expr18 = "0"
a_tbl.update()
a_tbl.close()
sys_send_keys("{F5}")
Next we run Build Random Game. This script is very important for our game since it switches the cells around to create a unique game and it randomly sets which fields are clues which further makes the game unique. Lets look at the magic.
'Declare Variables dim global rb1 as N dim global rb2 as N dim global rb3 as N dim global rb4 as N dim global rb5 as N dim global rb6 as N dim global rb7 as N dim global rb8 as N dim global rb9 as N dim global blkb as N rb1 = +1 + round(Rand()*6,0) rb2 = +1 + round(Rand()*6,0) rb3 = +1 + round(Rand()*6,0) rb4 = +1 + round(Rand()*6,0) rb5 = +1 + round(Rand()*6,0) rb6 = +1 + round(Rand()*6,0) rb7 = +1 + round(Rand()*6,0) rb8 = +1 + round(Rand()*6,0) rb9 = +1 + round(Rand()*6,0)
'Randomly Set Puzzle Clues
a_tbl = table.open("spuzzletemplete")
update.fields = 12
update.field1 = "BCELL"
update.expr1 = "if(between(Cell,11,19),if(mod((Cell-10),var->rb1)=0,.f.,.t.),BCELL)"
update.field2 = "BCELL"
update.expr2 = "if(between(Cell,21,29),if(mod((Cell-20),Var->rb2)=0,.f.,.t.) ,BCELL)"
update.field3 = "BCELL"
update.expr3 = "if(between(Cell,31,39),if(mod((Cell-30),Var->rb3)=0,.f.,.t.) ,BCELL)"
update.field4 = "BCELL"
update.expr4 = "if(between(Cell,41,49),if(mod((Cell-40),Var->rb4)=0,.f.,.t.) ,BCELL)"
update.field5 = "BCELL"
update.expr5 = "if(between(Cell,51,59),if(mod((Cell-50),Var->rb5)=0,.f.,.t.) ,BCELL)"
update.field6 = "BCELL"
update.expr6 = "if(between(Cell,61,69),if(mod((Cell-60),Var->rb6)=0,.f.,.t.) ,BCELL)"
update.field7 = "BCELL"
update.expr7 = "if(between(Cell,71,79),if(mod((Cell-70),Var->rb7)=0,.f.,.t.) ,BCELL)"
update.field8 = "BCELL"
update.expr8 = "if(between(Cell,81,89),if(mod((Cell-80),Var->rb8)=0,.f.,.t.) ,BCELL)"
update.field9 = "BCELL"
update.expr9 = "if(between(Cell,91,99),if(mod((Cell-90),Var->rb9)=0,.f.,.t.) ,BCELL)"
'Shuffle Blocks
update.field10 = "BLOCK"
update.expr10 = "if(block=10,20,If(block=20,30,If(block=30,10,If(Block=40,50,If(Block=50,60,if(block=60,40,if(Block=70,80,if(Block=80,90,70))))))))"
'Shuffle Cells
update.field11 = "CELL"
update.expr11 = "if(Right(Alltrim(Str(CELL)),1)<\"7\",CELL+3,CELL-6)"
update.field12 = "CELL"
update.expr12 = "BLOCK+Val(Right(Alltrim(Str(CELL)),1))"
a_tbl.update()
a_tbl.close()
'Save Solution
a_tbl = table.open("currentpuzzlesolution")
post.t_db = "spuzzletemplete.DBF"
post.m_key = "Id"
post.t_key = "Id"
post.m_filter = ""
post.t_filter = ""
post.m_count = 81
post.m_field1 = "B1S1"
post.m_exp1 = "if(@Spuzzletemplete->Cell=11,@Spuzzletemplete->Value,B1S1)"
post.m_field2 = "B1s2"
post.m_exp2 = "if(@Spuzzletemplete->Cell=12,@Spuzzletemplete->Value,B1s2)"
post.m_field3 = "B1s3"
post.m_exp3 = "if(@Spuzzletemplete->Cell=13,@Spuzzletemplete->Value,B1s3)"
post.m_field4 = "B1s4"
post.m_exp4 = "if(@Spuzzletemplete->Cell=14,@Spuzzletemplete->Value,B1s4)"
post.m_field5 = "B1s5"
post.m_exp5 = "if(@Spuzzletemplete->Cell=15,@Spuzzletemplete->Value,B1s5)"
post.m_field6 = "B1s6"
post.m_exp6 = "if(@Spuzzletemplete->Cell=16,@Spuzzletemplete->Value,B1s6)"
post.m_field7 = "B1s7"
post.m_exp7 = "if(@Spuzzletemplete->Cell=17,@Spuzzletemplete->Value,B1s7)"
post.m_field8 = "B1s8"
post.m_exp8 = "if(@Spuzzletemplete->Cell=18,@Spuzzletemplete->Value,B1s8)"
post.m_field9 = "B1s9"
post.m_exp9 = "if(@Spuzzletemplete->Cell=19,@Spuzzletemplete->Value,B1s9)"
post.m_field10 = "B2s1"
post.m_exp10 = "if(@Spuzzletemplete->Cell=21,@Spuzzletemplete->Value,B2s1)"
post.m_field11 = "B2s2"
post.m_exp11 = "if(@Spuzzletemplete->Cell=22,@Spuzzletemplete->Value,B2s2)"
post.m_field12 = "B2s3"
post.m_exp12 = "if(@Spuzzletemplete->Cell=23,@Spuzzletemplete->Value,B2s3)"
post.m_field13 = "B2s4"
post.m_exp13 = "if(@Spuzzletemplete->Cell=24,@Spuzzletemplete->Value,B2s4)"
post.m_field14 = "B2s5"
post.m_exp14 = "if(@Spuzzletemplete->Cell=25,@Spuzzletemplete->Value,B2s5)"
post.m_field15 = "B2s6"
post.m_exp15 = "if(@Spuzzletemplete->Cell=26,@Spuzzletemplete->Value,B2s6)"
post.m_field16 = "B2s7"
post.m_exp16 = "if(@Spuzzletemplete->Cell=27,@Spuzzletemplete->Value,B2s7)"
post.m_field17 = "B2s8"
post.m_exp17 = "if(@Spuzzletemplete->Cell=28,@Spuzzletemplete->Value,B2s8)"
post.m_field18 = "B2s9"
post.m_exp18 = "if(@Spuzzletemplete->Cell=29,@Spuzzletemplete->Value,B2s9)"
post.m_field19 = "B3s1"
post.m_exp19 = "if(@Spuzzletemplete->Cell=31,@Spuzzletemplete->Value,B3s1)"
post.m_field20 = "B3s2"
post.m_exp20 = "if(@Spuzzletemplete->Cell=32,@Spuzzletemplete->Value,B3s2)"
post.m_field21 = "B3s3"
post.m_exp21 = "if(@Spuzzletemplete->Cell=33,@Spuzzletemplete->Value,B3s3)"
post.m_field22 = "B3s4"
post.m_exp22 = "if(@Spuzzletemplete->Cell=34,@Spuzzletemplete->Value,B3s4)"
post.m_field23 = "B3s5"
post.m_exp23 = "if(@Spuzzletemplete->Cell=35,@Spuzzletemplete->Value,B3s5)"
post.m_field24 = "B3s6"
post.m_exp24 = "if(@Spuzzletemplete->Cell=36,@Spuzzletemplete->Value,B3s6)"
post.m_field25 = "B3s7"
post.m_exp25 = "if(@Spuzzletemplete->Cell=37,@Spuzzletemplete->Value,B3s7)"
post.m_field26 = "B3s8"
post.m_exp26 = "if(@Spuzzletemplete->Cell=38,@Spuzzletemplete->Value,B3s8)"
post.m_field27 = "B3s9"
post.m_exp27 = "if(@Spuzzletemplete->Cell=39,@Spuzzletemplete->Value,B3s9)"
post.m_field28 = "B4s1"
post.m_exp28 = "if(@Spuzzletemplete->Cell=41,@Spuzzletemplete->Value,B4s1)"
post.m_field29 = "B4s2"
post.m_exp29 = "if(@Spuzzletemplete->Cell=42,@Spuzzletemplete->Value,B4s2)"
post.m_field30 = "B4s3"
post.m_exp30 = "if(@Spuzzletemplete->Cell=43,@Spuzzletemplete->Value,B4s3)"
post.m_field31 = "B4s4"
post.m_exp31 = "if(@Spuzzletemplete->Cell=44,@Spuzzletemplete->Value,B4s4)"
post.m_field32 = "B4s5"
post.m_exp32 = "if(@Spuzzletemplete->Cell=45,@Spuzzletemplete->Value,B4s5)"
post.m_field33 = "B4s6"
post.m_exp33 = "if(@Spuzzletemplete->Cell=46,@Spuzzletemplete->Value,B4s6)"
post.m_field34 = "B4s7"
post.m_exp34 = "if(@Spuzzletemplete->Cell=47,@Spuzzletemplete->Value,B4s7)"
post.m_field35 = "B4s8"
post.m_exp35 = "if(@Spuzzletemplete->Cell=48,@Spuzzletemplete->Value,B4s8)"
post.m_field36 = "B4s9"
post.m_exp36 = "if(@Spuzzletemplete->Cell=49,@Spuzzletemplete->Value,B4s9)"
post.m_field37 = "B5s1"
post.m_exp37 = "if(@Spuzzletemplete->Cell=51,@Spuzzletemplete->Value,B5s1)"
post.m_field38 = "B5s2"
post.m_exp38 = "if(@Spuzzletemplete->Cell=52,@Spuzzletemplete->Value,B5s2)"
post.m_field39 = "B5s3"
post.m_exp39 = "if(@Spuzzletemplete->Cell=53,@Spuzzletemplete->Value,B5s3)"
post.m_field40 = "B5s4"
post.m_exp40 = "if(@Spuzzletemplete->Cell=54,@Spuzzletemplete->Value,B5s4)"
post.m_field41 = "B5s5"
post.m_exp41 = "if(@Spuzzletemplete->Cell=55,@Spuzzletemplete->Value,B5s5)"
post.m_field42 = "B5s6"
post.m_exp42 = "if(@Spuzzletemplete->Cell=56,@Spuzzletemplete->Value,B5s6)"
post.m_field43 = "B5s7"
post.m_exp43 = "if(@Spuzzletemplete->Cell=57,@Spuzzletemplete->Value,B5s7)"
post.m_field44 = "B5s8"
post.m_exp44 = "if(@Spuzzletemplete->Cell=58,@Spuzzletemplete->Value,B5s8)"
post.m_field45 = "B5s9"
post.m_exp45 = "if(@Spuzzletemplete->Cell=59,@Spuzzletemplete->Value,B5s9)"
post.m_field46 = "B6s1"
post.m_exp46 = "if(@Spuzzletemplete->Cell=61,@Spuzzletemplete->Value,B6s1)"
post.m_field47 = "B6s2"
post.m_exp47 = "if(@Spuzzletemplete->Cell=62,@Spuzzletemplete->Value,B6s2)"
post.m_field48 = "B6s3"
post.m_exp48 = "if(@Spuzzletemplete->Cell=63,@Spuzzletemplete->Value,B6s3)"
post.m_field49 = "B6s4"
post.m_exp49 = "if(@Spuzzletemplete->Cell=64,@Spuzzletemplete->Value,B6s4)"
post.m_field50 = "B6s5"
post.m_exp50 = "if(@Spuzzletemplete->Cell=65,@Spuzzletemplete->Value,B6s5)"
post.m_field51 = "B6s6"
post.m_exp51 = "if(@Spuzzletemplete->Cell=66,@Spuzzletemplete->Value,B6s6)"
post.m_field52 = "B6s7"
post.m_exp52 = "if(@Spuzzletemplete->Cell=67,@Spuzzletemplete->Value,B6s7)"
post.m_field53 = "B6s8"
post.m_exp53 = "if(@Spuzzletemplete->Cell=68,@Spuzzletemplete->Value,B6s8)"
post.m_field54 = "B6s9"
post.m_exp54 = "if(@Spuzzletemplete->Cell=69,@Spuzzletemplete->Value,B6s9)"
post.m_field55 = "B7s1"
post.m_exp55 = "if(@Spuzzletemplete->Cell=71,@Spuzzletemplete->Value,B7s1)"
post.m_field56 = "B7s2"
post.m_exp56 = "if(@Spuzzletemplete->Cell=72,@Spuzzletemplete->Value,B7s2)"
post.m_field57 = "B7s3"
post.m_exp57 = "if(@Spuzzletemplete->Cell=73,@Spuzzletemplete->Value,B7s3)"
post.m_field58 = "B7s4"
post.m_exp58 = "if(@Spuzzletemplete->Cell=74,@Spuzzletemplete->Value,B7s4)"
post.m_field59 = "B7s5"
post.m_exp59 = "if(@Spuzzletemplete->Cell=75,@Spuzzletemplete->Value,B7s5)"
post.m_field60 = "B7s6"
post.m_exp60 = "if(@Spuzzletemplete->Cell=76,@Spuzzletemplete->Value,B7s6)"
post.m_field61 = "B7s7"
post.m_exp61 = "if(@Spuzzletemplete->Cell=77,@Spuzzletemplete->Value,B7s7)"
post.m_field62 = "B7s8"
post.m_exp62 = "if(@Spuzzletemplete->Cell=78,@Spuzzletemplete->Value,B7s8)"
post.m_field63 = "B7s9"
post.m_exp63 = "if(@Spuzzletemplete->Cell=79,@Spuzzletemplete->Value,B7s9)"
post.m_field64 = "B8s1"
post.m_exp64 = "if(@Spuzzletemplete->Cell=81,@Spuzzletemplete->Value,B8s1)"
post.m_field65 = "B8s2"
post.m_exp65 = "if(@Spuzzletemplete->Cell=82,@Spuzzletemplete->Value,B8s2)"
post.m_field66 = "B8s3"
post.m_exp66 = "if(@Spuzzletemplete->Cell=83,@Spuzzletemplete->Value,B8s3)"
post.m_field67 = "B8s4"
post.m_exp67 = "if(@Spuzzletemplete->Cell=84,@Spuzzletemplete->Value,B8s4)"
post.m_field68 = "B8s5"
post.m_exp68 = "if(@Spuzzletemplete->Cell=85,@Spuzzletemplete->Value,B8s5)"
post.m_field69 = "B8s6"
post.m_exp69 = "if(@Spuzzletemplete->Cell=86,@Spuzzletemplete->Value,B8s6)"
post.m_field70 = "B8s7"
post.m_exp70 = "if(@Spuzzletemplete->Cell=87,@Spuzzletemplete->Value,B8s7)"
post.m_field71 = "B8s8"
post.m_exp71 = "if(@Spuzzletemplete->Cell=88,@Spuzzletemplete->Value,B8s8)"
post.m_field72 = "B8s9"
post.m_exp72 = "if(@Spuzzletemplete->Cell=89,@Spuzzletemplete->Value,B8s9)"
post.m_field73 = "B9s1"
post.m_exp73 = "if(@Spuzzletemplete->Cell=91,@Spuzzletemplete->Value,B9s1)"
post.m_field74 = "B9s2"
post.m_exp74 = "if(@Spuzzletemplete->Cell=92,@Spuzzletemplete->Value,B9s2)"
post.m_field75 = "B9s3"
post.m_exp75 = "if(@Spuzzletemplete->Cell=93,@Spuzzletemplete->Value,B9s3)"
post.m_field76 = "B9s4"
post.m_exp76 = "if(@Spuzzletemplete->Cell=94,@Spuzzletemplete->Value,B9s4)"
post.m_field77 = "B9s5"
post.m_exp77 = "if(@Spuzzletemplete->Cell=95,@Spuzzletemplete->Value,B9s5)"
post.m_field78 = "B9s6"
post.m_exp78 = "if(@Spuzzletemplete->Cell=96,@Spuzzletemplete->Value,B9s6)"
post.m_field79 = "B9s7"
post.m_exp79 = "if(@Spuzzletemplete->Cell=97,@Spuzzletemplete->Value,B9s7)"
post.m_field80 = "B9s8"
post.m_exp80 = "if(@Spuzzletemplete->Cell=98,@Spuzzletemplete->Value,B9s8)"
post.m_field81 = "B9s9"
post.m_exp81 = "if(@Spuzzletemplete->Cell=99,@Spuzzletemplete->Value,B9s9)"
post.t_count = 0
a_tbl.post()
a_tbl.close()
'Create New Game Board
a_tbl = table.open("sudokupuzzlesolver")
post.t_db = "spuzzletemplete.DBF"
post.m_key = "Id"
post.t_key = "Id"
post.m_filter = ""
post.t_filter = ""
post.m_count = 81
post.m_field1 = "B1S1"
post.m_exp1 = "if(@Spuzzletemplete->Cell=11,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B1S1)"
post.m_field2 = "B1s2"
post.m_exp2 = "if(@Spuzzletemplete->Cell=12,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B1s2)"
post.m_field3 = "B1s3"
post.m_exp3 = "if(@Spuzzletemplete->Cell=13,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B1s3)"
post.m_field4 = "B1s4"
post.m_exp4 = "if(@Spuzzletemplete->Cell=14,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B1s4)"
post.m_field5 = "B1s5"
post.m_exp5 = "if(@Spuzzletemplete->Cell=15,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B1s5)"
post.m_field6 = "B1s6"
post.m_exp6 = "if(@Spuzzletemplete->Cell=16,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B1s6)"
post.m_field7 = "B1s7"
post.m_exp7 = "if(@Spuzzletemplete->Cell=17,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B1s7)"
post.m_field8 = "B1s8"
post.m_exp8 = "if(@Spuzzletemplete->Cell=18,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B1s8)"
post.m_field9 = "B1s9"
post.m_exp9 = "if(@Spuzzletemplete->Cell=19,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B1s9)"
post.m_field10 = "B2s1"
post.m_exp10 = "if(@Spuzzletemplete->Cell=21,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B2s1)"
post.m_field11 = "B2s2"
post.m_exp11 = "if(@Spuzzletemplete->Cell=22,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B2s2)"
post.m_field12 = "B2s3"
post.m_exp12 = "if(@Spuzzletemplete->Cell=23,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B2s3)"
post.m_field13 = "B2s4"
post.m_exp13 = "if(@Spuzzletemplete->Cell=24,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B2s4)"
post.m_field14 = "B2s5"
post.m_exp14 = "if(@Spuzzletemplete->Cell=25,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B2s5)"
post.m_field15 = "B2s6"
post.m_exp15 = "if(@Spuzzletemplete->Cell=26,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B2s6)"
post.m_field16 = "B2s7"
post.m_exp16 = "if(@Spuzzletemplete->Cell=27,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B2s7)"
post.m_field17 = "B2s8"
post.m_exp17 = "if(@Spuzzletemplete->Cell=28,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B2s8)"
post.m_field18 = "B2s9"
post.m_exp18 = "if(@Spuzzletemplete->Cell=29,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B2s9)"
post.m_field19 = "B3s1"
post.m_exp19 = "if(@Spuzzletemplete->Cell=31,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B3s1)"
post.m_field20 = "B3s2"
post.m_exp20 = "if(@Spuzzletemplete->Cell=32,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B3s2)"
post.m_field21 = "B3s3"
post.m_exp21 = "if(@Spuzzletemplete->Cell=33,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B3s3)"
post.m_field22 = "B3s4"
post.m_exp22 = "if(@Spuzzletemplete->Cell=34,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B3s4)"
post.m_field23 = "B3s5"
post.m_exp23 = "if(@Spuzzletemplete->Cell=35,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B3s5)"
post.m_field24 = "B3s6"
post.m_exp24 = "if(@Spuzzletemplete->Cell=36,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B3s6)"
post.m_field25 = "B3s7"
post.m_exp25 = "if(@Spuzzletemplete->Cell=37,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B3s7)"
post.m_field26 = "B3s8"
post.m_exp26 = "if(@Spuzzletemplete->Cell=38,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B3s8)"
post.m_field27 = "B3s9"
post.m_exp27 = "if(@Spuzzletemplete->Cell=39,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B3s9)"
post.m_field28 = "B4s1"
post.m_exp28 = "if(@Spuzzletemplete->Cell=41,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B4s1)"
post.m_field29 = "B4s2"
post.m_exp29 = "if(@Spuzzletemplete->Cell=42,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B4s2)"
post.m_field30 = "B4s3"
post.m_exp30 = "if(@Spuzzletemplete->Cell=43,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B4s3)"
post.m_field31 = "B4s4"
post.m_exp31 = "if(@Spuzzletemplete->Cell=44,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B4s4)"
post.m_field32 = "B4s5"
post.m_exp32 = "if(@Spuzzletemplete->Cell=45,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B4s5)"
post.m_field33 = "B4s6"
post.m_exp33 = "if(@Spuzzletemplete->Cell=46,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B4s6)"
post.m_field34 = "B4s7"
post.m_exp34 = "if(@Spuzzletemplete->Cell=47,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B4s7)"
post.m_field35 = "B4s8"
post.m_exp35 = "if(@Spuzzletemplete->Cell=48,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B4s8)"
post.m_field36 = "B4s9"
post.m_exp36 = "if(@Spuzzletemplete->Cell=49,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B4s9)"
post.m_field37 = "B5s1"
post.m_exp37 = "if(@Spuzzletemplete->Cell=51,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B5s1)"
post.m_field38 = "B5s2"
post.m_exp38 = "if(@Spuzzletemplete->Cell=52,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B5s2)"
post.m_field39 = "B5s3"
post.m_exp39 = "if(@Spuzzletemplete->Cell=53,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B5s3)"
post.m_field40 = "B5s4"
post.m_exp40 = "if(@Spuzzletemplete->Cell=54,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B5s4)"
post.m_field41 = "B5s5"
post.m_exp41 = "if(@Spuzzletemplete->Cell=55,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B5s5)"
post.m_field42 = "B5s6"
post.m_exp42 = "if(@Spuzzletemplete->Cell=56,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B5s6)"
post.m_field43 = "B5s7"
post.m_exp43 = "if(@Spuzzletemplete->Cell=57,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B5s7)"
post.m_field44 = "B5s8"
post.m_exp44 = "if(@Spuzzletemplete->Cell=58,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B5s8)"
post.m_field45 = "B5s9"
post.m_exp45 = "if(@Spuzzletemplete->Cell=59,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B5s9)"
post.m_field46 = "B6s1"
post.m_exp46 = "if(@Spuzzletemplete->Cell=61,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B6s1)"
post.m_field47 = "B6s2"
post.m_exp47 = "if(@Spuzzletemplete->Cell=62,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B6s2)"
post.m_field48 = "B6s3"
post.m_exp48 = "if(@Spuzzletemplete->Cell=63,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B6s3)"
post.m_field49 = "B6s4"
post.m_exp49 = "if(@Spuzzletemplete->Cell=64,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B6s4)"
post.m_field50 = "B6s5"
post.m_exp50 = "if(@Spuzzletemplete->Cell=65,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B6s5)"
post.m_field51 = "B6s6"
post.m_exp51 = "if(@Spuzzletemplete->Cell=66,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B6s6)"
post.m_field52 = "B6s7"
post.m_exp52 = "if(@Spuzzletemplete->Cell=67,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B6s7)"
post.m_field53 = "B6s8"
post.m_exp53 = "if(@Spuzzletemplete->Cell=68,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B6s8)"
post.m_field54 = "B6s9"
post.m_exp54 = "if(@Spuzzletemplete->Cell=69,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B6s9)"
post.m_field55 = "B7s1"
post.m_exp55 = "if(@Spuzzletemplete->Cell=71,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B7s1)"
post.m_field56 = "B7s2"
post.m_exp56 = "if(@Spuzzletemplete->Cell=72,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B7s2)"
post.m_field57 = "B7s3"
post.m_exp57 = "if(@Spuzzletemplete->Cell=73,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B7s3)"
post.m_field58 = "B7s4"
post.m_exp58 = "if(@Spuzzletemplete->Cell=74,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B7s4)"
post.m_field59 = "B7s5"
post.m_exp59 = "if(@Spuzzletemplete->Cell=75,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B7s5)"
post.m_field60 = "B7s6"
post.m_exp60 = "if(@Spuzzletemplete->Cell=76,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B7s6)"
post.m_field61 = "B7s7"
post.m_exp61 = "if(@Spuzzletemplete->Cell=77,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B7s7)"
post.m_field62 = "B7s8"
post.m_exp62 = "if(@Spuzzletemplete->Cell=78,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B7s8)"
post.m_field63 = "B7s9"
post.m_exp63 = "if(@Spuzzletemplete->Cell=79,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B7s9)"
post.m_field64 = "B8s1"
post.m_exp64 = "if(@Spuzzletemplete->Cell=81,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B8s1)"
post.m_field65 = "B8s2"
post.m_exp65 = "if(@Spuzzletemplete->Cell=82,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B8s2)"
post.m_field66 = "B8s3"
post.m_exp66 = "if(@Spuzzletemplete->Cell=83,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B8s3)"
post.m_field67 = "B8s4"
post.m_exp67 = "if(@Spuzzletemplete->Cell=84,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B8s4)"
post.m_field68 = "B8s5"
post.m_exp68 = "if(@Spuzzletemplete->Cell=85,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B8s5)"
post.m_field69 = "B8s6"
post.m_exp69 = "if(@Spuzzletemplete->Cell=86,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B8s6)"
post.m_field70 = "B8s7"
post.m_exp70 = "if(@Spuzzletemplete->Cell=87,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B8s7)"
post.m_field71 = "B8s8"
post.m_exp71 = "if(@Spuzzletemplete->Cell=88,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B8s8)"
post.m_field72 = "B8s9"
post.m_exp72 = "if(@Spuzzletemplete->Cell=89,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B8s9)"
post.m_field73 = "B9s1"
post.m_exp73 = "if(@Spuzzletemplete->Cell=91,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B9s1)"
post.m_field74 = "B9s2"
post.m_exp74 = "if(@Spuzzletemplete->Cell=92,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B9s2)"
post.m_field75 = "B9s3"
post.m_exp75 = "if(@Spuzzletemplete->Cell=93,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B9s3)"
post.m_field76 = "B9s4"
post.m_exp76 = "if(@Spuzzletemplete->Cell=94,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B9s4)"
post.m_field77 = "B9s5"
post.m_exp77 = "if(@Spuzzletemplete->Cell=95,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B9s5)"
post.m_field78 = "B9s6"
post.m_exp78 = "if(@Spuzzletemplete->Cell=96,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B9s6)"
post.m_field79 = "B9s7"
post.m_exp79 = "if(@Spuzzletemplete->Cell=97,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B9s7)"
post.m_field80 = "B9s8"
post.m_exp80 = "if(@Spuzzletemplete->Cell=98,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B9s8)"
post.m_field81 = "B9s9"
post.m_exp81 = "if(@Spuzzletemplete->Cell=99,if(@Spuzzletemplete->Bcell=.f.,@Spuzzletemplete->Value,\"\"),B9s9)"
post.t_count = 0
a_tbl.post()
a_tbl.close()
First please note that on each of these two scripts I am using high level operations to perform the updates and post. The code is not complicated and these internal operations in Alpha Five work excellent.
Here is where the cell BCell in our template table comes in. Using functions Between, Rand and Mod we set the value of BCell to F or T for each cell in our template table. First we build our randon number variables. One for each Block. Next we run an update against our table using between to test cells in each block group. The test is if the mod of the cell value minus 10 divided by our random number variable equals 0 then the value for BCell is F otherwise it is T. Please don’t ask me how I came up with this because honestly I don’t remember. It was a long time ago and since it ain’t broke I wont fix it. The final step in our update to to rotate the blocks rows and columns based on my sketch above.
Whew that gave me a headache just writing it. I am sure many of you are staring dazed and glassy eyed by now. So lets take a break. I will explain the rest of the script and the rest of the puzzle creation in the next lesson. As always, thanks for spending time with us and I hope you will stop by again.
Leave a comment