How to use current_score method in hypothesis

Best Python code snippet using hypothesis

Game_01.py

Source:Game_01.py Github

copy

Full Screen

1# for demp purposes2# cs 491 final project34#Hello5import random6789def create_deck():10 """ Takes no parameter11 Returns a 2D-list """1213 # an initially empty deck14 deck = []15 suits = ["SP", "CL", "HR", "DM"]16 faces = []1718 # creates a list of all face values19 for x in range(2, 10):20 faces.append(x)21 # faces = [x for x in range(2,10)] # an alternative technique - list comprehension22 # creates cards [s,f] and inserting them to the deck23 for s in suits:24 for f in faces:25 deck.append([s, f])26 return deck272829def shuffle(deck):30 """Takes a 2D-list31 Returns a shuffled 2D-list"""3233 # copies the deck, so the original deck remains same34 c_deck = deck35 random.shuffle(c_deck)36 return c_deck373839def deal(shuffle_deck):40 """41 Take out first 9 cards42 :param shuffle_deck:43 :return: Board, updated deck44 """45 if len(shuffle_deck) < 32:46 return shuffle_deck.pop(0), shuffle_deck47 board = []48 for _ in range(3):49 row = []50 for _ in range(3):51 row.append(shuffle_deck[0])52 del shuffle_deck[0]53 board.append(row)54 return board, shuffle_deck555657def print_board(board):58 """59 print the board60 :param board:61 :return: None62 """63 for i in board:64 print(end='| ')65 for j in i:66 print(j, end=' |')67 print()686970def update_card(board, new_card, index):71 """72 Updating the board73 :param board:74 :param new_card:75 :param index:76 :return: updated board77 """78 board[index[0]][index[1]] = new_card79 return board808182def verify_matching(board, current_score):83 if board[0][0][0] == board[0][1][0] == board[0][2][0] and board[0][0][1] - board[0][1][1] == board[0][1][1] - \84 board[0][2][1]:85 return True, 25 + current_score, 'Run'86 elif board[1][0][0] == board[1][1][0] == board[1][2][0] and board[1][0][1] - board[1][1][1] == board[1][1][1] - \87 board[1][2][1]:88 return True, 25 + current_score, 'Run'89 elif board[2][0][0] == board[2][1][0] == board[2][2][0] and board[2][0][1] - board[2][1][1] == board[2][1][1] - \90 board[2][2][1]:91 return True, 25 + current_score, 'Run'92 elif board[0][0][0] == board[1][0][0] == board[2][0][0] and board[0][0][1] - board[1][0][1] == board[1][0][1] - \93 board[2][0][1]:94 return True, 25 + current_score, 'Run'95 elif board[0][1][0] == board[1][1][0] == board[2][1][0] and board[0][1][1] - board[1][1][1] == board[1][1][1] - \96 board[2][1][1]:97 return True, 25 + current_score, 'Run'98 elif board[0][2][0] == board[1][2][0] == board[2][2][0] and board[0][2][1] - board[1][2][1] == board[1][2][1] - \99 board[2][2][1]:100 return True, 25 + current_score, 'Run'101 elif board[0][0][0] == board[1][1][0] == board[2][2][0] and board[0][0][1] - board[1][1][1] == board[1][1][1] - \102 board[2][2][1]:103 return True, 25 + current_score, 'Run'104 elif board[0][2][0] == board[1][1][0] == board[2][0][0] and board[0][2][1] - board[1][1][1] == board[1][1][1] - \105 board[2][0][1]:106 return True, 25 + current_score, 'Run'107108 if board[0][0][1] - board[0][1][1] in (-1, 1) and board[0][1][1] - board[0][2][1] in (-1, 1):109 return True, 20 + current_score, 'Simple Run'110 elif board[1][0][1] - board[1][1][1] in (-1, 1) and board[1][1][1] - board[1][2][1] in (-1, 1):111 return True, 20 + current_score, 'Simple Run'112 elif board[2][0][1] - board[2][1][1] in (-1, 1) and board[2][1][1] - board[2][2][1] in (-1, 1):113 return True, 20 + current_score, 'Simple Run'114 elif board[0][0][1] - board[1][0][1] in (-1, 1) and board[1][0][1] - board[2][0][1] in (-1, 1):115 return True, 20 + current_score, 'Simple Run'116 elif board[0][1][1] - board[1][1][1] in (-1, 1) and board[1][1][1] - board[2][1][1] in (-1, 1):117 return True, 20 + current_score, 'Simple Run'118 elif board[0][2][1] - board[1][2][1] in (-1, 1) and board[1][2][1] - board[2][2][1] in (-1, 1):119 return True, 20 + current_score, 'Simple Run'120 elif board[0][0][1] - board[1][1][1] in (-1, 1) and board[1][1][1] - board[2][2][1] in (-1, 1):121 return True, 20 + current_score, 'Simple Run'122 elif board[0][2][1] - board[1][1][1] in (-1, 1) and board[1][1][1] - board[2][0][1] in (-1, 1):123 return True, 20 + current_score, 'Simple Run'124125 if board[0][0][1] == board[0][1][1] == board[0][2][1]:126 return True, 15 + current_score, 'Set'127 elif board[1][0][1] == board[1][1][1] == board[1][2][1]:128 return True, 15 + current_score, 'Set'129 elif board[2][0][1] == board[2][1][1] == board[2][2][1]:130 return True, 15 + current_score, 'Set'131 elif board[0][0][1] == board[1][0][1] == board[2][0][1]:132 return True, 15 + current_score, 'Set'133 elif board[0][1][1] == board[1][1][1] == board[2][1][1]:134 return True, 15 + current_score, 'Set'135 elif board[0][2][1] == board[1][2][1] == board[2][2][1]:136 return True, 15 + current_score, 'Set'137 elif board[0][0][1] == board[1][1][1] == board[2][2][1]:138 return True, 15 + current_score, 'Set'139 elif board[0][2][1] == board[1][1][1] == board[2][0][1]:140 return True, 15 + current_score, 'Set'141142 if board[0][0][0] == board[0][1][0] == board[0][2][0]:143 return True, 10 + current_score, 'Simple Set'144 elif board[1][0][0] == board[1][1][0] == board[1][2][0]:145 return True, 10 + current_score, 'Simple Set'146 elif board[2][0][0] == board[2][1][0] == board[2][2][0]:147 return True, 10 + current_score, 'Simple Set'148 elif board[0][0][0] == board[1][0][0] == board[2][0][0]:149 return True, 10 + current_score, 'Simple Set'150 elif board[0][1][0] == board[1][1][0] == board[2][1][0]:151 return True, 10 + current_score, 'Simple Set'152 elif board[0][2][0] == board[1][2][0] == board[2][2][0]:153 return True, 10 + current_score, 'Simple Set'154 elif board[0][0][0] == board[1][1][0] == board[2][2][0]:155 return True, 10 + current_score, 'Simple Set'156 elif board[0][2][0] == board[1][1][0] == board[2][0][0]:157 return True, 10 + current_score, 'Simple Set'158159 return False, current_score, "Lost"160161162def game(shuffle_deck, continues_steps, board):163 """164 Main game165 :param shuffle_deck:166 :param continues_steps:167 :param board:168 :return: boolean for true or false, score, category of win169 """170 print_board(board)171 choice = input(f'Score: {continues_steps}, Deal or Done? ').lower()172 if choice == 'deal':173 new_card, shuffle_deck = deal(shuffle_deck)174 index = list(map(int, input(f'New card: {new_card}, enter location to replace card <row col>: ').split()))175 board = update_card(board, new_card, index)176 return game(shuffle_deck, continues_steps - 1, board)177 elif choice == 'done':178 t, v, s = verify_matching(board, continues_steps)179 return t, v, s180181182def main():183 # create a deck184 deck = create_deck()185186 # shuffle deck187 shuffle_deck = shuffle(deck)188 board, updated_deck = deal(shuffle_deck)189190 continues_steps = 0191 is_won, score, category = game(shuffle_deck, continues_steps, board)192193 if is_won:194 print(f'Congrats!! You\'ve got a {category} on the board, Score: {score}')195 else:196 print(f'You\'he lost the game with negative score of {score}.')197198199if __name__ == '__main__': ...

Full Screen

Full Screen

app.py

Source:app.py Github

copy

Full Screen

1import os2from dotenv import load_dotenv3from flask import Flask, jsonify, request4from flask_sqlalchemy import SQLAlchemy5from models import PlayerScores6from db import db7#load env variables8load_dotenv()9app = Flask(__name__)10######### Database Configuration ###########11DB_PASSWORD = os.getenv('DB_PASSWORD')12DB_USER = os.getenv('DB_USER')13DB_HOST = os.getenv('DB_HOST')14app.config["SQLALCHEMY_DATABASE_URI"] = f"postgresql://{DB_USER}:{DB_PASSWORD}@{DB_HOST}/mastermind"15app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False16db.init_app(app)17#####################18####### API Routes ############19'''API route to get all player scores and post new scores to database'''20@app.route("/player-scores", methods=['GET', 'POST'])21def player_scores():22 if request.method == 'GET':23 all_scores = PlayerScores.query.all()24 output = []25 for score in all_scores:26 current_score = {}27 current_score['name'] = score.name28 current_score['score'] = score.score29 output.append(current_score)30 31 return jsonify(output)32 if request.method == 'POST':33 player_data = request.get_json()34 player = PlayerScores(name=player_data['name'], score=player_data['score'])35 db.session.add(player)36 db.session.commit()37 38 return jsonify(player_data)39'''API route to get all the scores from a specific player'''40@app.route("/player-scores/<name>", methods=['GET'])41def get_my_score(name):42 scores = PlayerScores.query.filter_by(name=name).all()43 output = []44 for score in scores:45 current_score = {}46 current_score['name'] = score.name47 current_score['score'] = score.score48 output.append(current_score)49 return jsonify(output)50 51'''API route to only return the top 10 scores''' 52@app.route("/high-scores", methods=['GET'])53def high_scores():54 all_scores = PlayerScores.query.all()55 output = []56 for score in all_scores:57 current_score = {}58 current_score['name'] = score.name59 current_score['score'] = score.score60 output.append(current_score)61 62 high_scores = sorted(output, key=lambda d: d['score'], reverse=True)[:10]63 return jsonify(high_scores)64#################################65if __name__ == "__main__":...

Full Screen

Full Screen

task.py

Source:task.py Github

copy

Full Screen

1def task1():2 positions = read_input()3 max_pos = max(positions)4 min_pos = min(positions)5 best_pos = None6 best_score = 10000000000000007 for pos in range(min_pos, max_pos + 1):8 current_score = list(map(lambda x: x - pos, positions))9 current_score = sum([x * (-1) if x < 0 else x for x in current_score])10 if current_score < best_score:11 best_score = current_score12 best_pos = pos13 print(f"Best score {best_score} at position {best_pos}.")14def task2():15 positions = read_input()16 max_pos = max(positions)17 min_pos = min(positions)18 best_pos = None19 best_score = 100000000000000020 for pos in range(min_pos, max_pos + 1):21 current_score = list(map(lambda x: x - pos, positions))22 current_score = [x * (-1) if x < 0 else x for x in current_score]23 current_score = sum([sum(range(1, dist + 1)) for dist in current_score])24 if current_score < best_score:25 best_score = current_score26 best_pos = pos27 print(f"Best score {best_score} at position {best_pos}.")28def read_input():29 with open("input.txt") as file:30 lines = file.readlines()31 lines = [line.strip() for line in lines]32 positions = lines[0].split(',')33 positions = [int(x) for x in positions]34 return positions35if __name__ == "__main__":36 task1()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run hypothesis automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful