I am trying to test the logic of a particular method included in a project I am working on and so I have created a simple 3 by 3 Latin Square with which to do so. The basics of the program work fine, printing the board, entering numbers, determining when the grid is full and son on. However, the method that evaluates the values actually contained within the squares of the grid. To do so, I drew up a Boolean method which contains a series of nested loops to test the numbers against each other. The desired result would be to have the Boolean variable "checkValue" read true when the game has been won - that is when each row contains a unique value from 1 to 3 and likewise the columns. The grid is a mutli-dimensional array named "board" nad x and y are of course the horizontal and verticle coordinates. Here is my code:
public boolean check() { for (int x = 0; x < n; x++) { for (int y = 0; y < n; y++) { // Check row for (int i = 0; i < n; i++) { if (board[x][i] != board[x][y]) checkValue = true; } // Check column for (int i = 0; i < n; i++) { if (board[i][y] != board[x][y]) checkValue = true; } } } return checkValue; }