def main(): g = Klondike.new_game(False) print_game(g); print() game_state = 'Won' while not game_won(g): code, *instr = new_find_move(g) print(f'Code: {code!s}, instr: {instr}') if code == MOVE_CODE.DRAW: g.stock, g.pile = draw(g.stock, g.pile) elif code == MOVE_CODE.T_TO_F: g.tableaus[instr[0]], g.foundations[instr[1]] = move(1, g.tableaus[instr[0]], g.foundations[instr[1]]) elif code == MOVE_CODE.T_TO_T: g.tableaus[instr[0]], g.tableaus[instr[1]] = move(instr[2], g.tableaus[instr[0]], g.tableaus[instr[1]]) elif code == MOVE_CODE.P_TO_F: g.pile, g.foundations[instr[0]] = move(1, g.pile, g.foundations[instr[0]]) elif code == MOVE_CODE.P_TO_T: g.pile, g.tableaus[instr[0]] = move(1, g.pile, g.tableaus[instr[0]]) elif code == MOVE_CODE.ERROR: print('Cannot find any valid moves!') game_state = 'Over' break print_game(g) print() print(f'Game {game_state}')
def test_winrate(): wins: int = 0 random.seed(21522) for i in range(1000): g = Klondike.new_game() consecutive_draws = 0 while not game_won(g) and consecutive_draws < 24: code, *instr = new_find_move(g) if code == MOVE_CODE.DRAW: consecutive_draws += 1 g.stock, g.pile = draw(g.stock, g.pile, nb_cards=1) elif code == MOVE_CODE.T_TO_F: consecutive_draws = 0 g.tableaus[instr[0]], g.foundations[instr[1]] = move(1, g.tableaus[instr[0]], g.foundations[instr[1]]) elif code == MOVE_CODE.T_TO_T: consecutive_draws = 0 g.tableaus[instr[0]], g.tableaus[instr[1]] = move(instr[2], g.tableaus[instr[0]], g.tableaus[instr[1]]) elif code == MOVE_CODE.P_TO_F: consecutive_draws = 0 g.pile, g.foundations[instr[0]] = move(1, g.pile, g.foundations[instr[0]]) elif code == MOVE_CODE.P_TO_T: consecutive_draws = 0 g.pile, g.tableaus[instr[0]] = move(1, g.pile, g.tableaus[instr[0]]) if game_won(g): wins += 1 assert wins > 290 print(f'wins:\t\t{wins}\nlosses:\t\t{1000-wins}\npercentage:\t{wins/10}%')
def build_test_games() -> Tuple[Klondike, Klondike, Klondike, Klondike]: # No games are shuffled, to avoid random stuff game2 = Klondike.new_game(False) game2.stock, game2.pile = draw(game2.stock, game2.pile) game4 = deepcopy(game2) game4.tableaus[1], game4.tableaus[2] = move(1, game4.tableaus[1], game4.tableaus[2]) game4.tableaus[3], game4.tableaus[4] = move(1, game4.tableaus[3], game4.tableaus[4]) game4.tableaus[5], game4.tableaus[6] = move(1, game4.tableaus[5], game4.tableaus[6]) game4.tableaus[5], game4.tableaus[6] = move(1, game4.tableaus[5], game4.tableaus[6]) game3 = deepcopy(game4) game3.pile, game3.tableaus[2] = move(1, game3.pile, game3.tableaus[2]) game3.pile, game3.tableaus[0] = move(1, game3.pile, game3.tableaus[0]) game3.pile, game3.tableaus[1] = move(1, game3.pile, game3.tableaus[1]) game3.stock, game3.pile = draw(game3.stock, game3.pile) game3.pile, game3.tableaus[2] = move(1, game3.pile, game3.tableaus[2]) game3.stock, game3.pile = draw(game3.stock, game3.pile) game3.stock, game3.pile = draw(game3.stock, game3.pile) game3.pile, game3.tableaus[2] = move(1, game3.pile, game3.tableaus[2]) game3.stock, game3.pile = draw(game3.stock, game3.pile) game3.stock, game3.pile = draw(game3.stock, game3.pile) game3.stock, game3.pile = draw(game3.stock, game3.pile) game1 = deepcopy(game3) game1.pile, game1.foundations[0] = move(1, game1.pile, game1.foundations[0]) game1.stock, game1.pile = draw(game1.stock, game1.pile) game1.pile, game1.foundations[1] = move(1, game1.pile, game1.foundations[1]) game1.pile, game1.foundations[2] = move(1, game1.pile, game1.foundations[2]) game1.pile, game1.foundations[3] = move(1, game1.pile, game1.foundations[3]) game1.pile, game1.foundations[1] = move(1, game1.pile, game1.foundations[1]) game1.pile, game1.foundations[2] = move(1, game1.pile, game1.foundations[2]) game1.pile, game1.foundations[3] = move(1, game1.pile, game1.foundations[3]) game1.pile, game1.foundations[0] = move(1, game1.pile, game1.foundations[0]) game1.pile, game1.foundations[1] = move(1, game1.pile, game1.foundations[1]) return game2, game4, game3, game1
def test_draw(stock: List[Card], pile: List[Card], exp_lens: Dict[str, int]): _stock, _pile = draw(stock, pile, nb_cards=3) assert len(_stock) == exp_lens['stock'] assert len(_pile) == exp_lens['pile']
'L: Klettern': {'name': 'L: Klettern', 'max': 10, 'users': [] }, 'E: Badminton': {'name': 'E: Badminton', 'max': 10, 'users': [] }, 'L: Segeln': {'name': 'L: Segeln', 'max': 10, 'users': [] }, 'M: Fußball': {'name': 'M: Fußball', 'max': 10, 'users': [] } } """ def process(user): return logic.attach_importance(logic.normalize(user)) users = map(process, users) print 'Users: %d Courses: %d' % (len(users), len(courses.values())) print 'Begin selection process ... (This may take a while)' logic.draw(users, logic.Q1, list(courses.values())) logic.draw(users, logic.Q2, list(courses.values())) writer = csv.DictWriter(open('output.csv', 'w'), ('Anmeldename', 'Q1', 'Q1-Rating', 'Q2', 'Q2-Rating')) for user in users: def index(year): index = 1 for selection in user['selection'][year]: if selection['name'] == user['result'][year]: return str(index) index += 1 return '-1' writer.writerow({'Anmeldename': user['login'], 'Q1': user['result'][logic.Q1],
gamestate = 5 if currentlevel.check_if_exit(): gamestate = 3 sound.stop_music() sound.play_door() screen.fill(color.BLACK) pygame.display.flip() pygame.time.wait(3000) currentlevelno += 1 if currentlevelno == logic.maxlevels: gamestate = 6 currentlevelno = logic.maxlevels - 1 currentlevel = logic.levellist[currentlevelno] logic.player1.x, logic.player1.y = currentlevel.start logic.game(currentlevel) logic.draw(currentlevel, screen, seconds, debug) group.update(ticks) group.draw(screen) for event in pygame.event.get(): logic.handle_inputs(logic.player1, event) if event.type == pygame.QUIT: gamestate = 0 if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: gamestate = 0 if event.key == pygame.K_BACKQUOTE: debug = not debug if gamestate == 5: menu_items = ('Game Over', 'Better luck next time!') gm = titles.Screen(screen, menu_items) gm.run()
'L: Segeln': {'name': 'L: Segeln', 'max': 10, 'users': [] }, 'M: Fußball': {'name': 'M: Fußball', 'max': 10, 'users': [] } } """ def process(user): return logic.attach_importance(logic.normalize(user)) users = map(process, users) print 'Users: %d Courses: %d' % (len(users), len(courses.values())) print 'Begin selection process ... (This may take a while)' logic.draw(users, logic.Q1, list(courses.values())) logic.draw(users, logic.Q2, list(courses.values())) writer = csv.DictWriter(open('output.csv', 'w'), ('Anmeldename', 'Q1', 'Q1-Rating', 'Q2', 'Q2-Rating')) for user in users: def index(year): index = 1 for selection in user['selection'][year]: if selection['name'] == user['result'][year]: return str(index) index += 1 return '-1'