private void STATE_BEGIN_DISPLAYING(Request theRequest) { myState = solverState.BEGIN_DISPLAYING; Request req = new Request(this, RequestType.GetSolved); APIMonitor.Instance.NewRequest(req); }
private void STATE_CLEARING(Request theRequest) { myState = solverState.CLEARING; Request req = new Request(this, RequestType.Reset); APIMonitor.Instance.NewRequest(req); myMainWindow.ResetDisplay(); }
private void STATE_INVALID(Request theRequest) { myState = solverState.END_CHECKING_VALID; ErrorMessage em = new ErrorMessage("This board is invalid."); em.ShowDialog(); myMainWindow.EnableClearButton(); myMainWindow.EnableExitButton(); }
private void STATE_COMPL_DISPLAY(Request theRequest) { myMainWindow.DisplayResultsBoard(theRequest.GetByteData()); myState = solverState.COMPL_DISPLAYING; myMainWindow.EnableClearButton(); myMainWindow.EnableExitButton(); }
private void STATE_EXITING(Request theRequest) { myState = solverState.EXITING; if (myState != solverState.IDLE) { APIMonitor.Instance.NewRequest(new Request(this, RequestType.Shutdown)); } else { EventOccured(transitionEvent.DATA_RCVD, null); } }
public SolverFSM(Main theMainWindow) { myMainWindow = theMainWindow; myFSM = new myDelegate[(int)solverState.ALL_STATES, (int)transitionEvent.ALL_TXNS]; myFSM[(int)solverState.IDLE, (int)transitionEvent.SOLVE_CLICKED] = new myDelegate(STATE_SOLVING); myFSM[(int)solverState.IDLE, (int)transitionEvent.CLEAR_CLICKED] = new myDelegate(STATE_CLEARING); myFSM[(int)solverState.IDLE, (int)transitionEvent.EXIT_BUTTON_CLICKED] = new myDelegate(STATE_EXITING); myFSM[(int)solverState.SOLVING, (int)transitionEvent.WAIT_FOR_RESPONSE] = new myDelegate(STATE_POLLING); myFSM[(int)solverState.POLLING, (int)transitionEvent.DATA_RCVD] = new myDelegate(DISPLAYING_EXTRA_DATA); myFSM[(int)solverState.POLLING, (int)transitionEvent.BOARD_SOLVED] = new myDelegate(STATE_BEGIN_DISPLAYING); myFSM[(int)solverState.POLLING, (int)transitionEvent.CLEAR_CLICKED] = new myDelegate(STATE_CLEARING); myFSM[(int)solverState.POLLING, (int)transitionEvent.SOLVE_CLICKED] = new myDelegate(IgnoreEvent); myFSM[(int)solverState.POLLING, (int)transitionEvent.EXIT_BUTTON_CLICKED] = new myDelegate(STATE_EXITING); myFSM[(int)solverState.POLLING, (int)transitionEvent.BOARD_IS_INVALID] = new myDelegate(STATE_INVALID); myFSM[(int)solverState.POLLING, (int)transitionEvent.CONTINUE] = new myDelegate(STATE_POLLING); myFSM[(int)solverState.BEGIN_DISPLAYING, (int)transitionEvent.DATA_RCVD] = new myDelegate(STATE_COMPL_DISPLAY); myFSM[(int)solverState.COMPL_DISPLAYING, (int)transitionEvent.DATA_RCVD] = new myDelegate(DISPLAYING_EXTRA_DATA); myFSM[(int)solverState.COMPL_DISPLAYING, (int)transitionEvent.CLEAR_CLICKED] = new myDelegate(STATE_CLEARING); myFSM[(int)solverState.COMPL_DISPLAYING, (int)transitionEvent.EXIT_BUTTON_CLICKED] = new myDelegate(STATE_CLOSING); myFSM[(int)solverState.COMPL_DISPLAYING, (int)transitionEvent.SOLVE_CLICKED] = new myDelegate(STATE_SOLVING); myFSM[(int)solverState.COMPL_DISPLAYING, (int)transitionEvent.EXIT_BUTTON_CLICKED] = new myDelegate(STATE_EXITING); myFSM[(int)solverState.CLEARING, (int)transitionEvent.SOLVE_CLICKED] = new myDelegate(STATE_SOLVING); myFSM[(int)solverState.CLEARING, (int)transitionEvent.CLEAR_CLICKED] = new myDelegate(STATE_CLEARING); myFSM[(int)solverState.CLEARING, (int)transitionEvent.DATA_RCVD] = new myDelegate(IgnoreEvent); myFSM[(int)solverState.CLEARING, (int)transitionEvent.BOARD_NOT_SOLVED] = new myDelegate(IgnoreEvent); myFSM[(int)solverState.CLEARING, (int)transitionEvent.EXIT_BUTTON_CLICKED] = new myDelegate(STATE_EXITING); myFSM[(int)solverState.CLEARING, (int)transitionEvent.BOARD_SOLVED] = new myDelegate(IgnoreEvent); myFSM[(int)solverState.END_CHECKING_VALID, (int)transitionEvent.SOLVE_CLICKED] = new myDelegate(STATE_SOLVING); myFSM[(int)solverState.END_CHECKING_VALID, (int)transitionEvent.DATA_RCVD] = new myDelegate(STATE_POLLING); myFSM[(int)solverState.END_CHECKING_VALID, (int)transitionEvent.CLEAR_CLICKED] = new myDelegate(STATE_CLEARING); myFSM[(int)solverState.END_CHECKING_VALID, (int)transitionEvent.EXIT_BUTTON_CLICKED] = new myDelegate(STATE_EXITING); myFSM[(int)solverState.EXITING, (int)transitionEvent.DATA_RCVD] = new myDelegate(STATE_CLOSING); myFSM[(int)solverState.EXITING, (int)transitionEvent.EXIT_BUTTON_CLICKED] = new myDelegate(IgnoreEvent); myFSM[(int)solverState.CLOSING, (int)transitionEvent.EXIT_BUTTON_CLICKED] = new myDelegate(IgnoreEvent); myState = solverState.IDLE; myResponseCounter = 0; }
private void STATE_SOLVING(Request theRequest) { myState = solverState.SOLVING; SudokuLibApi.EnableGuessing(); myMainWindow.DisableClearButton(); myMainWindow.DisableExitButton(); // Convert the user input to a byte array to send to the Sudoku API byte[] myBytes = new byte[81]; int byteIdx = 0; for (int i = 1; i <= 9; ++i) { for (int j = 1; j <= 9; ++j) { if (myMainWindow.myInputBoxes[i, j].Text != string.Empty) { if (myMainWindow.myInputBoxes[i, j].Text == "?") { myBytes[byteIdx] = Convert.ToByte(0); } else { myBytes[byteIdx] = Convert.ToByte(Int32.Parse(myMainWindow.myInputBoxes[i, j].Text)); } ++byteIdx; } else { myBytes[byteIdx] = Convert.ToByte(0); ++byteIdx; } } } // Call the Sudoko API to initialize the board SudokuLibApi.Reset(); SudokuLibApi.Initialize(myBytes); EventOccured(SolverFSM.transitionEvent.WAIT_FOR_RESPONSE, null); }
private void STATE_IDLE(Request theRequest) { myState = solverState.IDLE; }
public void Run() { myState = solverState.IDLE; }
private void STATE_CLOSING(Request theRequest) { myState = solverState.CLOSING; myMainWindow.Shutdown(); }
private void STATE_POLLING(Request theRequest) { myState = solverState.POLLING; APIMonitor.Instance.NewRequest(new Request(this, RequestType.GetBoardData)); }