Bug 619

Summary: While loop always make the result not valid.
Product: CS3343 Chinese Checker Reporter: yutongmen2-c
Component: Algorithm ComponentAssignee: yutongmen2-c
Status: CONFIRMED ---    
Severity: minor CC: yutongmen2-c
Priority: ---    
Version: unspecified   
Hardware: All   
OS: All   

Description yutongmen2-c 2021-11-29 11:54:51 HKT
Short description:

While loop always make the result not valid.



Steps To Reproduce:

Change to do while loop and change the stream.



Actual Output:

Always invalid



Expected Output:

Valid move will go on to show tips
Comment 1 yutongmen2-c 2021-11-29 11:55:07 HKT
Previous code:

if (in.hasNextInt()) {

                start_x = in.nextInt();

                start_y = in.nextInt();

            }



            Point ps = new Point(start_x, start_y);

            StartMove start_m = new StartMove(ps);

            while (!start_m.isValidStartMove()) {

                // wait until the move is valid

                System.out.println("Not valid start move, please input again");

                start_x = in.nextInt();

                start_y = in.nextInt();

                ps = new Point(start_x, start_y);

                start_m = new StartMove(ps);

            }



Modified code:

do {

	if (in.hasNextInt()) {

		start_x = in.nextInt();

                start_y = in.nextInt();

      	}

} while (start_x < 0 || start_x > 8 || start_y < 0 || start_y > 8);

Point ps = Graph.getInstance().chessboard[start_x][start_y];

           

while (!StartMove.isValidStartMove(ps)) {

// wait until the move is valid

System.out.println("Not valid start move, please input again");

do {

     if (in.hasNextInt()) {

          start_x = in.nextInt();

           start_y = in.nextInt();

      }

} while (start_x < 0 || start_x > 8 || start_y < 0 || start_y > 8);