Bug 571

Summary: Wrong input will make the chessboard array overflow
Product: CS3343 Chinese Checker Reporter: yutongmen2-c
Component: Algorithm ComponentAssignee: yutongmen2-c
Status: RESOLVED FIXED    
Severity: enhancement CC: yutongmen2-c
Priority: ---    
Version: unspecified   
Hardware: All   
OS: All   

Description yutongmen2-c 2021-11-17 23:51:12 HKT
The program does not have an input check at the early phase. A wrong input will lead to program crash.

Steps to reproduce:

1. Start the game.
2. Input 0 9

Actual outcome: 

The game crashes.

Expected outcome:

The program detects the input is invalid and requests another valid input.
Comment 1 yutongmen2-c 2021-11-17 23:51:36 HKT
Former partial code:

 System.out.println("Please input start move");
            int start_x = 0;
            int start_y = 0;

            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);



New partial code:

System.out.println("Please input start move");
            int start_x = 0;
            int start_y = 0;

            // if start_x or start_y is out of range [0,8]
            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];