mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-22 23:26:40 -08:00
fix edge case: comptuer picks all remaining items
This commit is contained in:
@@ -237,7 +237,12 @@ sub computers_move {
|
||||
|
||||
$pile_size -= $remove_amount;
|
||||
|
||||
printf "COMPUTER TAKES %d AND LEAVES %d.\n", $remove_amount, $pile_size;
|
||||
if ($pile_size <= 0) {
|
||||
printf "COMPUTER TAKES %d AND WINS.\n", $remove_amount;
|
||||
return (1, $pile_size);
|
||||
} else {
|
||||
printf "COMPUTER TAKES %d AND LEAVES %d.\n", $remove_amount, $pile_size;
|
||||
}
|
||||
|
||||
return (0, $pile_size);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user