def test_incomplete_detective_same_as_no_detective(): _, _, games = new_game(2, 19, 0, 0) gwd = mafia.eval_strat_rc(games, original_strat) _, _, dgames = new_game(2, 18, 1, 0) dwd = mafia.eval_strat_rc(dgames, incomplete_detective) assert mafia.winner_probabilities(games, gwd) == mafia.winner_probabilities( dgames, dwd)
def test_proper_detective_beats_incomplete_detective(): _, _, games = new_game(2, 18, 1, 0) idwd = mafia.eval_strat_rc(games, incomplete_detective) pdwd = mafia.eval_strat_rc(games, proper_detective) imw, icw = mafia.winner_probabilities(games, idwd) pmw, pcw = mafia.winner_probabilities(games, pdwd) # proper detective wins more often assert pcw > icw
def test_all_peeks_verified_after_detective_out(): dpl, dgs, dgame = new_game(2, 5, 1, 0) igs = get_all_incomplete_gs(dgame) bad_states = [] for i in igs: if (i.players[mafia.PType.PeekedMafia] > 0 or i.players[mafia.PType.PeekedCitizen] > 0 ) and i.players[mafia.PType.VerifiedDetective] > 0: bad_states.append(i) assert len(bad_states) == 0
def test_strategy_with_detective_sum_is_one(): pl, gs, games = new_game(2, 4, 1, 0) mgs, cgs, dgs = [ x.data[1] for x in games[0].children(games[0].root) if x.data[0] != "Detective Out" ] mgs_outcomes = incomplete_detective(mgs) cgs_outcomes = incomplete_detective(cgs) dgs_outcomes = incomplete_detective(dgs) assert sum(mgs_outcomes.values()) == 1 assert sum(cgs_outcomes.values()) == 1 assert sum(dgs_outcomes.values()) == 1
def test_new_game(self): data = main.new_game() expected_data = [[None, None, None, None, None, None, None, None], ['b', 'b', 'b', 'b', 'b', 'b', 'b', 'b'], [None, None, None, None, None, None, None, None], [None, None, None, None, None, None, None, None], [None, None, None, None, None, None, None, None], [None, None, None, None, None, None, None, None], ['w', 'w', 'w', 'w', 'w', 'w', 'w', 'w'], [None, None, None, None, None, None, None, None]] self.assertEqual(expected_data, data)
def test_leaves_match_children(): """ All leaves that aren't game ending should have a corresponding starter node in the next days' game tree. This isn't checked right now until a strategy is evaluated. """ pl, gs, games = new_game(2, 18, 1, 0) for idx, t in enumerate(games): for node in t.leaves(): if mafia.winner(node.data[1]) != 0: continue else: targets = [] for x in games[idx + 1].children(games[idx + 1].root): if x.data[1] == node.data[1]: targets.append(x.identifier) assert len(targets) == 1
if map[row][col][1]: columns.append(str(map[row][col][0])) else: columns.append(' ') print(row + 1, '|', ' | '.join(columns), '|') print(' ', '-' * 33) if __name__ == "__main__": ''' ========== EXAMPLES BELLOW ========== ''' from main import new_game, losses, get_input, uncover, wins game_map = new_game() while True: print_map(game_map) if wins(game_map): print('Congratulations! You win!') print('Thank you for playing Minesweeper!') break elif losses(game_map): print('Oh no! You lose!') print('Thank you for playing Minesweeper!') break values = get_input(game_map)
def original_game(): pl, gs, games = new_game(2, 19, 0, 0) weight_dict = mafia.eval_strat_rc(games, original_strat) return pl, gs, games, weight_dict
def test_can_play_proper_detective(): pl, gs, games = new_game(2, 18, 1, 0) weight_dict = mafia.eval_strat_rc(games, proper_detective) mafia_win, citizen_win = mafia.winner_probabilities(games, weight_dict) assert mafia_win + citizen_win == 1
def test_incomplete_detective_original_strat_same(): pl, gs, games = new_game(2, 19, 0, 0) weight_dict_original = mafia.eval_strat_rc(games, original_strat) weight_dict_simple = mafia.eval_strat_rc(games, incomplete_detective) assert weight_dict_original == weight_dict_simple
def initUI(self): self.board.title("Settlers of Catan - Play") self.board.geometry(self.style.board_geometry) # Create splash window # global splash self.splash = Toplevel(background=self.style.menu_color) #splash.geometry("400x300+100+100") self.splash.title("Settlers of Catan - Welcome") # global splash_canvas # splash_canvas = Canvas(self.splash, background=menu_color) # Welcome text game_label = Label(self.splash, text="Settlers of Catan", font=(self.style.txt_font,36), background=self.style.menu_color) game_label.pack() version_label = Label(self.splash, text="Version "+version, font=(self.style.txt_font,18), background=self.style.menu_color) version_label.pack(pady=30) # Buttons play_button = Button(self.splash, font=(self.style.txt_font,16), text="Local Game", command=lambda : new_game(self)) play_button.configure(width=20, activebackground=self.style.active_button_color) play_button.pack(pady=10) start_button = Button(self.splash, font=(self.style.txt_font,16), text="New Remote Game", command=lambda : remote_game(self)) start_button.configure(width=20, activebackground=self.style.active_button_color) start_button.pack(pady=10) load_button = Button(self.splash, font=(self.style.txt_font,16), text="Load Remote Game", command=lambda : load_game(self)) load_button.configure(width=20, activebackground=self.style.active_button_color) load_button.pack(pady=10) quit_button = Button(self.splash, font=(self.style.txt_font,16), text="Quit", command=self.quit) quit_button.configure(width=10, activebackground=self.style.active_button_color) quit_button.pack(pady=10) # Create player selection window # global player_window self.player_window = Toplevel(background=self.style.menu_color) #self.player_window.geometry("470x350+300+100") self.player_window.title("Settlers of Catan - Select Players") # global player_1_type,player_1_name, player_2_type,player_2_name # global player_3_type,player_3_name, player_4_type,player_4_name player_type_options = ["Human","Computer","None"] player_1_label = Label(self.player_window, text="Player 1:", font=(self.style.txt_font,22), background=self.style.menu_color) player_1_label.grid(row=0,column=0,padx=20,pady=10) self.player_1_type = StringVar() self.player_1_type.set(player_type_options[1]) player_1_type_menu = OptionMenu(self.player_window, self.player_1_type, *player_type_options) player_1_type_menu.grid(row=1,column=0,padx=20,pady=10) self.player_1_name = StringVar() self.player_1_name.set("Player 1") player_1_name_entry = Entry(self.player_window, textvariable=self.player_1_name) player_1_name_entry.grid(row=2,column=0,padx=20,pady=5) player_2_label = Label(self.player_window, text="Player 2:", font=(self.style.txt_font,22), background=self.style.menu_color) player_2_label.grid(row=0,column=1,padx=20,pady=10) self.player_2_type = StringVar() self.player_2_type.set(player_type_options[1]) player_2_type_menu = OptionMenu(self.player_window, self.player_2_type, *player_type_options) player_2_type_menu.grid(row=1,column=1,padx=20,pady=10) self.player_2_name = StringVar() self.player_2_name.set("Player 2") player_2_name_entry = Entry(self.player_window, textvariable=self.player_2_name) player_2_name_entry.grid(row=2,column=1,padx=20,pady=5) player_3_label = Label(self.player_window, text="Player 3:", font=(self.style.txt_font,22), background=self.style.menu_color) player_3_label.grid(row=3,column=0,padx=20,pady=10) self.player_3_type = StringVar() self.player_3_type.set(player_type_options[1]) player_3_type_menu = OptionMenu(self.player_window, self.player_3_type, *player_type_options) player_3_type_menu.grid(row=4,column=0,padx=20,pady=10) self.player_3_name = StringVar() self.player_3_name.set("Player 3") player_3_name_entry = Entry(self.player_window, textvariable=self.player_3_name) player_3_name_entry.grid(row=5,column=0,padx=20,pady=5) player_4_label = Label(self.player_window, text="Player 4:", font=(self.style.txt_font,22), background=self.style.menu_color) player_4_label.grid(row=3,column=1,padx=20,pady=10) self.player_4_type = StringVar() self.player_4_type.set(player_type_options[1]) player_4_type_menu = OptionMenu(self.player_window, self.player_4_type, *player_type_options) player_4_type_menu.grid(row=4,column=1,padx=20,pady=10) self.player_4_name = StringVar() self.player_4_name.set("Player 4") player_4_name_entry = Entry(self.player_window, textvariable=self.player_4_name) player_4_name_entry.grid(row=5,column=1,padx=20,pady=5) # global button_chosen self.button_chosen = IntVar() self.button_chosen.set(-1) ready_button = Button(self.player_window, font=(self.style.txt_font,16), text="Okay", command=lambda : self.set_button_chosen(1)) ready_button.configure(width=10, activebackground=self.style.active_button_color) ready_button.grid(row=6,pady=30,columnspan=2) # Hide player selection window self.player_window.withdraw() # Create board window's canvas and items # global board_canvas self.board_canvas = Canvas(self.board, background=self.style.background_color) self.board_canvas.pack(fill=BOTH, expand=1) # Generate 49 tiles # global tiles self.pieces.tiles = [] for i in range(49): self.pieces.tiles.append(Tile(i)) draw_tile_skeleton(self) # global click_x,click_y self.click_x = IntVar() # Tkinter variable that can be watched self.click_y = IntVar() # Tkinter variable that can be watched self.click_x.set(0) self.click_y.set(0) # Define board bindings & protocols def click_set(event): """On click event, sets the x and y coordinates of the click""" self.click_x.set(event.x) self.click_y.set(event.y) # print(self.click_x.get(),self.click_y.get()) def reset_size(event): """Resizes board elements when the window size is changed.""" win_width = event.width win_height = event.height self.style = Style(win_width,win_height) redraw_board(self) def user_closed(): """Closes board window nicely if user manually closes it.""" # Later may use this to create saves # Get out of any waiting that was happening self.set_button_chosen(-1) click_set(Point(0,0,0)) # Just needs to have .x and .y attributes # Clear board self.board_canvas.delete(ALL) # Close all windows close_all(self) # Set board bindings & protocols self.board_canvas.bind("<Button-1>", click_set) self.board_canvas.bind("<Configure>", reset_size) self.board.protocol("WM_DELETE_WINDOW", user_closed) # Prevent manual closing of player window self.player_window.protocol("WM_DELETE_WINDOW", user_closed) # Hide board window self.board.withdraw()