Example #1
0
 public TableRulesForm(TableFormField tableFormField)
 {
     InitializeComponent();
     _tableFormField = tableFormField;
     _oldTableRules  = tableFormField.Rules;
     RulesChanged    = false;
     UpdateUI();
 }
Example #2
0
        private void UpdateUI()
        {
            TableRules rules = _tableFormField.Rules;

            _ch_RowsLineSeparator.Checked           = (rules & TableRules.RowsLineSeparator) == TableRules.RowsLineSeparator;
            _ch_EqualFixedLineHeight.Checked        = (rules & TableRules.EqualFixedLineHeight) == TableRules.EqualFixedLineHeight;
            _ch_EqualFixedRowHeight.Checked         = (rules & TableRules.EqualFixedRowHeight) == TableRules.EqualFixedRowHeight;
            _ch_MultiPageTableHeaderRepeted.Checked = (rules & TableRules.MultiPageTableHeaderRepeted) == TableRules.MultiPageTableHeaderRepeted;
        }
Example #3
0
        private void _ch_CheckedChanged(object sender, EventArgs e)
        {
            TableRules rules = TableRules.NoRules;

            if (_ch_RowsLineSeparator.Checked)
            {
                rules |= TableRules.RowsLineSeparator;
            }
            if (_ch_EqualFixedLineHeight.Checked)
            {
                rules |= TableRules.EqualFixedLineHeight;
            }
            if (_ch_EqualFixedRowHeight.Checked)
            {
                rules |= TableRules.EqualFixedRowHeight;
            }
            if (_ch_MultiPageTableHeaderRepeted.Checked)
            {
                rules |= TableRules.MultiPageTableHeaderRepeted;
            }
            _tableFormField.Rules = rules;
        }
 /**
  * Get logic table names based on actual table name.
  *
  * @param actualTableName actual table name
  * @return logic table name
  */
 public ICollection <string> GetLogicTableNames(string actualTableName)
 {
     return(TableRules.Where(o => o.IsExisted(actualTableName)).Select(o => o.LogicTable).ToList());
 }
 /**
  * Find column name of generated key.
  *
  * @param logicTableName logic table name
  * @return column name of generated key
  */
 public string FindGenerateKeyColumnName(string logicTableName)
 {
     return(TableRules
            .Where(o => o.LogicTable.EqualsIgnoreCase(logicTableName) && o.GetGenerateKeyColumn() != null)
            .Select(o => o.GetGenerateKeyColumn()).FirstOrDefault());
 }
 /**
  * Judge is sharding column or not.
  *
  * @param columnName column name
  * @param tableName table name
  * @return is sharding column or not
  */
 public bool IsShardingColumn(string columnName, string tableName)
 {
     return(TableRules.Any(o => o.LogicTable.EqualsIgnoreCase(tableName) && IsShardingColumn(o, columnName)));
 }
 /**
  * Find table rule via actual table name.
  *
  * @param actualTableName actual table name
  * @return table rule
  */
 public TableRule FindTableRuleByActualTable(string actualTableName)
 {
     return(TableRules.Where(o => o.IsExisted(actualTableName)).FirstOrDefault());
 }
 /**
  * Find table rule.
  *
  * @param logicTableName logic table name
  * @return table rule
  */
 public TableRule FindTableRule(string logicTableName)
 {
     return(TableRules.FirstOrDefault(o => o.LogicTable.EqualsIgnoreCase(logicTableName)));
 }
Example #9
0
        private void button1_Click(object sender, EventArgs e)
        {
            Statement1 = txtStatement1.Text;
            Statement2 = txtStatement2.Text;
            Statement3 = txtStatement3.Text;

            Conclusion1 = txtConclusion1.Text;
            Conclusion2 = txtConclusion2.Text;
            Conclusion3 = txtConclusion3.Text;
            Conclusion4 = txtConclusion4.Text;


            Result1 = TableRules.AddStatements(Statement1, Statement2);

            Result2 = TableRules.AddStatements(Statement2, Statement3);

            Result3 = TableRules.AddStatements(Statement1, Statement3);

            //Consider Conclusion1 by taking subject and predicate.
            Conclusion1Subject   = SyllogismRules.GetSubjectByProposition(Conclusion1);
            Conclusion1Predicate = SyllogismRules.GetPredicateByProposition(Conclusion2);
            if (Conclusion1Subject.ToUpper() != "INVALID TYPE" || Conclusion1Predicate.ToUpper() != "INVALID TYPE")
            {
                // ToD0 :- Check Which of the given statements having this suject and predicate by conclusion.
                string[] allStatements    = new string[] { Statement1, Statement2, Statement3 };
                string[] sortedStatements = new string[] { };
                sortedStatements = SyllogismRules.GetPairedStatementsByConclusion(allStatements, Conclusion1);
            }

            if (Conclusion1 != string.Empty && Conclusion2 != string.Empty)
            {
                var r1 = TableRules.CheckConclusionByStatements(Conclusion1, Statement1, Statement2, Result1).ToUpper();

                var r2 = TableRules.CheckConclusionByStatements(Conclusion2, Statement1, Statement2, Result1).ToUpper();

                if (r1.ToUpper() == "CONCLUSION IS VALID" && r2.ToUpper() == "CONCLUSION IS NOT VALID")
                {
                    lblResult.Text = "ONLY CONCLUSION 1 FOLLOWS";
                }
                else if (r1.ToUpper() == "CONCLUSION IS NOT VALID" && r2.ToUpper() == "CONCLUSION IS VALID")
                {
                    lblResult.Text = "ONLY CONCLUSION 2 FOLLOWS";
                }
                else if (r1.ToUpper() == "CONCLUSION IS VALID" && r2.ToUpper() == "CONCLUSION IS VALID")
                {
                    lblResult.Text = "BOTH CONCLUSION 1 AND CONCLUSION 2 FOLLOWS";
                }
                else if (r1.ToUpper() == "CONCLUSION IS NOT VALID" && r2.ToUpper() == "CONCLUSION IS NOT VALID")
                {
                    lblResult.Text = ComplementaryPair.IsComplementaryPair(Conclusion1, Conclusion2)
                        ? "EITHER CONCLUSION 1 OR CONCLUSION 2 FOLLOWS"
                        : "NEITHER CONCLUSION 1 NOR CONCLUSION 2 FOLLOWS";
                }
                else
                {
                    lblResult.Text = "NEITHER CONCLUSION 1 NOR CONCLUSION 2 FOLLOWS";
                }
            }
            else if (Conclusion1 != string.Empty)
            {
                var r1 = TableRules.CheckConclusionByStatements(Conclusion1, Statement1, Statement2, Result1).ToUpper();
                lblResult.Text = r1.ToUpper();
            }
            else if (Conclusion2 != string.Empty)
            {
                var r2 = TableRules.CheckConclusionByStatements(Conclusion2, Statement1, Statement2, Result1).ToUpper();

                lblResult.Text = r2.ToUpper();
            }
            else
            {
                lblResult.Text = Result1;
            }
        }
Example #10
0
        /// <summary>
        /// The console program.  Stakes seven players with 100,000 chips each (or $1,000.00 if you like), and
        /// plays blackjack until all but the card counters lose their entire stack.
        /// </summary>
        /// <param name="args">(optional) Filename of a CSV file - one line is output after every game</param>
        static int Main(string[] args)
        {
            Console.WriteLine("{0} - version {1}",
                              Assembly.GetExecutingAssembly().GetName().Name,
                              Assembly.GetExecutingAssembly().GetName().Version
                              );

            // Initialize the blackjack table.
            TableRules Rules        = new TableRules(500, -1, 8, 8, 4, 0.10, 0.15);
            int        InitialStake = 100000;

            Player[] Players = new Player[7];
            Players[0] = new WikiPlayer(new ChipStack(InitialStake));
            Players[1] = new DarwinCCPlayer(new ChipStack(InitialStake));
            Players[2] = new PositiveProgDarwinPlayer(new ChipStack(InitialStake));
            Players[3] = new NoBustPlayer(new ChipStack(InitialStake));
            Players[4] = new Dealer(new ChipStack(InitialStake));
            for (int i = 3; i < Players.Length; i++)
            {
                Players[i] = new DarwinPlayer(new ChipStack(InitialStake));
            }
            Table table = new Table(Rules, Players);

            bool[]    PlayerBankrupt = new bool[Players.Length];
            int       GamesPlayed    = 0;
            Stopwatch Timer          = new Stopwatch();

            DateTime LastShowedProgress = DateTime.Now;
            DateTime LastShowedStats    = DateTime.Now;

            StreamWriter CSVWriter = null;

            // Consider the DarwinCCPlayer bankrupt, so as to end the processing without letting it go on and on.
            PlayerBankrupt[1] = true;

            if (args.Length == 1)
            {
                FileInfo FI = new FileInfo(args[0]);
                try
                {
                    CSVWriter = FI.CreateText();
                }
                catch (IOException e)
                {
                    Console.Error.WriteLine("Error: Could not open {0} for write: {1}", args[0], e.Message);
                    return(-1);
                }
                string CSVHeader = String.Join(",", "Games Played", "Time in Play (ticks)", table.CSVHeader());
                CSVWriter.WriteLine(CSVHeader);
            }

            Predicate <bool[]> AllPlayersBusted = (x) =>
            {
                bool Busted = true;
                for (int i = 0; i < x.Length; i++)
                {
                    Busted = Busted && x[i];
                }
                return(Busted);
            };

            Console.WriteLine("Starting blackjack games");

            // Go play, as long as players still have money.
            while (!AllPlayersBusted(PlayerBankrupt))
            {
                Timer.Start();
                table.Play();
                Timer.Stop();
                GamesPlayed++;
                Debug.WriteLine(String.Format("Round {0} played", GamesPlayed));

                // See who is bankrupt.  Fill in the PlayerBankrupt[] array.
                for (int i = 0; i < table.Players.Length; i++)
                {
                    if (PlayerBankrupt[i] == false &&
                        table.Players[i].CashOnHand < table.Rules.MinimumBet)
                    {
                        Console.Write("\r\n");
                        Console.WriteLine("Player {0} bankrupt after {1} games played", i, GamesPlayed);
                        PlayerBankrupt[i] = true;
                    }
                }

                // Output statistics, if needed.
                if (CSVWriter != null)
                {
                    string CSVLine = String.Join(",", GamesPlayed, Timer.ElapsedTicks, table.CSVString());
                    CSVWriter.WriteLine(CSVLine);
                }

                // Give the user some feedback to let them know the system is still working.
                if (GamesPlayed % 500 == 0 && (DateTime.Now - LastShowedProgress).Milliseconds > 100)
                {
                    Console.Write("Games Played: {0}\r", GamesPlayed);
                    if (CSVWriter != null)
                    {
                        CSVWriter.Flush();
                    }
                    LastShowedProgress = DateTime.Now;
                }
                if (GamesPlayed % 5000 == 0 && (DateTime.Now - LastShowedStats).Seconds > 1)
                {
                    Console.Write("\r\n");
                    Console.WriteLine(table.Scoreboard());
                    LastShowedStats = DateTime.Now;
                }
            }

            Console.Write("---ALL PLAYERS BANKRUPT---\r\nStatistics for this run:\r\n");
            Console.WriteLine(table.Scoreboard());

            if (CSVWriter != null)
            {
                ScorePerHand Aggregate = new ScorePerHand();
                foreach (Player player in table.Players)
                {
                    Aggregate += player.Score;
                }
                CSVWriter.WriteLine(Aggregate.PerHandCSVHeader());
                CSVWriter.WriteLine(Aggregate.PerHandCSVString());
                CSVWriter.WriteLine(Aggregate.StreakCSVHeader());
                CSVWriter.WriteLine(Aggregate.StreakCSVString());
                CSVWriter.Close();
            }

            ScorePerHand SavedScore;
            FileStream   ScoreFileSR;

            try
            {
                ScoreFileSR = new FileStream(@"d:\users\brian\documents\ScorePerHand.bin", FileMode.Open);
                try
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    SavedScore = (ScorePerHand)bf.Deserialize(ScoreFileSR);
                }
                catch (SerializationException e)
                {
                    Console.WriteLine("Failed to read aggregate scores: Serialization error: {0}", e.Message);
                    SavedScore = new ScorePerHand();
                }
                ScoreFileSR.Close();
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine("Failed to read aggregate scores: File error: {0}", e.Message);
                SavedScore = new ScorePerHand();
            }

            for (int i = 0; i < table.Players.Length; i++)
            {
                try
                {
                    SavedScore += table.Players[i].Score;
                }
                catch (OverflowException e)
                {
                    Console.WriteLine("Failed to add score: {0}", e.Message);
                }
            }

            try
            {
                ScoreFileSR = new FileStream(@"d:\users\brian\documents\ScorePerHand.bin", FileMode.OpenOrCreate);
                try
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    bf.Serialize(ScoreFileSR, SavedScore);
                }
                catch (SerializationException e)
                {
                    Console.WriteLine("Failed to save aggregate scores: Serialization error: {0}", e.Message);
                }
                ScoreFileSR.Close();
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine("Failed to save aggregate scores: File error: {0}", e.Message);
            }

            Console.Write("\r\n\r\nStatistics for all runs:\r\n");
            Console.WriteLine(SavedScore.Scoreboard());

            /* "In the casino, the cardinal rule is to keep them playing and to keep them coming back.
             * The longer they play, the more they lose, and in the end, we get it all."
             */
#if DEBUG
            Console.WriteLine("Hit any key to quit");
            Console.ReadKey();
#endif
            return(0);
        }