Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat event vcounts #48

Open
wants to merge 12 commits into
base: development
Choose a base branch
from
2 changes: 2 additions & 0 deletions event_table.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name,type,majority_mod,cycle,start_delay,hammer,cuorum,uses
Calabozo,jail,1,24,0,0,1,-1
85 changes: 77 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import config
import user
import vote_count
import test_jail_count
import test_exile_count
import test_pyre_count
import player_list as pl
import modules.thread_reader as tr
import states.stage as stages
Expand Down Expand Up @@ -90,6 +93,37 @@ def run(update_tick: int):
bot_cycle=bot_cycles,
n_players=len(Players.players)
)

JailEventCount = test_jail_count.JailCount(
staff=staff,
day_start_post=current_day_start_post,
bot_cycle=bot_cycles,
n_players=len(Players.players)
)

ExileEventCount = test_exile_count.ExileCount(
staff=staff,
day_start_post=current_day_start_post,
bot_cycle=bot_cycles,
n_players=len(Players.players)
)

PyreEventCount = test_pyre_count.PyreCount(
staff=staff,
day_start_post=current_day_start_post,
bot_cycle=bot_cycles,
n_players=len(Players.players)
)

## Try to make this less shameful
event_counts = {
actions.Action.exile: ExileEventCount,
actions.Action.unexile: ExileEventCount,
actions.Action.pyre: PyreEventCount,
actions.Action.unpyre: PyreEventCount,
actions.Action.unjail: JailEventCount,
actions.Action.jail: JailEventCount
}

print('We are on day time!')

Expand Down Expand Up @@ -126,6 +160,7 @@ def run(update_tick: int):

resolve_action_queue(queue=action_queue,
vcount=VoteCount,
ecounts=event_counts,
Players=Players,
last_count=last_votecount_id,
day_start = current_day_start_post,
Expand All @@ -135,7 +170,14 @@ def run(update_tick: int):
## Check If there is still time left to play. Otherwise, start the EoD
if game_status.is_end_of_stage(current_time = get_current_ntp_time()) and not majority_reached:

last_valid_action = [action for action in action_queue if action.post_time < game_status.get_end_of_stage()].pop()
last_action_list = [action for action in action_queue if action.post_time < game_status.get_end_of_stage()]

if last_action_list:
last_valid_action = last_action_list.pop()
last_valid_action_post = last_valid_action.id
else:
last_valid_action_post = 0

majority_reached = True ## This will stop the bot in the next iteration
logging.info("EoD detected. Pushing last valid votecount and preparing flip routine")

Expand Down Expand Up @@ -168,11 +210,25 @@ def run(update_tick: int):

if should_update:
logging.info('Pushing a new votecount')
push_vote_count(vote_table=VoteCount._vote_table,
alive_players=Players.players,
last_parsed_post=last_thread_post,
current_majority=VoteCount.current_majority
)
User = user.User(config=settings)
vcounts = {
actions.Action.vote: VoteCount,
actions.Action.jail: JailEventCount,
actions.Action.pyre: PyreEventCount,
actions.Action.exile: ExileEventCount
}
User.push_all_counts(
vcounts=vcounts,
alive_players=Players.players,
post_id=last_thread_post
)
del User
# push_vote_count(vote_table=VoteCount._vote_table,
# alive_players=Players.players,
# last_parsed_post=last_thread_post,
# current_majority=VoteCount.current_majority
# )

else:
logging.info('Recent votecount detected. ')

Expand Down Expand Up @@ -205,7 +261,7 @@ def run(update_tick: int):

#TODO: Handle actual permissions without a giant if/else
#TODO: This func. is prime candidate for refactoring
def resolve_action_queue(queue: list, vcount: vote_count.VoteCount, Players: pl.Players, last_count:int, day_start:int, eod_time:int):
def resolve_action_queue(queue: list, vcount: vote_count.VoteCount, ecounts: dict, Players: pl.Players, last_count:int, day_start:int, eod_time:int):
'''
Parameters: \n
queue: A list of game actions.\n
Expand Down Expand Up @@ -238,10 +294,23 @@ def resolve_action_queue(queue: list, vcount: vote_count.VoteCount, Players: pl.
reveal=f"{Players.get_player_role(game_action.victim)} - {Players.get_player_team(game_action.victim)}"
)
break


elif game_action.type in ecounts.keys():
## some kind of unvote
if "un" in game_action.type.name:
ecounts[game_action.type].unvote_player(action=game_action)
else:
ecounts[game_action.type].vote_player(action=game_action)

elif game_action.type == actions.Action.unvote:
vcount.unvote_player(action=game_action)

elif game_action.type == actions.Action.jail and Players.player_exists(game_action.victim):
ecount.vote_player(action=game_action)

elif game_action.type == actions.Action.unjail:
ecount.unvote_player(action=game_action)

elif game_action.type == actions.Action.lylo:

logging.info(f'{game_action.author} requested an vcount lock at {game_action.id}')
Expand Down
6 changes: 6 additions & 0 deletions modules/game_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ def __init__(self, post_id: int, post_time: int, contents: str, author: str):
## Available commands
self._action_responses = {
actions.Action.vote: self._parse_vote,
actions.Action.jail: self._parse_vote,
actions.Action.unvote: self._parse_unvote,
actions.Action.unjail: self._parse_unvote,
actions.Action.pyre: self._parse_vote,
actions.Action.unpyre: self._parse_unvote,
actions.Action.exile: self._parse_vote,
actions.Action.unexile: self._parse_unvote,
actions.Action.replace_player: self._replace_player,
actions.Action.request_count: self._parse_vote_count_request,
actions.Action.vote_history: self._set_victim_from_arg,
Expand Down
8 changes: 7 additions & 1 deletion modules/thread_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,13 @@ def get_actions_from_page(game_thread:str, page_to_scan:int, start_from_post:int
# I'm ignoring edit div elements because players should not edit while
# playing.

posts = parser.findAll('div', class_ = ['cf post','cf post z','cf post first'])
posts = parser.findAll('div', class_ = [
'cf post',
'cf post z',
'cf post first',
'cf post op',
'cf post z op'
])

for post in posts:

Expand Down
6 changes: 6 additions & 0 deletions states/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ class Action(enum.Enum):
winner = "ganador"
shoot = "disparo"
revive = "reanimar"
jail = "encierro"
unjail = "libero"
pyre = "condeno"
unpyre = "perdono"
exile = "exilio"
unexile = "acojo"



Expand Down
Loading