def to_table(command, eq_list, keyword_list, prop_dct=None): CONFIG = utils.load_yaml(utils.AUCTION_CONFIG) special_cols = ['thread', 'link', 'date' ] # these have to be added last for formatting reasons # special formatting def format_stats(c): c.max_width = CONFIG[command]['stat_col_width'] return c def format_price(c): c.data = [str(int_to_price(x)) for x in c.data] return c format_rules = dict(stats=format_stats, price=format_price) # get cols col_names = misc.get_col_names( keyword_list=keyword_list, default_cols=CONFIG[command]['default_cols'], key_map=CONFIG['key_map']) cols = misc.get_cols(data=eq_list, special_cols=special_cols, col_names=col_names, format_rules=format_rules, CONFIG=CONFIG) # add date col if 'date' in col_names: data = [] for x in eq_list: x['date'] = epoch_to_date(x['time']) tmp = utils.render(CONFIG['date_template'], x) data.append(tmp) cols.append(Column(data=data, header=CONFIG['equip_headers']['date'])) # add link col if 'link' in col_names: cols.append( Column(data=[x['link'] for x in eq_list], header=CONFIG['equip_headers']['link'], is_link=True)) # add thread col if 'thread' in col_names: cols.append( Column(data=[x['thread'] for x in eq_list], header=CONFIG['equip_headers']['thread'], is_link=True)) # add attrs if requested ret = Table(cols) if prop_dct: for x in prop_dct: ret.__dict__[x] = prop_dct[x] return ret
def __init__(self, name, columns, pk): ncols = [] for col in columns: if col != pk: ncols.append(Column(col, BIGNAME)) else: pkcol = Column(col, BIGNAME) pkcol.constraint.pk = 1 ncols[0:0] = [pkcol] Table.__init__(self, name, ncols)
def __init__(self, table): if not issubclass(table.__class__, Table): raise Error, 'need to pass a Table' table = deepcopy(table) #remove constraints from original table's columns for col in table.columns: col.constraint.clear() table.columns += make_default_log_columns() tablename = 'lp_log_' + table.name Table.__init__(self, tablename, table.columns)
def runTest(self): BinBuilder(self.rouletteWheel) currentTable = Table() currentTable.Table(self.rouletteWheel) player = Passenger57(currentTable) game = RouletteGame(self.rouletteWheel, currentTable) cycleSummary = game.cycle(player) """Se a winning bin, conter o mesmo outcome que uma bet do jogador""" for oc in cycleSummary['activeBets']: self.assertIn(oc, cycleSummary['winningBin'].outcomes)
def setUp(self): # creating wheel with nonrandom value self.notSoRandom = NonRandom() self.notSoRandom.setSeed(33) self.rouletteWheel = Wheel(self.notSoRandom) BinBuilder(self.rouletteWheel) self.currentTable = Table() self.currentTable.Table(self.rouletteWheel) self.currentTable.betMinimum = 5 self.game = RouletteGame(self.rouletteWheel, self.currentTable)
def to_table(command, lst, keyword_list, prop_dct=None): CONFIG = utils.load_yaml(utils.ITEM_CONFIG) special_cols = ['date' ] # these have to be added last for formatting reasons # special formatting def format_stats(c): c.max_width = CONFIG[command]['stat_col_width'] return c def format_price(c): c.data = [str(int_to_price(x)) for x in c.data] return c def format_quant(c): c.data = [f"{int(x):,}" for x in c.orig_data] return c format_rules = dict(stats=format_stats, price=format_price, unit_price=format_price, quantity=format_quant) # get cols col_names = misc.get_col_names( default_cols=CONFIG[command]['default_cols'], key_map=CONFIG['key_map'], keyword_list=keyword_list) cols = misc.get_cols(data=lst, special_cols=special_cols, col_names=col_names, format_rules=format_rules, CONFIG=CONFIG) # add date col if 'date' in col_names: data = [] for x in lst: x['date'] = epoch_to_date(x['time']) tmp = utils.render(CONFIG['date_template'], x) data.append(tmp) cols.append(Column(data=data, header=CONFIG['equip_headers']['date'])) # add attrs if requested ret = Table(cols) if prop_dct: for x in prop_dct: ret.__dict__[x] = prop_dct[x] # return return ret
def phasedout_play(player_id, table, turn_history, phase_status, hand, discard): """phasedout_play returns the best move given the game status.""" # get current game status player = Player(player_id, phase_status[player_id], hand) table = Table(table, turn_history, phase_status, discard) curr_phase = table.status[player_id].phase try: last_move = table.history[-1][-1][-1][0] except IndexError: last_move = 0 analysis = card_count(player, table) best_discard, viable = analysis[0], analysis[1] if last_move == 0 or last_move == 5: if table.discard.name in viable: return (2, table.discard.name) else: return (1, None) # try move 3 if (last_move == 1 or last_move == 2) and curr_phase is None: return phase_play(player, table, best_discard) # phase has been played, try move 4 elif curr_phase is not None: return valid_4s(player, table, best_discard)
def main(): run = True ball1 = Ball(WIN, red, 500, 500, 50, 10, [0, 0]) ball2 = Ball(WIN, blue, 500, 500, 20, 10, [0, 0]) table = Table(WIN, [ball1]) held_object = None time = 0 startx = 0 starty = 0 while run: clock.tick(FPS) if held_object: time += 1 WIN.fill(black) table.update() for event in pygame.event.get(): if not held_object: if event.type == pygame.QUIT: run = False if event.type == pygame.MOUSEBUTTONDOWN: x, y = pygame.mouse.get_pos() for obj in table.objects: if (x - obj.x)**2 + (y - obj.y)**2 <= obj.radius**2: startx = x starty = y held_object = obj obj.change_hold() if held_object: x, y = pygame.mouse.get_pos() obj.x, obj.y = x, y if event.type == pygame.MOUSEBUTTONUP: obj.V = [ 0.1 * (x - startx) / (0.01 * time), 0.1 * (y - starty) / (0.01 * time) ] time = 0 startx = starty = 0 obj.change_hold() held_object = None pygame.display.update()
def runTest(self): BinBuilder(self.rouletteWheel) currentTable = Table() currentTable.Table(self.rouletteWheel) myOutcome = self.rouletteWheel.getOutcome('Split 5-6') myBet = Bet(10, myOutcome) myOutcome2 = self.rouletteWheel.getOutcome('Number 1') myBet2 = Bet(191, myOutcome2) currentTable.placeBet(myBet) """Exception needs to be raised because the bet exceeds the table limit""" with self.assertRaises(InvalidBet): currentTable.placeBet(myBet2) myOutcome3 = self.rouletteWheel.getOutcome('Black Bet') myBet3 = Bet(75, myOutcome3) currentTable.placeBet(myBet3) """Check if bets are indeed at the table""" activeBets = [x.outcome.name for x in currentTable.__iter__()] self.assertIn(myOutcome, activeBets) self.assertIn(myOutcome3, activeBets)
def __init__(self, name, columns): columns = [Bigname(field) for field in columns] Table.__init__(self, name, columns)
def create_tables(num_of_tables, num): tables = [] i = 0 while i+1 <= num_of_tables: table = Table() bank = Bank() if i + 1 is num_of_tables: if num%3 == 0: for m in range(3): print("Insert the name of player {}".format(i*3 + m + 1)) name = input() player = Player() player.name = name deck = Deck() player.decks.append(deck) table.players.append(player) table.hand = shuffle_cards() table.id = i + 1 bank.name = "Bank" bank.status = False table.bank = bank tables.append(table) if (i*3 + m + 1) == num: break if (num-i*3)%2 == 0 and (num-i*3)//2 == 1: for m in range(2): print("Insert the name of player {}".format(i*3 + m + 1)) name = input() player = Player() player.name = name deck = Deck() player.decks.append(deck) table.players.append(player) table.hand = shuffle_cards() table.id = i + 1 bank.name = "Bank" bank.status = False table.bank = bank tables.append(table) if i*3 + m + 1 == num: break if ((num-3*i)//1) == 1: for m in range(1): print("Insert the name of player {}".format(i*3 + m + 1)) name = input() player = Player() player.name = name deck = Deck() player.decks.append(deck) table.players.append(player) table.hand = shuffle_cards() table.id = i + 1 bank.name = "Bank" bank.status = False table.bank = bank tables.append(table) if (i*3 + m + 1) == num: break else: for m in range(3): print("Insert the name of player {}".format(i*3 + m + 1)) name = input() player = Player() player.name = name deck = Deck() player.decks.append(deck) table.players.append(player) table.hand = shuffle_cards() table.id = i + 1 bank.name = "Bank" bank.status = False table.bank = bank tables.append(table) i = i + 1 return tables
def __init__(self, tablename, related_table, primary_column, other_columns): primary_column.set_fk(related_table) Table.__init__(self, tablename, [primary_column] + other_columns)
def __init__(self, tablename, fieldname): Table.__init__(self, tablename, [PkName(fieldname)])
import re import os from classes import Table as tableClass from classes import FileHandler as file_handler file = file_handler.FileHandler FILE_PATH = "/home/sree/SREEVISHAL/Project/ohr/backend/app/models.py" table_name = input("Enter the sql alchemy model class name:") sql_alchemy_file = open(FILE_PATH, "r").read() tables = re.findall(r"class (.+?)\(Base\):", sql_alchemy_file) if table_name in tables: if not os.path.exists(f"./output/{table_name}"): os.makedirs(f"./output/{table_name}") sql_alchemy_model = file.get_body(FILE_PATH, f"class {table_name}(Base):", f"class {tables[tables.index(table_name) + 1]}(Base):") imports = file.get_body("./template/imports.txt", "{sql_alchemy}", "{/sql_alchemy}", True) result = imports + "\n" + sql_alchemy_model file.writeTo(f"./output/{table_name}/db_model_{table_name}.py", result) table_obj = tableClass.Table(table_name, sql_alchemy_model) table_obj.generate() else: print("Table not found!")
class test_Game(unittest.TestCase): def setUp(self): # creating wheel with nonrandom value self.notSoRandom = NonRandom() self.notSoRandom.setSeed(33) self.rouletteWheel = Wheel(self.notSoRandom) BinBuilder(self.rouletteWheel) self.currentTable = Table() self.currentTable.Table(self.rouletteWheel) self.currentTable.betMinimum = 5 self.game = RouletteGame(self.rouletteWheel, self.currentTable) def tearDown(self): del self.game del self.notSoRandom def test_Player_Passenger57(self): playerPassenger = Passenger57(self.currentTable) playerPassenger.initialBet = 5 expectedStake = [205, 210, 215, 210, 205, 200, 205] for i in range(6): self.game.cycle(playerPassenger, 0) self.assertEqual(playerPassenger.stake, expectedStake[i]) def test_Player_Martingale(self): playerMartingale = Martingale(self.currentTable) playerMartingale.initialBet = 5 expectedStake = [205, 210, 215, 210, 200, 180, 220] """Expect Player to left the game because lack of funds.""" for i in range(6): self.game.cycle(playerMartingale, 0) self.assertEqual(playerMartingale.stake, expectedStake[i]) def test_Player_SevenReds(self): playerSevenReds = SevenReds(self.currentTable) self.notSoRandom.setCustomSequence( [32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33]) for i in range(17): if i == 8: self.assertEqual(playerSevenReds.stake, 190) if i == 16: self.assertEqual(playerSevenReds.stake, 210) self.game.cycle(playerSevenReds, 0) def test_Player_PlayerRandom(self): playerRandom = PlayerRandom(self.currentTable, self.notSoRandom) self.game.cycle(playerRandom, 0) self.assertIn(playerRandom.favoriteBet, self.rouletteWheel.getBin(self.notSoRandom.value)) def test_Player_Player1326(self): player1326 = Player1326(self.currentTable) self.notSoRandom.setCustomSequence( [33, 33, 33, 33, 32, 33, 33, 33, 32, 33, 33, 32, 33, 32]) expectedStake = [ 210, 240, 260, 320, 310, 320, 350, 370, 310, 320, 350, 330, 340, 310 ] for roll in range(14): self.game.cycle(player1326, 0) if roll == 3: # win whole strategy self.assertIsInstance(player1326.state, Player1326ZeroWins) self.assertEqual(player1326.stake, expectedStake[roll]) elif roll == 7: # got three wins self.assertIsInstance(player1326.state, Player1326ThreeWins) self.assertEqual(player1326.stake, expectedStake[roll]) elif roll == 10: # got two wins self.assertIsInstance(player1326.state, Player1326TwoWins) self.assertEqual(player1326.stake, expectedStake[roll]) elif roll == 12: # got one win self.assertIsInstance(player1326.state, Player1326OneWins) self.assertEqual(player1326.stake, expectedStake[roll]) elif roll == 13: # got no wins self.assertIsInstance(player1326.state, Player1326ZeroWins) self.assertEqual(player1326.stake, expectedStake[roll])
def test_Table(self): self.assertEqual(Table().players, []) self.assertEqual(Table().id, 0) self.assertEqual(Table().hand, [])
def main(): data = load_data() fgraph = nx.Graph(data.functions) hgraph = nx.Graph(data.humanppi) T = Table(name='proteindata') for p, ans in data.test1: T.add('Protein', p) T.add('Degree', p.degree(hgraph)) T.add('CP Degree', p.cp_degree(hgraph)) T.add('Fn CP Degree', p.fn_cp_degree(hgraph, fgraph)) T.add('Fn CP Weight', p.fn_cp_weight(hgraph, fgraph)) T.add('Cancer Weight', p.cancerweight(hgraph, fgraph)) T.add('CP Degree Nbrs', p.cp_degree_of_neighbors(hgraph)) T.add('Answer', ans) T.order = [ 'Protein', 'Degree', 'CP Degree', 'Fn CP Degree', 'Fn CP Weight', 'Cancer Weight', 'CP Degree Nbrs', 'Answer' ] write_table_to_file(T, 'test1data.csv')
#Loading modules from classes import Player, CPU, Deck, Table #Build in Python 3.9.2 if __name__ == "__main__": #mainPlayer = Player() C1 = CPU() C2 = CPU() C3 = CPU() table = Table(Player.player_list) #Loop of a game while True: #Loop of a batch table.startup() while table.round != "Stop": #Loop of a round (A player must play 4 times) for _ in range(0, 4): #Players play one at time for player in table.player_list: table.display_round() table.display_top() #mainPlayer.display_hand() #mainPlayer.display_offhand() player.play(table) table.next_round() table.next_batch() input()
from classes import Wheel, Table from player import Martingale, SevenReds, Passenger57, PlayerRandom from roulette import RouletteGame from simulator import Simulator from utility import NonRandom from contextlib import suppress from exceptions import InvalidBet, PlayerError from statistics import IntegerStatistics as stats notSoRandom = NonRandom() notSoRandom.setSeed(4) rouletteWheel = Wheel() BinBuilder(rouletteWheel) rouletteTable = Table() rouletteTable.Table(rouletteWheel) rouletteGame = RouletteGame(rouletteWheel, rouletteTable) rouletteSimulation = Simulator(PlayerRandom(rouletteTable), rouletteGame) (maxima, minima, duration) = rouletteSimulation.gather() zipped = zip(maxima, minima, duration) print('{:>7} {:>4} {:>4} {:>3}'.format('Session', 'Max', 'Min', 'Dur')) for i, (a, b, c) in enumerate(zipped): print('{:>7} {:>4} {:>4} {:>2}'.format(i + 1, a, b, c)) print('Mean of maximum values: {}'.format(stats.mean(maxima))) print('Standard deviation of maximum: {}'.format(stats.stdev(maxima))) print('Mean of minima values: {}'.format(stats.mean(minima)))
def main(): data = load_data() fgraph = nx.Graph(data.functions) hgraph = nx.Graph(data.humanppi) T = Table(name='proteindata') for p, ans in data.test1: T.add('Protein', p) T.add('Degree', p.degree(hgraph) ) T.add('CP Degree', p.cp_degree(hgraph) ) T.add('Fn CP Degree', p.fn_cp_degree(hgraph, fgraph) ) T.add('Fn CP Weight', p.fn_cp_weight(hgraph, fgraph)) T.add('Cancer Weight', p.cancerweight(hgraph, fgraph)) T.add('CP Degree Nbrs', p.cp_degree_of_neighbors(hgraph)) T.add('Answer', ans) T.order = ['Protein', 'Degree', 'CP Degree', 'Fn CP Degree', 'Fn CP Weight', 'Cancer Weight', 'CP Degree Nbrs', 'Answer'] write_table_to_file(T, 'test1data.csv')
def phasedout_is_valid_play(play, player_id, table, turn_history, phase_status, hand, discard): """phasedout_is_valid_play returns validity of "play" given game status.""" curr_player = Player(player_id, phase_status[player_id], hand) stats = Table(table, turn_history, phase_status, discard) return stats.check_play(play, curr_player)