Give the characters breakout its bricks as collision geometry

`HITTEST`, `XBRICK` and `YBRICK` are gone -- about forty lines that divided
pixels by cell sizes to recover a grid index, tested the ball's leading edge
rather than its box, and could miss a brick clipped at the corner by seven
pixels' worth of ball. In their place: sixty `SOLID` rectangles registered as the
wall is built, `COLLISION 2, BRICKHIT`, and a fifteen-line handler.

The handler reads better than what it replaces because it asks rather than
derives. `RCOLLISION(1, 1)` is which brick -- the id is the array index plus one,
so nothing is looked up. Fields 2, 3 and 4 are the way out and how far, so the
ball is pushed exactly clear instead of being restored to a remembered `OX#`/`OY#`.
Field 7 is which axis to reverse, which `TESTCELL` in the other game computes by
hand from an overlap rectangle.

`MOVEBAL` loses its two brick calls and its position backup. `KILLBR` retires the
rectangle in the same breath as clearing the array element, so the next frame
cannot hit a brick that is no longer drawn.

**A latent defect in the target prescan had to be fixed first, and `RCOLLISION`
is the first name in the language to reach it.** `src/renumber.c` walks a line
character by character looking for `GOTO`, `GOSUB`, `COLLISION` and the rest, and
checked only the character *after* a match -- so `RCOLLISION(1, 1)` found
`COLLISION` at its second character, read the `(1,` that followed as a handler
line number, and refused the whole program with "branch to line 1, which the
program did not number", naming a line that contains no branch at all. It now
requires a word boundary on both sides. The comment there was already right that
the trailing check protects `GOTOX#`; nothing protected `XGOTO#`.
`tests/unnumbered.c` covers all three shapes and TODO.md section 6 item 42
records it.

The game runs ninety seconds headless with no error line and the attract mode
scores 1320, so bricks are being found and broken through the new path.

Chapter 17 is not updated yet -- that is the other half of section 6 item 39, and
it is a bigger edit than this one.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EwxGB6TdoVvZ11KQQME9cL
This commit is contained in:
2026-08-02 11:17:34 -04:00
parent fdb3421b2a
commit 9e43acc0b0
4 changed files with 121 additions and 43 deletions

View File

@@ -300,6 +300,41 @@ static void test_a_number_in_a_string_is_not_a_target(void)
* it touches comes out numbered -- so the branch the check refused a moment ago
* is now naming a number the program owns. That is the remedy the refusal names.
*/
/**
* @brief A name that merely *contains* a branch verb is not a branch.
*
* The target prescan walks a line character by character looking for `GOTO`,
* `GOSUB`, `COLLISION` and the rest, and it checked only the character *after* a
* match. So `RCOLLISION(1, 1)` found `COLLISION` at its second character, read
* the `(1,` that followed as a handler line number, and refused the whole
* program with "branch to line 1, which the program did not number" -- naming a
* line containing no branch at all.
*
* `RCOLLISION` is the first name in the language to reach it. The general case
* is any identifier ending in a branch verb, which is why the second half of
* this test does not mention collision at all.
*/
static void test_verb_inside_a_name_is_not_a_branch(void)
{
TEST_REQUIRE_OK(run_program("X# = 0\n"
"T# = RCOLLISION(1, 1)\n"
"PRINT \"RAN \" + T#\n"));
TEST_REQUIRE_STR(HARNESS_OUTPUT, "RAN 0\n");
harness_stop();
/* And the general shape: a variable whose name ends in a branch verb. */
TEST_REQUIRE_OK(run_program("MYGOTO# = 7\n"
"PRINT MYGOTO#\n"));
TEST_REQUIRE_STR(HARNESS_OUTPUT, "7\n");
harness_stop();
/* The trailing check still works: a name *starting* with one is not a branch. */
TEST_REQUIRE_OK(run_program("GOTOX# = 9\n"
"PRINT GOTOX#\n"));
TEST_REQUIRE_STR(HARNESS_OUTPUT, "9\n");
harness_stop();
}
static void test_renumber_makes_numeric_branches_legal(void)
{
TEST_REQUIRE_OK(harness_start(NULL));
@@ -350,6 +385,7 @@ int main(void)
test_numeric_branch_to_an_empty_line_is_allowed();
test_label_targets_are_never_refused();
test_a_number_in_a_string_is_not_a_target();
test_verb_inside_a_name_is_not_a_branch();
test_renumber_makes_numeric_branches_legal();
test_renumber_marks_every_line_numbered();
return akbasic_test_failures;