Buggy code:
if ( ( horizontalWalls [ tempX ] [ i ] ) == 1 ) countY ++ ; } if ( ( tempY == 7 ) || ( tempY == 9 ) ) { countX -= 2 ; } if ( ( countX >= 2 ) || ( countY >= 2 ) ) flag = true ; } if ( ! flag ) { tempXv = tempX + ( getRandom ( 0 , 1 ) ) ; tempYv = tempY - ( getRandom ( 0 , 1 ) ) ; if ( ( ( ( verticalWalls [ tempXv ] [ tempYv ] ) == 1 ) || ( ( verticalWalls [ ( tempXv - 1 ) ] [ tempYv ] ) == 1 ) ) || ( ( verticalWalls [ ( tempXv + 1 ) ] [ tempYv ] ) == 1 ) ) flag = true ; if ( ( ( verticalWalls [ tempXv ] [ ( tempYv - 1 ) ] ) == 1 ) || ( ( verticalWalls [ tempXv ] [ ( tempYv + 1 ) ] ) == 1 ) ) flag = true ; if ( ( ( horizontalWalls [ tempXv ] [ tempYv ] ) == 1 ) || ( ( horizontalWalls [ ( tempXv - 1 ) ] [ tempYv ] ) == 1 ) ) flag = true ; if ( ( ( horizontalWalls [ tempXv ] [ ( tempYv - 1 ) ] ) == 1 ) || ( ( horizontalWalls [ ( tempXv - 1 ) ] [ ( tempYv - 1 ) ] ) == 1 ) ) flag = true ; if ( ( ( verticalWalls [ ( tempXv - 1 ) ] [ ( tempYv - 1 ) ] ) == 1 ) || ( ( verticalWalls [ ( tempXv - 1 ) ] [ ( tempYv + 1 ) ] ) == 1 ) ) flag = true ; if ( ( ( verticalWalls [ ( tempXv + 1 ) ] [ ( tempYv + 1 ) ] ) == 1 ) || ( ( verticalWalls [ ( tempXv + 1 ) ] [ ( tempYv - 1 ) ] ) == 1 ) ) flag = true ; if ( ! flag ) { countX = countY = 0 ; for ( i = 1 ; i < 15 ; i ++ ) { if ( ( verticalWalls [ i ] [ tempYv ] ) == 1 ) countX ++ ; if ( ( verticalWalls [ tempXv ] [ i ] ) == 1 ) countY ++ ; } if ( ( tempXv == 7 ) || ( tempXv == 9 ) ) { countY -= 2 ; } if ( ( countX >= 2 ) || ( countY >= 2 ) ) flag = true ; } } if ( compteLoop1 > 1000 ) { restart = true ; } } while ( flag && ( ! restart ) ) ; horizontalWalls [ tempX ] [ tempY ] = 1 ; verticalWalls [ tempXv ] [ tempYv ] = 1 ; } } while ( restart ) ; Boolean flag ; int cibleX = 0 ; int cibleY = 0 ; do { flag = false ; cibleX = getRandom ( 0 , 15 ) ; cibleY = getRandom ( 0 , 15 ) ; if ( ( ( horizontalWalls [ cibleX ] [ cibleY ] ) == 0 ) && ( ( horizontalWalls [ cibleX ] [ ( cibleY + 1 ) ] ) == 0 ) ) flag = true ; if ( ( ( verticalWalls [ cibleX ] [ cibleY ] ) == 0 ) && ( ( verticalWalls [ ( cibleX + 1 ) ] [ cibleY ] ) == 0 ) ) flag = true ; if ( ( ( ( ( cibleX == 7 ) && ( cibleY == 7 ) ) || ( ( cibleX == 7 ) && ( cibleY == 8 ) ) ) || ( ( cibleX == 8 ) && ( cibleY == 7 ) ) ) || ( ( cibleX == 8 ) && ( cibleY == 8 ) ) ) flag = true ; } while ( flag ) ; <START_BUG> String [ ] typesOfCibles = new String [ ] { "cj" , "cr" , "cb" , "cj" , "cm" } ; <END_BUG> ArrayList < GridElement > data = translateArraysToMap ( horizontalWalls , verticalWalls ) ; data . add ( new GridElement ( cibleX , cibleY , typesOfCibles [ getRandom ( 0 , 4 ) ] ) ) ; String [ ] typesOfRobots = new String [ ] { "rr" , "rb" , "rj" , "rv" } ; ArrayList < GridElement > robotsTemp = new ArrayList < GridElement > ( ) ; int cX ; int cY ; for ( String currentRobotType : typesOfRobots ) { do { flag = false ; cX = getRandom ( 0 , 15 ) ; cY = getRandom ( 0 , 15 ) ; for ( GridElement robot : robotsTemp ) { if ( ( ( robot . getX ( ) ) == cX ) && ( ( robot . getY ( ) ) == cY ) ) flag = true ; } if ( ( ( ( ( cX == 7 ) && ( cY == 7 ) ) || ( ( cX == 7 ) && ( cY == 8 ) ) ) || ( ( cX == 8 ) && ( cY == 7 ) ) ) || ( ( cX == 8 ) && ( cY == 8 ) ) ) flag = true ; if ( ( cX == cibleX ) && ( cY == cibleY ) ) flag = true ; } while ( flag ) ; robotsTemp . add ( new GridElement ( cX , cY , currentRobotType ) ) ; } data . addAll ( robotsTemp ) ; return data ; } }

Fix:
String [ ] typesOfCibles = new String [ ] { "cj" , "cr" , "cb" , "cv" , "cm" } ;