public static bool ReadDataFromStockQuotesFile() { if (File.Exists(Globals.fileLocStockQuotes) == false) { return(false); } bool retval = true; try { var fileStream = new FileStream(Globals.fileLocStockQuotes, FileMode.Open, FileAccess.Read); stockQuotesListDelimComma.Clear(); stockQuotesHashTable.Clear(); using (var streamReader = new StreamReader(fileStream)) { string line; while ((line = streamReader.ReadLine()) != null) { if (line.Trim().Length == 0) { continue; } //lineList.Add(line); // each line should have data in the format <Number>,<Y-Match, N-No match> string[] tokens = line.Split(','); string stockdate = tokens[0]; string seqnum = tokens[1]; string stockquote = tokens[2]; // adding a comma to each number, so that we can create a string pattern of numbers // such as 1,2,3,4, and then look for patterns in the string stockQuotesListDelimComma.Add(stockquote + ","); StockQuote sq = new StockQuote(stockdate, seqnum, stockquote); stockQuotesHashTable.Add(seqnum, sq); } } //lines = lineList.ToArray(); } catch { retval = false; } return(retval); }
private void StartProcessOfGuessingTheNextQuote() { try { // Generate the next random number //GenerateandDisplayNextRandomNumberQuote(); // Guess the next number aiGuessNum = AIGuessTheNextStockQuote(); } catch (Exception ex) { MessageBox.Show("Error processing random quote." + ex.Message); return; } ValidatetheAIResult(); string resultStr; int nextRandSeqNum = Convert.ToInt32(Globals.randStockQuote.seqNum) + 1; StockQuote nextStockQuote = (StockQuote)Globals.stockQuotesHashTable[nextRandSeqNum.ToString()]; int nextRandNumPrice = Convert.ToInt32(nextStockQuote.stockPrice); string nextRandDateStr = nextStockQuote.date.ToString(); if (aiGuessNum == nextRandNumPrice) { resultStr = "SUCCESS !!!"; successCount++; } else { resultStr = "Guess Again"; } labelRandDate.Text = nextRandDateStr; labelRandValue.Text = nextRandNumPrice.ToString(); labelGuessResult.Text = resultStr; PatternNumberResult.PrintToPatternHitsFile(" "); PatternNumberResult.PrintToPatternHitsFile(DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff")); PatternNumberResult.PrintToPatternHitsFile("------- Result --------"); PatternNumberResult.PrintToPatternHitsFile("AI Stock Price Guess: " + aiGuessNum.ToString()); PatternNumberResult.PrintToPatternHitsFile("Actual Next day Stock Price: " + nextRandNumPrice.ToString()); //PatternNumberResult.PrintToPatternHitsFile("Random Number: " + randNum.ToString()); PatternNumberResult.PrintToPatternHitsFile("Result: " + resultStr); PatternNumberResult.PrintToPatternHitsFile("----------------------------------------------------------------------"); }