예제 #1
0
 /// <summary>
 /// Definition Board size
 /// </summary>
 /// <param name="x">Count cards on coordinate x</param>
 /// <param name="y">Count cards on coordinate y</param>
 /// <param name="PackCard">Definition Card in Package, which will by put on the board.</param>
 public DefinitionBoardSize(int x, int y, PackCards PackCard)
 {
     AppSB.Log("Inicialization board [" + x.ToString() + "," + y.ToString() + "] with PackCards count [" + PackCard.Items.Count + "]");
     this.maximumSolutionCardsOnBoard    = new List <BoardDeskAndPackCard>();
     this.maxNumberOfInsertedCardOnBoard = -1;
     Board           = new BoardDeskAndPackCard(x, y);
     this.boardSizeX = x;
     this.boardSizeY = y;
     Board.PackCard  = PackCard;
 }
예제 #2
0
        void boardTask_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            this.richtxtLog.Dispatcher.Invoke(new Action(() =>
            {
                this.richtxtLog.Document.Blocks.Clear();
                AppSB.Log("Start the processing at " + DateTime.Now.ToLongTimeString() + Environment.NewLine);
                AppSB.Log("Please wait ... (I perform high performance computing)");
            }));

            smileProcessing = new Smile.ProcessingSmileBoard();
        }
예제 #3
0
        public void Run()
        {
            try
            {
                this.watch = System.Diagnostics.Stopwatch.StartNew();

                AppSB.Log("Inicialization all card on position [0,0]");
                foreach (var itm in Board.GetCardAvaibleToPosition(0, 0))
                {
                    BoardProcessingCollection.Push(itm);
                }
                this.InsertCardOnBoard(this.boardSizeX * this.boardSizeY);
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show("Application Error: " + ex.ToString());
            }
        }
예제 #4
0
 private void btCompare_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (boardTask != null && boardTask.IsBusy)
         {
             System.Windows.MessageBox.Show("Processing is running. Please wait to finish processing!!");
             return;
         }
         btCompare.IsEnabled           = false;
         boardTask                     = new System.ComponentModel.BackgroundWorker();
         boardTask.RunWorkerCompleted += boardTask_RunWorkerCompleted;
         boardTask.DoWork             += boardTask_DoWork;
         boardTask.RunWorkerAsync();
     }
     catch (Exception ex)
     {
         AppSB.Log(ex.ToString());
         MessageBox.Show(ex.ToString());
     }
 }
예제 #5
0
        private void InsertCardOnBoard(int numberCardOnBoardToEnd)
        {
            while (BoardProcessingCollection.Count > 0)
            {
                for (int t = 1; t < System.Environment.ProcessorCount * 2; t++)
                {
                    if (BoardProcessingCollection.Count == 0)
                    {
                        continue;
                    }
                    BoardDeskAndPackCard boardAndCards = BoardProcessingCollection.Pop();
                    TaskItems.Add(Task.Factory.StartNew(() =>
                    {
                        foreach (var itm in boardAndCards.GetAllPossibilityBoardAndCardsOnNextPosition())
                        {
                            if (itm.actualPositionCard > maxNumberOfInsertedCardOnBoard)
                            {
                                maxNumberOfInsertedCardOnBoard = itm.actualPositionCard;
                                maximumSolutionCardsOnBoard.Clear();
                            }
                            if ((itm.actualPositionCard) == maxNumberOfInsertedCardOnBoard)
                            {
                                maximumSolutionCardsOnBoard.Add(itm);
                            }
                            BoardProcessingCollection.Push(itm);
                        }
                    }));
                }
                Task.WaitAll(TaskItems.ToArray());
                TaskItems.Clear();
            }

            if (maxNumberOfInsertedCardOnBoard + 1 == (numberCardOnBoardToEnd)) // +1 -> count with zero number
            {
                this.watch.Stop();
                if (maximumSolutionCardsOnBoard.Any(im => im.CounterSkipPosition == 0))
                {
                    AppSB.Log("Winner - All card is on board. Count of solution: " + maximumSolutionCardsOnBoard.Count(im => im.CounterSkipPosition == 0).ToString() + ". Time processing: " + watch.Elapsed.TotalSeconds.ToString(), true);
                    AppSB.Log("One Board card: " + Environment.NewLine + maximumSolutionCardsOnBoard[0].ShowBoard());
                }
                else
                {
                    AppSB.Log("Winner with several empty card(s) on Board. Count  Solution: " + maximumSolutionCardsOnBoard.Count(im => im.CounterSkipPosition != 0).ToString() + ". Time processing: " + watch.Elapsed.TotalSeconds.ToString(), true);
                    AppSB.Log("One Board card with empty card: " + Environment.NewLine + maximumSolutionCardsOnBoard[0].ShowBoard());
                }
            }
            else
            {
                this.watch.Stop();;
                AppSB.Log("The solution is not possible - Maximum card on board:  " + (maxNumberOfInsertedCardOnBoard + 1).ToString() + " . Calculate solution: " + maximumSolutionCardsOnBoard.Count.ToString() + " Time processing: " + watch.Elapsed.TotalSeconds.ToString(), true);
                AppSB.Log("One Board without complete all cards: " + Environment.NewLine + maximumSolutionCardsOnBoard[0].ShowBoard());

                if (System.Windows.MessageBox.Show("Continue with inserting empty Card on position [" + (maximumSolutionCardsOnBoard[0].actualPositionCard + 1).ToString() + "] on board? ", "Question", System.Windows.MessageBoxButton.YesNo) == System.Windows.MessageBoxResult.Yes)
                {
                    if (maxNumberOfInsertedCardOnBoard + 2 >= numberCardOnBoardToEnd)
                    {
                        AppSB.Log("Is not possible to move the next position." + (maxNumberOfInsertedCardOnBoard + 1).ToString() + " . Calculate solution: " + maximumSolutionCardsOnBoard.Count.ToString() + " Time processing: " + watch.Elapsed.TotalSeconds.ToString(), true);
                    }
                    this.watch.Start();
                    maximumSolutionCardsOnBoard.ForEach(it =>
                    {
                        it.SkipPosition();
                        BoardProcessingCollection.Push(it);
                    });
                    InsertCardOnBoard(numberCardOnBoardToEnd);
                }
                this.watch.Start();
            }
        }
예제 #6
0
 void boardTask_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
 {
     AppSB.Log("Smile program is Complete :)");
     btCompare.IsEnabled = true;
 }