Esempio n. 1
0
 def start(self):
     if self.status == Status.JOINABLE:
         raise NotAllowedCommand(_('error_started'))
     else:
         self.status = Status.JOINABLE
         self.team_red = Team(ColorGame.RED, 'Red')
         self.team_blue = Team(ColorGame.BLUE, 'Blue')
Esempio n. 2
0
def results(teamsec):
    team = Team(teamsec, name=secpasswords_teams[teamsec], places=app.game.places)

    table = []
    for ts in teams_secret_passwords.values():
        x = Team(ts, name=secpasswords_teams[ts], places=app.game.places).get_results()
        table.append(x)
    for i, t in enumerate(sorted(table, key=lambda x: -x[-1])):
        t = [i + 1] + t
        table[i] = t
    return render_template('results.html', teamsec=teamsec, table=table)
Esempio n. 3
0
    def from_config(cls, config, player_position_generator):
        ball = Ball.from_config(config)
        home_team = Team.from_config(config)
        away_team = Team.from_config(config)
        home_goal = Goal.from_config(config)
        away_goal = Goal.from_config(config)
        away_goal.position = -away_goal.position
        field = Field.from_config(config)
        duration = config["duration"]
        friction = config["friction"]

        return Game(ball, home_team, away_team, home_goal, away_goal, field, duration, friction, player_position_generator)
Esempio n. 4
0
def tasks(teamsec, msg=""):
    team = Team(teamsec, name=secpasswords_teams[teamsec], places=app.game.places)
    ttable = team.task_table(tasks=app.game.tasks)

    def render_answ(x):
        a = ""
        for answ, c in x:
            if c:
                tag = "b"
            else:
                tag = "del"
            a += "<%s>%s</%s> " % (tag, answ, tag)
        return a

    for t in ttable:
        link = t[1]
        if link:
            t[1] = '<a href="%s">odkaz</a>' % link
        t[2] = render_answ(t[2])

    return render_template('tasks.html', teamsec=teamsec, table=ttable, msg=msg)
Esempio n. 5
0
    def __init__(self):
        self.img = None

        self.ally_low_hp = 0.75
        self.ally_critical_hp = 0.25
        self._my_loc = (-1, -1)
        self._my_fountain_coords = None
        self._my_team_side = None
        self._general_enemy_dir_coords = None
        self._has_game_started = False
        self._is_in_fountain = True
        self._is_adc_hp_low = False
        self._is_adc_hp_critical = False
        self._is_adc_dead = False
        #self._is_in_fountain = False
        #self_is_camera_locked = False

        self.yummi = Yummi()
        self.team = Team()
Esempio n. 6
0
def home(teamsec):
    team = Team(teamsec, name=secpasswords_teams[teamsec], places=app.game.places)
    text = team.statustext()

    form = SubmitTask(request.form)
    if team.state == "MOVE":
        templ = "move"
        moving_options = team.moving_options()
        ch = [(i, "%s (%d času, %d Kčs)" % (n, d, p)) for i, (n, (d, p)) in enumerate(moving_options)]
        form.answer = SelectField('Place:', validators=[validators.required()],
                                  choices=ch
                                  )
        form.ch = "".join('<option value="%d">%s</option>' % o for o in ch)

    else:
        templ = "home"
        moving_options = []

    if form.validate():
        answer = request.form["answer"]
        if team.state == "MOVE":
            try:
                new_place = moving_options[int(answer)][0]
            except ValueError:
                return "Posíláš odpověď na úkol, který už někdo z tvého týmu vyřešil. Refreshuj."

            res, msg = team.check_move(app.game.places[new_place])
            if res:
                templ = "home"
                flash(msg)
                return redirect('/home/%s' % teamsec)
            flash(msg)
        else:  # answering question
            res, msg = team.check_answer(answer)
            if res:  # correct answer changes state
                flash(msg)
                return redirect('/home/%s' % teamsec)
            flash(msg)
    else:
        if request.method == "POST":
            flash("Pošli odpověď.")
    return render_template('%s.html' % templ, teamsec=teamsec, text=text, form=form, moving=moving_options)
Esempio n. 7
0
    parser.add_argument('-v', '--verbose', action='count', default=0)
    parser.add_argument('-q', '--quiet', action='count', default=0)
    parser.add_argument('-d', '--debug', action='store_true', default=False)
    parser.add_argument('-n', '--n_battle', action='store', default=1000)
    args = parser.parse_args()

    dbg_format = '%(levelname)-8s %(module)-16s %(lineno)4s: %(message)s'
    logging.basicConfig(level=logging.WARN + 10 * (args.quiet - args.verbose),
                        format=dbg_format if args.debug else None)
    tf.logging.set_verbosity(tf.logging.ERROR)

    teams: List[Team] = [
        # プレイヤーチームのユニット構成
        Team(0, [
            Unit(statuses[Side.PLAYER][0]),
            Unit(statuses[Side.PLAYER][1]),
            Unit(statuses[Side.PLAYER][2]),
        ]),
        # モンスターチームのユニット構成
        Team(1, [
            Unit(statuses[Side.MONSTER][0]),
            Unit(statuses[Side.MONSTER][1]),
            Unit(statuses[Side.MONSTER][2]),
        ]),
    ]

    gambits: List[Gambit] = [
        # プレイヤーの戦闘AI
        NaiveGambit(),
        # モンスターの戦闘AI
        NaiveGambit(),
Esempio n. 8
0
    parser.add_argument('-v', '--verbose', action='count', default=0)
    parser.add_argument('-q', '--quiet', action='count', default=0)
    parser.add_argument('-d', '--debug', action='store_true', default=False)
    parser.add_argument('-n', '--n_battle', action='store', default=1000)
    args = parser.parse_args()

    dbg_format = '%(levelname)-8s %(module)-16s %(lineno)4s: %(message)s'
    logging.basicConfig(level=logging.WARN + 10 * (args.quiet - args.verbose),
                        format=dbg_format if args.debug else None)
    tf.logging.set_verbosity(tf.logging.ERROR)

    teams: List[Team] = [
        # プレイヤーチームのユニット構成
        Team(0, [
            Unit(statuses[Side.PLAYER][0]),
            Unit(statuses[Side.PLAYER][1]),
            Unit(statuses[Side.PLAYER][2]),
        ]),
        # モンスターチームのユニット構成
        Team(1, [
            Unit(statuses[Side.MONSTER][0]),
            Unit(statuses[Side.MONSTER][1]),
            Unit(statuses[Side.MONSTER][2]),
        ]),
    ]

    gambits: List[Gambit] = [
        # プレイヤーの戦闘AI
        NaiveGambit(),
        # モンスターの戦闘AI
        NaiveGambit(),
Esempio n. 9
0
def unlock_hint(teamsec, task, hint):
    team = Team(teamsec, name=secpasswords_teams[teamsec], places=app.game.places)
    msg = team.unlock_hint(task, hint)
    return tasks(teamsec)
Esempio n. 10
0
class Match:
    """A class to represent the match. It stores the guild, the channel, the list of members, the status and if the stat
    us of the match is Status.PLAY also the StartedMatch object.

       """
    def __init__(self, guild, channel):
        self.guild = guild
        self.channel = channel
        self.status = Status.NOT_STARTED
        self.team_red = None
        self.team_blue = None
        self.winner = None
        self.grid_table = None
        self.current_turn = None
        self.next_turn = None

    def point(self):
        s = _('word_point')+'\n'
        s += '{}: {}\\{} \n{}: {}\\{}'.format(
            _('team', team = self.team_red.name), self.grid_table.get_red_point(), self.grid_table.number_red,
            _('team', team=self.team_blue.name), self.grid_table.get_blue_point(), self.grid_table.number_blue
        )
        return s

    def verify_victory_condition(self):
        if self.grid_table.get_red_point() == self.grid_table.number_red:
            return self.team_red
        elif self.grid_table.get_blue_point() == self.grid_table.number_blue:
            return self.team_blue
        else:
            return None

    def get_team_member(self, member):
        if member.id in self.team_red.members.keys():
            return self.team_red
        if member.id in self.team_blue.members.keys():
            return self.team_blue
        return None

    def join(self, member):
        if self.status != Status.JOINABLE:
            raise NotAllowedCommand(_('error_joinable'))
        if self.get_team_member(member) is None:
            self.auto_join(member)
        else:
            raise NotAllowedCommand(_('error_already_joined', team=self.get_team_member(member).name))

    def leave(self, member):
        if self.status != Status.JOINABLE:
            raise NotAllowedCommand(_('error_joinable'))
        team = self.get_team_member(member)
        if team is not None:
            team.leave(member)
        else:
            raise NotAllowedCommand(_('error_not_join'))

    def start(self):
        if self.status == Status.JOINABLE:
            raise NotAllowedCommand(_('error_started'))
        else:
            self.status = Status.JOINABLE
            self.team_red = Team(ColorGame.RED, 'Red')
            self.team_blue = Team(ColorGame.BLUE, 'Blue')

    def play(self, tag):
        if self.status != Status.JOINABLE:
            raise NotAllowedCommand(_('error_joinable'))
        elif not self.has_masters():
            raise NotAllowedCommand(_('error_need_two_master'))
        else:
            self.status = Status.PLAY
            self.grid_table = WordTable()
            self.grid_table.generate_words(tag)
            self.current_turn = self.team_red
            self.next_turn = self.team_blue

    def stop(self):
        if self.status == Status.NOT_STARTED or self.status == Status.STOPPED:
            raise NotAllowedCommand(_('error_not_started'))
        else:
            self.status = Status.STOPPED

    def print_members(self):
        s = _('members') + ':\n'
        s += self.team_red.print_members()
        s += self.team_blue.print_members()
        return s

    def print_status(self):
        s = "Guild id: {}, channel id: {}, status: {} \n".format(self.guild.name, self.channel.name, self.status)

        s += self.team_red.print_status() + '\n' + self.team_blue.print_status() + '\n'
        if self.status == Status.PLAY:
            s += 'current turn: {} team\n'.format(self.current_turn.name)
            s += self.grid_table.print_status()
        if s == '':
            return 'no match found'
        return s

    def join_as_master(self, member):
        """Joins the member to one team if available

           Args:
               member: A member instance

           Returns:
               A string with the name of the team

           Raises:
               NotAllowedCommand: An error occured when there are not spaces to be master available
           """
        if self.status != Status.JOINABLE:
            raise NotAllowedCommand(_('error_joinable'))
        else:
            return self.join_team_as_master(member)

    def has_masters(self):
        return self.team_red.master is not None and self.team_blue.master is not None

    def join_team_as_master(self, member):
        if self.team_red.master is not None and self.team_blue.master is not None:
            raise NotAllowedCommand(_('error_master_already_set'))
        if self.team_red.master is None and member.id not in self.team_blue.members.keys():
            self.team_red.set_master(member)
            return self.team_red.name
        elif self.team_blue.master is None and member.id not in self.team_red.members.keys():
            self.team_blue.set_master(member)
            return self.team_blue.name
        else:
            raise NotAllowedCommand(_('error_master_other_team'))

    def show(self, member, word):
        if self.status == Status.PLAY:
            if member.id in self.current_turn.members.keys():
                found, color = self.grid_table.show(word)
                if not found:
                    raise NotAllowedCommand(_('error_word_not_found', word=word))
                elif color == ColorGame.ASSASSIN:
                    self.status = Status.STOPPED
                    self.winner = self.next_turn

                    return ActionResult.FINISH
                elif self.verify_victory_condition() is None:
                    if color != self.current_turn.color:
                        self.current_turn, self.next_turn = self.next_turn, self.current_turn
                        return ActionResult.NOT_GUESS
                    else:
                        return ActionResult.GUESS
                else:
                    self.winner = self.verify_victory_condition()
                    self.status = Status.STOPPED
                    return ActionResult.FINISH
            else:
                raise NotAllowedCommand(_('error_team_not_allowed', team=self.current_turn.name))
        else:
            raise NotAllowedCommand(_('error_not_started'))

    def pass_turn(self, member):
        if self.status == Status.PLAY:
            if member.id in self.current_turn.members.keys():
                self.current_turn, self.next_turn = self.next_turn, self.current_turn
            else:
                raise NotAllowedCommand(_('error_team_not_allowed', team=self.current_turn.name))
        else:
            raise NotAllowedCommand(_('error_not_started'))

    def auto_join(self, member):
        team = self.choose_team()
        team.join(member)

    def choose_team(self):
        if len(self.team_red.members) < len(self.team_blue.members):
            return self.team_red
        elif len(self.team_red.members) > len(self.team_blue.members):
            return self.team_blue
        else:
            return random.sample([self.team_blue, self.team_red], 1)[0]

    def change_team(self, member):
        if self.status != Status.JOINABLE:
            raise NotAllowedCommand(_('error_joinable'))
        if member.id in self.team_red.members.keys():
            self.team_red.leave(member)
            self.team_blue.join(member)
        elif member.id in self.team_blue.members.keys():
            self.team_blue.leave(member)
            self.team_red.join(member)
        else:
            raise NotAllowedCommand(_('error_not_join'))
Esempio n. 11
0
 def __init__(self, teams=2):
     self.map = Map(self)
     self.team_to_character = [Team() for _ in range(teams)]