Ejemplo n.º 1
0
    def _build_kill(self):
        for idx, cell in enumerate(self.state):
            if cell != 46:
                child_state = self.state.copy()
                child_state[idx] = 46
                Rules.calculate_next_state(child_state)

                child = Node(child_state, not self.my_turn, self, MoveType.KILL, idx)
                if cell == settings.PLAYER_ID:
                    self.best_kill_moves.append({'idx': idx, 'score': child.minimax_value})
                self.children.append(child)
Ejemplo n.º 2
0
    def _build_birth(self):
        for idx, cell in enumerate(self.state):
            if cell == 46:
                for a, b in itertools.combinations(self.best_kill_moves, 2):
                    a_idx = a['idx']
                    b_idx = b['idx']

                    child_state = self.state.copy()
                    child_state[idx] = settings.PLAYER_ID
                    child_state[a_idx] = 46
                    child_state[b_idx] = 46
                    Rules.calculate_next_state(child_state)

                    child = Node(child_state, not self.my_turn, self, MoveType.BIRTH, idx, (a_idx, b_idx))
                    self.children.append(child)
Ejemplo n.º 3
0
    def _build_kill(self):
        for idx, cell in enumerate(self.state):
            if cell != 46:
                child_state = self.state.copy()
                child_state[idx] = 46
                Rules.calculate_next_state(child_state)

                child = Node(child_state, not self.my_turn, self,
                             MoveType.KILL, idx)
                if cell == settings.PLAYER_ID:
                    self.best_kill_moves.append({
                        'idx': idx,
                        'score': child.minimax_value
                    })
                self.children.append(child)
Ejemplo n.º 4
0
    def _build_birth(self):
        for idx, cell in enumerate(self.state):
            if cell == 46:
                for a, b in itertools.combinations(self.best_kill_moves, 2):
                    a_idx = a['idx']
                    b_idx = b['idx']

                    child_state = self.state.copy()
                    child_state[idx] = settings.PLAYER_ID
                    child_state[a_idx] = 46
                    child_state[b_idx] = 46
                    Rules.calculate_next_state(child_state)

                    child = Node(child_state, not self.my_turn, self,
                                 MoveType.BIRTH, idx, (a_idx, b_idx))
                    self.children.append(child)
Ejemplo n.º 5
0
 def _build_pass(self):
     # passing doesn't change the intermediate state
     child_state = self.state.copy()
     Rules.calculate_next_state(child_state)
     child = Node(child_state, not self.my_turn, self, MoveType.PASS)
     self.children.append(child)
 def calc1000():
     for i in range(1, 1000):
         Rules.calculate_next_state(first_state)
Ejemplo n.º 7
0
 def _build_pass(self):
     # passing doesn't change the intermediate state
     child_state = self.state.copy()
     Rules.calculate_next_state(child_state)
     child = Node(child_state, not self.my_turn, self, MoveType.PASS)
     self.children.append(child)