HashMap kod do wygranej

0

go.anna
3 minuty temu
Witam,
mam pytanie, ponieważ programuje w javie gre kólko krzyzyk. Mam napisany kod dla wygranych kolumn i wierszy - ale nie wiem jak zrobic jeszcze przekatne. Czy jest ktoś mi w stanie pomoc bo nie wiem co robie zle ze mi nie wychodzi:
public boolean checkDiagonalRight(List <position>positions){
Map<Integer, Integer> diagonal = new HashMap<>();
for (Position position: positions){
if (diagonal.containsKey(position.getColumn()) && diagonal.containsValue((position.getRow()))){
int value = diagonal.get(position.getColumn());
diagonal.put(position.getColumn(), ++value);
} else {
diagonal.put(position.getColumn(), 1);
}
}
return diagonal.values().stream().anyMatch(i -> i==3);
}
Czy jest mi ktoś w stanie cos podpowiedziec? Dopiero zaczynam nauke i nie wiem jeszcze za duzo.

0

Pierwszy wynik w google.

   /** Return true if the player with "theSeed" has won after placing at
       (currentRow, currentCol) */
   public static boolean hasWon(int theSeed, int currentRow, int currentCol) {
      return (board[currentRow][0] == theSeed         // 3-in-the-row
                   && board[currentRow][1] == theSeed
                   && board[currentRow][2] == theSeed
              || board[0][currentCol] == theSeed      // 3-in-the-column
                   && board[1][currentCol] == theSeed
                   && board[2][currentCol] == theSeed
              || currentRow == currentCol            // 3-in-the-diagonal
                   && board[0][0] == theSeed
                   && board[1][1] == theSeed
                   && board[2][2] == theSeed
              || currentRow + currentCol == 2  // 3-in-the-opposite-diagonal
                   && board[0][2] == theSeed
                   && board[1][1] == theSeed
                   && board[2][0] == theSeed);
   }
0

Musisz sprawdzić czy pola spełniające warunki x=y i x=-y są wypełnione tymi samymi symbolami.

1 użytkowników online, w tym zalogowanych: 0, gości: 1