public static void ComputePrizes(BingoGameEvent game_event, BingoGame game, List <wininfo> winners) { foreach (wininfo winner in winners) { foreach (BingoPrize prize in winner.prize_levels) { int total = 0; foreach (wininfo winner_with_prize in winners) { if (winner == winner_with_prize) { continue; } foreach (BingoPrize winner2_prize in winner.prize_levels) { if (winner2_prize.level.Equals(prize.level)) { total++; break; } } } long change; long value = prize.amount / total; if ((change = value % 100) > 0) { value += 100; value -= change; } winner.amount += value; } } }
public BingoGameState StepReplay(bool use_blower) { // get one game of all the ones defined in the bingo core state... lock (this.step_lock) { BingoGame game = null; if (session.GameList == null) { return(null); } if (session.GameList.Count == 0) { // return an early result (no process) return(null); } { 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(StepToReplay(current_game_index++)); } }
public static BingoGameEvent Continue(BingoGameEvent prior_event, BingoGame new_game) { if (prior_event != null) { //this.game_event_row = game_event_data_table_row; prior_event.games.Add(new_game); } return(prior_event); }
/// <summary> /// Result game event is sourced by external or existing number generator... /// </summary> public BingoGameEvent(BingoGame game, BallDataInterface bdi = null) { this.games.Add(game); if (bdi != null) { this.ball_interface = bdi; } //game. }
/// <summary> /// this Loads the prize-validation balls for the given session/game_number /// </summary> /// <param name="dsn"></param> /// <param name="session"></param> /// <param name="game_number"></param> public BingoGameEvent(DsnConnection dsn, BingoSessionEvent session, int game_index) { List <byte> ball_list = new List <byte>(); int game_id = 0; int game_num = session.session.GameList[game_index].game_number; bool did_next; int start = 0; #if !use_prize_validations_for_balls do { MySQLDataTable win_table = new MySQLDataTable(dsn , "select bingo_game_id,ball from bingo_game_balls" + " join bingo_game using(bingo_game_id)" + " where bingoday=" + DsnSQLUtil.MakeDateOnly(dsn, session.bingoday) + " and session=" + session.session_number + " and game=" + game_num + " and uncalled=0" + " order by game desc,bingo_game_id desc,called_at desc,bingo_game_ball_id desc" ); if (win_table != null && win_table.Rows.Count > 0) { int max_row; for (max_row = 0; max_row < win_table.Rows.Count; max_row++) { int this_row_game_id = Convert.ToInt32(win_table.Rows[max_row]["bingo_game_id"]); if (game_id == 0) { game_id = this_row_game_id; } if (this_row_game_id == game_id) { ball_list.Add(Convert.ToByte(win_table.Rows[max_row]["ball"])); } else { break; } } if (game_num == 2) { start = 1; } } game_id = 0; did_next = false; if (session.session.GameList[game_index].into) { BingoGame game = session.session.GameList[game_index]; BingoGame next_game = game.prior_group_game; if (next_game == null) { next_game = game.prior_game; if (next_game.game_number == game.game_number) { next_game = game.prior_group_game; } } if (next_game != null) { game_index = session.session.GameList.IndexOf(next_game); game_num = session.session.GameList[game_index].game_number; did_next = true; } } }while(did_next); playing_balls = new int[ball_list.Count]; for (int row = start; row < ball_list.Count; row++) { playing_balls[row - start] = ball_list[(ball_list.Count - row) - 1]; } #else // this data should be represented as a ball data... MySQLDataTable win_table = new MySQLDataTable(dsn , "select ball_list,balls from prize_validations where bingoday=" + DsnSQLUtil.MakeDateOnly(dsn, session.bingoday) + " and session_id=" + session.session_number + " and game_id=" + session.session.GameList[game_index].game_number + " group by ball_list,balls" + " order by ID desc" ); if (win_table != null && win_table.Rows.Count > 0) { int nRow; for (nRow = 0; nRow < win_table.Rows.Count; nRow++) { if (Convert.ToInt32(win_table.Rows[nRow]["balls"]) >= 75) { continue; } DataRow win = win_table.Rows[nRow]; String string_numbers = win["ball_list"].ToString(); int count = Convert.ToInt32(win["balls"]); String[] numbers = string_numbers.Split(); playing_balls = new int[numbers.Length]; for (int n = 0; n < count; n++) { if (numbers[n].Length > 0) { playing_balls[n] = Convert.ToByte(numbers[n]); } } break; } } #endif }
// double action determines whether card[X,,] goes from 0-0 or 0-1 (triple action? 0-2?) // check one card, get the best mask, and the best count_away // return the number of balls in ball array it won on. public static bool check_single_card( BingoCardState card , BingoGameEvent game_event , int game_index , int[] playing_balls , int faces , int columns , int pattern_index ) { int mark_count = 0; if (card.pack.pack_info.flags.big3) { card.CheckBig3(card.marks[0]); } else { //foreach( BingoGame game in game_event.games ) BingoGame game = game_event.games[game_index]; { foreach (Pattern pattern in game.patterns) { BingoCardState.BingoCardPatternMarkInfo marks = card.GetCurrentMark(pattern_index); switch (pattern.algorithm) { case PatternDescriptionTable.match_types.ExternalJavaEngine: break; default: if (card.MarkNew(marks, faces, columns, playing_balls)) { mark_count++; } break; } } } if (mark_count == 0) { return(false); } { // get last marked cardmask //foreach( BingoGame game in game_event.games ) { if (game.patterns[0].algorithm == PatternDescriptionTable.match_types.CrazyMark) { return(card.CheckCrazy(card.marks[0], game.patterns[0].repeat_count)); } else if (game.patterns[0].algorithm == PatternDescriptionTable.match_types.ExternalJavaEngine) { //return } else { List <int> patterns = game.pattern_list.pattern_bitmask_list; //foreach ( int check_mask in patterns ) { if (card.CheckPattern(card.marks[0], patterns)) { card.WinningGame = game; card.WinningGameEvent = game_event; return(true); } } // end of foreach( pattern ) } } } } return(false); }
// 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); } }
public BingoGame(BingoGameList game_list, DataRow group_game) { BingoGame _game = ((game_list.Count > 0) ? game_list[game_list.Count - 1] : null); ScheduleDataSet schedule = game_list.schedule; Init(); Name = group_game.ToString(); game_number = Convert.ToInt32(group_game[SessionGame.NumberColumn]); //game_list. //dataRow_game_group_game = group_game; { DataRow[] tmp = group_game.GetChildRows("session_game_has_session_game_group"); int n = 0; foreach (DataRow row in tmp) { BingoGameGroup bgg; this.game_group = bgg = game_list.game_group_list.GetGameGroup(row.GetParentRow("session_game_group_in_session_game")); bgg.Add(this); { DataRow session_game_group = row.GetParentRow("session_game_group_in_session_game"); DataRow[] game_prizes = session_game_group.GetChildRows("game_group_has_pack"); //DataRow[] game_prizes = group_packs. //DataRow[] game_group_prizes = game_group_row.GetChildRows( "game_group_has_prize_level" ); foreach (DataRow game_prize in game_prizes) { DataRow _prize = game_prize.GetParentRow("prize_level_in_game_group"); if (_prize[PrizeLevelNames.PrimaryKey] == null) { int a = 3; } prizes.Add(new BingoPrize(_prize[PrizeLevelNames.PrimaryKey], 50)); } // should further check against overrides to get corrected prizes. } } } { Patterns new_patterns = new Patterns(schedule); DataRow[] GamePatterns = schedule.game_patterns.GetPatterns(group_game); //Log.log( "Selected " + GamePatterns.Length + " game pattes for " + group["game_info_id"] ); foreach (DataRow pattern in GamePatterns) { object pattern_id = pattern[schedule.patterns.PrimaryKeyName]; Log.log("Looking up pattern " + pattern_id); Pattern GamePattern = new Pattern(pattern, new_patterns); new_patterns.Add(GamePattern); } SetPatterns(new_patterns.ToArray()); } if (Convert.ToBoolean(group_game["single_hotball"])) { cashballs = 1; } //double_action = Convert.ToBoolean( group_game["double_action"] ); // Load all of the packs defined in this session. // these are used to validate sales loaded into players.... // they are also used to collect raw informatino to match by name // the pack sales to pack definitions such ad dealer parameters. DataRow[] game_group_packs; { game_group_packs = schedule.session_games.GetGameGroupPacks(group_game); BingoPack pack = null; if (game_group_packs != null) { foreach (DataRow info in game_group_packs) { BingoGameGroup use_group = null; bool found = false; //foreach( BingoGameGroup game_group in game_groups ) { DataRow real_game_group = info.GetParentRow("game_group_prize_level_has_pack"); if (game_group.ID.Equals(real_game_group[PackGroupTable.PrimaryKey])) { use_group = game_group; found = true; break; } } if (!found) { game_group = use_group = new BingoGameGroup(info[PackGroupTable.PrimaryKey]); } game_group_packs = schedule.session_games.GetPacks(group_game); foreach (DataRow ggp in game_group_packs) { pack = game_list.pack_list.MakePack(use_group, ggp); while (pack_card_counts.Count <= pack.pack_type) { pack_card_counts.Add(0); } } if (pack == null) { } if (pack != null) { pack_card_counts[pack.pack_type] = pack.count; } } } prior_group_game = null; foreach (BingoGame g in game_list) { if (g == this) { continue; } //foreach( BingoGameGroup gamegroup in g.game_groups ) { //foreach( BingoGameGroup this_group in this.game_groups ) if (g.game_group != null && this.game_group != null) // this isn't set during loading... { if (g.game_group.ID.Equals(this.game_group.ID)) { prior_group_game = g; break; } } } } if (prior_group_game == null) { page_skip = 0; // this isn't really an into, prior game might be 'normal' progressive, but // that's really into the next part, not this one. into = false; } else if (into) { page_skip = prior_group_game.page_skip; } else { page_skip = prior_group_game.page_skip + 1; } //game_group_id = group_id; } // setup progressive game, and game skips (by page, and by absolute ball-set) { progressive = (Convert.ToInt32(group_game["progressive"]) != 0); if (_game != null) { if (_game.progressive) { ballset_number = _game.ballset_number; into = true; } else { ballset_number = _game.ballset_number + 1; } } else { ballset_number = 0; } } // setup page_skip. { if (prior_group_game == null) { page_skip = 0; // this isn't really an into, prior game might be 'normal' progressive, but // that's really into the next part, not this one. into = false; } else if (into) { page_skip = prior_group_game.page_skip; } else { page_skip = prior_group_game.page_skip + 1; } } //game_number = game_number; prior_game = _game; //_game = game; }