import stp.play as play
import stp.tactic as tactic

from rj_gameplay.tactic import capture_tactic, nmark_tactic, goalie_tactic, wall_tactic
import stp.skill as skill
import stp.role as role
from stp.role.assignment.naive import NaiveRoleAssignment
import stp.rc as rc
from typing import Dict, Generic, Iterator, List, Optional, Tuple, Type, TypeVar

class DefendRestart(play.IPlay):

    def __init__(self):
        # TODO: add chipper tactic here
        self.goalie = goalie_tactic.GoalieTactic()
        self.two_mark = nmark_tactic.NMarkTactic(5)
        self.role_assigner = NaiveRoleAssignment()

    def compute_props(self, prev_props):
        pass

    def tick(
        self,
        world_state: rc.WorldState,
        prev_results: role.assignment.FlatRoleResults,
        props,
    ) -> Tuple[Dict[Type[tactic.SkillEntry], List[role.RoleRequest]], List[tactic.SkillEntry]]:

        # Get role requests from all tactics and put them into a dictionary
        role_requests: play.RoleRequests = {}
        # role_requests[self.striker_tactic] = self.striker_tactic.get_requests(world_state, None)
        role_requests[self.two_mark] = (self.two_mark.get_requests(world_state, None))
        role_requests[self.goalie] = self.goalie.get_requests(world_state, None)

        # Flatten requests and use role assigner on them
        flat_requests = play.flatten_requests(role_requests)
        flat_results = self.role_assigner.assign_roles(flat_requests, world_state, prev_results)
        role_results = play.unflatten_results(flat_results)

        # Get list of all skills with assigned roles from tactics

        # skills = self.striker_tactic.tick(role_results[self.striker_tactic]) + self.two_mark.tick(role_results[self.two_mark])
        skills = self.two_mark.tick(role_results[self.two_mark])
        skills += self.goalie.tick(role_results[self.goalie])
        skill_dict = {}
        # skill_dict.update(role_results[self.striker_tactic])
        skill_dict.update(role_results[self.two_mark])
        skill_dict.update(role_results[self.goalie])

        return (skill_dict, skills)

    def is_done(self, world_state):
        return False
@@ -506,24 +506,23 @@
    self.
-two_
 mark
+ers
  = nmark
@@ -1011,18 +1011,16 @@
 %0A       
- #
  role_re
@@ -1035,131 +1035,32 @@
 elf.
-striker_tactic%5D = self.striker_tactic.get_requests(world_state, None)%0A        role_requests%5Bself.two_mark%5D = (self.two_mark
+markers%5D = (self.markers
 .get
@@ -1517,26 +1517,24 @@
 ics%0A%0A       
- #
  skills = se
@@ -1540,175 +1540,46 @@
 elf.
-striker_tactic.tick(role_results%5Bself.striker_tactic%5D) + self.two_mark.tick(role_results%5Bself.two_mark%5D)%0A        skills = self.two_mark.tick(role_results%5Bself.two_mark
+markers.tick(role_results%5Bself.markers
 %5D)%0A 
@@ -1670,18 +1670,16 @@
 %0A       
- #
  skill_d
@@ -1711,77 +1711,15 @@
 elf.
-striker_tactic%5D)%0A        skill_dict.update(role_results%5Bself.two_
 mark
+ers
 %5D)%0A 
@@ -1863,9 +1863,38 @@
 urn 
-False
+self.markers.is_done(world_state)%0A

change is_done, cleanup play a little