Bug 619 - While loop always make the result not valid.
Summary: While loop always make the result not valid.
Status: CONFIRMED
Alias: None
Product: CS3343 Chinese Checker
Classification: Unclassified
Component: Algorithm Component (show other bugs)
Version: unspecified
Hardware: All All
: --- minor
Assignee: yutongmen2-c
URL:
Depends on:
Blocks:
 
Reported: 2021-11-29 11:54 HKT by yutongmen2-c
Modified: 2021-11-29 11:55 HKT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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);