From: John L. <jr...@us...> - 2006-06-01 22:51:00
|
Update of /cvsroot/wxlua/wxLua/samples In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv9228/wxLua/samples Modified Files: wxluasudoku.wx.lua Log Message: some cleanup Index: wxluasudoku.wx.lua =================================================================== RCS file: /cvsroot/wxlua/wxLua/samples/wxluasudoku.wx.lua,v retrieving revision 1.51 retrieving revision 1.52 diff -C2 -d -r1.51 -r1.52 *** wxluasudoku.wx.lua 31 May 2006 21:26:32 -0000 1.51 --- wxluasudoku.wx.lua 1 Jun 2006 22:50:54 -0000 1.52 *************** *** 2961,2969 **** sudokuGUI.difficulty = keep ! local solve_progress = 0 ! local start_time = os.time() ! local last_time = start_time local solve_completed = true ! local msg_idx = 1 local progressDialog = wx.wxProgressDialog("wxLuaSudoku - Generating...", --- 2961,2970 ---- sudokuGUI.difficulty = keep ! ! local solve_progress = 0 ! local start_time = os.time() ! local last_time = start_time local solve_completed = true ! local msg_idx = 1 local progressDialog = wx.wxProgressDialog("wxLuaSudoku - Generating...", *************** *** 2976,2981 **** function sudoku.GeneratePuzzleHook(count, cell) if solve_completed == false then return false end -- canceled ! solve_progress = solve_progress + 1 ! if solve_progress >= 10000 then solve_progress = 0 end if solve_progress%10 ~= 0 then return true end if (msg_idx < sudokuGUI.sayings_n) and (os.time() - last_time > 4) then --- 2977,2981 ---- function sudoku.GeneratePuzzleHook(count, cell) if solve_completed == false then return false end -- canceled ! solve_progress = iff(solve_progress+1 >= 10000, 0, solve_progress + 1) if solve_progress%10 ~= 0 then return true end if (msg_idx < sudokuGUI.sayings_n) and (os.time() - last_time > 4) then *************** *** 2994,2997 **** --- 2994,3001 ---- -- have complete puzzle, now remove cells + local diff_count = 0 + local diff_i = 0 + local diff_cell = 0 + -- define handler function here so it'll work w/o gui function sudoku.GeneratePuzzleDifficultyHook(count, i, cell) *************** *** 3010,3017 **** -- hook into brute force solver to update the generate puzzle progress dialog - solve_progress = 0 function sudoku.SolveBruteForceHook(guesses, cell) ! solve_progress = solve_progress + 1 ! if (solve_progress >= 10000) then solve_progress = 0 end if solve_progress%10 ~= 0 then return true end return sudoku.GeneratePuzzleDifficultyHook(diff_count, diff_i, diff_cell) --- 3014,3019 ---- -- hook into brute force solver to update the generate puzzle progress dialog function sudoku.SolveBruteForceHook(guesses, cell) ! solve_progress = iff(solve_progress+1 >= 10000, 0, solve_progress + 1) if solve_progress%10 ~= 0 then return true end return sudoku.GeneratePuzzleDifficultyHook(diff_count, diff_i, diff_cell) *************** *** 3021,3033 **** while ret == wx.wxOK do ! msg_idx = 1 ! last_time = os.time() ! local diff_count = 0 ! local diff_i = 0 ! local diff_cell = 0 ! solve_progress = 0 ! start_time = os.time() solve_completed = true progressDialog = wx.wxProgressDialog("wxLuaSudoku - Ensuring Uniqueness...", --- 3023,3035 ---- while ret == wx.wxOK do ! diff_count = 0 ! diff_i = 0 ! diff_cell = 0 ! solve_progress = 0 ! start_time = os.time() ! last_time = start_time solve_completed = true + msg_idx = 1 progressDialog = wx.wxProgressDialog("wxLuaSudoku - Ensuring Uniqueness...", *************** *** 3075,3079 **** local ret = wx.wxMessageBox( "The puzzle you've opened has invalid values.\n".. ! "Press 'Ok' to correct them using 'Create' before continuing.", "wxLuaSudoku - Invalid puzzle", wx.wxOK + wx.wxCANCEL + wx.wxICON_ERROR, --- 3077,3082 ---- local ret = wx.wxMessageBox( "The puzzle you've opened has invalid values.\n".. ! "Press 'Ok' to correct them using 'Create' before continuing ".. ! "otherwise 'Cancel' to ignore them.", "wxLuaSudoku - Invalid puzzle", wx.wxOK + wx.wxCANCEL + wx.wxICON_ERROR, *************** *** 3112,3116 **** sudokuGUI.frame:SetTitle("wxLuaSudoku - "..sudokuGUI.fileName) else ! wx.wxMessageBox( "Unable to save file\n"..fileName, "wxLuaSudoku - Save file error", wx.wxOK + wx.wxICON_ERROR, --- 3115,3119 ---- sudokuGUI.frame:SetTitle("wxLuaSudoku - "..sudokuGUI.fileName) else ! wx.wxMessageBox( "Unable to save file\n'"..fileName.."'", "wxLuaSudoku - Save file error", wx.wxOK + wx.wxICON_ERROR, *************** *** 3195,3209 **** local ret = wx.wxOK ! local msg_idx = 1 ! local last_time = os.time() ! local solve_progress = 0 ! local start_time = os.time() local solve_completed = true -- define handler function here so it'll work w/o gui function sudoku.SolveBruteForceHook(guesses, cell) if solve_completed == false then return false end -- canceled ! solve_progress = solve_progress + 1 ! if (solve_progress >= 1000) then solve_progress = 0 end if (solve_progress-1)%10 ~= 0 then return true end if (msg_idx < sudokuGUI.sayings_n) and (os.time() - last_time > 4) then --- 3198,3211 ---- local ret = wx.wxOK ! local solve_progress = 0 ! local start_time = os.time() ! local last_time = start_time local solve_completed = true + local msg_idx = 1 -- define handler function here so it'll work w/o gui function sudoku.SolveBruteForceHook(guesses, cell) if solve_completed == false then return false end -- canceled ! solve_progress = iff(solve_progress+1 >= 10000, 0, solve_progress + 1) if (solve_progress-1)%10 ~= 0 then return true end if (msg_idx < sudokuGUI.sayings_n) and (os.time() - last_time > 4) then *************** *** 3217,3229 **** while ret == wx.wxOK do ! msg_idx = 1 ! last_time = os.time() ! local diff_count = 0 ! local diff_i = 0 ! local diff_cell = 0 ! ! solve_progress = 0 ! start_time = os.time() solve_completed = true progressDialog = wx.wxProgressDialog("wxLuaSudoku - Ensuring Uniqueness...", --- 3219,3227 ---- while ret == wx.wxOK do ! solve_progress = 0 ! start_time = os.time() ! last_time = start_time solve_completed = true + msg_idx = 1 progressDialog = wx.wxProgressDialog("wxLuaSudoku - Ensuring Uniqueness...", *************** *** 3312,3316 **** -- Use the brute force method to solve it function sudokuGUI.SolveBruteForce(sudokuTable) - local solve_progress = 0 local s = TableCopy(sudokuTable or sudokuGUI.GetCurrentTable()) --- 3310,3313 ---- *************** *** 3352,3365 **** wx.wxPD_AUTO_HIDE+wx.wxPD_CAN_ABORT+wx.wxPD_ELAPSED_TIME) local solve_completed = true ! local start_time = os.time() ! local last_time = start_time ! local msg_idx = 1 -- define handler function here so it'll work w/o gui function sudoku.SolveBruteForceHook(guesses, cell) if solve_completed == false then return false end -- canceled ! solve_progress = solve_progress + 1 ! if (solve_progress >= 1000) then solve_progress = 0 end if (solve_progress-1)%10 ~= 0 then return true end if (msg_idx < sudokuGUI.sayings_n) and (os.time() - last_time > 4) then --- 3349,3362 ---- wx.wxPD_AUTO_HIDE+wx.wxPD_CAN_ABORT+wx.wxPD_ELAPSED_TIME) + local solve_progress = 0 + local start_time = os.time() + local last_time = start_time local solve_completed = true ! local msg_idx = 1 -- define handler function here so it'll work w/o gui function sudoku.SolveBruteForceHook(guesses, cell) if solve_completed == false then return false end -- canceled ! solve_progress = iff(solve_progress+1 >= 10000, 0, solve_progress + 1) if (solve_progress-1)%10 ~= 0 then return true end if (msg_idx < sudokuGUI.sayings_n) and (os.time() - last_time > 4) then *************** *** 3428,3436 **** local has_show_flag = false for n = sudoku.ELIMINATE_FLAG_MIN, sudoku.ELIMINATE_FLAG_MAX do ! local id = sudokuGUI.ID_ELIMINATE_NAKEDPAIRS + n - sudoku.ELIMINATE_FLAG_MIN sudokuTable.flags[n] = sudokuGUI.IsCheckedMenuItem(id) ! local show_id = sudokuGUI.ID_SHOW_NAKEDPAIRS + n - sudoku.ELIMINATE_FLAG_MIN ! if sudokuGUI.IsCheckedMenuItem(show_id) == true then has_show_flag = true end end --- 3425,3435 ---- local has_show_flag = false for n = sudoku.ELIMINATE_FLAG_MIN, sudoku.ELIMINATE_FLAG_MAX do ! local id = n + sudokuGUI.ID_ELIMINATE_NAKEDPAIRS - sudoku.ELIMINATE_FLAG_MIN sudokuTable.flags[n] = sudokuGUI.IsCheckedMenuItem(id) ! local show_id = n + sudokuGUI.ID_SHOW_NAKEDPAIRS - sudoku.ELIMINATE_FLAG_MIN ! if (not has_show_flag) and (sudokuGUI.IsCheckedMenuItem(show_id) == true) then ! has_show_flag = true ! end end *************** *** 3924,3928 **** local notebookPages = {} local page1 = sudokuGUI.PreferencesDialogPageUI.Create(notebook) ! notebook:AddPage(page1, "Fonts & Colors", true) notebookPages[1] = sudokuGUI.PreferencesDialogPageUI --- 3923,3927 ---- local notebookPages = {} local page1 = sudokuGUI.PreferencesDialogPageUI.Create(notebook) ! notebook:AddPage(page1, "Fonts and Colors", true) notebookPages[1] = sudokuGUI.PreferencesDialogPageUI *************** *** 4280,4287 **** function (event) -- need to solve it ourselves first ! if not sudokuGUI.sudokuSolnTable then ! sudokuGUI.sudokuSolnTable = sudokuGUI.SolveBruteForce(sudokuGUI.sudokuTables[1]) if not sudokuGUI.sudokuSolnTable then ! event:SetInt(0) -- uncheck sudokuGUI.frame:GetMenuBar():Check(sudokuGUI.ID_SHOW_MISTAKES, false) end --- 4279,4287 ---- function (event) -- need to solve it ourselves first ! if (event:IsChecked()) and (not sudokuGUI.sudokuSolnTable) then ! sudokuGUI.sudokuSolnTable = sudokuGUI.VerifyUniquePuzzle(sudokuGUI.GetInitTable()) ! if not sudokuGUI.sudokuSolnTable then ! event:SetInt(0) -- uncheck for MenuCheckUpdate function sudokuGUI.frame:GetMenuBar():Check(sudokuGUI.ID_SHOW_MISTAKES, false) end |