コード例 #1
0
 def nextCoord(self, sub_board: SubBoard):
     arr = [[-9999 for x in range(3)] for y in range(3)]
     for x in range(0, len(sub_board.get_playable_coords())):
         arr[(sub_board.get_playable_coords()[x]).row][(
             sub_board.get_playable_coords()[x]
         ).col] = self.subBoardHeuristic(sub_board,
                                         sub_board.get_playable_coords()[x])
     #print(self.main_board)
     #print(sub_board)
     #print(arr)
     #print("----------------")
     return self.getMaxValue(arr)
コード例 #2
0
ファイル: mcts.py プロジェクト: LisaJD/Internship
 def CreateChildren(self):
     print(SubBoard)
     print(SubBoard.get_playable_coords(SubBoard))
     legal_moves = list(self.board_state.get_playable_coords())
     print(legal_moves)
     for move in legal_moves:
         self.children.append(Node(SubBoard.add_my_move(move)))
コード例 #3
0
ファイル: test_sub_board.py プロジェクト: RainkQ/UTTT
def test_whenBoardIsFinishedThenGetValidMovesIsEmpty():
    board = SubBoard().add_my_move(SubBoardCoords(0, 0))\
                        .add_opponent_move(SubBoardCoords(0, 1))\
                        .add_my_move(SubBoardCoords(1, 1))\
                        .add_opponent_move(SubBoardCoords(0, 2))\
                        .add_my_move(SubBoardCoords(2, 2))

    assert len(board.get_playable_coords()) is 0
コード例 #4
0
ファイル: test_sub_board.py プロジェクト: RainkQ/UTTT
def test_whenBoardIsPlayedThenGetValidMovesReturnsCorrectly():
    board = SubBoard().add_my_move(SubBoardCoords(0, 0))\
                .add_opponent_move(SubBoardCoords(1, 1))\
                .add_my_move(SubBoardCoords(2, 1))

    assert board.get_playable_coords() == \
                        [SubBoardCoords(0, 1), SubBoardCoords(0, 2), \
                         SubBoardCoords(1, 0), SubBoardCoords(1, 2), \
                         SubBoardCoords(2, 0), SubBoardCoords(2, 2)]
コード例 #5
0
 def winnableBy(self, subBoard: SubBoard):
     #print(subBoard)
     playable = subBoard.get_playable_coords()
     for x in range(0, len(subBoard.get_playable_coords())):
         tmpBoard = subBoard.add_opponent_move(
             SubBoardCoords(playable[x].row, playable[x].col))
         if tmpBoard.is_finished:
             if tmpBoard.winner == Player.ME or tmpBoard.winner == Player.OPPONENT:
                 #print(tmpBoard.winner)
                 return tmpBoard.winner
     for x in range(0, len(subBoard.get_playable_coords())):
         tmpBoard = subBoard.add_my_move(
             SubBoardCoords(playable[x].row, playable[x].col))
         if tmpBoard.is_finished:
             if tmpBoard.winner == Player.ME or tmpBoard.winner == Player.OPPONENT:
                 #print(tmpBoard.winner)
                 return tmpBoard.winner
     return 0
コード例 #6
0
ファイル: heuristics.py プロジェクト: LisaJD/Internship
    def pick_heuristics_sub_board_coords(sub_board: SubBoard) -> SubBoardCoords:
        possible_moves = sub_board.get_playable_coords()
        for move in possible_moves:
            sub_board = sub_board.add_my_move
            opponents_next_pos_moves = sub_board_next_player_must_play.get_playable_coords()
            opps_sub_board = sub_board_next_player_must_play.get_playable_coords()
            if sub_board.is_finished:
                score += 1 #move wins me small board
            elif 
        #next_best_move =
        return random.choice(sub_board.get_playable_coords())

        @staticmethod
        def Minmax():
            for i in range(len(emptycells)):
                cell = emptycell[i]
                cell_score = scoring(cell)
                branch_value = MinMax(cell)
                if branch_value >= current_best_val:
                    current_best_val = branch_value
                    best_move = cell  #or 'i'?
コード例 #7
0
 def pick_random_sub_board_coords(sub_board: SubBoard) -> SubBoardCoords:
     return random.choice(sub_board.get_playable_coords())