2017-03-26 14 views
0

안녕하세요 처음으로 아주 좋은 내 모든 영어 이달 너무 실례합니다. tic-tac-toe를위한 MinMax 알고리즘을 작성했는데 정말 잘 동작했습니다. 그래서 저는 4 대를위한 MinMax 알고리즘을 사용하여 슬프게도 원하는대로 작동하지 않습니다. 그런 다음 Google에서 알파 베타 MinMax를 찾았습니다. 마침내 그것을 이해했을 때 그것을 시도했지만 재앙이었습니다 ^^. 여기에 내 MinMax는 내가 4 연결을 위해 무엇을했는지 누군가가 나에게 알파와 베타를 구현할 수있는 조언을 해줄 수 있습니까?넷 연결 인공 지능 알파 베타 MINMAX

private int computerzug(Color[][] board, int depth, Color spielerFarbe) 
{ 

    if(getGameLogic().hasWon(board, spielerFarbe)) 
    { 
     System.out.println("hy"); 
     return -10 -depth; 
    } 
    if(getGameLogic().hasDraw(board)) 
    { 
     return 0; 
    } 
    if(depth==6) 
    { 
     return 0; 
    } 
    int max = Integer.MIN_VALUE; 
    int index = 0; 
    for(int i =0;i<board[0].length;i++) 
    { 
     if(board[0][i].equals(Color.WHITE)) 
     { 
      Color[][] board1 = new Color[board.length][board[0].length]; 
      board1 = copy(board); 
      board1[getRow(board, i)][i] = spielerFarbe; 
      int moval = -computerzug(board1, depth+1, (spielerFarbe.equals(Color.BLUE)?Color.RED:Color.BLUE)); 
      if(moval> max) 
      { 
       max = moval; 
       index = i; 
      } 
     } 
    } 
    if(depth==0) 
    { 
     col = index; 
     row = getRow(this.board, index); 
    } 
    return max; 
} 

보드를 시뮬레이트하기 위해 2D 배열 색상으로 작업하고 있습니다.

+0

에 대한 매우 낮은 (음) 값은 Java 또는 알고리즘에 대한 조언 : 나는 항상 새로운 것을 배울까지입니다 –

답변

0

코드가 최소 최대 작동되는 점, 알파 베타 변종 (내가 그것을 테스트 할 수있다)과 같아야합니다 가정 :

private int computerzug(Color[][] board, int depth, Color spielerFarbe, int alpha, int beta) 
{ 

    if(getGameLogic().hasWon(board, spielerFarbe)) 
    { 
     System.out.println("hy"); 
     return -10 -depth; 
    } 
    if(getGameLogic().hasDraw(board)) 
    { 
     return 0; 
    } 
    if(depth==6) 
    { 
     return 0; 
    } 
    int max = Integer.MIN_VALUE; 
    int index = 0; 
    for(int i =0;i<board[0].length;i++) 
    { 
     if(board[0][i].equals(Color.WHITE)) 
     { 
      Color[][] board1 = new Color[board.length][board[0].length]; 
      board1 = copy(board); 
      board1[getRow(board, i)][i] = spielerFarbe; 
      int moval = -computerzug(board1, depth+1, (spielerFarbe.equals(Color.BLUE)?Color.RED:Color.BLUE), -beta, -alpha); 
      if(moval >= beta) 
       return moval; // fail-soft beta-cutoff 
      if(moval > max) { 
       max = moval; 
       index = i; 
       if(moval > alpha) 
        alpha = moval; 
      }   
     } 
    } 
    if(depth==0) 
    { 
     col = index; 
     row = getRow(this.board, index); 
    } 
    return max; 
} 

를 초기 호출, 당신은에 대해 아주 높은 값을 사용 나는 또한 몇 가지 일반적인 감사 알파와 베타