Esempio n. 1
0
        public BingoGameState StepToReplay(int game_index)
        {
            BingoGameState result;

            if (game_index < this.BingoGameEvents.Count && this.BingoGameEvents[game_index] != null)
            {
                result = this.BingoGameEvents[game_index];
                return(StepToUsing(game_index, result));
            }

            result = new BingoGameState();

            if (game_index >= session.GameList.Count)
            {
                return(result);
            }
            // setup this ahead of time.
            //result.game = session.GameList[game_index];
            result.game_event = new BingoGameEvent(Local.dsn, this, game_index);
            result.game_event.games.Add(result.game);

            while (game_index >= BingoGameEvents.Count)
            {
                BingoGameEvents.Add(null);
            }

            BingoGameEvents[game_index] = result;

            return(StepToUsing(game_index, result));
        }
Esempio n. 2
0
        public BingoGameState Step()
        {
            // get one game of all the ones defined in the bingo core state...
            BingoGameState result = new BingoGameState();

            lock (this.step_lock)
            {
                BingoGame game = null;

                if (session.GameList == null)
                {
                    return(result);
                }

                if (session.GameList.Count == 0)
                {
                    // return an early result (no process)
                    return(result);
                }

                {
                    if (game != null && game.prior_game != null)
                    {
                        // game we're coming from has to finish playing...
                        while (game.prior_game.playing)
                        {
                            Thread.SpinWait(1);
                        }
                    }
                }
                return(StepTo(current_game_index++));
            }
        }
Esempio n. 3
0
        public static void CountStarburst(BingoGameState s)
        {
            bool do_starburst = false;

            if (s.game != null && s.game.starburst)
            {
                do_starburst = true;
            }

            if (do_starburst)
            {
                foreach (wininfo card in s.winning_cards)
                {
                    byte[, ,] playing_card = card.playing_card.CardData;
                    if (playing_card[0, 2, 2] == s.game_event.playing_balls[s.bestwin])
                    {
                        card.starburst = true;
                        lock (s.game_event)
                            s.game_event.starburst_wins++;
                    }
                    else
                    {
                        for (int ball = 0; ball < (s.bestwin - 1); ball++)
                        {
                            if (s.game_event.playing_balls[ball] == playing_card[0, 2, 2])
                            {
                                lock (s.game_event)
                                    s.game_event.starburst_marks++;
                                card.starburst_marked = true;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        public static void CountHotball(ref BingoGameState s, int[] playing_balls)
        {
            int check_balls = 0;

            if (s.game == null)
            {
                return;
            }

            check_balls = s.game.cashballs;

            if (check_balls > 0)
            {
                foreach (wininfo info in s.winning_cards)
                {
                    int card = info.card_index;
                    int mask = info.mask;
                    byte[, ,] playing_card = info.playing_card.CardData;
                    bool didwin    = false;
                    int  hot_match = check_5ball(mask, ref playing_card
                                                 , ref s.game_event.playing_hotballs
                                                 , check_balls
                                                 , playing_balls[s.bestwin - 1], ref didwin);
                    if (didwin)
                    {
                        //s.best
                        //hotball_wins[s.game.game_ID, hot_match - 1]++;
                        info.hotball       = true;
                        info.hotball_count = hot_match;
                    }
                }
            }
        }
Esempio n. 5
0
        public BingoGameState StepTo(int game_index)
        {
            BingoGameState result;

            result = new BingoGameState();

            active_games.Add(result);

            return(StepToUsing(game_index, result));
        }
Esempio n. 6
0
 public void LoadPlayerCards(BingoGameState game_event)
 {
     foreach (BingoPlayer player in _PlayerList)
     {
         foreach (PlayerTransaction player_transaction in player.transactions)
         {
             LoadPlayerCards(player_transaction, null, game_event);
         }
     }
 }
Esempio n. 7
0
 //static int play_lock;
 /// <summary>
 /// Plays a single bingo event.
 /// </summary>
 /// <param name="State">the state to play - should have used a 'Step' function to get this</param>
 public void PlayGame(BingoGameState State)
 {
     BingoMatchEngine.Play(State);
     if (opened)
     {
         BingoPrize.ComputePrizes(State.game_event, State.game, State.winning_cards);
         foreach (wininfo win in State.winning_cards)
         {
             Local.bingo_tracking.AddWinner(win.playing_card.ID, win.mask, win.amount);
         }
     }
 }
Esempio n. 8
0
        public static int GetPackCardGroupSize(BingoGameState s)
        {
            Pattern pattern = s.game.patterns[0];

            if (pattern.algorithm == PatternDescriptionTable.match_types.CrazyMultiCard ||
                pattern.algorithm == PatternDescriptionTable.match_types.TopMiddleBottom ||
                pattern.algorithm == PatternDescriptionTable.match_types.TopMiddleBottomCrazy
                )
            {
                return(pattern.sub_patterns.Count);
            }
            return(1);
        }
Esempio n. 9
0
        public static bool IsPackPattern(BingoGameState s)
        {
            Pattern pattern = s.game.patterns[0];

            if (pattern.algorithm == PatternDescriptionTable.match_types.CrazyMultiCard ||
                pattern.algorithm == PatternDescriptionTable.match_types.TopMiddleBottom ||
                pattern.algorithm == PatternDescriptionTable.match_types.TopMiddleBottomCrazy
                )
            {
                return(true);
            }
            return(false);
        }
Esempio n. 10
0
        public void DoPlayState(object param)
        {
            BingoGameState s = param as BingoGameState;

            if (s.valid)
            {
                session.UpdateStatus("Playing game " + s.game.game_number + "(" + s.game.game_ID + ")" + " in session " + session_number + " on " + bingoday.Date + "...");
                BingoMatchEngine.Play(s);
                session.UpdateStatus("Game completed " + s.game.game_number + "(" + s.game.game_ID + ")" + " in session " + session_number + " on " + bingoday.Date + "...");
            }
            else
            {
                session.UpdateStatus("Invalid state. Ignoring.");
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Checks to see if the game ended with the last 5 balls being from
        /// specific and in order columns 'B', 'I', 'N', 'G', 'O' and if so,
        /// checks to see if any of the winning cards matched on the last
        /// five ball picks.
        /// </summary>
        /// <param name="s"></param>
        /// <param name="playing_balls"></param>
        public static void CountLastLettersBINGO(ref BingoGameState s, int[] playing_balls)
        {
            if (s.game != null && s.game.last_letter_bingo)
            {
                int last = playing_balls.Length - 5;
                int idx  = 0;

                if (last < 0)
                {
                    return;
                }

                // Check to see if last 5 called balls spelled BINGO (in order)
                if ((((playing_balls[last++] - 1) / 15) != 0) ||
                    (((playing_balls[last++] - 1) / 15) != 1) ||
                    (((playing_balls[last++] - 1) / 15) != 2) ||
                    (((playing_balls[last++] - 1) / 15) != 3) ||
                    (((playing_balls[last] - 1) / 15) != 4))
                {
                    return;
                }

                // We already know that the last ball is in the last column,
                // let's find out what row it appears in for a given winning card.
                foreach (wininfo card in s.winning_cards)
                {
                    for (idx = 0; idx < 5; idx++)
                    {
                        if (card.playing_card.CardData[0, 4, idx] == playing_balls[last])
                        {
                            break;
                        }
                    }

                    if ((card.mask & (0x01F00000 >> (idx * 5))) == (0x01F00000 >> (idx * 5)))
                    {
                        card.bingo_match = true;
                        lock (s.game_event)
                        {
                            s.game_event.bingo_match_wins++;
                            s.game_event.wins++;
                        }
                    }
                }
            }
        }
Esempio n. 12
0
		static bool GameCounts( BingoGameState s )
		{
			int game_number = s.game.game_number;
			DataRow drSession = s.session_event.session.dataRowSession;

			if( drSession != null )
			{
				DbDataReader r = input_db.KindExecuteReader( "select rate from rate_rank_game_config"
					+ " join elec_sch2_session_game_group_game using(session_game_group_game_id)"
					+ " where game_number=" + game_number + " and session_id=" + drSession[SessionTable.PrimaryKey]
					);
				if( r.HasRows )
				{
					while( r.Read() )
					{
						if( r.GetBoolean( r.GetOrdinal( "rate" ) ) )
							return true;
					}
				}

			}
			else
			{
				DbDataReader r = input_db.KindExecuteReader( "select rate from rate_rank_game_config"
					+ " join elec_sch2_session_game_group_game using(session_game_group_game_id)"
					+ " join elec_sch2_session_macro_session using(session_id)"
					+ " join elec_sch2_session_macro_schedule using(session_macro_id)"
					+ " where game_number=" + game_number 
					+ " and session_number=" + s.session_event.session.session
					+ " and starting_date<=" + DsnSQLUtil.MakeDateOnly( input_db, s.session_event.bingoday )
					+ " order by starting_date desc"
					+ " limit 1"
					);
				if( r != null && r.HasRows )
				{
					while( r.Read() )
					{
						if( r.GetBoolean( r.GetOrdinal( "rate" ) ) )
							return true;
					}
				}

			}
			return false;
		}
Esempio n. 13
0
        public BingoGameState[] StepToReplay(DataRow row)
        {
            BingoGameState[] results = null;
            int game_number          = (int)row["game_id"];
            int found = 0;

            foreach (BingoGame game in session.GameList)
            {
                if (game_number == game.game_number)
                {
                    found++;
                }
            }
            Log.log("Found " + found + " games using game number " + game_number);
            if (found > 0)
            {
                results = new BingoGameState[found];
                found   = 0;
                foreach (BingoGame game in session.GameList)
                {
                    if (game.game_number == game_number)
                    {
                        results[found] = new BingoGameState();
                        //results[found].game = game;
                        results[found].game_event = new BingoGameEvent((row.Table as MySQLDataTable).Connection
                                                                       , this, row);
                        results[found].game_event.games.Add(game);

                        //results[found].game_event.playing_balls = new byte[0];
                        // fill in the remaininig common info
                        StepToUsing(0, results[found]);

                        found++;
                    }
                }
            }
            return(results);
        }
Esempio n. 14
0
 /// <summary>
 /// this just plays the current state, it doesn't attempt to call more balls.  It's a one-shot, expecting balls to be updated externally.
 /// </summary>
 /// <param name="s">the state to play</param>
 public static void PlayNow(BingoGameState s)
 {
     Play(s, true);
 }
Esempio n. 15
0
 public static void Play(BingoGameState s)
 {
     Play(s, false);
 }
Esempio n. 16
0
        /// <summary>
        /// Plays a single state of bingo, uses the balls specified in playing_balls.
        /// </summary>
        /// <param name="s"></param>
        static void Play(BingoGameState s, bool single_ball)
        {
            BingoGameInterfaces.BallDataInterface bdi;
            if (s.session_event.ball_data != null)
            {
                bdi = s.session_event.ball_data;
            }
            else
            {
                bdi = s.game_event.balls;
            }
            if (bdi == null)
            {
                return;
            }

            if (s.winning_cards == null)
            {
                return;
            }
            if (s.playing_cards.Count == 0)
            {
                return;
            }

            s.winning_cards.Clear();

            int[] playing_balls;

            playing_balls    = bdi.GetBalls(s.game.ignore_b_balls, s.game.ignore_i_balls, s.game.ignore_n_balls, s.game.ignore_g_balls, s.game.ignore_o_balls);
            s.starting_balls = playing_balls.Length;
            if (playing_balls.Length == 0)
            {
                if (!single_ball)
                {
                    // draw ball should be written as wait mode.... and throw exceptions I suppose
                    bdi.DrawBall();
                    bdi.WaitForBall();
                    playing_balls = bdi.GetBalls(s.game.ignore_b_balls, s.game.ignore_i_balls, s.game.ignore_n_balls, s.game.ignore_g_balls, s.game.ignore_o_balls);
                }
                else
                {
                    return; // balls need to be setup ahead of time
                }
            }
            // so this plays a single game.
            lock (s.game)
            {
                if (playing_balls == null || playing_balls.Length == 0)
                {
                    // Check to see if we are ignoring a column.  If so, Length == 0
                    // is a legitimate length and we should continue calling balls.
                    if ((!s.game.ignore_b_balls &&
                         !s.game.ignore_i_balls &&
                         !s.game.ignore_n_balls &&
                         !s.game.ignore_g_balls &&
                         !s.game.ignore_o_balls) ||
                        playing_balls == null)
                    {
                        // this is used to skip ball counts... return just 1 ball needed.
                        s.bestaway = 1;
                        return;
                    }
                }

                int faces   = s.playing_cards[0].card.GetLength(0);
                int columns = s.playing_cards[0].card.GetLength(2);

                do
                {
                    // int pack_number = 0;
                    int card_id = 0;

                    s.game_event.playing_balls = playing_balls;
                    s.bestaway = s.session_event.session.max_balls;
                    s.bestwin  = playing_balls.Length;

                    foreach (PlayerPack pack in s.playing_packs)
                    {
                        int away;
                        if (!pack.pack_info.flags.upickem)
                        {
                            continue;
                        }
                        int face_size = pack.pack_info.face_size;
                        foreach (BingoCardState card in pack.Cards[s.game.game_ID])
                        {
                            int mark_count = 0;
                            BingoCardState.BingoCardPatternMarkInfo marks = card.GetCurrentMark(0);
                            if (card.MarkNew(marks, faces, columns, playing_balls))
                            {
                                mark_count++;
                            }

                            if (card.CheckCrazy(marks, face_size))
                            {
                                away = 0;
                            }
                            else
                            {
                                away = face_size - marks.mark_index;
                            }

                            if (away < s.bestaway)
                            {
                                s.bestaway = away;
                            }

                            if (away == 0)
                            {
                                int ball_count = 0;
                                for (int n = 0; n < playing_balls.Length; n++)
                                {
                                    if (playing_balls[n] > 0)
                                    {
                                        ball_count++;
                                    }
                                }
                                // this card is a winner.
                                // there is also a game.bestwin now
                                // perhaps we should remove s.bestwin?
                                // but I thik maybe we need a lock on the game?
                                //
                                {
                                    // this is in a ball-length check mode.
                                    if (card.BallCount < ball_count)
                                    {
                                        // had this as a message box... but ... should silence it... it is a flaw somewhere.
                                        Log.log("Sleeper bingo found on card " + card.unit_card_number + " in " + card.BallCount + " balls instead of " + playing_balls.Length + " balls");
                                    }
                                    wininfo tmpwin;
                                    s.AddWinner(tmpwin = new wininfo(card_id, card));
                                    if (Local.StoreToDatabase)
                                    {
                                        Local.bingo_tracking.StoreVerifiedCard(card.player.ID, card.pack.pack_info.ID, card.cardset_card_number, tmpwin.mask, card.card);
                                    }
                                }
                            }
                        }
                    }


                    foreach (BingoGame game in s.game_event.games)
                    {
                        if (game.upick_size > 0)
                        {
                            /*
                             * foreach( BingoCardState card in s.playing_cards )
                             * {
                             *  BingoCardState.BingoCardPatternMarkInfo cardmarks;
                             *  card.MarkNew( cardmarks = card.GetCurrentMark( 0 ), faces, columns, playing_balls );
                             *  int away = game.upick_size - cardmarks.mark_index;
                             *  if( away < s.bestaway )
                             *      s.bestaway = away;
                             * }
                             */
                        }
                        else
                        {
                            foreach (Pattern pattern in game.patterns)
                            {
                                if (pattern.algorithm == PatternDescriptionTable.match_types.CrazyMultiCard ||
                                    pattern.algorithm == PatternDescriptionTable.match_types.TopMiddleBottom ||
                                    pattern.algorithm == PatternDescriptionTable.match_types.TopMiddleBottomCrazy
                                    )
                                {
                                    foreach (BingoCardState card in s.playing_cards)
                                    {
                                        foreach (Pattern sub_pattern in pattern.pattern_list)
                                        {
                                            int sub_pattern_index = pattern.pattern_list.IndexOf(sub_pattern);
                                            card.MarkNew(card.GetCurrentMark(sub_pattern_index), faces, columns, playing_balls);
                                        }
                                    }

                                    foreach (PlayerPack pack in s.playing_packs)
                                    {
                                        int away;


                                        if (check_pack(pack, game.ballset_number, pattern))
                                        {
                                            s.AddWinner(new wininfo(card_id, pack.Cards[game.ballset_number][0]));
                                            away = 0;
                                        }
                                        else
                                        {
                                            if (pack.state != null)
                                            {
                                                away = pack.state[game.ballset_number].best_card_away;
                                            }
                                            else
                                            {
                                                away = 75;
                                            }
                                        }
                                        if (away < s.bestaway)
                                        {
                                            s.bestaway = away;
                                        }
                                    }
                                }
                                else if (pattern.algorithm == PatternDescriptionTable.match_types.CrazyMark)
                                {
                                    foreach (BingoCardState card in s.playing_cards)
                                    {
                                        int away;
                                        faces = card.pack.pack_info.flags.double_action ? 2 : 1;
                                        if (!card.MarkNew(card.GetCurrentMark(0), faces, columns, playing_balls))
                                        {
                                            continue;
                                        }
                                        if (card.marks[0].mark_index == pattern.repeat_count)
                                        {
                                            away = 0;
                                        }
                                        else
                                        {
                                            away = pattern.repeat_count - card.marks[0].mark_index;
                                        }
                                        if (away < s.bestaway)
                                        {
                                            s.bestaway = away;
                                        }
                                    }
                                }
                                if (pattern.algorithm == PatternDescriptionTable.match_types.ExternalJavaEngine)
                                {
                                    foreach (BingoCardState card in s.playing_cards)
                                    {
                                        int away;
                                        faces = card.pack.pack_info.flags.double_action ? 2 : 1;

                                        if (check_single_card(card, s.game_event, s.game_event_index, playing_balls, faces, columns, 0))
                                        {
                                            away = 0;
                                        }
                                        else
                                        {
                                            away = card.BestAway();
                                        }
                                        if (away < s.bestaway)
                                        {
                                            s.bestaway = away;
                                        }

                                        // count is the count of balls that this card won in.
                                        // compared with one of the above matchings.
                                        // these are common to all prior code.
                                        if (away == 0)
                                        {
                                            int ball_count = 0;
                                            for (int n = 0; n < playing_balls.Length; n++)
                                            {
                                                if (playing_balls[n] > 0)
                                                {
                                                    ball_count++;
                                                }
                                            }

                                            // this card is a winner.
                                            //if( s.game.game_number == 10 )
#if null
                                            if (false)
                                            {
                                                xperdex.classes.Log.log("winner on start:" + card.pack.start_card + " face:" + card);
                                                xperdex.classes.Log.log("player: " + card.player.card + "  unit:" + card.pack.unit_number);
                                                xperdex.classes.Log.log("game " + s.game.game_number + " card:" + (card.unit_card_number)
                                                                        );
                                            }
#endif
                                            // there is also a game.bestwin now
                                            // perhaps we should remove s.bestwin?
                                            // but I thik maybe we need a lock on the game?
                                            //
                                            {
                                                // this is in a ball-length check mode.
                                                if (card.BallCount < ball_count)
                                                {
                                                    // had this as a message box... but ... should silence it... it is a flaw somewhere.
                                                    Log.log("Sleeper bingo found on card " + card.unit_card_number + " in " + card.BallCount + " balls instead of " + playing_balls.Length + " balls");
                                                }
                                                wininfo tmpwin;
                                                s.AddWinner(tmpwin = new wininfo(card_id, card));
                                                if (Local.StoreToDatabase)
                                                {
                                                    Local.bingo_tracking.StoreVerifiedCard(card.player.ID, card.pack.pack_info.ID, card.cardset_card_number, tmpwin.mask, card.card);
                                                }
                                            }
                                        }
                                        //card_number++;
                                    }
                                    card_id++;
                                } // end or cards
                                else if ((pattern.algorithm == PatternDescriptionTable.match_types.Normal) ||
                                         (pattern.algorithm == PatternDescriptionTable.match_types.TwoGroups) ||
                                         (pattern.algorithm == PatternDescriptionTable.match_types.TwoGroupsPrime) ||
                                         (pattern.algorithm == PatternDescriptionTable.match_types.TwoGroupsNoOver) ||
                                         (pattern.algorithm == PatternDescriptionTable.match_types.TwoGroupsPrimeNoOver))

                                {
                                    foreach (BingoCardState card in s.playing_cards)
                                    {
                                        int away;
                                        faces = card.pack.pack_info.flags.double_action ? 2 : 1;

                                        if (check_single_card(card, s.game_event, s.game_event_index, playing_balls, faces, columns, 0))
                                        {
                                            away = 0;
                                        }
                                        else
                                        {
                                            away = card.BestAway();
                                        }
                                        if (away < s.bestaway)
                                        {
                                            s.bestaway = away;
                                        }

                                        // count is the count of balls that this card won in.
                                        // compared with one of the above matchings.
                                        // these are common to all prior code.
                                        if (away == 0)
                                        {
                                            int ball_count = 0;
                                            for (int n = 0; n < playing_balls.Length; n++)
                                            {
                                                if (playing_balls[n] > 0)
                                                {
                                                    ball_count++;
                                                }
                                            }
                                            // this card is a winner.
                                            // there is also a game.bestwin now
                                            // perhaps we should remove s.bestwin?
                                            // but I thik maybe we need a lock on the game?
                                            //
                                            {
                                                // this is in a ball-length check mode.
                                                if (card.BallCount < ball_count)
                                                {
                                                    // had this as a message box... but ... should silence it... it is a flaw somewhere.
                                                    Log.log("Sleeper bingo found on card " + card.unit_card_number + " in " + card.BallCount + " balls instead of " + playing_balls.Length + " balls");
                                                }
                                                wininfo tmpwin;
                                                s.AddWinner(tmpwin = new wininfo(card_id, card));
                                                if (Local.StoreToDatabase)
                                                {
                                                    Local.bingo_tracking.StoreVerifiedCard(card.player.ID, card.pack.pack_info.ID, card.cardset_card_number, tmpwin.mask, card.card);
                                                }
                                            }
                                        }
                                        //card_number++;
                                    }
                                    card_id++;
                                } // end or cards
                            }
                        }
                    }


                    if (s.bestwincount == 0)
                    {
                        if (!single_ball)
                        {
                            // no cards I guess... somehow we called all balls and got no winners.
                            int maxBallsInPlay =
                                s.session_event.session.max_balls -
                                ((s.game.ignore_b_balls) ? 15 : 0) -
                                ((s.game.ignore_i_balls) ? 15 : 0) -
                                ((s.game.ignore_n_balls) ? 15 : 0) -
                                ((s.game.ignore_g_balls) ? 15 : 0) -
                                ((s.game.ignore_o_balls) ? 15 : 0);

                            //if( playing_balls != null && playing_balls.Length == s.session_event.session.max_balls )
                            if (playing_balls != null && playing_balls.Length == maxBallsInPlay)
                            {
                                break;
                            }

                            // need at least this many more balls anyhow...
                            for (int skip = 0; skip < s.bestaway; skip++)
                            {
                                bdi.DrawBall();
                                bdi.WaitForBall();
                            }
                            playing_balls = bdi.GetBalls(s.game.ignore_b_balls, s.game.ignore_i_balls, s.game.ignore_n_balls, s.game.ignore_g_balls, s.game.ignore_o_balls);
                        }
                    }
                    else
                    {
                        break;
                    }
                }  // end for players
                while(!single_ball);

                if (!s.game.progressive)
                {
                    bdi.DropBalls();                      // game finished?
                }
            }

            if (s.bestwincount > 0)
            {
                // this bit of code is run
                // after all players and all cards have been played
                // we compute stats for the game.

                CountStarburst(s);

                CountHotball(ref s, playing_balls);

                if (s.bestwin <= playing_balls.Length)
                {
                    lock (s.game_event)
                    {
                        s.game_event.wins += s.bestwincount;
                        //s.game_event.best_wins[s.bestwin] += s.bestwincount;
                    }
                }
            }

            s.game_event.playing_balls = playing_balls;

            // certain modes don't set s.game
            if (s.game != null)
            {
                //Local.bingo_tracking.SaveWinners( s.wining_cards );

                //Local.bingo_tracking.CloseGame();

                s.game.playing = false; // all done playign this game... all stats updates appropriately.
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Counts BINGOs when the entire BINGO is the same random generated color;
        /// </summary>
        /// <param name="s"></param>
        /// <param name="playing_balls"></param>
        public static int CountRandomColorBingo(ref BingoGameState s, int[] playing_balls)
        {
            int num_matches = 0;

            if (s != null)
            {
                int  row = 0;
                int  col = 0;
                char color;
                int  cardGridValue = 0;
                int  bitMask;
                bool matches;

                char[] randomColors = s.game_event.balls.GetRandomColors();

                // Check the mask against the card, get the number from the card,
                // and look up the color in the random color table.

                foreach (wininfo card in s.winning_cards)
                {
                    color   = (char)0x00;
                    matches = true;
                    bitMask = 0x01000000;

                    for (row = 0; matches && row < 5; row++)
                    {
                        for (col = 0; matches && col < 5; col++)
                        {
                            if ((card.mask & bitMask) == bitMask)
                            {
                                cardGridValue = card.playing_card.CardData[0, col, row];
                                if (color == 0x00)
                                {
                                    color = randomColors[cardGridValue - 1];
                                }
                                else if (color != randomColors[cardGridValue - 1])
                                {
                                    matches = false;
                                }
                            }
                            bitMask /= 2;
                        }
                    }

                    if (matches)
                    {
                        card.random_color_match = true;
                        num_matches++;
                    }
                }

                if (num_matches > 0)
                {
                    lock (s.game_event)
                    {
                        s.game_event.random_color_wins += num_matches;
                        s.game_event.wins += num_matches;
                    }
                }
            }

            return(num_matches);
        }
Esempio n. 18
0
        // all cards in the session? the game lists should maintain this good enough?
        //public card_list playing_cards;



        /// <summary>
        /// This completes final initialization fo a bingo game state, including loading the cards for each player
        /// </summary>
        /// <param name="game_index">if game== null, index will be used to get the GameList entry at the index.</param>
        /// <param name="result">this is the partial state we're going to use...</param>
        /// <returns>result or NULL if fails</returns>
        public BingoGameState StepToUsing(int game_index, BingoGameState result, BallDataInterface bdi = null)
        {
            // setup a play state for an absolute game number...
            // get one game of all the ones defined in the bingo core state...

            lock (this.step_lock)
            {
                BingoGame game = null;
                result.game_needs_balls = false;

                // no games in state.
                if (session.GameList == null || session.GameList.Count == 0)
                {
                    // return an early result (no process)
                    return(result);
                }

                result.session_event = this;
                {
                    {
                        // if game is already set, no reason to use game_index
                        if (result.game == null)
                        {
                            if (game_index >= session.GameList.Count)
                            {
                                Log.log("StepTo passed a game number beyond the current list.");
                                return(result);
                                // need to do a step of session.
                                // setup some hotballs ....
                            }

                            // new session, played all players and all their cards
                            game = session.GameList[game_index];
                        }
                        else
                        {
                            game = result.game;
                        }
                        // should wait before running the NEXT game...
                        // for that game to finish...
                        while (game.playing)
                        {
                            Thread.SpinWait(1);
                        }

                        if (result.game == null)
                        {
                            // though at this point I should have result.session_event... and we should have
                            // been progressing through that...


                            // with events, I need to know the prior event ....
                            // but the threaded nature of this makes this impossible... since we are
                            // not really within a session container... it's really an observation of
                            // game by game...

                            if (prior_game_event != null && game.prior_game != null && game.into)
                            {
                                result.game_event       = BingoGameEvent.Continue(prior_game_event, game);
                                result.game_event_index = result.game_event.games.Count - 1;
                            }
                            else
                            {
                                result.game_event = new BingoGameEvent(game, bdi);
                                prior_game_event  = result.game_event;
                            }

                            string[] str = game.Name.Split('\t');
                            if (my_store_to_database)
                            {
                                game.ID = Local.bingo_tracking.OpenGame(game_index + 1, game.ballset_number, str[1]);                                   //game.Name );
                            }
                            if (game.number_colored > 0)
                            {
                                int[] newballs = new int[game.number_colored];
                                int   n;
                                for (n = 0; n < game.number_colored; n++)
                                {
                                    newballs[n] = -1 - n;
                                }
                                result.game_event.balls.AddExtraBalls(newballs);
                            }
                            if (game.cashballs == 5)
                            {
                                byte[] card = result.game_event.card_factory.Create5Card();
                                result.game_event.playing_hotballs = new int[card.Length];
                                for (int n = 0; n < card.Length; n++)
                                {
                                    result.game_event.playing_hotballs[n] = card[n];
                                }
                            }
                            else
                            {
                                result.game_event.playing_hotballs = result.game_event.balls.CallBalls(game.cashballs);
                            }
                        }
                    }
                }

                result.bestwin = session.max_balls;                // game.bestwin; // start at more than any level...

                // this is indexed with -1... soo [card, ball-1] == count away.
                result.winning_cards = new List <wininfo>();
                // this resultset is the whole sess's cards?
                result.playing_cards = new List <BingoCardState>();                 // playing_cards;
                result.playing_packs = new List <PlayerPack>();

                result.valid = true;

                result.session_event = this;

                List <object> game_pack_set_ids = new List <object>();
                if (opened)
                {
                    if (my_store_to_database)
                    //foreach( BingoGameGroup group in result.game.game_groups )
                    {
                        game_pack_set_ids.Add(result.game.game_group.group_pack_set_id = Local.bingo_tracking.AddPackSetToGame(result.game.game_group.pack_set_id));
                    }
                }
                else
                {
                    game_pack_set_ids.Add(Guid.Empty);
                }

                /*
                 * if( _PlayerList != null )
                 * {
                 *      foreach( BingoPlayer player in _PlayerList )
                 *      {
                 *              LoadPlayerCards( player, game_pack_set_ids, result );
                 *      }
                 * }
                 */
                // return this state so we can unlock it.
                // with these balls and cards referenced
                // we should not have a problem with multi-threading this.
                return(result);
            }
        }
Esempio n. 19
0
 public void CloseGame(BingoGameState state)
 {
     active_games.Remove(state);
 }
Esempio n. 20
0
        public static BingoGameState Load(DateTime date, int session, int game)
        {
            BingoGameState s = new BingoGameState();

            return(s);
        }
Esempio n. 21
0
        /// <summary>
        /// This literally loads the packs each player is playing into the bingo game state
        /// </summary>
        /// <param name="_Player"></param>
        /// <param name="s"></param>
        void LoadPlayerCards(BingoPlayer _Player, List <object> game_pack_set_ids, BingoGameState s)
        {
            int            pack_number = 0;
            BingoGameGroup game_group  = s.game.game_group;

            while (_Player._played_cards.Count <= game_group.game_group_ID)
            {
                _Player._played_cards.Add(new List <BingoCardState>());
            }

            List <BingoCardState> player_card_list = _Player._played_cards[game_group.game_group_ID];

            // already loaded these cards?
            if (player_card_list.Count > 0)
            {
                return;
            }
            //player_card_list.Clear();

            //foreach( PlayerTransaction trans in _Player.transactions )
            {
                foreach (PlayerPack _pack in _Player.played_packs)
                {
                    bool skip_pack = true;
                    if (_pack.pack_info.game_groups.Count > 0)
                    {
                        foreach (BingoGameGroup group in _pack.pack_info.game_groups)
                        {
                            if (group.Contains(s.game))
                            {
                                // this pack is in this game, load cards for it.
                                game_group = group;
                                skip_pack  = false;
                                break;
                            }
                        }
                        if (skip_pack)
                        {
                            continue;
                        }
                    }
                    while (_pack.Cards.Count <= s.game.game_ID)
                    {
                        _pack.Cards.Add(new List <BingoCardState>());
                    }

                    pack_number++;

                    _pack.played = true;

                    int card_count = _pack.pack_info.count;                    // s.game.GetCardCount( _pack.pack_info );
                    if (_pack.pack_info.count == 0)
                    {
                        // pack does not play this game, skip it.
                        continue;
                    }

                    s.playing_packs.Add(_pack);

                    List <BingoCardState> game_cards = _pack.Cards[s.game.game_ID];

                    if (game_cards.Count < card_count)
                    {
                        if (_pack.dealer == null)
                        {
                            Log.log("Fatality, dealer not assigned on pack.");
                            continue;
                        }

                        int base_real_card = _pack.dealer.Add((_pack.start_card),
                                                              !_pack.paper
                                                                ? s.game.ballset_number
                                                                : s.game.page_skip);

                        //if( base_real_card > 320000 )
                        {
                            //	MessageBox.Show( "Card is out of range!" );
                        }


                        int col = 0;
                        int row = 0;
                        for (int card = 0; card < card_count; card++)
                        {
                            byte[, ,] card_faces;
                            row++;
                            if (row >= _pack.pack_info.rows)
                            {
                                col++;
                                row = 0;
                            }
                            //if( col == _pack.pack_info.
                            // dealer does a subtract 1, this is a 0 based physical card index.
                            if (base_real_card == 512301)
                            {
                                int a = 3;
                            }
                            int unit_card = _pack.dealer.GetNext(base_real_card, row, col, card);
                            int real_card = _pack.dealer.GetPhysicalNext(base_real_card, row, col, card);

                            if (_pack.dealer.card_data == null)
                            {
                                card_faces = new byte[1, 5, 5] {
                                    { { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 } }
                                };
                            }
                            else
                            {
                                if (_pack.pack_info.name == "Double Double" || _pack.pack_info.name == "Dual Daub")
                                {
                                    int a = 3;
                                }
                                card_faces = _pack.dealer.card_data.Create(
                                    real_card
                                    , _pack.pack_info.flags.double_action ? 2 : 1
                                    , _pack.pack_info.flags.starburst
                                    );
                            }

                            BingoCardState cs = new BingoCardState(card_faces);
                            cs.player = _Player;
                            cs.pack   = _pack;
                            //cs.prize_level_id = _pack.pack_info._dealer.prize_level_id;
                            cs.unit_card_number    = unit_card;
                            cs.cardset_card_number = real_card;
                            cs.game = s.game_event;
                            game_cards.Add(cs);
                            cs.pack_card_index = game_cards.IndexOf(cs);

                            player_card_list.Add(cs);
                            s.playing_cards.Add(cs);

                            if (s.session_event.opened)
                            {
                                cs.ID = Local.bingo_tracking.AddCard(game_group.group_pack_set_id, _pack.ID, s.game.ballset_number, cs.unit_card_number, cs.CardData);
                            }
                        }
                    }
                    else
                    {
                        for (int card = 0; card < card_count; card++)
                        {
                            BingoCardState cs = _pack.Cards[s.game.game_ID][card];
                            s.playing_cards.Add(cs);
                            player_card_list.Add(cs);
                            if (s.session_event.opened)
                            {
                                cs.ID = Local.bingo_tracking.AddCard(null, _pack.ID, s.game.ballset_number, cs.unit_card_number, cs.CardData);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 22
0
 public void EndGame(BingoGameState state)
 {
     //state.session_event.ball_data.BallCalled -= new BingoEvents.SimpleIntEvent( ball_data_BallCalled );
 }
Esempio n. 23
0
 /// <summary>
 /// Plays a single bingo event; in a thread.
 /// </summary>
 /// <param name="State">the state to play - should have used a 'Step' function to get this</param>
 public void Play(BingoGameState State)
 {
     Log.log("Starting new state... game:" + State.game);
     t = new Thread(DoPlayState);
     t.Start(State);
 }
Esempio n. 24
0
		public static bool Calculate( BingoGameState s )
		{
			//return false;
			if( !s.game.rate )
				return false;
			//if( !GameCounts( s ) )
			//   return false;
            int electronic_one_away;
            int paper_one_away;
            if( s.session_event.session.schedule != null )
            {
                {
                    //DataRow[] e = game_points.Select( "type=1 and " + OpenSkieScheduler.Relations.SessionGameGroupGameOrder.PrimaryKey + "=" + s.game.session_game_group_game_id );
                    //electronic_one_away = e.Length > 0 ? Convert.ToInt32( e[0]["points"] ) : 0;
                    //DataRow[] p = game_points.Select( "type=2 and " + OpenSkieScheduler.Relations.SessionGameGroupGameOrder.PrimaryKey + "=" + s.game.session_game_group_game_id );
                    //paper_one_away = p.Length > 0 ? Convert.ToInt32( p[0]["points"] ) : 0;
                }
            }
			//if( s.bestwin < max_balls )
			{
				int[] totals = new int[26];
				//int[, ,] player_totals = new int[s.Players, s.Packs, 26];
				//int[] limited_totals = new int[26];
				//int[, ,] limited_player_totals = new int[s.Players, s.Packs, 26];
				List<PlayerBestCard>[] all_bests = new List<PlayerBestCard>[s.Players];
				//List<PlayerBestPackSet>[] all_pack_bests = new List<PlayerBestPackSet>[s.Packs];
				if( s.session_event._PlayerList != null )
				{
					int count = 0;

					int game_index = s.game.game_ID;

					//Log.log( "calculating for game " + game_index );

					foreach( PlayerPack pack in s.playing_packs )
//					foreach( BingoCardState card in s.playing_cards )
					//foreach( BingoPlayer player in s.session_event._PlayerList )
					{
						BingoPlayer player = pack.player;
						//PlayerPack pack = card.pack;
						int max_set = 0;
						int min_set = s.Packs;

						while( pack.card_away_count.Count <= game_index )
						{
							pack.card_away_count.Add( new List<CardPoints>() );
							//player.card_away_count.
						}

						{
							int set = pack.pack_set;
							if( set > 0 )
							{
								//while( set > best_packs.Count )
								//	best_packs.Add( new PlayerBestPackSet() );
								//best_packs[set - 1].member_packs.Add( pack.pack_info );
								//best_packs[set - 1].points = 0;
								if( set > max_set )
									max_set = set;
								if( set < min_set )
									min_set = set;
							}
							int this_count = s.game.GetCardCount( pack.pack_info );

							//Log.log( "Processing pack " + pack );

							foreach( BingoCardState card in pack.Cards[s.game.game_group.game_group_ID] )
							//lock( pack.card_away_count )
							{
								while( pack.card_away_count[game_index].Count <= card.pack_card_index )
								{
									// expand for number of cards in this game that this pack is...
									pack.card_away_count[game_index].Add( new CardPoints() );
								}

								int pack_points = 0;
								//for( int card = 0; card < count; card++ )

								{
									int away_count = card.BestAway();
									//Log.log( "Card away is " + away_count );
									pack.card_away_count[game_index][card.pack_card_index].away = away_count;
									if( away_count == 1 )
									{
										//if( pack.paper )
										//	pack.card_away_count[game_index][card.pack_card_index].points = paper_one_away;
										//else
										//	pack.card_away_count[game_index][card.pack_card_index].points = electronic_one_away;
									}
									else
										pack.card_away_count[game_index][card.pack_card_index].points = 0;

#if old_scoring_system
									DataRow[] value = points.Select( "away_count=" + away_count );
									if( value.Length > 0 )
										//best_packs[set - 1].points += Convert.ToInt32( value[0]["points"] );
										pack.card_away_count[game_index][card.pack_card_index].points = Convert.ToInt32( value[0]["points"] );

									pack.card_away_count[game_index][card.pack_card_index].away = away_count;
									//if( away_count > 0 )
									//player_totals[player.ID, pack_number, away_count]++;
									totals[away_count]++;
									//player_totals[player.ID, set, away_count]++;
#endif
#if using_absolute_best_cards
									if( max_rated_cards == 0 ||
											bests.Count < max_rated_cards )
									{
										//Log.log( "less than 84... adding " + away_count );
										bests.Add( new PlayerBestCard( pack_number, card_id, player, away_count ) );
									}
									else
									{
										int worst_away = 0;
										foreach( PlayerBestCard a in bests )
										{
											if( a.away_count > worst_away )
												worst_away = a.away_count;
										}
										//Log.log( "worst is " + worst_away + " this is " + away_count );
										if( worst_away > away_count )
										{
											// okay there is a card worse than this somewhere... get it and replace it.
											int swapout = bests.FindIndex( delegate( PlayerBestCard a ) { return ( a.away_count == worst_away ); } );
											if( swapout >= 0 )
											{
												//Log.log( "swapping " + swapout );
												bests[swapout] = new PlayerBestCard( pack_number, card_id, player, away_count );
											}
										}
									}
#endif
								}
							}
							count += s.game.GetCardCount( pack.pack_info );
						}

					}
				}
				else
				{
#if asdfasdf
					for( int player = 0; player < ( s.Players ); player++ )
					{
						for( int _card = 0; _card < ( s.Cards ); _card++ )
						{
							int card = player * s.Cards + _card;
							//Console.WriteLine( card+"=="+ s.playing_card_away[card, s.bestwin] );
							totals[s.playing_card_away[card, s.bestwin - 1]]++;
							player_totals[player, _card / s.PackSize, s.playing_card_away[card, s.bestwin - 1]]++;
						}
					}
#endif
				}
				//s.playing_card_away_totals = totals;
				//s.playing_card_away_pack_player_totals = player_totals;
				//s.playing_card_away_totals_limited = limited_totals;
				//s.playing_card_away_pack_player_totals_limited = limited_player_totals;
			}
			return true;
		}
Esempio n. 25
0
 void Events_GameChanged(object sender, BingoEvents.BingoSimpleIntEventArgs e)
 {
     game_state = session_event.StepTo(e.arg);
 }