private void ProcessRequests() { if (myExecutingRequest == null) { if (myRequests.Count > 0) { Request req = myRequests.First(); myExecutingRequest = req; if (myRequests.TryDequeue(out req)) { if (req.myRequestType == RequestType.Initialize) { try { SudokuLibApi.Initialize(req.GetByteData()); } catch (Exception e) { ErrorMessage em = new ErrorMessage(e.Message); em.ShowDialog(); } } if (req.myRequestType == RequestType.Solve) { SudokuLibApi.Solve(); } else if (req.myRequestType == RequestType.Reset) { SudokuLibApi.Reset(); } else if (req.myRequestType == RequestType.IsSolved) { bool theResult = SudokuLibApi.GetIsSolved(); req.SetData(theResult); req.SetQueueSize(myRequests.Count); SolverFSM m = (SolverFSM)req.myRequester; if (m != null) { m.RequestResponse(req); } } else if (req.myRequestType == RequestType.GetSolved) { IntPtr theCurrentBoard = SudokuLibApi.GetCurrentBoard(); byte[] bytes = new byte[SudokuLibApi.RESPONSE_SIZE]; Marshal.Copy(theCurrentBoard, bytes, 0, SudokuLibApi.RESPONSE_SIZE); req.SetData(bytes); req.SetQueueSize(myRequests.Count); SolverFSM m = (SolverFSM)req.myRequester; if (m != null) { m.RequestResponse(req); } } else if (req.myRequestType == RequestType.Shutdown) { bool theResult = SudokuLibApi.Shutdown(); req.SetData(theResult); req.SetQueueSize(myRequests.Count); SolverFSM m = (SolverFSM)req.myRequester; if (m != null) { m.RequestResponse(req); } } else if (req.myRequestType == RequestType.GetBoardData) { IntPtr theBoardData = SudokuLibApi.GetBoardData(); int[] bytes = new int[SudokuLibApi.RESPONSE_SIZE]; Marshal.Copy(theBoardData, bytes, 0, SudokuLibApi.RESPONSE_SIZE); req.SetData(bytes); req.SetQueueSize(myRequests.Count); SolverFSM m = (SolverFSM)req.myRequester; if (m != null) { m.RequestResponse(req); } } } myExecutingRequest = null; } } }
public Main() { InitializeComponent(); try { GuidanceManager.Initialize(); numGuesses.Text = "0"; lowestScoreLabel.Text = "0"; surrenderCountLabel.Text = "0"; invalidCountLabel.Text = "0"; //enableGuessingButton.Enabled = false; //disableGuessing.Enabled = false; mySolverFSM = new SolverFSM(this); // Start the threads // This thread communicates with the solver engine in the DLL myAPIServiceThread = new Thread(() => StartAPIServices()); myAPIServiceThread.IsBackground = true; myAPIServiceThread.Start(); // This thread runs the display FSM by getting results from the server engine. myFSMThread = new Thread(() => mySolverFSM.Run()); myFSMThread.IsBackground = true; myFSMThread.Start(); o_block_1_1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; o_block_1_2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; o_block_1_3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; o_block_2_1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; o_block_2_2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; o_block_2_3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; o_block_3_1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; o_block_3_2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; o_block_3_3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; o_block_1_1.BackColor = System.Drawing.Color.Wheat; o_block_1_2.BackColor = System.Drawing.Color.Wheat; o_block_1_3.BackColor = System.Drawing.Color.Wheat; o_block_2_1.BackColor = System.Drawing.Color.Wheat; o_block_2_2.BackColor = System.Drawing.Color.Wheat; o_block_2_3.BackColor = System.Drawing.Color.Wheat; o_block_3_1.BackColor = System.Drawing.Color.Wheat; o_block_3_2.BackColor = System.Drawing.Color.Wheat; o_block_3_3.BackColor = System.Drawing.Color.Wheat; i_block_1_1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; i_block_1_2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; i_block_1_3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; i_block_2_1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; i_block_2_2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; i_block_2_3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; i_block_3_1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; i_block_3_2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; i_block_3_3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; i_block_1_1.BackColor = System.Drawing.Color.Wheat; i_block_1_2.BackColor = System.Drawing.Color.Wheat; i_block_1_3.BackColor = System.Drawing.Color.Wheat; i_block_2_1.BackColor = System.Drawing.Color.Wheat; i_block_2_2.BackColor = System.Drawing.Color.Wheat; i_block_2_3.BackColor = System.Drawing.Color.Wheat; i_block_3_1.BackColor = System.Drawing.Color.Wheat; i_block_3_2.BackColor = System.Drawing.Color.Wheat; i_block_3_3.BackColor = System.Drawing.Color.Wheat; } catch (Exception e1) { ErrorMessage em = new ErrorMessage(e1.Message); em.ShowDialog(); } try { myResultsDisplay = new TextBox[10, 10]; myInputBoxes = new TextBox[10, 10]; myInputBoxes[1, 1] = i_sqr_1_1; myInputBoxes[1, 2] = i_sqr_1_2; myInputBoxes[1, 3] = i_sqr_1_3; myInputBoxes[1, 4] = i_sqr_1_4; myInputBoxes[1, 5] = i_sqr_1_5; myInputBoxes[1, 6] = i_sqr_1_6; myInputBoxes[1, 7] = i_sqr_1_7; myInputBoxes[1, 8] = i_sqr_1_8; myInputBoxes[1, 9] = i_sqr_1_9; myInputBoxes[2, 1] = i_sqr_2_1; myInputBoxes[2, 2] = i_sqr_2_2; myInputBoxes[2, 3] = i_sqr_2_3; myInputBoxes[2, 4] = i_sqr_2_4; myInputBoxes[2, 5] = i_sqr_2_5; myInputBoxes[2, 6] = i_sqr_2_6; myInputBoxes[2, 7] = i_sqr_2_7; myInputBoxes[2, 8] = i_sqr_2_8; myInputBoxes[2, 9] = i_sqr_2_9; myInputBoxes[3, 1] = i_sqr_3_1; myInputBoxes[3, 2] = i_sqr_3_2; myInputBoxes[3, 3] = i_sqr_3_3; myInputBoxes[3, 4] = i_sqr_3_4; myInputBoxes[3, 5] = i_sqr_3_5; myInputBoxes[3, 6] = i_sqr_3_6; myInputBoxes[3, 7] = i_sqr_3_7; myInputBoxes[3, 8] = i_sqr_3_8; myInputBoxes[3, 9] = i_sqr_3_9; myInputBoxes[4, 1] = i_sqr_4_1; myInputBoxes[4, 2] = i_sqr_4_2; myInputBoxes[4, 3] = i_sqr_4_3; myInputBoxes[4, 4] = i_sqr_4_4; myInputBoxes[4, 5] = i_sqr_4_5; myInputBoxes[4, 6] = i_sqr_4_6; myInputBoxes[4, 7] = i_sqr_4_7; myInputBoxes[4, 8] = i_sqr_4_8; myInputBoxes[4, 9] = i_sqr_4_9; myInputBoxes[5, 1] = i_sqr_5_1; myInputBoxes[5, 2] = i_sqr_5_2; myInputBoxes[5, 3] = i_sqr_5_3; myInputBoxes[5, 4] = i_sqr_5_4; myInputBoxes[5, 5] = i_sqr_5_5; myInputBoxes[5, 6] = i_sqr_5_6; myInputBoxes[5, 7] = i_sqr_5_7; myInputBoxes[5, 8] = i_sqr_5_8; myInputBoxes[5, 9] = i_sqr_5_9; myInputBoxes[6, 1] = i_sqr_6_1; myInputBoxes[6, 2] = i_sqr_6_2; myInputBoxes[6, 3] = i_sqr_6_3; myInputBoxes[6, 4] = i_sqr_6_4; myInputBoxes[6, 5] = i_sqr_6_5; myInputBoxes[6, 6] = i_sqr_6_6; myInputBoxes[6, 7] = i_sqr_6_7; myInputBoxes[6, 8] = i_sqr_6_8; myInputBoxes[6, 9] = i_sqr_6_9; myInputBoxes[7, 1] = i_sqr_7_1; myInputBoxes[7, 2] = i_sqr_7_2; myInputBoxes[7, 3] = i_sqr_7_3; myInputBoxes[7, 4] = i_sqr_7_4; myInputBoxes[7, 5] = i_sqr_7_5; myInputBoxes[7, 6] = i_sqr_7_6; myInputBoxes[7, 7] = i_sqr_7_7; myInputBoxes[7, 8] = i_sqr_7_8; myInputBoxes[7, 9] = i_sqr_7_9; myInputBoxes[8, 1] = i_sqr_8_1; myInputBoxes[8, 2] = i_sqr_8_2; myInputBoxes[8, 3] = i_sqr_8_3; myInputBoxes[8, 4] = i_sqr_8_4; myInputBoxes[8, 5] = i_sqr_8_5; myInputBoxes[8, 6] = i_sqr_8_6; myInputBoxes[8, 7] = i_sqr_8_7; myInputBoxes[8, 8] = i_sqr_8_8; myInputBoxes[8, 9] = i_sqr_8_9; myInputBoxes[9, 1] = i_sqr_9_1; myInputBoxes[9, 2] = i_sqr_9_2; myInputBoxes[9, 3] = i_sqr_9_3; myInputBoxes[9, 4] = i_sqr_9_4; myInputBoxes[9, 5] = i_sqr_9_5; myInputBoxes[9, 6] = i_sqr_9_6; myInputBoxes[9, 7] = i_sqr_9_7; myInputBoxes[9, 8] = i_sqr_9_8; myInputBoxes[9, 9] = i_sqr_9_9; myResultsDisplay[1, 1] = o_sqr_1_1; myResultsDisplay[1, 2] = o_sqr_1_2; myResultsDisplay[1, 3] = o_sqr_1_3; myResultsDisplay[1, 4] = o_sqr_1_4; myResultsDisplay[1, 5] = o_sqr_1_5; myResultsDisplay[1, 6] = o_sqr_1_6; myResultsDisplay[1, 7] = o_sqr_1_7; myResultsDisplay[1, 8] = o_sqr_1_8; myResultsDisplay[1, 9] = o_sqr_1_9; myResultsDisplay[2, 1] = o_sqr_2_1; myResultsDisplay[2, 2] = o_sqr_2_2; myResultsDisplay[2, 3] = o_sqr_2_3; myResultsDisplay[2, 4] = o_sqr_2_4; myResultsDisplay[2, 5] = o_sqr_2_5; myResultsDisplay[2, 6] = o_sqr_2_6; myResultsDisplay[2, 7] = o_sqr_2_7; myResultsDisplay[2, 8] = o_sqr_2_8; myResultsDisplay[2, 9] = o_sqr_2_9; myResultsDisplay[3, 1] = o_sqr_3_1; myResultsDisplay[3, 2] = o_sqr_3_2; myResultsDisplay[3, 3] = o_sqr_3_3; myResultsDisplay[3, 4] = o_sqr_3_4; myResultsDisplay[3, 5] = o_sqr_3_5; myResultsDisplay[3, 6] = o_sqr_3_6; myResultsDisplay[3, 7] = o_sqr_3_7; myResultsDisplay[3, 8] = o_sqr_3_8; myResultsDisplay[3, 9] = o_sqr_3_9; myResultsDisplay[4, 1] = o_sqr_4_1; myResultsDisplay[4, 2] = o_sqr_4_2; myResultsDisplay[4, 3] = o_sqr_4_3; myResultsDisplay[4, 4] = o_sqr_4_4; myResultsDisplay[4, 5] = o_sqr_4_5; myResultsDisplay[4, 6] = o_sqr_4_6; myResultsDisplay[4, 7] = o_sqr_4_7; myResultsDisplay[4, 8] = o_sqr_4_8; myResultsDisplay[4, 9] = o_sqr_4_9; myResultsDisplay[5, 1] = o_sqr_5_1; myResultsDisplay[5, 2] = o_sqr_5_2; myResultsDisplay[5, 3] = o_sqr_5_3; myResultsDisplay[5, 4] = o_sqr_5_4; myResultsDisplay[5, 5] = o_sqr_5_5; myResultsDisplay[5, 6] = o_sqr_5_6; myResultsDisplay[5, 7] = o_sqr_5_7; myResultsDisplay[5, 8] = o_sqr_5_8; myResultsDisplay[5, 9] = o_sqr_5_9; myResultsDisplay[6, 1] = o_sqr_6_1; myResultsDisplay[6, 2] = o_sqr_6_2; myResultsDisplay[6, 3] = o_sqr_6_3; myResultsDisplay[6, 4] = o_sqr_6_4; myResultsDisplay[6, 5] = o_sqr_6_5; myResultsDisplay[6, 6] = o_sqr_6_6; myResultsDisplay[6, 7] = o_sqr_6_7; myResultsDisplay[6, 8] = o_sqr_6_8; myResultsDisplay[6, 9] = o_sqr_6_9; myResultsDisplay[7, 1] = o_sqr_7_1; myResultsDisplay[7, 2] = o_sqr_7_2; myResultsDisplay[7, 3] = o_sqr_7_3; myResultsDisplay[7, 4] = o_sqr_7_4; myResultsDisplay[7, 5] = o_sqr_7_5; myResultsDisplay[7, 6] = o_sqr_7_6; myResultsDisplay[7, 7] = o_sqr_7_7; myResultsDisplay[7, 8] = o_sqr_7_8; myResultsDisplay[7, 9] = o_sqr_7_9; myResultsDisplay[8, 1] = o_sqr_8_1; myResultsDisplay[8, 2] = o_sqr_8_2; myResultsDisplay[8, 3] = o_sqr_8_3; myResultsDisplay[8, 4] = o_sqr_8_4; myResultsDisplay[8, 5] = o_sqr_8_5; myResultsDisplay[8, 6] = o_sqr_8_6; myResultsDisplay[8, 7] = o_sqr_8_7; myResultsDisplay[8, 8] = o_sqr_8_8; myResultsDisplay[8, 9] = o_sqr_8_9; myResultsDisplay[9, 1] = o_sqr_9_1; myResultsDisplay[9, 2] = o_sqr_9_2; myResultsDisplay[9, 3] = o_sqr_9_3; myResultsDisplay[9, 4] = o_sqr_9_4; myResultsDisplay[9, 5] = o_sqr_9_5; myResultsDisplay[9, 6] = o_sqr_9_6; myResultsDisplay[9, 7] = o_sqr_9_7; myResultsDisplay[9, 8] = o_sqr_9_8; myResultsDisplay[9, 9] = o_sqr_9_9; for (int row = 1; row <= 9; ++row) { for (int col = 1; col <= 9; ++col) { SetControlBgColor(myResultsDisplay[row, col], System.Drawing.Color.White); SetControlBgColor(myInputBoxes[row, col], System.Drawing.Color.White); } } clearButton.Select(); } catch (Exception e) { } }