| Summary: | Wrong input will make the chessboard array overflow | ||
|---|---|---|---|
| Product: | CS3343 Chinese Checker | Reporter: | yutongmen2-c |
| Component: | Algorithm Component | Assignee: | 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
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];
|