Example #1
0
def players_embed():
    """
    Returns a embed message with the list of current players.
    """
    players = get_players()
    embed = discord.Embed(title='Player list',
                          description='Current players in game',
                          colour=discord.Colour.dark_magenta(),
                          url=SERVER + INFO)
    embed.set_footer(text='https://risenfromashes.us/', )
    embed.set_thumbnail(
        url=
        'https://risenfromashes.us/phpBB3/styles/digi_darkblue/theme/images/logo.png'
    )
    middle = len(players) // 2
    pplayers1 = '{}'.format('\n'.join([
        '**{}**\n> score: {}\n> ping: {}\n'.format(player[0], player[1],
                                                   player[2])
        for player in players[:middle]
    ]))
    pplayers2 = '{}'.format('\n'.join([
        '**{}**\n> score: {}\n> ping: {}\n'.format(player[0], player[1],
                                                   player[2])
        for player in players[middle:]
    ]))
    logging.info(pplayers1)
    logging.info(pplayers2)
    embed.add_field(name='🎮', value=pplayers1, inline=False)
    embed.add_field(name='🕹', value=pplayers2, inline=False)
    return embed
Example #2
0
def add_stats():
	if users.is_admin():
		form = StatForm(request.form)

		if request.method == "GET":
			games = events.get_games()
			games_list =  [(g[2], (str(g[0]) + " " + g[1])) for g in games]
			games_list.append([0, "Valitse ottelu"])
			pl_list = players.get_players()
			player_list = [(pl[3], (str(pl[2]) + " " + pl[0] + " " + pl[1])) for pl in pl_list]
			player_list.append([0, "Valitse pelaaja"])
			form.player_id.choices = player_list
			form.event_id.choices = games_list
			return render_template("add_stats.html", form=form)

		if request.method == "POST":
			if users.get_csrf_token() != form.csrf_token.data:
				return render_template("error.html", message="Kielletty!")

			if form.submit.data:
				if form.event_id.data != "0" and form.player_id.data != "0":
					stats.add_game_stats(form.event_id.data, form.player_id.data, form.min.data, form.fg.data, form.fg_a.data, form.three.data, form.three_a.data, form.ft.data, form.ft_a.data,
					form.dreb.data, form.oreb.data, form.foul.data, form.ass.data, form.tover.data, form.steal.data, form.block.data)
					return redirect("/stats")
				else:
					return render_template("error.html", message="Pelaaja ja tapahtuma pitää olla valittuna")
			else:
				return render_template("error.html", message="Virhe tilastoiden syöttämisessä")
		else:
			return render_template("error.html", message="Virhe tilastoiden syöttämisessä")
	else:
		return render_template("error.html", message="Ei oikeutta")
Example #3
0
def run_two_clients(name1, name2):
    all_players = players.get_players()
    player1 = all_players[name1]
    player2 = all_players[name2]

    s = server.BattleshipServer(10, 10, [2, 3, 3, 4, 5], player1.getClientProxy(player2), player2.getClientProxy(player1))
    winner = s.run()
    print "winner:", winner
Example #4
0
def player_list():

	if users.is_admin():
		mod_rights = True
	else:
		mod_rights =  False
	player_list = players.get_players()
	return render_template("player_list.html", players=player_list, mod_rights=mod_rights)
Example #5
0
    def __init__(self):
        self.out_file = file("results.txt", "w")
        all_players = players.get_players()
        if "human" in all_players:  # Don't include the human client in our multi-round run
            del all_players["human"]
        self.all_players = all_players.values()

        # Start with the number of ties set to 0, then add each player with a zero score
        self.wins = {None: 0}
        for player in self.all_players:
            self.wins[player.name] = 0
Example #6
0
def run_all_clients():
    out_file = file("results.txt", "w")
    all_players = players.get_players()
    if "human" in all_players:  # Don't include the human client in our multi-round run
        del all_players["human"]
    all_players = all_players.values()
    # Start with the number of ties set to 0, then add each player with a zero score
    wins = {None: 0}
    for player in all_players:
        wins[player.name] = 0
    for i in range(len(all_players)):
        for j in range(i + 1, len(all_players)):
            player1 = all_players[i]
            player2 = all_players[j]

            print ".",
            for round in range(NUM_ROUNDS):
                winner = None
                s = server.BattleshipServer(10, 10, [2, 3, 3, 4, 5],
                                            player1.getClientProxy(player2),
                                            player2.getClientProxy(player1))
                winner = s.run()
                wins[winner] += 1
                x = 0
                if winner == player1.name:
                    x = 1
                elif winner == player2.name:
                    x = -1
                out_file.write("%s\t%s\t%d\n" %
                               (player1.name, player2.name, x))
                out_file.flush()
                s.player1.client.stdin.close()
                s.player1.client.stdout.close()
                s.player1.client.stderr.close()
                s.player2.client.stdin.close()
                s.player2.client.stdout.close()
                s.player2.client.stderr.close()
                s.player1.client.kill()
                s.player2.client.kill()

    print ""
    print "scores:"
    for key, value in wins.items():
        print key, ":", value
    out_file.close()
Example #7
0
def run_all_clients():
    out_file = file("results.txt", "w")
    all_players = players.get_players()
    if "human" in all_players:  # Don't include the human client in our multi-round run
        del all_players["human"]
    all_players = all_players.values()
    # Start with the number of ties set to 0, then add each player with a zero score
    wins = {None: 0}
    for player in all_players:
        wins[player.name] = 0
    for i in range(len(all_players)):
        for j in range(i+1, len(all_players)):
            player1 = all_players[i]
            player2 = all_players[j]

            print ".",
            for round in range(NUM_ROUNDS):
                winner = None
                s = server.BattleshipServer(10, 10, [2, 3, 3, 4, 5], player1.getClientProxy(player2), player2.getClientProxy(player1))
                winner = s.run()
                wins[winner] += 1
                x = 0
                if winner == player1.name:
                    x = 1
                elif winner == player2.name:
                    x = -1
                out_file.write("%s\t%s\t%d\n" % (player1.name, player2.name, x))
                out_file.flush()
                s.player1.client.stdin.close()
                s.player1.client.stdout.close()
                if s.player1.client.stderr:
                    s.player1.client.stderr.close()
                s.player2.client.stdin.close()
                s.player2.client.stdout.close()
                if s.player2.client.stderr:
                    s.player2.client.stderr.close()
                s.player1.client.kill()
                s.player2.client.kill()

    print ""
    print "scores:"
    for key, value in wins.items():
        print key, ":", value
    out_file.close()
Example #8
0
def player_embed(message):
    received = message.content.split()
    exists_params = len(received) > 1
    embed = discord.Embed(title='Is playing?',
                          colour=discord.Colour.dark_magenta(),
                          url=SERVER)
    embed.set_author(name='Hello {}!'.format(message.author.name),
                     icon_url=message.author.avatar_url)
    if exists_params:
        players = get_players()
        player = received[1]
        playing = is_playing(players, player)
        if playing:
            embed.description = '😁 {} is playing'.format(player)
        else:
            embed.description = '😢 {} isn\'t playing'.format(player)
    else:
        embed.description = '😕 You must supply the name of one player'
    return embed
Example #9
0
    elif option == "7":
        #
        # Print vision standings
        #
        division = raw_input("\n\t\tPlease enter the division number: ")
        try:
            players.print_standing(int(division))
        except:
            print("Division not found")

    elif option == "8":
        #
        # Update points for all players
        #
        points = 0
        player_list = players.get_players()
        for player in player_list:
            # get a valid points value
            while points == 0:
                try:
                    points = int(raw_input("\n\t\tPoints this round for " + player['forename'] + " " + player['surname'] + ": "))
                except:
                    # default to zero if bad input
                    points = 0
            players.edit_player(player['forename'],player['surname'],'','',edit_none,points+player['points_current'],edit_none,edit_none)
            points = 0
        # trigger save on exit
        modified = 1

    elif option == "9":
        #
 def GET(self):
     return str(players.get_players())+"\n"
Example #11
0
    elif option == "7":
        #
        # Print vision standings
        #
        division = raw_input("\n\t\tPlease enter the division number: ")
        try:
            players.print_standing(int(division))
        except:
            print("Division not found")

    elif option == "8":
        #
        # Update points for all players
        #
        points = 0
        player_list = players.get_players()
        for player in player_list:
            # get a valid points value
            while points == 0:
                try:
                    points = int(
                        raw_input("\n\t\tPoints this round for " +
                                  player['forename'] + " " +
                                  player['surname'] + ": "))
                except:
                    # default to zero if bad input
                    points = 0
            players.edit_player(player['forename'], player['surname'], '', '',
                                edit_none, points + player['points_current'],
                                edit_none, edit_none)
            points = 0