buttonmen-dev / buttonmen

Buttonmen - an online dice game
Other
16 stars 24 forks source link

Clean up argument parsing for replay_loop #2971

Closed cgolubi1 closed 4 months ago

cgolubi1 commented 4 months ago

This sets up basic argument parsing and help text, and also makes number of games, player button, and opponent button, independently configurable.

cgolubi1 commented 4 months ago

Marking as draft so i can stand up a new replay site and do a full round of testing to make sure i didn't break anything.

cgolubi1 commented 4 months ago

Testing: help text:

$ ./replay_loop -h
usage: replay_loop [-h] [--archive-games] [--local-replay] [--skip-init]
                   [--num-games NUM_GAMES]
                   [--player-button-names PLAYER_BUTTON_NAMES]
                   [--opponent-button-names OPPONENT_BUTTON_NAMES]

Test game logic by brute force, by playing games and taking random actions.

Once started, this script runs indefinitely in a loop, cycling
between the actions it has been configured to take:
* play novel games: play a batch of NUM_GAMES novel games, randomly
  selecting buttons and moves, using random_ai to play the games.
  Save output from the games in an internal "game log" format.
* replay recorded games: unpack a tarball of previously-recorded
  games, translate them from the internal game log format to the
  PHP syntax used by responderTestFramework, and test that file using phpunit.

optional arguments:
  -h, --help            show this help message and exit
  --archive-games, -a   archive novel games for replay by other sites
  --local-replay, -l    replay each batch of novel games locally after
                        recording it
  --skip-init, -s       skip initial batch of novel games, so the first action
                        is replaying a batch
  --num-games NUM_GAMES, -n NUM_GAMES
                        number of novel games to play in each batch (default
                        100)
  --player-button-names PLAYER_BUTTON_NAMES, -pb PLAYER_BUTTON_NAMES
                        comma-separated list of buttons for player one to use
                        in novel games (e.g. 'Avis,Timea')
  --opponent-button-names OPPONENT_BUTTON_NAMES, -ob OPPONENT_BUTTON_NAMES
                        comma-separated list of buttons for player two to use
                        in novel games (e.g. 'Avis,Timea')
cgolubi1 commented 4 months ago

Testing:

Default behavior:

$ ./replay_loop
 * Starting MySQL database server mysqld
   ...done.
 * Stopping Apache httpd web server apache2
 * 
 * Starting Apache httpd web server apache2
 * 
mysqlshow: Unknown database 'buttonmen'
Creating buttonmen
Populating buttonmen
buttonmen_test already exists - recreating it
Creating buttonmen_test
Populating buttonmen_test
mysql: [Warning] Using a password on the command line interface can be insecure.
Starting game 1
Starting game 2
...

Hmm, tried several flags, and everything looks fine, except that it stops after one iteration:

$ ./replay_loop -n 5 -l -ob Avis,Timea,Hammer
 * Starting MySQL database server mysqld
   ...done.
 * Stopping Apache httpd web server apache2
 *
 * Starting Apache httpd web server apache2
 *
mysqlshow: Unknown database 'buttonmen'
Creating buttonmen
Populating buttonmen
buttonmen_test already exists - recreating it
Creating buttonmen_test
Populating buttonmen_test
mysql: [Warning] Using a password on the command line interface can be insecure.
Starting game 1
Starting game 2
Starting game 3
Starting game 4
Starting game 5
Prepping game for replay from: ./output/game00001.pck
Prepping game for replay from: ./output/game00002.pck
Prepping game for replay from: ./output/game00003.pck
Prepping game for replay from: ./output/game00004.pck
Prepping game for replay from: ./output/game00005.pck
<?php
require_once 'responderTestFramework.php';
class responder99Test extends responderTestFramework {
Prepping game for replay from: ./output/game00001.pck
Prepping game for replay from: ./output/game00002.pck
Prepping game for replay from: ./output/game00003.pck
Prepping game for replay from: ./output/game00004.pck
Prepping game for replay from: ./output/game00005.pck
 * Starting MySQL database server mysqld
   ...done.
About to execute: sudo -u root sh -c "phpunit --bootstrap /usr/local/etc/buttonmen_phpunit.php --group fulltest_deps /buttonmen/test/src/api/ 2>&1" | tee /srv/bmgames/chaos-test/replay_state/replay-cgolubi1-2953_replay_improvements/local.20240729.022129.output
PHPUnit 5.1.3 by Sebastian Bergmann and contributors.

......                                                              6 / 6 (100%)

Time: 41.74 seconds, Memory: 24.00Mb

OK (6 tests, 1459 assertions)

Database contents from those games look good:

# game
id      start_time      last_action_time        status_id       game_state      n_players       round_number    turn_number_in_round    n_target_wins   n_recent_draws  n_recent_passes creator_id      current_player_id       last_winner_id  tournament_id   description     chat    previous_game_id
1       2024-07-29 02:18:39     2024-07-29 02:19:04     3       60      2       4       0       3       0       0       3       NULL    NULL    NULL            NULL    NULL
2       2024-07-29 02:19:07     2024-07-29 02:19:51     3       60      2       5       0       3       0       0       3       NULL    NULL    NULL            NULL    NULL
3       2024-07-29 02:19:53     2024-07-29 02:20:20     3       60      2       3       0       3       0       0       3       NULL    NULL    NULL            NULL    NULL
4       2024-07-29 02:20:22     2024-07-29 02:20:58     3       60      2       4       0       3       0       0       3       NULL    NULL    NULL            NULL    NULL
5       2024-07-29 02:21:00     2024-07-29 02:21:26     3       60      2       4       0       3       0       0       3       NULL    NULL    NULL            NULL    NULL

# game_player_view
game_id player_id       button_id       original_recipe alt_recipe      position        did_win_initiative      is_awaiting_action      n_rounds_won    n_rounds_lost   n_rounds_drawn  handicap        is_player_hidden        last_action_time        was_game_dismissed      is_button_random        has_player_accepted     is_chat_private cards_drawn     player_name     autopass        fire_overshooting       is_on_vacation  button_name     n_target_wins
1       3       147     (4) (8) (8) (12) r(4) r(4) r(8) r(10)   NULL    0       1       0       1       3       0       0       0       2024-07-29 02:19:02     0       0       1       0       NULL    responder003    1       0       NULL    Sailor Mercury  3
1       5       786     d(4) s(8) z(10) h(10) (X)       NULL    1       0       0       3       1       0       0       0       2024-07-29 02:19:05     0       0       1       0       NULL    responder004    1       0       NULL    Timea   3
2       3       604     f(4) g(6) s(6) (V) (X)  NULL    0       1       0       3       2       0       0       0       2024-07-29 02:19:51     0       0       1       0       NULL    responder003    1       0       NULL    Maine   3
2       5       256     (4) (4) (10) (12) (X)   NULL    1       0       0       2       3       0       0       0       2024-07-29 02:19:50     0       0       1       0       NULL    responder004    1       0       NULL    Avis    3
3       3       396     z(8/12) (4/16) s(6/10) z(X) s(U)        NULL    0       1       0       3       0       0       0       0       2024-07-29 02:20:19     0       0       1       0       NULL    responder003    1       0       NULL    CactusJack      3
3       5       257     (6) (12) (20) (20) (X)  NULL    1       0       0       0       3       0       0       0       2024-07-29 02:20:20     0       0       1       0       NULL    responder004    1       0       NULL    Hammer  3
4       3       367     sf(4) (8) s(10) (16) (X)        NULL    0       1       0       3       1       0       0       0       2024-07-29 02:20:56     0       0       1       0       NULL    responder003    1       0       NULL    Count Dracula   3
4       5       257     (6) (12) (20) (20) (X)  NULL    1       0       0       1       3       0       0       0       2024-07-29 02:20:58     0       0       1       0       NULL    responder004    1       0       NULL    Hammer  3
5       3       519     d(2) p(6/20)! zp(12) n(T,T) B(X)? +(Y)  d(2) p(6/20)! zp(12) n(T,T) B(X)?       0       0       0       3       1       0       0       0       2024-07-29 02:21:26     0       0       1       0       NULL    responder003    1       0       NULL    spindisc        3
5       5       786     d(4) s(8) z(10) h(10) (X)       NULL    1       1       0       1       3       0       0       0       2024-07-29 02:21:25     0       0       1       0       NULL    responder004    1       0       NULL    Timea   3

Okay, and i see the problem that caused the loop to stop, and i'm committing that change now.

cgolubi1 commented 4 months ago

Okay, the new version looks good to me. Listing it as ready for review.

blackshadowshade commented 4 months ago

Changes are entirely to do with the replay loop. If Chaos is happy with this, then I'm happy to merge it.