diff options
Diffstat (limited to 'apps/recorder/wormlet.c')
-rw-r--r-- | apps/recorder/wormlet.c | 104 |
1 files changed, 77 insertions, 27 deletions
diff --git a/apps/recorder/wormlet.c b/apps/recorder/wormlet.c index 84ee55062c..71a356134f 100644 --- a/apps/recorder/wormlet.c +++ b/apps/recorder/wormlet.c | |||
@@ -334,10 +334,10 @@ static bool line_in_rect(int startx, int starty, int endx, int endy, int x, int | |||
334 | compa = MIN(compa, compb); | 334 | compa = MIN(compa, compb); |
335 | compb = MAX(temp, compb); | 335 | compb = MAX(temp, compb); |
336 | 336 | ||
337 | if (simplemin <= simple && simple < simplemax) { | 337 | if (simplemin <= simple && simple <= simplemax) { |
338 | if ((compmin <= compa && compa < compmax) || | 338 | if ((compmin <= compa && compa <= compmax) || |
339 | (compmin <= compb && compb < compmax) || | 339 | (compmin <= compb && compb <= compmax) || |
340 | (compa <= compmin && compb > compmax)) { | 340 | (compa <= compmin && compb >= compmax)) { |
341 | retval = true; | 341 | retval = true; |
342 | } | 342 | } |
343 | } | 343 | } |
@@ -473,7 +473,7 @@ static bool worm_food_collision(struct worm *w, int foodIndex) | |||
473 | bool retVal = false; | 473 | bool retVal = false; |
474 | 474 | ||
475 | retVal = worm_in_rect(w, foodx[foodIndex], foody[foodIndex], | 475 | retVal = worm_in_rect(w, foodx[foodIndex], foody[foodIndex], |
476 | FOOD_SIZE, FOOD_SIZE); | 476 | FOOD_SIZE - 1, FOOD_SIZE - 1); |
477 | 477 | ||
478 | return retVal; | 478 | return retVal; |
479 | } | 479 | } |
@@ -512,7 +512,7 @@ static bool worm_argh_collision(struct worm *w, int arghIndex) | |||
512 | bool retVal = false; | 512 | bool retVal = false; |
513 | 513 | ||
514 | retVal = worm_in_rect(w, arghx[arghIndex], arghy[arghIndex], | 514 | retVal = worm_in_rect(w, arghx[arghIndex], arghy[arghIndex], |
515 | ARGH_SIZE, ARGH_SIZE); | 515 | ARGH_SIZE - 1, ARGH_SIZE - 1); |
516 | 516 | ||
517 | return retVal; | 517 | return retVal; |
518 | } | 518 | } |
@@ -1507,6 +1507,20 @@ static void test_worm_food_collision(void) { | |||
1507 | 1507 | ||
1508 | } | 1508 | } |
1509 | 1509 | ||
1510 | |||
1511 | static bool expensive_worm_in_rect(struct worm *w, int rx, int ry, int rw, int rh){ | ||
1512 | int x, y; | ||
1513 | bool retVal = false; | ||
1514 | for (x = rx; x < rx + rw; x++){ | ||
1515 | for (y = ry; y < ry + rh; y++) { | ||
1516 | if (specific_worm_collision(w, x, y) != -1) { | ||
1517 | retVal = true; | ||
1518 | } | ||
1519 | } | ||
1520 | } | ||
1521 | return retVal; | ||
1522 | } | ||
1523 | |||
1510 | static void test_worm_argh_collision(void) { | 1524 | static void test_worm_argh_collision(void) { |
1511 | int i; | 1525 | int i; |
1512 | int dir; | 1526 | int dir; |
@@ -1738,6 +1752,26 @@ static int testline_in_rect(void) { | |||
1738 | testfailed = 13; | 1752 | testfailed = 13; |
1739 | } | 1753 | } |
1740 | 1754 | ||
1755 | /* test 14 */ | ||
1756 | rx = 9; | ||
1757 | ry = 15; | ||
1758 | rw = 4; | ||
1759 | rh = 4; | ||
1760 | |||
1761 | x1 = 10; | ||
1762 | y1 = 10; | ||
1763 | x2 = 10; | ||
1764 | y2 = 19; | ||
1765 | if (!(line_in_rect(x1, y1, x2, y2, rx, ry, rw, rh) && | ||
1766 | line_in_rect(x2, y2, x1, y1, rx, ry, rw, rh))) { | ||
1767 | lcd_drawline(x1, y1, x2, y2); | ||
1768 | lcd_invertrect(rx, ry, rw, rh); | ||
1769 | lcd_putsxy(0, 0, "failed 14", 0); | ||
1770 | lcd_update(); | ||
1771 | button_get(true); | ||
1772 | testfailed = 14; | ||
1773 | } | ||
1774 | |||
1741 | lcd_clear_display(); | 1775 | lcd_clear_display(); |
1742 | 1776 | ||
1743 | return testfailed; | 1777 | return testfailed; |
@@ -1789,51 +1823,65 @@ static void test_make_argh(void){ | |||
1789 | int seed = 0; | 1823 | int seed = 0; |
1790 | int hit = 0; | 1824 | int hit = 0; |
1791 | int failures = 0; | 1825 | int failures = 0; |
1826 | int last_failures = 0; | ||
1827 | int i, worm_idx; | ||
1792 | lcd_clear_display(); | 1828 | lcd_clear_display(); |
1793 | init_worm(&worms[0], 10, 20); | 1829 | worm_count = 3; |
1794 | add_growing(&worms[0], 40 - INITIAL_WORM_LENGTH); | 1830 | |
1831 | for (worm_idx = 0; worm_idx < worm_count; worm_idx++) { | ||
1832 | init_worm(&worms[worm_idx], 10 + worm_idx * 20, 20); | ||
1833 | add_growing(&worms[worm_idx], 40 - INITIAL_WORM_LENGTH); | ||
1834 | } | ||
1795 | 1835 | ||
1796 | for (dir = EAST; dir < EAST + 4; dir++) { | 1836 | for (dir = EAST; dir < EAST + 4; dir++) { |
1797 | int i; | 1837 | for (worm_idx = 0; worm_idx < worm_count; worm_idx++) { |
1798 | set_worm_dir(&worms[0], dir % 4); | 1838 | set_worm_dir(&worms[worm_idx], dir % 4); |
1799 | for (i = 0; i < 10; i++) { | 1839 | for (i = 0; i < 10; i++) { |
1800 | if (!(dir % 4 == NORTH && i == 9)) { | 1840 | if (!(dir % 4 == NORTH && i == 9)) { |
1801 | move_worm(&worms[0]); | 1841 | move_worm(&worms[worm_idx]); |
1802 | draw_worm(&worms[0]); | 1842 | draw_worm(&worms[worm_idx]); |
1843 | } | ||
1803 | } | 1844 | } |
1804 | } | 1845 | } |
1805 | } | 1846 | } |
1806 | 1847 | ||
1807 | lcd_update(); | 1848 | lcd_update(); |
1808 | 1849 | ||
1809 | srand(seed); | ||
1810 | for (seed = 0; hit < 20; seed += 2) { | 1850 | for (seed = 0; hit < 20; seed += 2) { |
1811 | int x = rand() % (FIELD_RECT_WIDTH - ARGH_SIZE); | ||
1812 | int y = rand() % (FIELD_RECT_HEIGHT - ARGH_SIZE); | ||
1813 | |||
1814 | if (worm_in_rect(&worms[0], x, y, ARGH_SIZE, ARGH_SIZE)) { | ||
1815 | char buf[20]; | 1851 | char buf[20]; |
1852 | int x, y; | ||
1853 | srand(seed); | ||
1854 | x = rand() % (FIELD_RECT_WIDTH - ARGH_SIZE); | ||
1855 | y = rand() % (FIELD_RECT_HEIGHT - ARGH_SIZE); | ||
1856 | |||
1857 | for (worm_idx = 0; worm_idx < worm_count; worm_idx++){ | ||
1858 | if (expensive_worm_in_rect(&worms[worm_idx], x, y, ARGH_SIZE, ARGH_SIZE)) { | ||
1859 | int tries = 0; | ||
1816 | srand(seed); | 1860 | srand(seed); |
1817 | make_argh(0); | ||
1818 | draw_argh(0); | ||
1819 | lcd_invertrect(x + FIELD_RECT_X, y+ FIELD_RECT_Y, ARGH_SIZE, ARGH_SIZE); | ||
1820 | 1861 | ||
1821 | if (x == arghx[0] && y == arghy[0]) { | 1862 | tries = make_argh(0); |
1863 | if ((x == arghx[0] && y == arghy[0]) || tries < 2) { | ||
1822 | failures ++; | 1864 | failures ++; |
1823 | } | 1865 | } |
1824 | 1866 | ||
1825 | snprintf(buf, sizeof buf, "hit at x%d y%d fail%d", x, y, failures); | 1867 | snprintf(buf, sizeof buf, "(%d;%d) fail%d try%d", x, y, failures, tries); |
1826 | lcd_putsxy(0, LCD_HEIGHT - 8, buf, 0); | 1868 | lcd_putsxy(0, LCD_HEIGHT - 8, buf, 0); |
1827 | lcd_update(); | 1869 | lcd_update(); |
1870 | lcd_invertrect(x + FIELD_RECT_X, y+ FIELD_RECT_Y, ARGH_SIZE, ARGH_SIZE); | ||
1871 | lcd_update(); | ||
1872 | draw_argh(0); | ||
1873 | lcd_update(); | ||
1828 | lcd_invertrect(x + FIELD_RECT_X, y + FIELD_RECT_Y, ARGH_SIZE, ARGH_SIZE); | 1874 | lcd_invertrect(x + FIELD_RECT_X, y + FIELD_RECT_Y, ARGH_SIZE, ARGH_SIZE); |
1829 | lcd_clearrect(arghx[0] + FIELD_RECT_X, arghy[0] + FIELD_RECT_Y, ARGH_SIZE, ARGH_SIZE); | 1875 | lcd_clearrect(arghx[0] + FIELD_RECT_X, arghy[0] + FIELD_RECT_Y, ARGH_SIZE, ARGH_SIZE); |
1830 | 1876 | ||
1831 | if (failures > 0) { | 1877 | if (failures > last_failures) { |
1832 | button_get(true); | 1878 | button_get(true); |
1833 | } | 1879 | } |
1880 | last_failures = failures; | ||
1834 | hit ++; | 1881 | hit ++; |
1835 | } | 1882 | } |
1836 | } | 1883 | } |
1884 | } | ||
1837 | } | 1885 | } |
1838 | 1886 | ||
1839 | static void test_worm_argh_collision_in_moves(void) { | 1887 | static void test_worm_argh_collision_in_moves(void) { |
@@ -1847,7 +1895,7 @@ static void test_worm_argh_collision_in_moves(void) { | |||
1847 | draw_argh(0); | 1895 | draw_argh(0); |
1848 | 1896 | ||
1849 | set_worm_dir(&worms[0], EAST); | 1897 | set_worm_dir(&worms[0], EAST); |
1850 | for (i = 0; i < 10; i++) { | 1898 | for (i = 0; i < 20; i++) { |
1851 | char buf[20]; | 1899 | char buf[20]; |
1852 | move_worm(&worms[0]); | 1900 | move_worm(&worms[0]); |
1853 | draw_worm(&worms[0]); | 1901 | draw_worm(&worms[0]); |
@@ -1857,11 +1905,15 @@ static void test_worm_argh_collision_in_moves(void) { | |||
1857 | snprintf(buf, sizeof buf, "in 5 moves hits: %d", hit_count); | 1905 | snprintf(buf, sizeof buf, "in 5 moves hits: %d", hit_count); |
1858 | lcd_putsxy(0, LCD_HEIGHT - 8, buf, 0); | 1906 | lcd_putsxy(0, LCD_HEIGHT - 8, buf, 0); |
1859 | lcd_update(); | 1907 | lcd_update(); |
1908 | } | ||
1909 | if (hit_count != ARGH_SIZE + 5) { | ||
1860 | button_get(true); | 1910 | button_get(true); |
1861 | } | 1911 | } |
1862 | } | 1912 | } |
1863 | #endif /* DEBUG_WORMLET */ | 1913 | #endif /* DEBUG_WORMLET */ |
1864 | 1914 | ||
1915 | extern bool use_old_rect; | ||
1916 | |||
1865 | /** | 1917 | /** |
1866 | * Main entry point from the menu to start the game control. | 1918 | * Main entry point from the menu to start the game control. |
1867 | */ | 1919 | */ |
@@ -1870,14 +1922,13 @@ Menu wormlet(void) | |||
1870 | bool wormDead = false; | 1922 | bool wormDead = false; |
1871 | int button; | 1923 | int button; |
1872 | #ifdef DEBUG_WORMLET | 1924 | #ifdef DEBUG_WORMLET |
1925 | testline_in_rect(); | ||
1873 | test_worm_argh_collision_in_moves(); | 1926 | test_worm_argh_collision_in_moves(); |
1874 | test_make_argh(); | 1927 | test_make_argh(); |
1875 | testline_in_rect(); | ||
1876 | test_worm_food_collision(); | 1928 | test_worm_food_collision(); |
1877 | test_worm_argh_collision(); | 1929 | test_worm_argh_collision(); |
1878 | test_specific_worm_collision(); | 1930 | test_specific_worm_collision(); |
1879 | #endif | 1931 | #endif |
1880 | |||
1881 | lcd_setmargins(0,0); | 1932 | lcd_setmargins(0,0); |
1882 | 1933 | ||
1883 | /* Setup screen */ | 1934 | /* Setup screen */ |
@@ -1912,7 +1963,6 @@ Menu wormlet(void) | |||
1912 | } | 1963 | } |
1913 | } | 1964 | } |
1914 | lcd_puts(0, 2, buf); | 1965 | lcd_puts(0, 2, buf); |
1915 | |||
1916 | lcd_update(); | 1966 | lcd_update(); |
1917 | 1967 | ||
1918 | /* user selection */ | 1968 | /* user selection */ |